






















@@ -1,72 +1,17 @@
1-import fs from "node:fs/promises";
2-import os from "node:os";
3-import path from "node:path";
4-import { afterEach, describe, expect, it } from "vitest";
5-import { clearConfigCache, clearRuntimeConfigSnapshot } from "../config/config.js";
6-import { clearSessionStoreCacheForTest } from "../config/sessions/store.js";
7-import { captureEnv } from "../test-utils/env.js";
8-import {
9-connectTestGatewayClient,
10-ensurePairedTestGatewayClientIdentity,
11-getFreeGatewayPort,
12-} from "./gateway-cli-backend.live-helpers.js";
13-import { startGatewayServer } from "./server.js";
1+import { describe, expect, it } from "vitest";
2+import { connectTestGatewayClient } from "./gateway-cli-backend.live-helpers.js";
3+import { getFreePort, installGatewayTestHooks, startGatewayServer } from "./test-helpers.js";
14415-const GATEWAY_CONNECT_TIMEOUT_MS = 90_000;
5+const GATEWAY_CONNECT_TIMEOUT_MS = 10_000;
166177describe("gateway cli backend connect", () => {
18-afterEach(() => {
19-clearRuntimeConfigSnapshot();
20-clearConfigCache();
21-clearSessionStoreCacheForTest();
22-});
8+installGatewayTestHooks();
2392410it(
2511"connects a same-process test gateway client in minimal mode",
2612async () => {
27-const envSnapshot = captureEnv([
28-"HOME",
29-"OPENCLAW_STATE_DIR",
30-"OPENCLAW_CONFIG_PATH",
31-"OPENCLAW_GATEWAY_TOKEN",
32-"OPENCLAW_SKIP_CHANNELS",
33-"OPENCLAW_SKIP_PROVIDERS",
34-"OPENCLAW_SKIP_GMAIL_WATCHER",
35-"OPENCLAW_SKIP_CRON",
36-"OPENCLAW_SKIP_CANVAS_HOST",
37-"OPENCLAW_SKIP_BROWSER_CONTROL_SERVER",
38-"OPENCLAW_BUNDLED_PLUGINS_DIR",
39-"OPENCLAW_TEST_MINIMAL_GATEWAY",
40-]);
41-42-const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-gateway-connect-home-"));
43-const configPath = path.join(tempHome, ".openclaw", "openclaw.json");
44-const bundledPluginsDir = path.join(tempHome, "openclaw-test-no-bundled-extensions");
4513const token = `test-${Date.now()}`;
46-process.env.HOME = tempHome;
47-process.env.OPENCLAW_STATE_DIR = path.join(tempHome, ".openclaw");
48-process.env.OPENCLAW_CONFIG_PATH = configPath;
49-process.env.OPENCLAW_GATEWAY_TOKEN = token;
50-process.env.OPENCLAW_SKIP_CHANNELS = "1";
51-process.env.OPENCLAW_SKIP_PROVIDERS = "1";
52-process.env.OPENCLAW_SKIP_GMAIL_WATCHER = "1";
53-process.env.OPENCLAW_SKIP_CRON = "1";
54-process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
55-process.env.OPENCLAW_SKIP_BROWSER_CONTROL_SERVER = "1";
56-process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledPluginsDir;
57-process.env.OPENCLAW_TEST_MINIMAL_GATEWAY = "1";
58-await fs.mkdir(path.dirname(configPath), { recursive: true });
59-await fs.mkdir(bundledPluginsDir, { recursive: true });
60-await fs.writeFile(
61-configPath,
62-`${JSON.stringify({ gateway: { auth: { mode: "token", token } } }, null, 2)}\n`,
63-);
64-clearRuntimeConfigSnapshot();
65-clearConfigCache();
66-clearSessionStoreCacheForTest();
67-68-const deviceIdentity = await ensurePairedTestGatewayClientIdentity();
69-const port = await getFreeGatewayPort();
14+const port = await getFreePort();
7015const server = await startGatewayServer(port, {
7116bind: "loopback",
7217auth: { mode: "token", token },
@@ -78,7 +23,9 @@ describe("gateway cli backend connect", () => {
7823client = await connectTestGatewayClient({
7924url: `ws://127.0.0.1:${port}`,
8025 token,
81- deviceIdentity,
26+timeoutMs: 5_000,
27+maxAttemptTimeoutMs: 5_000,
28+requestTimeoutMs: 5_000,
8229});
8330const health = await client.request("health", undefined, {
8431timeoutMs: 5_000,
@@ -89,8 +36,6 @@ describe("gateway cli backend connect", () => {
8936} finally {
9037await client?.stopAndWait({ timeoutMs: 1_000 }).catch(() => {});
9138await server.close({ reason: "gateway connect regression complete" });
92-await fs.rm(tempHome, { recursive: true, force: true });
93-envSnapshot.restore();
9439}
9540},
9641GATEWAY_CONNECT_TIMEOUT_MS,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。