diff --git a/scripts/e2e/cron-mcp-cleanup-docker-client.ts b/scripts/e2e/cron-mcp-cleanup-docker-client.ts index 4ce5f7c4f19..567fb347381 100644 --- a/scripts/e2e/cron-mcp-cleanup-docker-client.ts +++ b/scripts/e2e/cron-mcp-cleanup-docker-client.ts @@ -127,13 +127,13 @@ async function runCronCleanupScenario(params: { enabled: true, schedule: { kind: "every", everyMs: 60_000 }, sessionTarget: "isolated", - wakeMode: "now", + wakeMode: "next-heartbeat", payload: { kind: "agentTurn", message: "Use available context and then stop.", timeoutSeconds: 90, lightContext: true, - toolsAllow: ["cronCleanupProbe__cleanup_probe"], + toolsAllow: ["bundle-mcp", "cronCleanupProbe__cleanup_probe"], }, delivery: { mode: "none" }, }); diff --git a/scripts/e2e/mcp-channels-harness.ts b/scripts/e2e/mcp-channels-harness.ts index f44e6c34fc7..3e2d4781145 100644 --- a/scripts/e2e/mcp-channels-harness.ts +++ b/scripts/e2e/mcp-channels-harness.ts @@ -205,103 +205,69 @@ async function connectGatewayOnce(params: { pending.clear(); }); - const connectId = randomUUID(); - ws.send( - JSON.stringify({ + const sendGatewayRequest = ( + method: string, + requestParams: unknown, + timeoutMs: number, + ): Promise => { + const id = randomUUID(); + const frame = JSON.stringify({ type: "req", - id: connectId, - method: "connect", - params: { - minProtocol: PROTOCOL_VERSION, - maxProtocol: PROTOCOL_VERSION, - client: { - id: "openclaw-tui", - displayName: "docker-mcp-channels", - version: "1.0.0", - platform: process.platform, - mode: "ui", + id, + method, + params: requestParams ?? {}, + }); + return new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + pending.delete(id); + reject(new Error(`gateway request timeout: ${method}`)); + }, timeoutMs); + timeout.unref?.(); + pending.set(id, { + resolve: (value) => { + clearTimeout(timeout); + resolve(value as T); }, - role: "operator", - scopes: requestedScopes, - caps: [], - auth: { token: params.token }, + reject: (error) => { + clearTimeout(timeout); + reject(error); + }, + }); + try { + ws.send(frame); + } catch (error) { + clearTimeout(timeout); + pending.delete(id); + reject(error instanceof Error ? error : new Error(String(error))); + } + }); + }; + + await sendGatewayRequest( + "connect", + { + minProtocol: PROTOCOL_VERSION, + maxProtocol: PROTOCOL_VERSION, + client: { + id: "openclaw-tui", + displayName: "docker-mcp-channels", + version: "1.0.0", + platform: process.platform, + mode: "ui", }, - }), + role: "operator", + scopes: requestedScopes, + caps: [], + auth: { token: params.token }, + }, + GATEWAY_RPC_TIMEOUT_MS, ); - await new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - pending.delete(connectId); - reject(new Error("gateway connect timeout")); - }, GATEWAY_RPC_TIMEOUT_MS); - timeout.unref?.(); - pending.set(connectId, { - resolve: () => { - clearTimeout(timeout); - resolve(); - }, - reject: (error) => { - clearTimeout(timeout); - reject(error); - }, - }); - }); - - await new Promise((resolve, reject) => { - const id = randomUUID(); - const timeout = setTimeout(() => { - pending.delete(id); - reject(new Error("gateway sessions.subscribe timeout")); - }, GATEWAY_RPC_TIMEOUT_MS); - timeout.unref?.(); - pending.set(id, { - resolve: () => { - clearTimeout(timeout); - resolve(); - }, - reject: (error) => { - clearTimeout(timeout); - reject(error); - }, - }); - ws.send( - JSON.stringify({ - type: "req", - id, - method: "sessions.subscribe", - params: {}, - }), - ); - }); + await sendGatewayRequest("sessions.subscribe", {}, GATEWAY_RPC_TIMEOUT_MS); return { request(method, requestParams) { - const id = randomUUID(); - ws.send( - JSON.stringify({ - type: "req", - id, - method, - params: requestParams ?? {}, - }), - ); - return new Promise((resolve, reject) => { - const timeout = setTimeout(() => { - pending.delete(id); - reject(new Error(`gateway request timeout: ${method}`)); - }, GATEWAY_REQUEST_TIMEOUT_MS); - timeout.unref?.(); - pending.set(id, { - resolve: (value) => { - clearTimeout(timeout); - resolve(value as T); - }, - reject: (error) => { - clearTimeout(timeout); - reject(error); - }, - }); - }); + return sendGatewayRequest(method, requestParams, GATEWAY_REQUEST_TIMEOUT_MS); }, events, async close() {