fix(evidence): validate closure projections and browser body coverage

Share ledger status, coverage, reports, graphs, Evidence links and closure commitments between the producer and readiness validation. Preserve limitation-driven unknown results and reject stale or inconsistent projections.

Distinguish malformed CDP response envelopes from unavailable JSON payload shapes. Validate required encoding flags and preserve partial request facts.

Validation: 116 focused tests, static and architecture checks, documentation checks. Browser regression coverage uses controlled CDP responses.
This commit is contained in:
morluto
2026-10-12 08:59:14 +08:00
parent f889a69fb9
commit aada0ca812
11 changed files with 955 additions and 411 deletions
@@ -131,6 +131,178 @@ it("preserves unavailable response observations and captures completed peers", a
).toEqual(["missing-body", "available"]);
});
it("marks malformed JSON body shapes unavailable while preserving partial request shapes", async () => {
const browser = await startFakeCdpBrowser({
commandEvents(command, origin) {
if (command.method !== "Network.enable") return undefined;
const session =
command.sessionId === undefined ? {} : { sessionId: command.sessionId };
return ["unavailable", "partial"].flatMap((requestId) => {
const url = `${origin}/${requestId}`;
return [
{
...session,
method: "Network.requestWillBeSent",
params: {
requestId,
request: {
url,
method: requestId === "partial" ? "POST" : "GET",
...(requestId === "partial"
? {
headers: { "Content-Type": "application/json" },
postData: '{"request":true}',
}
: {}),
},
initiator: { type: "other" },
},
},
{
...session,
method: "Network.responseReceived",
params: {
requestId,
response: { url, status: 200, mimeType: "application/json" },
},
},
{
...session,
method: "Network.loadingFinished",
params: { requestId, encodedDataLength: 0 },
},
];
});
},
commandResult(command) {
return command.method === "Network.getResponseBody"
? { body: "{", base64Encoded: false }
: undefined;
},
});
trackBrowser(browser);
const result = await new CdpBrowserProvider().inspectPage(
inspectWebPageInputSchema.parse({
cdp_endpoint: browser.endpoint,
allowed_origins: [browser.allowedOrigin],
target_id: "allowed-page",
observation_ms: 20,
include_json_body_shapes: true,
}),
);
if (!result.ok) throw result.error;
expect(result.value.network.requests).toEqual([
expect.objectContaining({
request_id: "unavailable",
body_shapes: { status: "unavailable", request: null, response: null },
}),
expect.objectContaining({
request_id: "partial",
body_shapes: {
status: "partial",
request: expect.any(Object),
response: null,
},
}),
]);
expect(result.value.completeness.unavailable_sections).toContain(
"json_body_shapes",
);
expect(result.value.completeness.excluded).not.toContainEqual(
expect.objectContaining({
section: "json_body_shapes",
reason: "invalid_protocol_value",
}),
);
});
it("rejects malformed response-body envelopes and preserves request shapes", async () => {
const browser = await startFakeCdpBrowser({
commandEvents(command, origin) {
if (command.method !== "Network.enable") return undefined;
const session =
command.sessionId === undefined ? {} : { sessionId: command.sessionId };
return ["missing-encoding-flag", "invalid-encoding-flag"].flatMap(
(requestId) => {
const url = `${origin}/${requestId}`;
return [
{
...session,
method: "Network.requestWillBeSent",
params: {
requestId,
request: {
url,
method:
requestId === "invalid-encoding-flag" ? "POST" : "GET",
...(requestId === "invalid-encoding-flag"
? {
headers: { "Content-Type": "application/json" },
postData: '{"request":true}',
}
: {}),
},
initiator: { type: "other" },
},
},
{
...session,
method: "Network.responseReceived",
params: {
requestId,
response: { url, status: 200, mimeType: "application/json" },
},
},
{
...session,
method: "Network.loadingFinished",
params: { requestId, encodedDataLength: 0 },
},
];
},
);
},
commandResult(command) {
if (command.method !== "Network.getResponseBody") return undefined;
return command.params.requestId === "missing-encoding-flag"
? { body: '{"response":true}' }
: { body: '{"response":true}', base64Encoded: "false" };
},
});
trackBrowser(browser);
const result = await new CdpBrowserProvider().inspectPage(
inspectWebPageInputSchema.parse({
cdp_endpoint: browser.endpoint,
allowed_origins: [browser.allowedOrigin],
target_id: "allowed-page",
observation_ms: 20,
include_json_body_shapes: true,
}),
);
if (!result.ok) throw result.error;
expect(result.value.network.requests).toEqual([
expect.objectContaining({
request_id: "missing-encoding-flag",
body_shapes: { status: "unavailable", request: null, response: null },
}),
expect.objectContaining({
request_id: "invalid-encoding-flag",
body_shapes: {
status: "partial",
request: expect.any(Object),
response: null,
},
}),
]);
expect(result.value.completeness.excluded).toContainEqual({
section: "json_body_shapes",
reason: "invalid_protocol_value",
count: 2,
});
});
it.each([
{
options: {