diff --git a/src/lib/domain.ts b/src/lib/domain.ts index 535e9f5..606c4da 100644 --- a/src/lib/domain.ts +++ b/src/lib/domain.ts @@ -84,7 +84,7 @@ export type DecisionInput = { const PARCEL_SCOPED_KINDS: Readonly> = { "courier.progress": true, "customer.dispute": true, - "support.proof": false, + "support.proof": true, "support.dispute_cleared": true, }; diff --git a/tests/core/event-audit.native.ts b/tests/core/event-audit.native.ts index 406bb46..b647322 100644 --- a/tests/core/event-audit.native.ts +++ b/tests/core/event-audit.native.ts @@ -240,3 +240,86 @@ test("unknown and incomplete envelopes are refused with typed errors, not stored handle.close(); } }); + +test("a proof with no parcel target is a typed rejection that changes nothing", () => { + const handle = freshDatabase("core-proof-no-parcel"); + try { + const before = loadCaseSnapshot(handle, HERO); + assert.ok(before !== null); + const chargerBefore = before.parcels.find((parcel) => parcel.id === CHARGER); + assert.ok(chargerBefore !== undefined); + + const proofBase = { + caseId: HERO, + kind: "support.proof" as const, + occurredAt: "2026-10-14T16:00:00.000Z", + receivedAt: "2026-10-14T16:00:30.000Z", + providerRevision: null, + payload: { evidenceRef: "core-proof-no-parcel" }, + }; + + const missing = policy.ingestEvent(handle, { + ...proofBase, + providerEventId: "core-proof-null-1", + parcelId: null, + }); + assert.ok( + "error" in missing, + `a proof without a parcel target must be a typed rejection, got ${JSON.stringify(missing)}`, + ); + assert.equal(missing.error, "parcel_required"); + + const foreign = policy.ingestEvent(handle, { + ...proofBase, + providerEventId: "core-proof-foreign-1", + parcelId: "parcel-1055-headphones", + }); + assert.ok( + "error" in foreign, + `a proof aimed at another case's parcel must be refused, got ${JSON.stringify(foreign)}`, + ); + assert.equal(foreign.error, "parcel_not_found"); + + const after = loadCaseSnapshot(handle, HERO); + assert.ok(after !== null); + assert.equal(after.case.revision, before.case.revision, "a refused proof must not move the case revision"); + assert.equal(after.evidence.length, before.evidence.length, "a refused proof must not enter the audit"); + const chargerAfter = after.parcels.find((parcel) => parcel.id === CHARGER); + assert.equal( + chargerAfter?.receivedProofAt, + chargerBefore.receivedProofAt, + "a refused proof must not touch the parcel projection", + ); + assert.equal(after.case.disputeOpen, true, "a refused proof must not clear the open dispute"); + + const applied = policy.ingestEvent(handle, { + ...proofBase, + providerEventId: "core-proof-valid-1", + parcelId: CHARGER, + }); + assert.ok("outcome" in applied, `a targeted proof must still apply, got ${JSON.stringify(applied)}`); + assert.equal(applied.outcome, "applied"); + const afterValid = loadCaseSnapshot(handle, HERO); + assert.ok(afterValid !== null); + assert.equal(afterValid.case.disputeOpen, true, "proof is evidence, never an implicit dispute clearance"); + + const replay = policy.ingestEvent(handle, { + ...proofBase, + providerEventId: "core-proof-valid-1", + parcelId: CHARGER, + }); + assert.ok("outcome" in replay, `a repeated proof must replay its original receipt, got ${JSON.stringify(replay)}`); + assert.equal(replay.outcome, "duplicate"); + + const conflict = policy.ingestEvent(handle, { + ...proofBase, + providerEventId: "core-proof-valid-1", + parcelId: CHARGER, + payload: { evidenceRef: "core-proof-valid-1-changed" }, + }); + assert.ok("error" in conflict, `a changed proof payload must conflict, got ${JSON.stringify(conflict)}`); + assert.equal(conflict.error, "event_id_payload_conflict"); + } finally { + handle.close(); + } +});