* 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
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import {
|
|
mkdtemp,
|
|
open,
|
|
rm,
|
|
writeFile,
|
|
type FileHandle,
|
|
} from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { expect, it, vi } from "vitest";
|
|
|
|
import { LldbReadbackFiles } from "../../../../src/native/LldbReadbackFiles.js";
|
|
|
|
it("bounds PID readback while retaining newline-terminated producer fixtures", async () => {
|
|
const directory = await mkdtemp(join(tmpdir(), "rea-lldb-pid-"));
|
|
const values = [
|
|
["max-safe.pid", String(Number.MAX_SAFE_INTEGER), Number.MAX_SAFE_INTEGER],
|
|
[
|
|
"max-safe-crlf.pid",
|
|
`${Number.MAX_SAFE_INTEGER}\r\n`,
|
|
Number.MAX_SAFE_INTEGER,
|
|
],
|
|
["lf.pid", "12345\n", 12345],
|
|
["crlf.pid", "12345\r\n", 12345],
|
|
["unsafe.pid", "9007199254740992", undefined],
|
|
["too-many-digits.pid", "10000000000000000", undefined],
|
|
["empty.pid", "", undefined],
|
|
["oversized.pid", "1".repeat(64), undefined],
|
|
] as const;
|
|
for (const [name, contents] of values)
|
|
await writeFile(join(directory, name), contents);
|
|
const sample = await open(join(directory, "max-safe.pid"), "r");
|
|
const prototype = Object.getPrototypeOf(sample) as {
|
|
read(
|
|
this: FileHandle,
|
|
buffer: Buffer,
|
|
offset: number,
|
|
length: number,
|
|
position: number,
|
|
): Promise<{ bytesRead: number; buffer: Buffer }>;
|
|
readFile(this: FileHandle, encoding: "utf8"): Promise<string>;
|
|
};
|
|
await sample.close();
|
|
let bytesRead = 0;
|
|
const requestedLengths: number[] = [];
|
|
const originalReadFile = prototype.readFile;
|
|
const readFileSpy = vi
|
|
.spyOn(prototype, "readFile")
|
|
.mockImplementation(async function (this: FileHandle, ...args) {
|
|
const value = await originalReadFile.call(this, ...args);
|
|
bytesRead += Buffer.byteLength(value);
|
|
return value;
|
|
});
|
|
const originalRead = prototype.read;
|
|
const readSpy = vi
|
|
.spyOn(prototype, "read")
|
|
.mockImplementation(async function (this: FileHandle, ...args) {
|
|
const requestedLength = typeof args[2] === "number" ? args[2] : 0;
|
|
requestedLengths.push(requestedLength);
|
|
const result = await originalRead.call(
|
|
this,
|
|
args[0],
|
|
args[1],
|
|
Math.min(requestedLength, 1),
|
|
args[3],
|
|
);
|
|
bytesRead += result.bytesRead;
|
|
return result;
|
|
});
|
|
const files = new LldbReadbackFiles();
|
|
try {
|
|
for (const [name, , expected] of values) {
|
|
const before = bytesRead;
|
|
expect(await files.readTargetPid(join(directory, name))).toBe(expected);
|
|
expect(bytesRead - before).toBeLessThanOrEqual(19);
|
|
}
|
|
expect(
|
|
await files.readTargetPid(join(directory, "missing.pid")),
|
|
).toBeUndefined();
|
|
expect(requestedLengths.length).toBeGreaterThan(0);
|
|
expect(requestedLengths.every((length) => length <= 19)).toBe(true);
|
|
expect(bytesRead).toBeLessThanOrEqual(19 * values.length);
|
|
} finally {
|
|
readSpy.mockRestore();
|
|
readFileSpy.mockRestore();
|
|
await files.retryCleanup();
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|
|
});
|