Files
reverse-engineering-anything/src/process/ProcessInspectionCancellation.test.ts
T
morlutoandCursor Agent be14c9d475 test: own temporary directories through createTestTempDirectory in src/ tests (#12725)
Give per-test temporary directories to the shared helper so Vitest removes
them after the case. Keep directories whose lifetime is the assertion, or
that are shared from beforeAll, on their existing cleanup.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-20 04:10:06 +00:00

60 lines
2.4 KiB
TypeScript

import { access, readFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
import {
isProcessOwnershipInspectionCancellation,
ProcessOwnershipInspectionCancelled,
} from "./ProcessInspectionCancellation.js";
import { systemProcessOwnershipHost } from "./ProcessOwnershipObservation.js";
import { spawnOwnedProviderProcess } from "./ProviderProcess.js";
it("does not turn a physical OS read failure into inspection cancellation when reused as the abort reason", async () => {
const root = await createTestTempDirectory("rea-inspection-origin-");
const failure = await readFile(join(root, "missing")).catch(
(cause: unknown) => cause,
);
expect(failure).toMatchObject({ code: "ENOENT" });
const controller = new AbortController();
controller.abort(failure);
expect(isProcessOwnershipInspectionCancellation(failure)).toBe(false);
});
it("wraps an opaque non-cancellation analysis error at already-aborted spawn admission without launching", async () => {
const root = await createTestTempDirectory("rea-inspection-admission-");
const marker = join(root, "launched");
const prepare = vi
.spyOn(systemProcessOwnershipHost, "prepare")
.mockRejectedValue(new Error("Native inspection must not start"));
try {
const reason = new AnalysisOutputError(
"authored-admission",
"opaque reason",
);
const controller = new AbortController();
controller.abort(reason);
const failure = await spawnOwnedProviderProcess({
command: process.execPath,
arguments: [
"-e",
"require('node:fs').writeFileSync(process.argv[1], 'launched')",
marker,
],
runId: "authored-aborted-admission",
signal: controller.signal,
}).catch((cause: unknown) => cause);
expect(failure).not.toBe(reason);
expect(failure).toBeInstanceOf(ProcessOwnershipInspectionCancelled);
if (!(failure instanceof ProcessOwnershipInspectionCancelled))
throw failure;
expect(failure.reason).toBe(reason);
expect(failure.cause).toBe(reason);
expect(prepare).not.toHaveBeenCalled();
await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
} finally {
prepare.mockRestore();
}
});