fix(artifacts)!: retain cleanup owners through client shutdown
Keep failed reader, root descriptor, and output-tree cleanup with the caller. Drain admitted work before close, retry the same retained owners, and block new resource work while cleanup is incomplete. Preserve primary failures and complete inventory observations. Thread ownership through JavaScript reconstruction, the CLI's one-shot scope, MCP server shutdown, verifier scripts, and test fixtures. Remove redundant ownership flags and the unused validated test wrapper. Validate with 850 passing focused tests across 90 suites (two skipped), targeted classification and cleanup retries, static and unused-code checks, and real macOS CLI/MCP directory, ZIP, and DMG workflows. Native Windows and deep-analysis providers were not verified. BREAKING CHANGE: Direct artifact inventory/extraction and JavaScript analysis APIs require an explicit caller-owned ArtifactResourceScope. CLI and MCP input contracts are unchanged.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import type { ArtifactReader } from "./ArtifactReader.js";
|
||||
import { ArtifactResourceScope } from "./ArtifactResourceScope.js";
|
||||
|
||||
const deferred = <T>() => {
|
||||
let resolve: (value: T) => void = () => {};
|
||||
const promise = new Promise<T>((resolvePromise) => {
|
||||
resolve = resolvePromise;
|
||||
});
|
||||
return { promise, resolve };
|
||||
};
|
||||
|
||||
it("waits for admitted operations and shares concurrent close", async () => {
|
||||
const scope = new ArtifactResourceScope();
|
||||
const started = deferred<void>();
|
||||
const finish = deferred<void>();
|
||||
const operation = scope.run(async () => {
|
||||
started.resolve();
|
||||
await finish.promise;
|
||||
});
|
||||
await started.promise;
|
||||
|
||||
const close = scope.close();
|
||||
expect(scope.close()).toBe(close);
|
||||
await expect(scope.run(async () => undefined)).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
message: "Artifact resource scope is closed",
|
||||
});
|
||||
let closed = false;
|
||||
void close.then(() => {
|
||||
closed = true;
|
||||
});
|
||||
await Promise.resolve();
|
||||
expect(closed).toBe(false);
|
||||
|
||||
finish.resolve();
|
||||
await operation;
|
||||
await close;
|
||||
expect(closed).toBe(true);
|
||||
});
|
||||
|
||||
it("retains the same failed reader owner and retries before admitting work", async () => {
|
||||
const scope = new ArtifactResourceScope();
|
||||
let closeAttempts = 0;
|
||||
const reader = {
|
||||
async close() {
|
||||
closeAttempts += 1;
|
||||
if (closeAttempts < 4) throw new Error(`close attempt ${closeAttempts}`);
|
||||
},
|
||||
} as unknown as ArtifactReader;
|
||||
const owner = { kind: "reader" as const, resource: "fixture reader", reader };
|
||||
|
||||
expect(await scope.release(owner)).toMatchObject({ kind: "failed" });
|
||||
expect(closeAttempts).toBe(1);
|
||||
|
||||
await expect(scope.run(async () => "must not run")).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
message: "Artifact cleanup remains incomplete: fixture reader",
|
||||
});
|
||||
expect(closeAttempts).toBe(2);
|
||||
await expect(scope.close()).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
});
|
||||
expect(closeAttempts).toBe(3);
|
||||
await scope.close();
|
||||
expect(closeAttempts).toBe(4);
|
||||
});
|
||||
Reference in New Issue
Block a user