mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
test: drop duplicate timeout-fallback e2e and trim onboarding auth overlap
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { GatewayAuthConfig } from "../config/config.js";
|
||||
import { makeTempWorkspace } from "../test-helpers/workspace.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import {
|
||||
@@ -60,19 +59,6 @@ function getPseudoPort(base: number): number {
|
||||
|
||||
const runtime = createThrowingRuntime();
|
||||
|
||||
async function expectGatewayTokenAuth(params: {
|
||||
authConfig: GatewayAuthConfig | null | undefined;
|
||||
token: string;
|
||||
env: NodeJS.ProcessEnv;
|
||||
}) {
|
||||
const { authorizeGatewayConnect, resolveGatewayAuth } = await import("../gateway/auth.js");
|
||||
const auth = resolveGatewayAuth({ authConfig: params.authConfig, env: params.env });
|
||||
const resNoToken = await authorizeGatewayConnect({ auth, connectAuth: { token: undefined } });
|
||||
expect(resNoToken.ok).toBe(false);
|
||||
const resToken = await authorizeGatewayConnect({ auth, connectAuth: { token: params.token } });
|
||||
expect(resToken.ok).toBe(true);
|
||||
}
|
||||
|
||||
describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
let tempHome: string | undefined;
|
||||
@@ -129,7 +115,7 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
envSnapshot.restore();
|
||||
});
|
||||
|
||||
it("writes gateway token auth into config and gateway enforces it", async () => {
|
||||
it("writes gateway token auth into config", async () => {
|
||||
await withStateDir("state-noninteractive-", async (stateDir) => {
|
||||
const token = "tok_test_123";
|
||||
const workspace = path.join(stateDir, "openclaw");
|
||||
@@ -153,19 +139,13 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
const { resolveConfigPath } = await import("../config/paths.js");
|
||||
const configPath = resolveConfigPath(process.env, stateDir);
|
||||
const cfg = await readJsonFile<{
|
||||
gateway?: { auth?: GatewayAuthConfig };
|
||||
gateway?: { auth?: { mode?: string; token?: string } };
|
||||
agents?: { defaults?: { workspace?: string } };
|
||||
}>(configPath);
|
||||
|
||||
expect(cfg?.agents?.defaults?.workspace).toBe(workspace);
|
||||
expect(cfg?.gateway?.auth?.mode).toBe("token");
|
||||
expect(cfg?.gateway?.auth?.token).toBe(token);
|
||||
|
||||
await expectGatewayTokenAuth({
|
||||
authConfig: cfg.gateway?.auth,
|
||||
token,
|
||||
env: process.env,
|
||||
});
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
@@ -237,21 +217,14 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
gateway?: {
|
||||
bind?: string;
|
||||
port?: number;
|
||||
auth?: GatewayAuthConfig;
|
||||
auth?: { mode?: string; token?: string };
|
||||
};
|
||||
}>(configPath);
|
||||
|
||||
expect(cfg.gateway?.bind).toBe("lan");
|
||||
expect(cfg.gateway?.port).toBe(port);
|
||||
expect(cfg.gateway?.auth?.mode).toBe("token");
|
||||
const token = cfg.gateway?.auth?.token ?? "";
|
||||
expect(token.length).toBeGreaterThan(8);
|
||||
|
||||
await expectGatewayTokenAuth({
|
||||
authConfig: cfg.gateway?.auth,
|
||||
token,
|
||||
env: process.env,
|
||||
});
|
||||
expect((cfg.gateway?.auth?.token ?? "").length).toBeGreaterThan(8);
|
||||
});
|
||||
}, 60_000);
|
||||
});
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { extractPayloadText } from "../src/gateway/test-helpers.agent-results.js";
|
||||
import { startGatewayWithClient } from "../src/gateway/test-helpers.e2e.js";
|
||||
import { buildOpenAIResponsesTextSse } from "../src/gateway/test-helpers.openai-mock.js";
|
||||
import { buildOpenAiResponsesProviderConfig } from "../src/gateway/test-openai-responses-model.js";
|
||||
|
||||
describe("provider timeouts (e2e)", () => {
|
||||
it(
|
||||
"falls back when the primary provider aborts with a timeout-like AbortError",
|
||||
{ timeout: 60_000 },
|
||||
async () => {
|
||||
const prev = {
|
||||
home: process.env.HOME,
|
||||
configPath: process.env.OPENCLAW_CONFIG_PATH,
|
||||
token: process.env.OPENCLAW_GATEWAY_TOKEN,
|
||||
skipChannels: process.env.OPENCLAW_SKIP_CHANNELS,
|
||||
skipGmail: process.env.OPENCLAW_SKIP_GMAIL_WATCHER,
|
||||
skipCron: process.env.OPENCLAW_SKIP_CRON,
|
||||
skipCanvas: process.env.OPENCLAW_SKIP_CANVAS_HOST,
|
||||
};
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
const primaryBaseUrl = "https://primary.example/v1";
|
||||
const fallbackBaseUrl = "https://fallback.example/v1";
|
||||
const counts = { primary: 0, fallback: 0 };
|
||||
const fetchImpl = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
||||
const url =
|
||||
typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
||||
|
||||
if (url.startsWith(`${primaryBaseUrl}/responses`)) {
|
||||
counts.primary += 1;
|
||||
const err = new Error("request was aborted");
|
||||
err.name = "AbortError";
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (url.startsWith(`${fallbackBaseUrl}/responses`)) {
|
||||
counts.fallback += 1;
|
||||
return buildOpenAIResponsesTextSse("fallback-ok");
|
||||
}
|
||||
|
||||
if (!originalFetch) {
|
||||
throw new Error(`fetch is not available (url=${url})`);
|
||||
}
|
||||
return await originalFetch(input, init);
|
||||
};
|
||||
(globalThis as unknown as { fetch: unknown }).fetch = fetchImpl;
|
||||
|
||||
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-timeout-e2e-"));
|
||||
process.env.HOME = tempHome;
|
||||
process.env.OPENCLAW_SKIP_CHANNELS = "1";
|
||||
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = "1";
|
||||
process.env.OPENCLAW_SKIP_CRON = "1";
|
||||
process.env.OPENCLAW_SKIP_CANVAS_HOST = "1";
|
||||
|
||||
const token = `test-${randomUUID()}`;
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = token;
|
||||
|
||||
const configDir = path.join(tempHome, ".openclaw");
|
||||
await fs.mkdir(configDir, { recursive: true });
|
||||
const configPath = path.join(configDir, "openclaw.json");
|
||||
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: {
|
||||
primary: "primary/gpt-5.2",
|
||||
fallbacks: ["fallback/gpt-5.2"],
|
||||
},
|
||||
},
|
||||
},
|
||||
models: {
|
||||
mode: "replace",
|
||||
providers: {
|
||||
primary: buildOpenAiResponsesProviderConfig(primaryBaseUrl),
|
||||
fallback: buildOpenAiResponsesProviderConfig(fallbackBaseUrl),
|
||||
},
|
||||
},
|
||||
gateway: { auth: { token } },
|
||||
};
|
||||
|
||||
const { server, client } = await startGatewayWithClient({
|
||||
cfg,
|
||||
configPath,
|
||||
token,
|
||||
clientDisplayName: "vitest-timeout-fallback",
|
||||
});
|
||||
|
||||
try {
|
||||
const sessionKey = "agent:dev:timeout-fallback";
|
||||
await client.request("sessions.patch", {
|
||||
key: sessionKey,
|
||||
model: "primary/gpt-5.2",
|
||||
});
|
||||
|
||||
const runId = randomUUID();
|
||||
const payload = await client.request<{
|
||||
status?: unknown;
|
||||
result?: unknown;
|
||||
}>(
|
||||
"agent",
|
||||
{
|
||||
sessionKey,
|
||||
idempotencyKey: `idem-${runId}`,
|
||||
message: "say fallback-ok",
|
||||
deliver: false,
|
||||
},
|
||||
{ expectFinal: true },
|
||||
);
|
||||
|
||||
expect(payload?.status).toBe("ok");
|
||||
const text = extractPayloadText(payload?.result);
|
||||
expect(text).toContain("fallback-ok");
|
||||
expect(counts.primary).toBeGreaterThan(0);
|
||||
expect(counts.fallback).toBeGreaterThan(0);
|
||||
} finally {
|
||||
client.stop();
|
||||
await server.close({ reason: "timeout fallback test complete" });
|
||||
await fs.rm(tempHome, { recursive: true, force: true });
|
||||
(globalThis as unknown as { fetch: unknown }).fetch = originalFetch;
|
||||
if (prev.home === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = prev.home;
|
||||
}
|
||||
if (prev.configPath === undefined) {
|
||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
||||
} else {
|
||||
process.env.OPENCLAW_CONFIG_PATH = prev.configPath;
|
||||
}
|
||||
if (prev.token === undefined) {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
} else {
|
||||
process.env.OPENCLAW_GATEWAY_TOKEN = prev.token;
|
||||
}
|
||||
if (prev.skipChannels === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CHANNELS;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CHANNELS = prev.skipChannels;
|
||||
}
|
||||
if (prev.skipGmail === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_GMAIL_WATCHER;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_GMAIL_WATCHER = prev.skipGmail;
|
||||
}
|
||||
if (prev.skipCron === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CRON;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CRON = prev.skipCron;
|
||||
}
|
||||
if (prev.skipCanvas === undefined) {
|
||||
delete process.env.OPENCLAW_SKIP_CANVAS_HOST;
|
||||
} else {
|
||||
process.env.OPENCLAW_SKIP_CANVAS_HOST = prev.skipCanvas;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user