fix(process): decode bounded worker control frames as strict UTF-8 (#12162)

* fix(process): decode analyzer worker control frames as strict UTF-8

Refs #12145.

* fix(process): decode bounded control input without byte replacement

* fix(android): bound guardian readiness by the first UTF-8 frame (#12176)

Follows the readiness framing and lifecycle findings reported by @LcokHcak in #3048.
This commit is contained in:
morluto authored and GitHub committed 2026-11-19 04:00:02 +00:00
1 parent 85ac88fe87
commit 3493d6d252
15 files changed
+496 -208

No files matched your search

@@ -140,48 +140,67 @@ it("consumes fragmented CRLF admission and coalesced next-job frames in order",
}
});
it("drains oversized checkpoint admission, reports output failure, and serves the next job", async () => {
const server = await startServer();
try {
await server.next();
const first = await server.request();
const second = await server.request();
server.child.stdin.write(frame(first));
expect(await server.next()).toMatchObject({ kind: "static", id: first.id });
server.child.stdin.write(
"x".repeat(JAVASCRIPT_ANALYSIS_WORKER_DEFAULTS.protocolBytes),
);
server.child.stdin.write(
`x\n${frame(second)}${frame(admission(second.id))}`,
);
expect(await server.next()).toEqual({
kind: "failure",
id: first.id,
reason: "output",
resource: null,
limits: null,
message: expect.stringMatching(/admission frame.*missing or oversized/iu),
});
expect(await server.next()).toMatchObject({
kind: "static",
id: second.id,
});
expect(await server.next()).toMatchObject({
kind: "phase",
id: second.id,
phase: "transfer",
});
expect(await server.next()).toEqual({
kind: "complete",
id: second.id,
descriptor: null,
});
server.child.stdin.end();
expect((await server.closed)[0]).toBe(0);
} finally {
await server.close();
}
});
it.each([
["oversized", /admission frame.*missing or oversized/iu],
["malformed UTF-8", /admission frame.*not valid UTF-8/iu],
] as const)(
"reports %s checkpoint admission and serves the next job",
async (kind, failure) => {
const server = await startServer();
try {
await server.next();
const first = await server.request();
const second = await server.request();
server.child.stdin.write(frame(first));
expect(await server.next()).toMatchObject({
kind: "static",
id: first.id,
});
if (kind === "oversized") {
server.child.stdin.write(
"x".repeat(JAVASCRIPT_ANALYSIS_WORKER_DEFAULTS.protocolBytes + 1),
);
} else {
server.child.stdin.write(
Buffer.concat([
Buffer.from('{"id":"'),
Buffer.of(0xff),
Buffer.from(`",${JSON.stringify(admission(first.id)).slice(1)}`),
]),
);
}
server.child.stdin.write(
`\n${frame(second)}${frame(admission(second.id))}`,
);
expect(await server.next()).toEqual({
kind: "failure",
id: first.id,
reason: "output",
resource: null,
limits: null,
message: expect.stringMatching(failure),
});
expect(await server.next()).toMatchObject({
kind: "static",
id: second.id,
});
expect(await server.next()).toMatchObject({
kind: "phase",
id: second.id,
phase: "transfer",
});
expect(await server.next()).toEqual({
kind: "complete",
id: second.id,
descriptor: null,
});
server.child.stdin.end();
expect((await server.closed)[0]).toBe(0);
} finally {
await server.close();
}
},
);
it("reports missing checkpoint admission as output failure at stdin EOF", async () => {
const server = await startServer();
@@ -227,3 +246,25 @@ it.each(["lf", "eof", "open"] as const)(
}
},
);
it("rejects a valid-shaped initial request containing invalid UTF-8", async () => {
const server = await startServer();
try {
await server.next();
const request = await server.request();
const [before, after] = frame(request).split("app.mjs");
server.child.stdin.end(
Buffer.concat([
Buffer.from(before ?? ""),
Buffer.of(0xff),
Buffer.from(after ?? ""),
]),
);
expect((await server.closed)[0]).not.toBe(0);
expect(server.stderr()).toContain(
"TypeError: JavaScript worker request is not valid UTF-8",
);
} finally {
await server.close();
}
});