Files
reverse-engineering-anything/tests/support/publishedDirectoryCloseFailure.ts
T
morluto 60149282fc test: strengthen integration oracles and verification (#8295)
* test: strengthen integration oracles and verification

* test: bound lifecycle gates and strengthen workflow checks

* test: verify complete paged and extracted results

* test: preserve bytecode and cancellation evidence

* test: strengthen retained evidence and fixture cleanup

* test: require cross-projection bridge identities

* test: retain fixture owners through cleanup failures

* test: verify graph examples and project selectors

* test: tighten provider and lifecycle regressions

* test: consolidate hex coverage and bound cutter cleanup

* test: bound subprocess output waits and strengthen graph checks

* test: check mcp recovery and preserve cleanup owners

* test: verify structured mcp argument failures

* test: preserve artifact cleanup and gdb limit evidence

* test: preserve evidence identities and bound provider gates

* test: retain browser and comparison cleanup owners

* test: bound startup and strengthen fixture oracles

* test: bound lifecycle gates and verify recovered evidence

* test: verify public outcomes and lifecycle ownership

* test: assert precise evidence and release lifecycle gates

* test: verify selected facts and bound cleanup waits

* test: check retained evidence and decoded records

* test: verify final reports and retain cleanup ownership

* test: bound reviewed startup gates and retain cleanup

* test: verify PE errors and preserve MCP cleanup

* test: preserve MCP fixture cleanup ownership

* test: release provider gates before late startup
2026-11-01 00:15:28 +08:00

62 lines
2.0 KiB
TypeScript

import { stat } from "node:fs/promises";
import { dirname } from "node:path";
import { vi } from "vitest";
import { SafeOutputTree } from "../../src/artifacts/SafeOutputTree.js";
import { OwnedFileHandle } from "../../src/filesystem/OwnedFileHandle.js";
/** Fail closing the parent directory after publication until retry is allowed. */
export const injectPublishedDirectoryCloseFailure = async (
output: string,
persistent = false,
) => {
const parent = await stat(dirname(output));
const owners: OwnedFileHandle[] = [];
let committing = false;
let injected = false;
let denied = true;
const originalClose = OwnedFileHandle.prototype.close;
const close = vi
.spyOn(OwnedFileHandle.prototype, "close")
.mockImplementation(async function (this: OwnedFileHandle) {
if (committing && this.handle.fd >= 0) {
const identity = await this.handle.stat();
if (identity.dev === parent.dev && identity.ino === parent.ino) {
owners.push(this);
if (owners.length === 1) {
const handle = this.handle;
const closeHandle = handle.close.bind(handle);
handle.close = async () => {
if (denied) {
injected = true;
if (!persistent) denied = false;
throw new Error("injected published directory close failure");
}
handle.close = closeHandle;
await closeHandle();
};
}
}
}
await originalClose.call(this);
});
const originalCommit = SafeOutputTree.prototype.commit;
const commit = vi
.spyOn(SafeOutputTree.prototype, "commit")
.mockImplementation(function (this: SafeOutputTree, signal) {
committing = true;
return originalCommit.call(this, signal);
});
return {
owners,
wasInjected: () => injected,
allowCleanup: () => {
denied = false;
},
restore: () => {
commit.mockRestore();
close.mockRestore();
},
};
};