mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 18:21:50 +00:00
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
collectPreparedPrepackErrors,
|
|
resolvePrepackCommandTimeoutMs,
|
|
runPrepackCommand,
|
|
} from "../scripts/openclaw-prepack.ts";
|
|
|
|
describe("collectPreparedPrepackErrors", () => {
|
|
it("accepts prepared release artifacts", () => {
|
|
expect(
|
|
collectPreparedPrepackErrors(
|
|
["dist/index.mjs", "dist/control-ui/index.html"],
|
|
["dist/control-ui/assets/index-Bu8rSoJV.js"],
|
|
),
|
|
).toStrictEqual([]);
|
|
});
|
|
|
|
it("reports missing build and control ui artifacts", () => {
|
|
expect(collectPreparedPrepackErrors([], [])).toEqual([
|
|
"missing required prepared artifact: dist/index.js or dist/index.mjs",
|
|
"missing required prepared artifact: dist/control-ui/index.html",
|
|
"missing prepared Control UI asset payload under dist/control-ui/assets/",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("runPrepackCommand", () => {
|
|
it("returns captured output for successful commands", () => {
|
|
const result = runPrepackCommand(process.execPath, ["--eval", "process.stdout.write('ok')"], {
|
|
encoding: "utf8",
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
timeout: 1000,
|
|
});
|
|
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toBe("ok");
|
|
});
|
|
|
|
it("bounds commands that ignore termination", () => {
|
|
const startedAt = Date.now();
|
|
const result = runPrepackCommand(
|
|
process.execPath,
|
|
["--eval", "process.on('SIGTERM', () => {}); setInterval(() => {}, 1000);"],
|
|
{
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
timeout: 100,
|
|
},
|
|
);
|
|
|
|
expect(result.error).toBeInstanceOf(Error);
|
|
expect(Date.now() - startedAt).toBeLessThan(2500);
|
|
});
|
|
});
|
|
|
|
describe("resolvePrepackCommandTimeoutMs", () => {
|
|
it("uses a positive environment timeout", () => {
|
|
expect(resolvePrepackCommandTimeoutMs({ OPENCLAW_PREPACK_COMMAND_TIMEOUT_MS: "1234" })).toBe(
|
|
1234,
|
|
);
|
|
});
|
|
|
|
it("falls back when the environment timeout is invalid", () => {
|
|
expect(resolvePrepackCommandTimeoutMs({ OPENCLAW_PREPACK_COMMAND_TIMEOUT_MS: "nope" })).toBe(
|
|
30 * 60 * 1000,
|
|
);
|
|
});
|
|
|
|
it("falls back when the environment timeout has a numeric prefix", () => {
|
|
expect(resolvePrepackCommandTimeoutMs({ OPENCLAW_PREPACK_COMMAND_TIMEOUT_MS: "10m" })).toBe(
|
|
30 * 60 * 1000,
|
|
);
|
|
});
|
|
});
|