fix(io): retain cleanup ownership and honor cancellation

Keep failed JSON read handles in the existing server resource scope and fail admission until cleanup succeeds. Thread cancellation through every process CLI input read and replace timer-driven cancellation checks with a shared first-read gate.

Classify authenticated standalone Evidence as wrong-kind input while preserving tampered-record integrity failures and actionable messages across ledger, CLI, and MCP consumers. Record unrelated CS_RESTRICT process neighbors as unverified without weakening related-process ownership checks. Update stale ADB fixtures for the actual shell protocol.

Validated focused CLI, MCP, filesystem, ownership, and error projection tests; static, docs, and duplication gates pass. The host-level CS_RESTRICT load reproduction was not run. Refs #2050, #2035, #2064.
This commit is contained in:
morluto
2026-10-12 14:12:44 +08:00
parent e4532b5376
commit d8c76b6296
32 changed files with 1007 additions and 318 deletions
@@ -434,21 +434,8 @@ describe("evidence bundle filesystem adapter", () => {
},
);
it("names the failed bundle constraint for a single record or schema mismatch", async () => {
it("names schema mismatches that prevent bundle parsing", async () => {
const directory = await createTestTempDirectory("rea-evidence-");
const record = bundle().records[0];
const single = join(directory, "record.json");
await writeFile(single, JSON.stringify(record));
expect(await readEvidenceBundle(single)).toMatchObject({
ok: false,
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
`this JSON is one Evidence record (${String(record?.evidence_id)})`,
),
},
});
const partial = join(directory, "partial.json");
await writeFile(partial, JSON.stringify({ evidence_id: "typo" }));
const rejected = await readEvidenceBundle(partial);
@@ -477,3 +464,38 @@ describe("evidence bundle filesystem adapter", () => {
});
});
});
describe("standalone Evidence bundle inputs", () => {
it("classifies a record only after authenticating it", async () => {
const directory = await createTestTempDirectory("rea-evidence-");
const record = bundle().records[0];
const single = join(directory, "record.json");
await writeFile(single, JSON.stringify(record));
expect(await readEvidenceBundle(single)).toMatchObject({
ok: false,
error: {
_tag: "EvidenceFileError",
reason: "wrong-kind",
path: single,
userMessage: expect.stringContaining(
`this JSON is one Evidence record (${String(record?.evidence_id)})`,
),
},
});
const tamperedRecord = join(directory, "tampered-record.json");
await writeFile(
tamperedRecord,
JSON.stringify({ ...record, normalized_result: "changed" }),
);
expect(await readEvidenceBundle(tamperedRecord)).toMatchObject({
ok: false,
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
"does not match the bundle schema",
),
},
});
});
});