fix: isolate concurrent doctor cleanup scopes, trace JS fixture helpers, and share MCP/home lifecycles

Address all four PR review findings structurally:
- Isolate concurrent Doctor probes and host subsystems in child
  ArtifactResourceScope instances tracked via resources.track() so a failed
  cleanup on one probe cannot deadlock or abort sibling reads before close().
- Include tests/ JS/TS helper modules and fixture path literals in
  throughHelpers() and named() so changes to JS fixtures such as
  fakeHopperReplies.mjs reach transitive helper and socket tests.
- Extract generic createSharedMcpSession() and reuse it in lazyLocalToolsMcp()
  to preserve retryable cleanup draining and startup-failure attribution.
- Replace test-scoped createTestTempDirectory() with a file-scoped workspace
  in jsonInputStatus.test.ts so the shared isolated home persists across tests.
This commit is contained in:
morluto committed 2026-11-17 19:58:40 +08:00
1 parent 455c269566
commit 116f159a8a
10 files changed
+443 -289

No files matched your search

@@ -106,6 +106,29 @@ test("does not open a shared MCP server after file cleanup starts", async () =>
);
});
test("retries pending cleanup on later calls after a transient drain failure", async () => {
let connectAttempts = 0;
let cleanupFails = true;
const session = createSharedMcpSession(async (registerCleanup) => {
connectAttempts += 1;
registerCleanup(async () => {
if (cleanupFails) throw new Error("transient cleanup failure");
});
if (connectAttempts === 1) throw new Error("first handshake failed");
return fakeCall;
});
await expect(session.session.call()).rejects.toThrow(
"first handshake failed",
);
await expect(session.session.call()).rejects.toThrow(
"transient cleanup failure",
);
cleanupFails = false;
await expect(session.session.call()).resolves.toBe(fakeCall);
expect(connectAttempts).toBe(2);
await session.close();
});
test("keeps a failed MCP handshake when its cleanup also fails", async () => {
const startup = new Error("handshake failed");
const cleanup = new Error("teardown failed");