Files
NianAIGC/tests/worker-script.test.ts

32 lines
1.1 KiB
TypeScript

import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const execFileAsync = promisify(execFile);
const rootDir = fileURLToPath(new URL("../", import.meta.url));
describe("worker script configuration", () => {
it("fails fast in production when the internal worker token is missing", async () => {
await expect(execFileAsync(process.execPath, ["scripts/worker.mjs", "--once"], {
cwd: rootDir,
env: {
...process.env,
NODE_ENV: "production",
ZHINIAN_INTERNAL_WORKER_TOKEN: "",
ZHINIAN_WORKER_BASE_URL: "http://127.0.0.1:9"
}
})).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining("ZHINIAN_INTERNAL_WORKER_TOKEN is required")
});
});
it("bounds each internal tick request with AbortSignal.timeout", async () => {
const source = await import("node:fs/promises").then(({ readFile }) =>
readFile(new URL("../scripts/worker.mjs", import.meta.url), "utf8")
);
expect(source).toContain("AbortSignal.timeout(requestTimeoutMs)");
});
});