test(javascript): synchronize worker cleanup and validate candidate facts

This commit is contained in:
morluto committed 2026-10-14 12:21:22 +08:00
1 parent 7ad75bdc80
commit 5b5de1b527
2 files changed
+21

No files matched your search

@@ -31,3 +31,19 @@ it("versions fingerprints through the worker schema and rejects v1", () => {
false,
);
});
it("accepts candidate endpoint interpretations from static analysis", () => {
const facts = analyzeJavaScriptStaticSource(`http.request("POST", target);`);
expect(facts.endpoints).toContainEqual(
expect.objectContaining({
kind: "network",
value: "POST",
interpretation: "candidate",
}),
);
expect(
javaScriptWorkerStaticAnalysisSchema.safeParse(
JSON.parse(JSON.stringify(facts)) as unknown,
).success,
).toBe(true);
});
@@ -162,10 +162,14 @@ it("ends worker stdin and unreferences process handles when cleanup reports insp
let unreferenced = false;
let permitCleanup = false;
let childStdin: typeof process.stdin | undefined;
let childExit: Promise<void> | undefined;
const worker = new JavaScriptAnalysisWorker(
{ heapMb: 128, timeoutMs: 30_000 },
async (request) => {
const launched = await spawnOwnedProviderProcess(request);
childExit = new Promise((resolve) => {
launched.process.once("exit", () => resolve());
});
const originalUnref = launched.process.unref;
launched.process.unref = () => {
unreferenced = true;
@@ -208,6 +212,7 @@ it("ends worker stdin and unreferences process handles when cleanup reports insp
expect(childStdin?.listenerCount("error")).toBeLessThanOrEqual(
errorListeners ?? 0,
);
await childExit;
permitCleanup = true;
await worker.close();
} finally {