mirror of
https://github.com/morluto/rea.git
synced 2026-11-08 07:46:28 +00:00
Classify a native method-93 decoder window refusal once at the ZIP owner as limit/memory, retaining the fixed 128 MiB cap, native cause and existing corruption/CRC/size/cancellation handling. Derive recovery labels from the cap and share one independent frame fixture. Validated with 43 reader/translationtests,three actual CLI/stdio MCP cases, a pinned public GLFW payload rewrapped in independently verified ZIP controls, six equivalent CLI calls before/after, static checks and documentation checks. All input bytes remain unchanged, normal extraction matches exactly, and failed outputs are absent. ELF/GPU component refusal-policy gaps remain separate unverified full-format workflows. The original three unchecked human declarations are preserved. The explicitly authorized readiness-only exception applies after technical CI and review; no human-review attestation is added. Fixes #8623 Full technical CI 42279406899 passes, including all eight shards and required aggregates. Greptile reviews this head at 5/5; Codex cannot complete because the repository review quota is exhausted. The Author readiness-only exception is explicitly authorized; no human-review attestation is added. Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
121 lines
4.3 KiB
TypeScript
121 lines
4.3 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { access, readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
|
|
import { parseEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import {
|
|
zstandardWindowFrameFixture,
|
|
zstandardZipFixture,
|
|
} from "../../fixtures/zipZstandard.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const expectRefusal = (diagnostic: unknown, large: boolean): void => {
|
|
expect(diagnostic).toMatchObject({
|
|
code: large ? "truncated" : "artifact_operation_failed",
|
|
details: {
|
|
reason: large ? "limit" : "format",
|
|
...(large ? { boundary: "memory", truncated: true } : {}),
|
|
},
|
|
});
|
|
if (large) {
|
|
expect(diagnostic).toMatchObject({
|
|
message: expect.stringContaining("fixed 128 MiB allowance"),
|
|
remediation: {
|
|
action: expect.stringContaining("cannot be raised at runtime"),
|
|
},
|
|
});
|
|
expect(JSON.stringify(diagnostic)).not.toContain("fresh copy");
|
|
}
|
|
};
|
|
|
|
cliTest.for(["small", "large", "corrupt"] as const)(
|
|
"preserves ZIP window classification over CLI and stdio MCP: %s",
|
|
async (kind, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-zstd-window-");
|
|
const path = join(root, "fixture.zip");
|
|
const { content, compressed } = zstandardWindowFrameFixture(
|
|
kind === "large" ? 0x90 : 0x50,
|
|
);
|
|
if (kind === "corrupt") compressed[0] = 0;
|
|
const bytes = zstandardZipFixture(content, { compressed });
|
|
await writeFile(path, bytes);
|
|
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
const success = kind === "small";
|
|
const evidencePath = join(root, "inventory.json");
|
|
for (const operation of ["inspect-artifact", "extract-artifact"] as const) {
|
|
const outputRoot = join(root, `cli-${operation}`);
|
|
const reply = await cli.run({
|
|
arguments: [
|
|
operation,
|
|
path,
|
|
"--json",
|
|
...(operation === "inspect-artifact"
|
|
? ["--detail", "summary", "--evidence_output", evidencePath]
|
|
: ["--output-root", outputRoot]),
|
|
],
|
|
});
|
|
expect(reply.exitCode, reply.stderr).toBe(success ? 0 : 1);
|
|
if (!success) expectRefusal(reply.json, kind === "large");
|
|
else if (operation === "extract-artifact")
|
|
expect(
|
|
(await readFile(join(outputRoot, "member.txt"))).equals(content),
|
|
).toBe(true);
|
|
else {
|
|
const bundle = parseEvidenceBundle(
|
|
JSON.parse(await readFile(evidencePath, "utf8")),
|
|
);
|
|
expect(bundle.records).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
subject: expect.objectContaining({
|
|
digest: expect.objectContaining({ sha256 }),
|
|
}),
|
|
}),
|
|
]),
|
|
);
|
|
}
|
|
if (!success && operation === "extract-artifact")
|
|
await expect(access(outputRoot)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
}
|
|
|
|
const call = await cli.sharedMcpCall!();
|
|
const opened = await call("open_binary", { path });
|
|
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
|
try {
|
|
for (const operation of [
|
|
"inspect_artifact",
|
|
"extract_artifact",
|
|
] as const) {
|
|
const outputRoot = join(root, `mcp-${operation}`);
|
|
const reply = await call(
|
|
operation,
|
|
operation === "inspect_artifact"
|
|
? { detail: "summary" }
|
|
: { output_root: outputRoot },
|
|
);
|
|
if (!success) {
|
|
expectRefusal(parseMcpToolError(reply).error, kind === "large");
|
|
if (operation === "extract_artifact")
|
|
await expect(access(outputRoot)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
} else {
|
|
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
|
if (operation === "extract_artifact")
|
|
expect(
|
|
(await readFile(join(outputRoot, "member.txt"))).equals(content),
|
|
).toBe(true);
|
|
}
|
|
}
|
|
} finally {
|
|
expect((await call("close_binary", {})).isError).not.toBe(true);
|
|
}
|
|
expect((await readFile(path)).equals(bytes)).toBe(true);
|
|
},
|
|
);
|