fix(mcp): retain complete application results across response limits

Retain complete authenticated application Evidence when the repeated MCP representation exceeds the default receive frame or Node string limit. Return a typed transport constraint, keep useful followup queries available, and stream full canonical bundles to atomic destinations.

Verify complete Notion and Obsidian workflows on Linux and native Windows, full CLI/Evidence parity, and real large Chrome screenshot recovery. Preserve complete success contracts and caller-selected evidence paths.

Refs #1065, #1053.
This commit is contained in:
Ysopwnable
2026-10-08 23:46:02 +08:00
committed by GitHub
parent c701376777
commit a1ed4232de
43 changed files with 1314 additions and 186 deletions
+92 -2
View File
@@ -3,9 +3,15 @@ import { describe, expect } from "vitest";
import { createAnalysisProfile } from "./analysisProfile.js";
import type { BinaryTarget } from "./binaryTarget.js";
import { createEvidence, evidenceSchema, parseEvidence } from "./evidence.js";
import { MAX_JSON_DEPTH } from "./jsonValue.js";
import {
createEvidence,
evidenceRecordSchema,
evidenceSchema,
parseEvidence,
} from "./evidence.js";
import { MAX_JSON_DEPTH, type JsonValue } from "./jsonValue.js";
import { createEvidenceBundle } from "./evidenceBundle.js";
import { freezeJsonSnapshot } from "./immutableJson.js";
const TARGET: BinaryTarget = {
path: "/tmp/fixture",
@@ -18,6 +24,90 @@ const TARGET: BinaryTarget = {
const PROVIDER = { id: "fixture", name: "Fixture provider", version: "1" };
const PROFILE = createAnalysisProfile(PROVIDER, { loader: "default" });
it("preserves identity and bytes when reusing an owned immutable result", () => {
const value = { nested: { values: ["observed", 1] } };
const mutable = createEvidence(TARGET, PROVIDER, {
operation: "inspect",
parameters: {},
result: value,
});
const frozen = createEvidence(TARGET, PROVIDER, {
operation: "inspect",
parameters: {},
result: freezeJsonSnapshot(value),
});
expect(JSON.stringify(frozen)).toBe(JSON.stringify(mutable));
expect(frozen.normalized_result).toBe(value);
expect(Object.isFrozen(frozen)).toBe(true);
expect(parseEvidence(frozen)).toEqual(mutable);
const wire: unknown = JSON.parse(JSON.stringify(frozen));
expect(parseEvidence(wire)).toEqual(mutable);
expect(() =>
parseEvidence({ ...frozen, normalized_result: { changed: true } }),
).toThrow("semantic identifier");
});
it("applies the JSON depth boundary to owned immutable results", () => {
let result: JsonValue = 1;
for (let index = 0; index <= MAX_JSON_DEPTH; index += 1)
result = { nested: result };
const observe = () =>
createEvidence(TARGET, PROVIDER, {
operation: "inspect",
parameters: {},
result,
});
expect(observe).toThrow("maximum nesting depth");
freezeJsonSnapshot(result);
expect(observe).toThrow("maximum nesting depth");
});
it("preserves prototype-named own members when reusing an owned result", () => {
const result = { ["__proto__"]: { preserved: 7 }, constructor: "ordinary" };
const observation = { operation: "inspect", parameters: {}, result };
const ordinary = createEvidence(TARGET, PROVIDER, observation);
const owned = createEvidence(TARGET, PROVIDER, {
...observation,
result: freezeJsonSnapshot(result),
});
expect(owned.normalized_result).toBe(result);
expect(owned).toEqual(ordinary);
expect(parseEvidence(JSON.parse(JSON.stringify(owned)))).toEqual(owned);
expect(Object.getPrototypeOf(owned.normalized_result)).toBe(Object.prototype);
expect(Reflect.get(Object.prototype, "preserved")).toBeUndefined();
});
it("preserves producer envelope admission and profile validation", () => {
const legacy = createEvidence(TARGET, PROVIDER, {
operation: "inspect",
parameters: {},
result: { observed: [1, 2, 3] },
});
const profiled = createEvidence(TARGET, PROVIDER, {
operation: "inspect",
parameters: {},
result: { observed: [1, 2, 3] },
analysisProfile: PROFILE,
});
const candidates: unknown[] = [
legacy,
profiled,
{ ...legacy, analysis_profile: undefined },
{ ...legacy, analysis_profile: null },
{
...profiled,
analysis_profile: { ...PROFILE, provider: { ...PROVIDER, id: "other" } },
},
{ ...legacy, unexpected: true },
];
for (const candidate of candidates) {
const canonical = evidenceRecordSchema.safeParse(candidate);
if (canonical.success)
expect(parseEvidence(candidate)).toEqual(canonical.data);
else expect(() => parseEvidence(candidate)).toThrow();
}
});
it("snapshots caller-owned payloads before deriving their identity", () => {
const result = { nested: { values: ["observed"] } };
const rawResult = { entries: [{ value: "raw" }] };