mirror of
https://github.com/morluto/rea.git
synced 2026-11-26 06:08:37 +00:00
* fix(artifacts): preserve iNES shutdown ownership and I/O failures
* test(cli): publish complete doctor readiness before cancellation
* test(mcp): observe cleanup failures at their current delivery boundary
* fix(mcp): preserve workflow completion progress through delivery
* test(ci): assert current MCP and evidence ownership contracts
* test(setup): keep the Windows Kimi profile fixture on a supported profile
The Windows-only case at `clientConfigurationEnvironment.test.ts:226` wrote
`rea_mcp_input_schema_profile: "full"`. That profile was retired: the reader
now refuses it ("REA_MCP_INPUT_SCHEMA_PROFILE accepts only \"compact\" …"),
so `configureClientConfiguration` returned `failed/readback` before writing
and the case failed on every Windows run, including main's own
`Windows capability and package lane`.
The case has no Windows dependency — it passes an explicit `configPath` and
the Kimi write dialect is the same everywhere — so it now runs on every
platform, which is what let the stale value rot unnoticed. The fixture keeps
the lowercase explicit key the case is about, with the supported value.
Verified on `main` `d6bcfc10`: the same fixture driven through
`configureClientConfiguration(..., "win32")` on this host reproduced
`{"status":"failed","reason":"readback"}` with the retired value and now
returns `{"status":"configured"}` with `compact`. The file's 75 cases pass
here (66 run, 9 platform-conditioned skips) and `check:fast` passes.
* test(ci): restore verifier and MCP contract regressions
* test(captures): assert adapter-owned input issue field names
* fix(ghidra): avoid Java probes for missing installations
* test(capture): retain final cleanup progress assertions
* fix(artifacts): keep iNES shutdown ownership free of unrelated edits
The doctor readiness fixture and process-capture progress assertions
are not required by descriptor retirement or I/O failure precedence.
Restoring them, and the Ghidra installation test already merged in
#11732, leaves this change on the iNES reader, chunk reader, and
their regressions. The unused artifact chunk helper import is removed.
Co-authored-by: morluto <morluto@users.noreply.github.com>
* test(artifacts): age the iNES header race before same-size rewrites
Identity checks observe mtime, and a same-size overwrite inside one
clock tick is indistinguishable from the original file. The admission
test then reports a format error instead of source integrity. Age the
fixture the same way the prefix race already does.
* test(go): assert truncated Mach-O command tables by typed failure
An unstored oversized command table is a truncated Mach-O load-command
parse, projected as invalid_format. The old message lock named a
sentence the parser no longer produces.
Co-authored-by: morluto <morluto@users.noreply.github.com>
* test(artifacts): fold the paused iNES inventory close into the existing case
The standalone close test repeated the paused entries() refusal already
covered by the close/cancel pair. The borrowed-descriptor stat stays on
that close case.
Co-authored-by: morluto <morluto@users.noreply.github.com>
* fix(artifacts): preserve first iNES stream interruption
---------
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
Co-authored-by: g0at <50488370+g1at@users.noreply.github.com>
Co-authored-by: IvenKooLab <276572622@qq.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
123 lines
4.3 KiB
TypeScript
123 lines
4.3 KiB
TypeScript
import type { FileHandle } from "node:fs/promises";
|
|
import { Readable } from "node:stream";
|
|
|
|
/** Cancellation observed by the descriptor read, retaining the caller's exact reason. */
|
|
export class FileReadCancelled extends Error {
|
|
constructor(readonly reason: unknown) {
|
|
super("File read cancelled", { cause: reason });
|
|
this.name = "FileReadCancelled";
|
|
}
|
|
}
|
|
|
|
export interface FileHandleChunkOptions {
|
|
readonly start?: number | bigint;
|
|
readonly end?: number | bigint;
|
|
readonly signal?: AbortSignal | undefined;
|
|
readonly cancellationFailure?: (reason: unknown) => Error;
|
|
}
|
|
|
|
/** Physical descriptor coverage is separate from delivery of buffered stream bytes. */
|
|
export type FileHandleReadCoverage =
|
|
| { readonly kind: "incomplete"; readonly bytes: bigint }
|
|
| {
|
|
readonly kind: "complete";
|
|
readonly bytes: bigint;
|
|
readonly boundary: "eof" | "range";
|
|
};
|
|
|
|
export type FileHandleChunkStream = Readable & {
|
|
readCoverage(): FileHandleReadCoverage;
|
|
};
|
|
|
|
/** Stream positional reads while leaving descriptor cleanup to its owner. */
|
|
export const readFileHandleChunks = (
|
|
handle: Pick<FileHandle, "read">,
|
|
options: FileHandleChunkOptions = {},
|
|
): FileHandleChunkStream => {
|
|
const start = fileOffset(options.start ?? 0);
|
|
const unlimited = options.end === undefined || options.end === Infinity;
|
|
const end = unlimited ? undefined : fileOffset(options.end);
|
|
if (
|
|
start === undefined ||
|
|
(!unlimited && end === undefined) ||
|
|
(end !== undefined && end < start)
|
|
)
|
|
throw new RangeError("Invalid file read range");
|
|
let readState: "idle" | "pending" | "failed" = "idle";
|
|
let totalBytes = 0n;
|
|
let coverage:
|
|
| Extract<FileHandleReadCoverage, { kind: "complete" }>
|
|
| undefined;
|
|
const cancellationFailure = (): Error =>
|
|
options.cancellationFailure?.(options.signal?.reason) ??
|
|
new FileReadCancelled(options.signal?.reason);
|
|
const assertActive = (): void => {
|
|
if (options.signal?.aborted) throw cancellationFailure();
|
|
};
|
|
const source = Readable.from(
|
|
(async function* () {
|
|
let position = start;
|
|
while (end === undefined || position <= end) {
|
|
assertActive();
|
|
const remaining = end === undefined ? undefined : end - position + 1n;
|
|
const chunk = Buffer.allocUnsafe(
|
|
remaining === undefined || remaining > 64n * 1024n
|
|
? 64 * 1024
|
|
: Number(remaining),
|
|
);
|
|
readState = "pending";
|
|
let bytesRead: number;
|
|
try {
|
|
({ bytesRead } = await handle.read(chunk, 0, chunk.length, position));
|
|
readState = "idle";
|
|
} catch (cause: unknown) {
|
|
// The generator's rejection still has to reach Readable.from. Keep
|
|
// it primary while cancellation races that asynchronous forwarding.
|
|
readState = "failed";
|
|
throw cause;
|
|
}
|
|
totalBytes += BigInt(bytesRead);
|
|
if (bytesRead === 0)
|
|
coverage = Object.freeze({
|
|
kind: "complete",
|
|
bytes: totalBytes,
|
|
boundary: "eof",
|
|
});
|
|
else if (end !== undefined && position + BigInt(bytesRead) > end)
|
|
coverage = Object.freeze({
|
|
kind: "complete",
|
|
bytes: totalBytes,
|
|
boundary: "range",
|
|
});
|
|
assertActive();
|
|
if (bytesRead === 0) return;
|
|
position += BigInt(bytesRead);
|
|
yield chunk.subarray(0, bytesRead);
|
|
}
|
|
})(),
|
|
{
|
|
objectMode: false,
|
|
},
|
|
);
|
|
const onAbort = (): void => {
|
|
// A native descriptor read cannot be interrupted. Its rejection remains
|
|
// primary; a fulfilled read observes cancellation before yielding bytes.
|
|
if (readState === "idle" && !source.destroyed)
|
|
source.destroy(cancellationFailure());
|
|
};
|
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
source.once("close", () =>
|
|
options.signal?.removeEventListener("abort", onAbort),
|
|
);
|
|
if (options.signal?.aborted) onAbort();
|
|
return Object.assign(source, {
|
|
readCoverage: (): FileHandleReadCoverage =>
|
|
coverage ?? Object.freeze({ kind: "incomplete", bytes: totalBytes }),
|
|
});
|
|
};
|
|
|
|
const fileOffset = (value: number | bigint): bigint | undefined => {
|
|
if (typeof value === "bigint") return value >= 0n ? value : undefined;
|
|
return Number.isSafeInteger(value) && value >= 0 ? BigInt(value) : undefined;
|
|
};
|