test: harden decision storage round-trip evidence
This commit is contained in:
@@ -205,6 +205,10 @@ test('decision artifact validator enforces receipt status enum and required fiel
|
||||
const partialMissingBlocked = structuredClone(partialArtifact);
|
||||
partialMissingBlocked.spec.receipt.blocked_actions = [];
|
||||
assert.throws(() => validateDecisionRecordArtifact(partialMissingBlocked), /blocked_actions must be non-empty when delivery_state=partial/);
|
||||
|
||||
const partialMissingIntent = structuredClone(partialArtifact);
|
||||
partialMissingIntent.spec.receipt.enforcement_intent = [];
|
||||
assert.throws(() => validateDecisionRecordArtifact(partialMissingIntent), /enforcement_intent must be non-empty when delivery_state=partial/);
|
||||
});
|
||||
|
||||
test('decision artifact validator rejects unsupported receipt state combinations', () => {
|
||||
@@ -304,6 +308,103 @@ test('file decision store writes and reloads a validated decision artifact insid
|
||||
assert.equal(loaded.artifact.spec.receipt.delivery_state, 'pending_external_send');
|
||||
});
|
||||
|
||||
test('file decision store round-trips failed receipt through write load and consume', async (t) => {
|
||||
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-decision-store-'));
|
||||
t.after(() => fs.rmSync(sandbox, { recursive: true, force: true }));
|
||||
|
||||
const fakeRepoRoot = path.join(sandbox, 'repo');
|
||||
fs.mkdirSync(fakeRepoRoot, { recursive: true });
|
||||
|
||||
const planned = createPlannedDecision();
|
||||
const store = createFileDecisionStore({
|
||||
decisionsDir: path.join(fakeRepoRoot, 'state', 'decisions'),
|
||||
repoRootOverride: fakeRepoRoot,
|
||||
});
|
||||
|
||||
const written = store.write({
|
||||
decision: planned.decision,
|
||||
receipt: {
|
||||
...planned.receipt,
|
||||
status: 'failed',
|
||||
delivery_state: 'failed',
|
||||
notes: [...planned.receipt.notes, 'bridge send failed'],
|
||||
failure_reason: 'bridge_send_failed'
|
||||
},
|
||||
recordedAt: '2026-05-08T04:00:00.000Z',
|
||||
source: {
|
||||
event_id: 'evt_watchdog_failed_001',
|
||||
task_id: 'task-reporting-governance',
|
||||
correlation_id: 'corr-failed-001',
|
||||
},
|
||||
});
|
||||
|
||||
const consumed = store.consume(written.artifactPath, ({ artifact, artifactPath }) => ({
|
||||
artifactPath,
|
||||
receiptStatus: artifact.spec.receipt.status,
|
||||
deliveryState: artifact.spec.receipt.delivery_state,
|
||||
failureReason: artifact.spec.receipt.failure_reason,
|
||||
eventId: artifact.spec.source.event_id,
|
||||
}));
|
||||
|
||||
assert.equal(consumed.receiptStatus, 'failed');
|
||||
assert.equal(consumed.deliveryState, 'failed');
|
||||
assert.equal(consumed.failureReason, 'bridge_send_failed');
|
||||
assert.equal(consumed.eventId, 'evt_watchdog_failed_001');
|
||||
assert.equal(consumed.artifactPath, written.artifactPath);
|
||||
});
|
||||
|
||||
test('file decision store round-trips partial receipt with source linkage through write load and consume', async (t) => {
|
||||
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-decision-store-'));
|
||||
t.after(() => fs.rmSync(sandbox, { recursive: true, force: true }));
|
||||
|
||||
const fakeRepoRoot = path.join(sandbox, 'repo');
|
||||
fs.mkdirSync(fakeRepoRoot, { recursive: true });
|
||||
|
||||
const planned = createPlannedDecision();
|
||||
const store = createFileDecisionStore({
|
||||
decisionsDir: path.join(fakeRepoRoot, 'state', 'decisions'),
|
||||
repoRootOverride: fakeRepoRoot,
|
||||
});
|
||||
|
||||
const partialReceipt = {
|
||||
...planned.receipt,
|
||||
status: 'degraded',
|
||||
delivery_state: 'partial',
|
||||
enforcement_intent: [{ action: 'emit_event', mandatory: true }],
|
||||
blocked_actions: [{ action: 'notify_operator', mandatory: true, reason: 'sender binding unavailable' }],
|
||||
notes: [...planned.receipt.notes, 'event emitted but operator notice still blocked']
|
||||
};
|
||||
|
||||
const written = store.write({
|
||||
decision: planned.decision,
|
||||
receipt: partialReceipt,
|
||||
recordedAt: '2026-05-08T04:00:00.000Z',
|
||||
source: {
|
||||
event_id: 'state/operator-notify-bridge-receipts/notify_abc-partial.json',
|
||||
task_id: 'task-reporting-governance',
|
||||
correlation_id: 'corr-partial-001',
|
||||
},
|
||||
});
|
||||
|
||||
const consumed = store.consume(written.artifactPath, ({ artifact }) => ({
|
||||
taskId: artifact.spec.source.task_id,
|
||||
correlationId: artifact.spec.source.correlation_id,
|
||||
eventId: artifact.spec.source.event_id,
|
||||
receiptStatus: artifact.spec.receipt.status,
|
||||
deliveryState: artifact.spec.receipt.delivery_state,
|
||||
blockedActions: artifact.spec.receipt.blocked_actions,
|
||||
enforcementIntent: artifact.spec.receipt.enforcement_intent,
|
||||
}));
|
||||
|
||||
assert.equal(consumed.taskId, 'task-reporting-governance');
|
||||
assert.equal(consumed.correlationId, 'corr-partial-001');
|
||||
assert.equal(consumed.eventId, 'state/operator-notify-bridge-receipts/notify_abc-partial.json');
|
||||
assert.equal(consumed.receiptStatus, 'degraded');
|
||||
assert.equal(consumed.deliveryState, 'partial');
|
||||
assert.equal(consumed.blockedActions.length, 1);
|
||||
assert.equal(consumed.enforcementIntent.length, 1);
|
||||
});
|
||||
|
||||
test('file decision store load rejects corrupted or malformed artifacts', async (t) => {
|
||||
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-decision-store-'));
|
||||
t.after(() => fs.rmSync(sandbox, { recursive: true, force: true }));
|
||||
@@ -356,6 +457,29 @@ test('file decision store load rejects corrupted or malformed artifacts', async
|
||||
assert.throws(() => store.load(corruptedArtifactPath), /metadata\.recorded_at must be a non-empty string/);
|
||||
});
|
||||
|
||||
test('file decision store consume rejects non-function consumer', async (t) => {
|
||||
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-decision-store-'));
|
||||
t.after(() => fs.rmSync(sandbox, { recursive: true, force: true }));
|
||||
|
||||
const fakeRepoRoot = path.join(sandbox, 'repo');
|
||||
fs.mkdirSync(fakeRepoRoot, { recursive: true });
|
||||
|
||||
const planned = createPlannedDecision();
|
||||
const store = createFileDecisionStore({
|
||||
decisionsDir: path.join(fakeRepoRoot, 'state', 'decisions'),
|
||||
repoRootOverride: fakeRepoRoot,
|
||||
});
|
||||
|
||||
const written = store.write({
|
||||
decision: planned.decision,
|
||||
receipt: planned.receipt,
|
||||
recordedAt: '2026-05-08T04:00:00.000Z',
|
||||
source: { task_id: 'task-reporting-governance' }
|
||||
});
|
||||
|
||||
assert.throws(() => store.consume(written.artifactPath, null), /decision store consumer must be a function/);
|
||||
});
|
||||
|
||||
test('file decision store produces distinct filenames for same decision written twice', async (t) => {
|
||||
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'reporting-governance-decision-store-'));
|
||||
t.after(() => fs.rmSync(sandbox, { recursive: true, force: true }));
|
||||
|
||||
Reference in New Issue
Block a user