mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 04:42:44 +00:00
test(gateway): tighten e2e timeout budget
This commit is contained in:
@@ -17,6 +17,7 @@ import { buildOpenAiResponsesProviderConfig } from "./test-openai-responses-mode
|
|||||||
|
|
||||||
let writeConfigFile: typeof import("../config/config.js").writeConfigFile;
|
let writeConfigFile: typeof import("../config/config.js").writeConfigFile;
|
||||||
let resolveConfigPath: typeof import("../config/config.js").resolveConfigPath;
|
let resolveConfigPath: typeof import("../config/config.js").resolveConfigPath;
|
||||||
|
const GATEWAY_E2E_TIMEOUT_MS = 30_000;
|
||||||
|
|
||||||
describe("gateway e2e", () => {
|
describe("gateway e2e", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@@ -25,7 +26,7 @@ describe("gateway e2e", () => {
|
|||||||
|
|
||||||
it(
|
it(
|
||||||
"runs a mock OpenAI tool call end-to-end via gateway agent loop",
|
"runs a mock OpenAI tool call end-to-end via gateway agent loop",
|
||||||
{ timeout: 90_000 },
|
{ timeout: GATEWAY_E2E_TIMEOUT_MS },
|
||||||
async () => {
|
async () => {
|
||||||
const envSnapshot = captureEnv([
|
const envSnapshot = captureEnv([
|
||||||
"HOME",
|
"HOME",
|
||||||
@@ -120,119 +121,123 @@ describe("gateway e2e", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it("runs wizard over ws and writes auth token config", { timeout: 90_000 }, async () => {
|
it(
|
||||||
const envSnapshot = captureEnv([
|
"runs wizard over ws and writes auth token config",
|
||||||
"HOME",
|
{ timeout: GATEWAY_E2E_TIMEOUT_MS },
|
||||||
"OPENCLAW_STATE_DIR",
|
async () => {
|
||||||
"OPENCLAW_CONFIG_PATH",
|
const envSnapshot = captureEnv([
|
||||||
"OPENCLAW_GATEWAY_TOKEN",
|
"HOME",
|
||||||
"OPENCLAW_SKIP_CHANNELS",
|
"OPENCLAW_STATE_DIR",
|
||||||
"OPENCLAW_SKIP_GMAIL_WATCHER",
|
"OPENCLAW_CONFIG_PATH",
|
||||||
"OPENCLAW_SKIP_CRON",
|
"OPENCLAW_GATEWAY_TOKEN",
|
||||||
"OPENCLAW_SKIP_CANVAS_HOST",
|
"OPENCLAW_SKIP_CHANNELS",
|
||||||
"OPENCLAW_SKIP_BROWSER_CONTROL_SERVER",
|
"OPENCLAW_SKIP_GMAIL_WATCHER",
|
||||||
]);
|
"OPENCLAW_SKIP_CRON",
|
||||||
|
"OPENCLAW_SKIP_CANVAS_HOST",
|
||||||
|
"OPENCLAW_SKIP_BROWSER_CONTROL_SERVER",
|
||||||
|
]);
|
||||||
|
|
||||||
process.env.OPENCLAW_SKIP_CHANNELS = "1";
|
process.env.OPENCLAW_SKIP_CHANNELS = "1";
|
||||||
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = "1";
|
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = "1";
|
||||||
process.env.OPENCLAW_SKIP_CRON = "1";
|
process.env.OPENCLAW_SKIP_CRON = "1";
|
||||||
process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
|
process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
|
||||||
process.env.OPENCLAW_SKIP_BROWSER_CONTROL_SERVER = "1";
|
process.env.OPENCLAW_SKIP_BROWSER_CONTROL_SERVER = "1";
|
||||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
|
|
||||||
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-wizard-home-"));
|
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-wizard-home-"));
|
||||||
process.env.HOME = tempHome;
|
process.env.HOME = tempHome;
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
delete process.env.OPENCLAW_STATE_DIR;
|
||||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||||
|
|
||||||
const wizardToken = `wiz-${randomUUID()}`;
|
const wizardToken = `wiz-${randomUUID()}`;
|
||||||
const port = await getFreeGatewayPort();
|
const port = await getFreeGatewayPort();
|
||||||
const server = await startGatewayServer(port, {
|
const server = await startGatewayServer(port, {
|
||||||
bind: "loopback",
|
bind: "loopback",
|
||||||
auth: { mode: "token", token: wizardToken },
|
auth: { mode: "token", token: wizardToken },
|
||||||
controlUiEnabled: false,
|
controlUiEnabled: false,
|
||||||
wizardRunner: async (_opts, _runtime, prompter) => {
|
wizardRunner: async (_opts, _runtime, prompter) => {
|
||||||
await prompter.intro("Wizard E2E");
|
await prompter.intro("Wizard E2E");
|
||||||
await prompter.note("write token");
|
await prompter.note("write token");
|
||||||
const token = await prompter.text({ message: "token" });
|
const token = await prompter.text({ message: "token" });
|
||||||
await writeConfigFile({
|
await writeConfigFile({
|
||||||
gateway: { auth: { mode: "token", token: String(token) } },
|
gateway: { auth: { mode: "token", token: String(token) } },
|
||||||
});
|
});
|
||||||
await prompter.outro("ok");
|
await prompter.outro("ok");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const client = await connectGatewayClient({
|
const client = await connectGatewayClient({
|
||||||
url: `ws://127.0.0.1:${port}`,
|
url: `ws://127.0.0.1:${port}`,
|
||||||
token: wizardToken,
|
token: wizardToken,
|
||||||
clientDisplayName: "vitest-wizard",
|
clientDisplayName: "vitest-wizard",
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const start = await client.request<{
|
const start = await client.request<{
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
done: boolean;
|
done: boolean;
|
||||||
status: "running" | "done" | "cancelled" | "error";
|
status: "running" | "done" | "cancelled" | "error";
|
||||||
step?: {
|
step?: {
|
||||||
id: string;
|
id: string;
|
||||||
type: "note" | "select" | "text" | "confirm" | "multiselect" | "progress";
|
type: "note" | "select" | "text" | "confirm" | "multiselect" | "progress";
|
||||||
};
|
};
|
||||||
error?: string;
|
error?: string;
|
||||||
}>("wizard.start", { mode: "local" });
|
}>("wizard.start", { mode: "local" });
|
||||||
const sessionId = start.sessionId;
|
const sessionId = start.sessionId;
|
||||||
expect(typeof sessionId).toBe("string");
|
expect(typeof sessionId).toBe("string");
|
||||||
|
|
||||||
let next = start;
|
let next = start;
|
||||||
let didSendToken = false;
|
let didSendToken = false;
|
||||||
while (!next.done) {
|
while (!next.done) {
|
||||||
const step = next.step;
|
const step = next.step;
|
||||||
if (!step) {
|
if (!step) {
|
||||||
throw new Error("wizard missing step");
|
throw new Error("wizard missing step");
|
||||||
|
}
|
||||||
|
const value = step.type === "text" ? wizardToken : null;
|
||||||
|
if (step.type === "text") {
|
||||||
|
didSendToken = true;
|
||||||
|
}
|
||||||
|
next = await client.request("wizard.next", {
|
||||||
|
sessionId,
|
||||||
|
answer: { stepId: step.id, value },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const value = step.type === "text" ? wizardToken : null;
|
|
||||||
if (step.type === "text") {
|
expect(didSendToken).toBe(true);
|
||||||
didSendToken = true;
|
expect(next.status).toBe("done");
|
||||||
}
|
|
||||||
next = await client.request("wizard.next", {
|
const parsed = JSON.parse(await fs.readFile(resolveConfigPath(), "utf8"));
|
||||||
sessionId,
|
const token = (parsed as Record<string, unknown>)?.gateway as
|
||||||
answer: { stepId: step.id, value },
|
| Record<string, unknown>
|
||||||
});
|
| undefined;
|
||||||
|
expect((token?.auth as { token?: string } | undefined)?.token).toBe(wizardToken);
|
||||||
|
} finally {
|
||||||
|
client.stop();
|
||||||
|
await server.close({ reason: "wizard e2e complete" });
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(didSendToken).toBe(true);
|
const port2 = await getFreeGatewayPort();
|
||||||
expect(next.status).toBe("done");
|
const server2 = await startGatewayServer(port2, {
|
||||||
|
bind: "loopback",
|
||||||
const parsed = JSON.parse(await fs.readFile(resolveConfigPath(), "utf8"));
|
controlUiEnabled: false,
|
||||||
const token = (parsed as Record<string, unknown>)?.gateway as
|
|
||||||
| Record<string, unknown>
|
|
||||||
| undefined;
|
|
||||||
expect((token?.auth as { token?: string } | undefined)?.token).toBe(wizardToken);
|
|
||||||
} finally {
|
|
||||||
client.stop();
|
|
||||||
await server.close({ reason: "wizard e2e complete" });
|
|
||||||
}
|
|
||||||
|
|
||||||
const port2 = await getFreeGatewayPort();
|
|
||||||
const server2 = await startGatewayServer(port2, {
|
|
||||||
bind: "loopback",
|
|
||||||
controlUiEnabled: false,
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
const resNoToken = await connectDeviceAuthReq({
|
|
||||||
url: `ws://127.0.0.1:${port2}`,
|
|
||||||
});
|
});
|
||||||
expect(resNoToken.ok).toBe(false);
|
try {
|
||||||
expect(resNoToken.error?.message ?? "").toContain("unauthorized");
|
const resNoToken = await connectDeviceAuthReq({
|
||||||
|
url: `ws://127.0.0.1:${port2}`,
|
||||||
|
});
|
||||||
|
expect(resNoToken.ok).toBe(false);
|
||||||
|
expect(resNoToken.error?.message ?? "").toContain("unauthorized");
|
||||||
|
|
||||||
const resToken = await connectDeviceAuthReq({
|
const resToken = await connectDeviceAuthReq({
|
||||||
url: `ws://127.0.0.1:${port2}`,
|
url: `ws://127.0.0.1:${port2}`,
|
||||||
token: wizardToken,
|
token: wizardToken,
|
||||||
});
|
});
|
||||||
expect(resToken.ok).toBe(true);
|
expect(resToken.ok).toBe(true);
|
||||||
} finally {
|
} finally {
|
||||||
await server2.close({ reason: "wizard auth verify" });
|
await server2.close({ reason: "wizard auth verify" });
|
||||||
await fs.rm(tempHome, { recursive: true, force: true });
|
await fs.rm(tempHome, { recursive: true, force: true });
|
||||||
envSnapshot.restore();
|
envSnapshot.restore();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user