mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* feat(flutter): carry the value of each fixed Flutter allowance Each Flutter fixed allowance now passes limit and unit, so details.refusal states the ceiling. The ABI inventory refusal names the ceiling that was exceeded: the ABI count or the library path bytes. * fix(artifacts): name the ZIP decoder window ceiling in Flutter and trace refusals A Zstandard member whose window exceeds the ZIP reader's fixed 128 MiB allowance now carries that ceiling as a typed fixed allowance (limit, unit, and the recompression narrowing). Flutter reported any ZIP reader limit as its APK metadata read allowance, and Playwright trace import as a recorder-chunk limit; both now keep the reader's ceiling. * fix(flutter): report the APK expansion ceiling and keep JNI recompression advice A ZIP reader limit with a reader-owned parameter (the size-derived expansion budget) is no longer reported as the Flutter metadata read allowance; Flutter exposes no control for it, so it is a fixed ceiling with the reader's effective value. The JNI library failure message carries the reader-named ceiling's narrowing, since that report has no refusal field. * test(artifacts): compare decoder-window advice with its owning ceiling
138 lines
5.0 KiB
TypeScript
138 lines
5.0 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";
|
|
import { analysisRefusalRemediation } from "../../../src/domain/analysisRefusal.js";
|
|
import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../src/resources/ZipArtifactReader.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"),
|
|
details: {
|
|
refusal: {
|
|
kind: "fixed_ceiling",
|
|
allowance: ZIP_ZSTANDARD_WINDOW_CEILING.name,
|
|
limit: 2 ** 27,
|
|
unit: "bytes",
|
|
narrowing: ZIP_ZSTANDARD_WINDOW_CEILING.narrowing,
|
|
},
|
|
},
|
|
// The recovery is the reader's ceiling through the refusal formatter.
|
|
remediation: {
|
|
action: analysisRefusalRemediation({
|
|
kind: "fixed_ceiling",
|
|
operation: (diagnostic as { details: { operation: string } }).details
|
|
.operation,
|
|
ceiling: ZIP_ZSTANDARD_WINDOW_CEILING,
|
|
}),
|
|
},
|
|
});
|
|
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({
|
|
identity: 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);
|
|
},
|
|
);
|