test: eliminate fixture races and prune redundant scaffolding (#849)

* test: eliminate fixture races and prune redundant scaffolding

* fix(test): publish launcher capture readiness without renaming
This commit is contained in:
morluto
2026-10-07 12:25:37 +08:00
committed by GitHub
parent 5cbf06c7ad
commit f72931d9dd
22 changed files with 421 additions and 719 deletions
+5 -1
View File
@@ -8,8 +8,9 @@ const descriptorPath = arguments_.at(-1);
if (descriptorPath === undefined) process.exit(64);
const descriptor = JSON.parse(await readFile(descriptorPath, "utf8"));
const runtimeRoot = dirname(descriptorPath);
const capturePath = join(runtimeRoot, "launch-capture.json");
await writeFile(
join(runtimeRoot, "launch-capture.json"),
capturePath,
`${JSON.stringify({
arguments: arguments_,
environment: {
@@ -38,4 +39,7 @@ await writeFile(
})}\n`,
{ mode: 0o600 },
);
// A Windows private runtime retains directory handles that restrict renames.
// Publish readiness only after writeFile has closed the complete JSON capture.
await writeFile(`${capturePath}.ready`, "", { flag: "wx", mode: 0o600 });
setInterval(() => undefined, 1_000);
+1
View File
@@ -72,6 +72,7 @@ const onSocketData = (socket, server, chunk, state) => {
state.buffer.value = state.buffer.value.slice(newline + 1);
newline = state.buffer.value.indexOf("\n");
const request = JSON.parse(line);
process.send?.({ method: request.method });
if (request.token !== state.token) {
socket.end(
`${JSON.stringify({
+25 -3
View File
@@ -2,6 +2,14 @@ import { createServer } from "node:net";
const [socketPath, token, runId, shutdownMode = "acknowledge"] =
process.argv.slice(2);
const heldReplies = new Map();
if (process.send !== undefined)
process.on("message", (message) => {
const reply = heldReplies.get(message?.release);
if (reply === undefined) return;
heldReplies.delete(message.release);
reply();
});
const shutdownResult = () => ({
shutdown: true,
analysis_stopped: true,
@@ -115,7 +123,7 @@ const sendEchoWithProgress = (send, request) => {
message: "Hopper bridge started request",
},
});
setTimeout(() => {
const reply = () => {
send({
id: request.id,
event: {
@@ -128,7 +136,10 @@ const sendEchoWithProgress = (send, request) => {
},
});
send({ id: request.id, result: request.params ?? {} });
}, request.params?.delay ?? 0);
};
if (typeof request.params?.gate === "string")
heldReplies.set(request.id, reply);
else setTimeout(reply, request.params?.delay ?? 0);
};
const server = createServer((socket) => {
@@ -147,6 +158,11 @@ const server = createServer((socket) => {
let newline = buffer.indexOf("\n");
while (newline >= 0) {
const request = JSON.parse(buffer.slice(0, newline));
process.send?.({
id: request.id,
method: request.method,
params: request.params,
});
const bridgeEventMessages = bridgeEventFixtureMessages(request);
buffer = buffer.slice(newline + 1);
if (request.token !== token) {
@@ -169,7 +185,13 @@ const server = createServer((socket) => {
) {
send({ id: request.id, result: shutdownResult() });
if (shutdownMode !== "cleanup-required")
setTimeout(() => server.close(), 2);
setTimeout(
() =>
server.close(() => {
if (process.connected) process.disconnect();
}),
2,
);
} else if (request.method === "hang") {
// Deliberately leave the request pending.
} else if (request.method === "exit") {