chore: sync branch with latest main
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { mkdir, readdir, readFile, symlink, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
mkdir,
|
||||
readdir,
|
||||
readFile,
|
||||
stat,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -12,6 +19,7 @@ import {
|
||||
import { compareEvidenceBundlesCommand } from "../../../src/application/EvidenceBundleCommands.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import { writeTextParts } from "../../../src/application/JsonFiles.js";
|
||||
import {
|
||||
createEvidenceBundle,
|
||||
serializeEvidenceBundle,
|
||||
@@ -27,6 +35,39 @@ const bundle = (result = true) =>
|
||||
]);
|
||||
|
||||
describe("evidence bundle publication", () => {
|
||||
it.each([false, true])(
|
||||
"never publishes a partial streamed file (overwrite: %s)",
|
||||
async (overwrite) => {
|
||||
const root = await createTestTempDirectory("rea-stream-publication-");
|
||||
const path = join(root, "bundle.json");
|
||||
if (overwrite) await writeFile(path, "original");
|
||||
function* brokenParts() {
|
||||
yield "partial";
|
||||
throw new Error("Source stream failed");
|
||||
}
|
||||
expect(
|
||||
await writeTextParts(brokenParts(), path, overwrite),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "EvidenceFileError", reason: "io" },
|
||||
});
|
||||
expect(await readdir(root)).toEqual(overwrite ? ["bundle.json"] : []);
|
||||
if (overwrite) expect(await readFile(path, "utf8")).toBe("original");
|
||||
},
|
||||
);
|
||||
|
||||
it("counts complete Unicode bytes and publishes a private file", async () => {
|
||||
const root = await createTestTempDirectory("rea-stream-bytes-");
|
||||
const path = join(root, "bundle.json");
|
||||
const parts = ["雪", "😀", "\n"];
|
||||
expect(await writeTextParts(parts, path, false)).toEqual({
|
||||
ok: true,
|
||||
value: { path, bytes: Buffer.byteLength(parts.join("")) },
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe(parts.join(""));
|
||||
if (process.platform !== "win32")
|
||||
expect((await stat(path)).mode & 0o777).toBe(0o600);
|
||||
});
|
||||
it("allows only one simultaneous export without overwrite approval", async () => {
|
||||
const root = await createTestTempDirectory("rea-evidence-exclusive-");
|
||||
const path = join(root, "bundle.json");
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
||||
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { toCallToolResult } from "../../../src/server/toolResult.js";
|
||||
import { EvidenceLedger } from "../../../src/application/investigation/EvidenceLedger.js";
|
||||
|
||||
describe("large complete Evidence MCP delivery", () => {
|
||||
it("preserves retained content and returns an actionable framing constraint", () => {
|
||||
const normalized = {
|
||||
payload: "x".repeat(Math.ceil(STDIO_DEFAULT_MAX_BUFFER_SIZE / 3)),
|
||||
};
|
||||
const evidence = createEvidence(
|
||||
undefined,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
operation: "analyze_javascript_application",
|
||||
parameters: {},
|
||||
result: normalized,
|
||||
},
|
||||
);
|
||||
const ledger = new EvidenceLedger();
|
||||
expect(ledger.record(evidence).ok).toBe(true);
|
||||
const result = toCallToolResult(
|
||||
ok(evidence),
|
||||
toolContract("analyze_javascript_application"),
|
||||
{ retainedEvidenceId: evidence.evidence_id },
|
||||
);
|
||||
expect(result.isError).toBe(true);
|
||||
expect(result.structuredContent).toMatchObject({
|
||||
error: {
|
||||
code: "resource_constraint",
|
||||
category: "resource_constraint",
|
||||
details: {
|
||||
resource: "transport",
|
||||
reported_limits: {
|
||||
boundary: "mcp-response",
|
||||
constraint: "receive-buffer",
|
||||
evidence_reference: {
|
||||
kind: "retained-evidence",
|
||||
evidence_id: evidence.evidence_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(Buffer.byteLength(JSON.stringify(result))).toBeLessThan(
|
||||
STDIO_DEFAULT_MAX_BUFFER_SIZE,
|
||||
);
|
||||
expect(result.content).toEqual([
|
||||
{ type: "text", text: JSON.stringify(result.structuredContent) },
|
||||
]);
|
||||
const retained = ledger.get(evidence.evidence_id);
|
||||
expect(parseEvidence(retained)).toEqual(evidence);
|
||||
expect(retained?.normalized_result).toEqual(normalized);
|
||||
const detached = toCallToolResult(
|
||||
ok(evidence),
|
||||
toolContract("analyze_javascript_application"),
|
||||
);
|
||||
expect(detached.structuredContent).toMatchObject({
|
||||
error: {
|
||||
details: { reported_limits: { evidence_id: evidence.evidence_id } },
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(detached)).not.toContain("retained-evidence");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { STDIO_DEFAULT_MAX_BUFFER_SIZE } from "@modelcontextprotocol/server";
|
||||
|
||||
import { parseMcpResponseBudget } from "../../../src/config/mcpResponseBudget.js";
|
||||
|
||||
describe("MCP response budget configuration", () => {
|
||||
it("leaves the default policy to the MCP adapter", () => {
|
||||
expect(parseMcpResponseBudget(undefined)).toEqual({
|
||||
ok: true,
|
||||
value: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("requires the override to accommodate the pinned transport's default frames", () => {
|
||||
expect(
|
||||
parseMcpResponseBudget(String(STDIO_DEFAULT_MAX_BUFFER_SIZE)).ok,
|
||||
).toBe(true);
|
||||
expect(
|
||||
parseMcpResponseBudget(String(STDIO_DEFAULT_MAX_BUFFER_SIZE - 1)).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it.each(["10485760", "268435456", "1073741824"])(
|
||||
"accepts an explicit complete-response budget: %s",
|
||||
(value) => {
|
||||
expect(parseMcpResponseBudget(value)).toEqual({
|
||||
ok: true,
|
||||
value: Number(value),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"",
|
||||
"0",
|
||||
"-1",
|
||||
"1024",
|
||||
"1.5",
|
||||
"1e8",
|
||||
" 10485760",
|
||||
"Infinity",
|
||||
"9007199254740992",
|
||||
])("rejects malformed or unusable budgets: %j", (value) => {
|
||||
const parsed = parseMcpResponseBudget(value);
|
||||
expect(parsed.ok).toBe(false);
|
||||
if (parsed.ok) throw new Error("Expected invalid budget");
|
||||
expect(parsed.error.message).toContain("REA_MCP_MAX_RESPONSE_BYTES");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user