Files
reverse-engineering-anything/tests/boundary/filesystem/adbInputSnapshot.test.ts
T
morluto a891bb80ae refactor(filesystem): preserve admitted file facts
Return the validated descriptor and its original metadata from regular-file
admission. Propagate that contract through owned reads, hashes, snapshots,
artifact inventory and provider file workflows instead of replacing initial
facts with another stat. Keep arbitrary output-handle operations separate.

Preserve final descriptor/path identity proofs, borrowed-source verification,
BigInt precision, cancellation provenance and failed-close ownership. Remove
the obsolete source and owned-ZIP baseline stages and update their consumers
and regressions. Tie read completion faults to actual reads instead of the
retired duplicate stat; instrument real handles without fake handle wrappers.

Validation: fresh runtime/catalog build; focused source, lifecycle, filesystem,
CLI/MCP and authored provider-fixture tests; full static checks; docs checks;
test discovery; duplication check. Platform-specific cases remain skipped on
macOS. No installed provider or device behavior was verified.
2026-10-25 04:09:11 +08:00

72 lines
2.4 KiB
TypeScript

import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it } from "vitest";
import { ArtifactResourceScope } from "../../../src/artifacts/ArtifactResourceScope.js";
import { OwnedFileHandle } from "../../../src/filesystem/OwnedFileHandle.js";
import {
openRegularFile,
RegularFileAdmissionFailure,
} from "../../../src/filesystem/RegularFile.js";
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
import {
AdbInputSnapshotFailure,
snapshotAdbInput,
} from "../../../src/adb/AdbInputSnapshot.js";
it("retains and retries a source handle that fails close during admission", async () => {
const parent = await mkdtemp(join(tmpdir(), "rea-adb-snapshot-test-"));
const root = await PrivateRuntimeRoot.create({ parent });
const resources = new ArtifactResourceScope();
const sourcePath = join(parent, "selected.apk");
await writeFile(sourcePath, "selected bytes");
let closeAttempts = 0;
try {
await expect(
snapshotAdbInput(
sourcePath,
root,
resources,
"install_adb_package",
undefined,
{
openSource: async (path, options) => {
const { handle } = await openRegularFile(path, options);
const close = handle.close.bind(handle);
const owner = new OwnedFileHandle(handle);
handle.close = async () => {
closeAttempts += 1;
if (closeAttempts === 1)
throw new Error("controlled close failure");
await close();
};
throw new RegularFileAdmissionFailure(
path,
new Error("controlled admission failure"),
new Error("first close was not confirmed"),
owner,
);
},
},
),
).rejects.toMatchObject<Partial<AdbInputSnapshotFailure>>({
primaryCause: expect.objectContaining({
message: "controlled admission failure",
}),
cleanupResources: [expect.stringContaining("source handle")],
});
expect(resources.hasPending).toBe(true);
expect(closeAttempts).toBe(1);
await resources.retryCleanup();
expect(resources.hasPending).toBe(false);
expect(closeAttempts).toBe(2);
} finally {
await resources.close();
await root.close();
await rm(parent, { recursive: true, force: true });
}
});