mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-01 16:52:29 +00:00
fix(test): bound startup build helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
ensureCliStartupBuild,
|
||||
hasCliStartupBuild,
|
||||
resolveCliStartupBuildTimeoutMs,
|
||||
} from "../../scripts/ensure-cli-startup-build.mjs";
|
||||
|
||||
const tempRoots: string[] = [];
|
||||
@@ -80,7 +81,9 @@ describe("ensure-cli-startup-build", () => {
|
||||
args: [path.join(root, "scripts", "build-all.mjs"), "cliStartup"],
|
||||
options: expect.objectContaining({
|
||||
cwd: root,
|
||||
killSignal: "SIGKILL",
|
||||
stdio: "pipe",
|
||||
timeout: 10 * 60 * 1000,
|
||||
}),
|
||||
},
|
||||
]);
|
||||
@@ -107,12 +110,37 @@ describe("ensure-cli-startup-build", () => {
|
||||
args: [path.join(root, "scripts", "build-all.mjs"), "cliStartup"],
|
||||
options: expect.objectContaining({
|
||||
cwd: root,
|
||||
killSignal: "SIGKILL",
|
||||
stdio: "pipe",
|
||||
timeout: 10 * 60 * 1000,
|
||||
}),
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses the configured cliStartup build timeout", () => {
|
||||
const root = makeTempRoot();
|
||||
const calls: unknown[] = [];
|
||||
|
||||
ensureCliStartupBuild({
|
||||
rootDir: root,
|
||||
env: { OPENCLAW_CLI_STARTUP_BUILD_TIMEOUT_MS: "1234" },
|
||||
spawnSync: (command, args, options) => {
|
||||
calls.push({ command, args, options });
|
||||
return { status: 0 };
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
expect(calls).toEqual([
|
||||
expect.objectContaining({
|
||||
options: expect.objectContaining({
|
||||
timeout: 1234,
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("fails when the cliStartup build profile fails", () => {
|
||||
const root = makeTempRoot();
|
||||
|
||||
@@ -137,3 +165,23 @@ describe("ensure-cli-startup-build", () => {
|
||||
).toThrow("spawn denied");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveCliStartupBuildTimeoutMs", () => {
|
||||
it("uses a positive environment timeout", () => {
|
||||
expect(resolveCliStartupBuildTimeoutMs({ OPENCLAW_CLI_STARTUP_BUILD_TIMEOUT_MS: "4321" })).toBe(
|
||||
4321,
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back when the environment timeout is invalid", () => {
|
||||
expect(resolveCliStartupBuildTimeoutMs({ OPENCLAW_CLI_STARTUP_BUILD_TIMEOUT_MS: "nope" })).toBe(
|
||||
10 * 60 * 1000,
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back when the environment timeout has a numeric prefix", () => {
|
||||
expect(resolveCliStartupBuildTimeoutMs({ OPENCLAW_CLI_STARTUP_BUILD_TIMEOUT_MS: "10m" })).toBe(
|
||||
10 * 60 * 1000,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
ensureExtensionMemoryBuild,
|
||||
hasBuiltExtensionMemoryEntries,
|
||||
resolveExtensionMemoryBuildTimeoutMs,
|
||||
} from "../../scripts/ensure-extension-memory-build.mjs";
|
||||
|
||||
const tempRoots: string[] = [];
|
||||
@@ -97,12 +98,38 @@ describe("ensure-extension-memory-build", () => {
|
||||
args: [path.join(root, "scripts", "build-all.mjs"), "cliStartup"],
|
||||
options: expect.objectContaining({
|
||||
cwd: root,
|
||||
killSignal: "SIGKILL",
|
||||
stdio: "pipe",
|
||||
timeout: 10 * 60 * 1000,
|
||||
}),
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses the configured extension memory build timeout", () => {
|
||||
const root = makeTempRoot();
|
||||
const calls: unknown[] = [];
|
||||
|
||||
ensureExtensionMemoryBuild({
|
||||
rootDir: root,
|
||||
env: { OPENCLAW_EXTENSION_MEMORY_BUILD_TIMEOUT_MS: "1234" },
|
||||
requiredExtensionIds: ["discord"],
|
||||
spawnSync: (command, args, options) => {
|
||||
calls.push({ command, args, options });
|
||||
return { status: 0 };
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
expect(calls).toEqual([
|
||||
expect.objectContaining({
|
||||
options: expect.objectContaining({
|
||||
timeout: 1234,
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("fails when the cliStartup build profile fails", () => {
|
||||
const root = makeTempRoot();
|
||||
|
||||
@@ -115,3 +142,29 @@ describe("ensure-extension-memory-build", () => {
|
||||
).toThrow("cliStartup build profile failed with exit code 1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveExtensionMemoryBuildTimeoutMs", () => {
|
||||
it("uses a positive environment timeout", () => {
|
||||
expect(
|
||||
resolveExtensionMemoryBuildTimeoutMs({
|
||||
OPENCLAW_EXTENSION_MEMORY_BUILD_TIMEOUT_MS: "4321",
|
||||
}),
|
||||
).toBe(4321);
|
||||
});
|
||||
|
||||
it("falls back when the environment timeout is invalid", () => {
|
||||
expect(
|
||||
resolveExtensionMemoryBuildTimeoutMs({
|
||||
OPENCLAW_EXTENSION_MEMORY_BUILD_TIMEOUT_MS: "nope",
|
||||
}),
|
||||
).toBe(10 * 60 * 1000);
|
||||
});
|
||||
|
||||
it("falls back when the environment timeout has a numeric prefix", () => {
|
||||
expect(
|
||||
resolveExtensionMemoryBuildTimeoutMs({
|
||||
OPENCLAW_EXTENSION_MEMORY_BUILD_TIMEOUT_MS: "10m",
|
||||
}),
|
||||
).toBe(10 * 60 * 1000);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user