mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
* fix(artifacts)!: report reader admission limits as resource_constraint An artifact read refused by a reader limit (artifact_limits.*) or a release-fixed allowance was code partial, which the error contract reserves for a result cut short by a delivery or decode limit. The read was refused at admission, so it is now resource_constraint, like every other admission limit. The retry class is unchanged: change_first when the limit can be raised, never when it cannot. A limit without admission facts, such as a parser budget, stays partial. The reader's own recovery, which names the parameter, its supported range and the next step, and the reader_limit fact are unchanged. Refs #15323 BREAKING CHANGE: artifact refusals with details.reason "limit" and a details.reader_limit or fixed allowance report code and category resource_constraint instead of partial. Match resource_constraint, or read details.reason and details.reader_limit, which are unchanged. * fix(errors): catalogue each artifact admission limit with the retry it returns The catalogue listed one row for reader limits and fixed allowances with change_first, though a fixed allowance and a reader limit already at its maximum return never, and the release-fixed row still said partial. List the raisable reader limit, the reader limit at its maximum and the release-fixed allowance as separate rows, and test each row against the error it projects.
124 lines
4.8 KiB
TypeScript
124 lines
4.8 KiB
TypeScript
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { artifactInspectionResultSchema } from "../../../src/domain/artifactInspection.js";
|
|
import { artifactExtractionResultSchema } from "../../../src/domain/artifactGraph.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { fileLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
import {
|
|
MIXED_ANDROID_SPARSE_EXPANDED,
|
|
buildAndroidSparseImage,
|
|
mixedAndroidSparseImage,
|
|
} from "../../../src/domain/firmware/androidSparseImage.fixture.js";
|
|
|
|
const mcp = fileLocalToolsMcp({
|
|
REA_MCP_TOOL_FAMILIES: "session,artifact",
|
|
REA_MCP_INPUT_SCHEMA_PROFILE: "compact",
|
|
REA_MCP_OUTPUT_SCHEMA_PROFILE: "compact",
|
|
});
|
|
|
|
it("retains Android sparse image facts through compiled MCP", async () => {
|
|
const root = await createTestTempDirectory("rea-android-sparse-mcp-");
|
|
const path = join(root, "system.img");
|
|
await writeFile(path, mixedAndroidSparseImage());
|
|
const { call } = mcp;
|
|
let outputRoot: string | undefined;
|
|
try {
|
|
const opened = await call("open_binary", { path });
|
|
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
|
expect(opened.structuredContent).toMatchObject({
|
|
result: {
|
|
kind: "archive",
|
|
format: "android-sparse-image",
|
|
architecture: null,
|
|
},
|
|
});
|
|
const reply = await call("inspect_artifact", {});
|
|
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
|
const inspection = artifactInspectionResultSchema.parse(
|
|
parseEvidence(reply.structuredContent).normalized_result,
|
|
);
|
|
const inventory = inspection.substeps[0]!.evidence.normalized_result;
|
|
expect(inventory.coverage.status).toBe("complete");
|
|
expect(inventory.occurrences).toContainEqual(
|
|
expect.objectContaining({
|
|
logical_path: ".",
|
|
format_metadata: expect.objectContaining({
|
|
kind: "android-sparse-image",
|
|
expanded_size: 16,
|
|
checksums_verified: false,
|
|
}),
|
|
}),
|
|
);
|
|
const extracted = await call("extract_artifact", {});
|
|
expect(extracted.isError, JSON.stringify(extracted)).not.toBe(true);
|
|
const result = artifactExtractionResultSchema.parse(
|
|
parseEvidence(extracted.structuredContent).normalized_result,
|
|
);
|
|
outputRoot = result.output_root;
|
|
expect(result.containment_verified).toBe(true);
|
|
expect(
|
|
(await readFile(join(result.output_root, "image.raw"))).equals(
|
|
MIXED_ANDROID_SPARSE_EXPANDED,
|
|
),
|
|
).toBe(true);
|
|
} finally {
|
|
if (outputRoot !== undefined) await rm(outputRoot, { recursive: true });
|
|
}
|
|
});
|
|
|
|
it("refuses a major version 2 sparse image through compiled MCP open_binary", async () => {
|
|
const root = await createTestTempDirectory("rea-android-sparse-mcp-v2-");
|
|
const path = join(root, "system.img");
|
|
await writeFile(path, buildAndroidSparseImage({ majorVersion: 2 }));
|
|
const { call } = mcp;
|
|
const opened = await call("open_binary", { path });
|
|
expect(opened.isError).toBe(true);
|
|
expect(JSON.stringify(opened)).toContain("unsupported");
|
|
});
|
|
|
|
it("refuses a chunk table above the selected budget and admits it on retry through compiled MCP", async () => {
|
|
const root = await createTestTempDirectory("rea-android-sparse-mcp-chunks-");
|
|
const path = join(root, "system.img");
|
|
await writeFile(path, mixedAndroidSparseImage());
|
|
const { call } = mcp;
|
|
const opened = await call("open_binary", { path });
|
|
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
|
const refused = await call("inspect_artifact", {
|
|
artifact_limits: { android_sparse_image: { chunk_count: 3 } },
|
|
});
|
|
expect(parseMcpToolError(refused).error).toMatchObject({
|
|
code: "resource_constraint",
|
|
retryable: false,
|
|
details: {
|
|
reader_limit: {
|
|
parameter: "artifact_limits.android_sparse_image.chunk_count",
|
|
effective_value: 3,
|
|
unit: "count",
|
|
required_value: 4,
|
|
can_increase: true,
|
|
update_mode: "parameter",
|
|
},
|
|
},
|
|
});
|
|
const selected = { android_sparse_image: { chunk_count: 4 } };
|
|
const reply = await call("inspect_artifact", { artifact_limits: selected });
|
|
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
|
const evidence = parseEvidence(reply.structuredContent);
|
|
const inspection = artifactInspectionResultSchema.parse(
|
|
evidence.normalized_result,
|
|
);
|
|
const inventory = inspection.substeps[0]!.evidence.normalized_result;
|
|
expect(inventory.coverage.status).toBe("complete");
|
|
expect(inventory.effective_limits).toMatchObject(selected);
|
|
expect(inventory.occurrences).toContainEqual(
|
|
expect.objectContaining({
|
|
logical_path: ".",
|
|
format_metadata: expect.objectContaining({ total_chunks: 4 }),
|
|
}),
|
|
);
|
|
});
|