Files
reverse-engineering-anything/tests/boundary/cli/cliOwnedResources.test.ts
T
morlutoandCursor Agent 395b598383 refactor(admission): own inspector, web, and CLI state per host (#8058)
* refactor(admission): own inspector, web, and CLI state per host

Replace the process-global inspector, web-bundle, guidance, and JavaScript
counters with objects a host passes in, so independent instances do not
share admission or cleanup.

* fix(admission): keep worker and file cleanup on the host

Web-bundle and JavaScript workers retry only their host registry, and
each Inspector admission authorizes and closes its own file scope.
Browser providers can share one web-bundle admission.

* test(inspector): gate one admission's file cleanup

The isolation test delayed the first ArtifactResourceScope.retryCleanup
call, so a second call on a shared ElectronFileScope still finished.
Hold first.files.retryCleanup until the other admission's close
finishes, then release and join before restoring the method.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-10-30 05:23:33 +08:00

51 lines
1.8 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { ArtifactResourceScope } from "../../../src/artifacts/ArtifactResourceScope.js";
import { CliGuidanceResources } from "../../../src/cli/guidanceCommands.js";
import { CliJavaScriptAnalysisHost } from "../../../src/cli/javascriptApplicationAnalysis.js";
const originalClose = ArtifactResourceScope.prototype.close;
afterEach(() => {
ArtifactResourceScope.prototype.close = originalClose;
vi.restoreAllMocks();
});
it("keeps guidance descriptors on the host that created them", () => {
const first = new CliGuidanceResources();
const second = new CliGuidanceResources();
expect(first.resources()).toBe(first.resources());
expect(second.resources()).toBe(second.resources());
expect(first.resources()).not.toBe(second.resources());
});
it("does not share a JavaScript worker scope or its in-flight close", async () => {
let release = (): void => {};
const gate = new Promise<void>((resolve) => {
release = resolve;
});
ArtifactResourceScope.prototype.close = function (
this: ArtifactResourceScope,
) {
return gate.then(() => originalClose.call(this));
};
const first = new CliJavaScriptAnalysisHost();
const second = new CliJavaScriptAnalysisHost();
let firstClose: Promise<void> | undefined;
let secondClose: Promise<void> | undefined;
const firstScope = first.scope();
const secondScope = second.scope();
try {
expect(firstScope).not.toBe(secondScope);
firstClose = first.close();
expect(first.close()).toBe(firstClose);
secondClose = second.close();
expect(secondClose).not.toBe(firstClose);
} finally {
release();
await Promise.allSettled([firstClose, secondClose]);
}
expect(first.scope()).not.toBe(firstScope);
expect(second.scope()).not.toBe(secondScope);
});