fix(source-maps): retain primary failures through cleanup retries

This commit is contained in:
morluto committed 2026-10-25 08:25:17 +08:00
1 parent 42c16ba631
commit 760d9f6019
6 files changed
+207 -60

No files matched your search

@@ -67,19 +67,30 @@ it("retains failed cleanup ownership and retries it before another decode", asyn
expect(failed.ok).toBe(false);
if (failed.ok)
throw new Error("expected physical failure with cleanup failure");
expect(failed.error).toBeInstanceOf(SourceMapCleanupFailure);
if (!(failed.error instanceof SourceMapCleanupFailure))
throw new Error("expected source-map cleanup ownership");
expect(failed.error.cleanupOwner).toBeDefined();
const primary = failed.error.cleanupPrimary;
expect(primary).toMatchObject({
_tag: "ProviderAdapterError",
diagnostics: {
exit_code: 7,
stderr: "physical exit 7",
},
});
expect(primary?.capturedOutput?.stderr).toBe("physical exit 7");
expect(failed.error.capturedOutput).toEqual(primary?.capturedOutput);
expect(failed.error.cause).toBeInstanceOf(AggregateError);
expect((failed.error.cause as AggregateError).errors[0]).toBe(primary);
expect(failed.error.cleanupResources).toEqual([root.path]);
expect(failed.error.diagnostics).toMatchObject({
cleanup_failures: ["injected root cleanup failure"],
});
expect(failed.error.diagnostics).toMatchObject({
previous_error: expect.stringContaining(
"source-map-decoder adapter failed",
),
primary_error: { code: "execution_failure" },
cleanup_error: {
details: {
diagnostics: {
cleanup_failures: ["injected root cleanup failure"],
},
},
},
});
expect(projectAnalysisError(failed.error).code).toBe("cleanup_incomplete");
await expect(access(root.path)).resolves.toBeUndefined();
const invalidInput = { ...input, text: null } as unknown as typeof input;
@@ -92,11 +103,16 @@ it("retains failed cleanup ownership and retries it before another decode", asyn
await expect(access(root.path)).rejects.toMatchObject({ code: "ENOENT" });
expect(failed.error.cleanupIncomplete).toBe(false);
expect(failed.error.cleanupResources).toEqual([]);
expect(projectAnalysisError(failed.error).code).not.toBe(
"cleanup_incomplete",
);
expect(projectAnalysisError(failed.error).code).toBe("execution_failure");
expect(failed.error.cleanupPrimary).toBe(primary);
expect(failed.error.diagnostics).toMatchObject({
cleanup_failures: ["injected root cleanup failure"],
cleanup_error: {
details: {
diagnostics: {
cleanup_failures: ["injected root cleanup failure"],
},
},
},
});
} finally {
await decoder.close();
@@ -108,6 +124,7 @@ it("settles every source-map cleanup failure when final close releases the exact
prefix: "rea-source-map-final-cleanup-test-",
});
let attempts = 0;
const launchCause = new Error("controlled launch failure");
const decoder = new SourceMapDecoder({
prepareOwnership: async () => {},
createRuntime: async () => ({
@@ -120,12 +137,16 @@ it("settles every source-map cleanup failure when final close releases the exact
},
}),
launcher: async () => {
throw new Error("controlled launch failure");
throw launchCause;
},
});
try {
const initial = await decoder.trace(input);
if (initial.ok) throw new Error("expected initial cleanup failure");
expect(initial.error.cleanupPrimary?.cause).toBe(launchCause);
expect((initial.error.cause as AggregateError).errors[0]).toBe(
initial.error.cleanupPrimary,
);
const retry = await decoder.trace(input);
if (retry.ok) throw new Error("expected retry cleanup failure");
for (const failure of [initial.error, retry.error]) {
@@ -139,11 +160,22 @@ it("settles every source-map cleanup failure when final close releases the exact
for (const failure of [initial.error, retry.error]) {
expect(failure.cleanupIncomplete).toBe(false);
expect(failure.cleanupResources).toEqual([]);
expect(projectAnalysisError(failure).code).not.toBe("cleanup_incomplete");
expect(failure.diagnostics?.cleanup_failures).toEqual([
expect.stringContaining("runtime cleanup attempt"),
]);
expect(projectAnalysisError(failure).code).toBe("execution_failure");
}
expect(initial.error.cleanupPrimary?.cause).toBe(launchCause);
expect(initial.error.diagnostics).toMatchObject({
cleanup_error: {
details: {
diagnostics: {
cleanup_failures: ["runtime cleanup attempt 1 failed"],
},
},
},
});
expect(retry.error).toBeInstanceOf(SourceMapCleanupFailure);
expect(retry.error.diagnostics?.cleanup_failures).toEqual([
"runtime cleanup attempt 2 failed",
]);
} finally {
await decoder.close();
}