test: speed up non-interactive gateway onboarding suite
This commit is contained in:
@@ -4,7 +4,6 @@ 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 { getFreePortBlockWithPermissionFallback } from "../test-utils/ports.js";
|
||||
import {
|
||||
createThrowingRuntime,
|
||||
readJsonFile,
|
||||
@@ -18,6 +17,7 @@ const gatewayClientCalls: Array<{
|
||||
onHelloOk?: () => void;
|
||||
onClose?: (code: number, reason: string) => void;
|
||||
}> = [];
|
||||
const ensureWorkspaceAndSessionsMock = vi.fn(async (..._args: unknown[]) => {});
|
||||
|
||||
vi.mock("../gateway/client.js", () => ({
|
||||
GatewayClient: class {
|
||||
@@ -46,18 +46,16 @@ vi.mock("../gateway/client.js", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
async function getFreePort(): Promise<number> {
|
||||
return await getFreePortBlockWithPermissionFallback({
|
||||
offsets: [0],
|
||||
fallbackBase: 30_000,
|
||||
});
|
||||
}
|
||||
vi.mock("./onboard-helpers.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./onboard-helpers.js")>();
|
||||
return {
|
||||
...actual,
|
||||
ensureWorkspaceAndSessions: ensureWorkspaceAndSessionsMock,
|
||||
};
|
||||
});
|
||||
|
||||
async function getFreeGatewayPort(): Promise<number> {
|
||||
return await getFreePortBlockWithPermissionFallback({
|
||||
offsets: [0, 1, 2, 4],
|
||||
fallbackBase: 40_000,
|
||||
});
|
||||
function getPseudoPort(base: number): number {
|
||||
return base + (process.pid % 1000);
|
||||
}
|
||||
|
||||
const runtime = createThrowingRuntime();
|
||||
@@ -173,7 +171,7 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
|
||||
it("writes gateway.remote url/token and callGateway uses them", async () => {
|
||||
await withStateDir("state-remote-", async () => {
|
||||
const port = await getFreePort();
|
||||
const port = getPseudoPort(30_000);
|
||||
const token = "tok_remote_123";
|
||||
await runNonInteractiveOnboarding(
|
||||
{
|
||||
@@ -215,7 +213,7 @@ describe("onboard (non-interactive): gateway and remote auth", () => {
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
process.env.OPENCLAW_CONFIG_PATH = path.join(stateDir, "openclaw.json");
|
||||
|
||||
const port = await getFreeGatewayPort();
|
||||
const port = getPseudoPort(40_000);
|
||||
const workspace = path.join(stateDir, "openclaw");
|
||||
|
||||
await runNonInteractiveOnboarding(
|
||||
|
||||
Reference in New Issue
Block a user