11import { Client } from "@modelcontextprotocol/client" ;
22import { StdioClientTransport } from "@modelcontextprotocol/client/stdio" ;
3- import { execFile } from "node:child_process" ;
3+ import { createVerifierMcpOwner } from "./verifier-mcp-owner.mjs" ;
4+ import { withVerifierCleanup } from "./verifier-cleanup.mjs" ;
45import { readFile } from "node:fs/promises" ;
56import { join } from "node:path" ;
6- import { promisify } from "node:util" ;
77
88import { FULL_CATALOG_IDENTITY } from "../../dist/catalogIdentity.js" ;
99import { verifyCompleteToolCatalog } from "./verify-package-core.mjs" ;
1010
11- const execute = promisify ( execFile ) ;
12-
13- /** Install the selected archive or registry specifier before any protocol deadline. */
14- export async function installCanaryPackage ( specifier , workspace , environment ) {
11+ /** Install the selected archive or registry specifier with an owned ten-minute deadline. */
12+ export async function installCanaryPackage (
13+ specifier ,
14+ workspace ,
15+ environment ,
16+ commands ,
17+ ) {
1518 const prefix = join ( workspace , "installed" ) ;
16- await execute (
19+ await commands . exec (
1720 "npm" ,
1821 [
1922 "install" ,
@@ -26,7 +29,12 @@ export async function installCanaryPackage(specifier, workspace, environment) {
2629 prefix ,
2730 specifier ,
2831 ] ,
29- { cwd : workspace , env : environment , maxBuffer : 16 * 1024 * 1024 } ,
32+ {
33+ cwd : workspace ,
34+ env : environment ,
35+ timeout : 600000 ,
36+ maxBuffer : 16 * 1024 * 1024 ,
37+ } ,
3038 ) ;
3139 return join ( prefix , "node_modules" , "rea-agents" ) ;
3240}
@@ -36,7 +44,7 @@ export async function verifyInstalledCanaryPackage(
3644 packageRoot ,
3745 version ,
3846 workspace ,
39- environment ,
47+ { environment, commands } ,
4048) {
4149 const installed = JSON . parse (
4250 await readFile ( join ( packageRoot , "package.json" ) , "utf8" ) ,
@@ -47,9 +55,10 @@ export async function verifyInstalledCanaryPackage(
4755 ) ;
4856 const launcher = join ( packageRoot , "scripts" , "rea.mjs" ) ;
4957 for ( const option of [ "--help" , "--llms" ] )
50- await execute ( process . execPath , [ launcher , option ] , {
58+ await commands . exec ( process . execPath , [ launcher , option ] , {
5159 cwd : workspace ,
5260 env : environment ,
61+ timeout : 30000 ,
5362 maxBuffer : 16 * 1024 * 1024 ,
5463 } ) ;
5564 const transport = new StdioClientTransport ( {
@@ -65,22 +74,20 @@ export async function verifyInstalledCanaryPackage(
6574 if ( stderr . length < 16_384 )
6675 stderr += chunk . toString ( "utf8" ) . slice ( 0 , 16_384 - stderr . length ) ;
6776 } ) ;
68- try {
69- await client . connect ( transport ) ;
70- const toolNames = await verifyCompleteToolCatalog ( client ) ;
71- return {
72- mcpTools : toolNames . length ,
73- canonicalMcpTools : FULL_CATALOG_IDENTITY . counts . mcp_tools ,
74- } ;
75- } catch ( cause ) {
76- throw new Error ( `Installed package MCP verification failed: ${ stderr } ` , {
77- cause,
78- } ) ;
79- } finally {
77+ const owner = createVerifierMcpOwner ( ) ;
78+ commands . adopt ( owner , "installed package MCP transport" ) ;
79+ return withVerifierCleanup ( async ( ) => {
8080 try {
81- await client . close ( ) ;
82- } finally {
83- await transport . close ( ) ;
81+ await owner . open ( client , transport ) ;
82+ const toolNames = await verifyCompleteToolCatalog ( client ) ;
83+ return {
84+ mcpTools : toolNames . length ,
85+ canonicalMcpTools : FULL_CATALOG_IDENTITY . counts . mcp_tools ,
86+ } ;
87+ } catch ( cause ) {
88+ throw new Error ( `Installed package MCP verification failed: ${ stderr } ` , {
89+ cause,
90+ } ) ;
8491 }
85- }
92+ } , [ ( ) => owner . close ( ) ] ) ;
8693}
0 commit comments