From bc5902a8772bff6089c29386a54e64a686d18600 Mon Sep 17 00:00:00 2001 From: Eve Date: Fri, 8 May 2026 11:52:10 +0800 Subject: [PATCH] test: cover degraded runtime truth matrix --- .../runtime-integrated.integration.test.mjs | 112 +++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/plugins/reporting-governance/test/runtime-integrated.integration.test.mjs b/plugins/reporting-governance/test/runtime-integrated.integration.test.mjs index 282f3a4..2da99c4 100644 --- a/plugins/reporting-governance/test/runtime-integrated.integration.test.mjs +++ b/plugins/reporting-governance/test/runtime-integrated.integration.test.mjs @@ -208,6 +208,62 @@ function createDegradedDescriptor() { }; } +function createNoAdapterActionPack() { + return { + metadata: { id: 'no-adapter-action-pack', severity_default: 'high' }, + spec: { + evaluation_mode: 'any_rule_match', + rules: [ + { + id: 'no-adapter-action-pack.package-core-only', + title: 'Package-core-only route for degraded matrix coverage', + triggers: { event_types: ['silence_timeout'] }, + conditions: { + all: [ + { fact: 'checkpoint.is_overdue', equals: true } + ] + }, + decision_output: { + decision: 'force_checkpoint', + severity: 'high', + reason: 'checkpoint overdue triggered package-core-only route for degraded matrix coverage', + required_actions: [ + { action: 'emit_event', target: 'event_stream', mandatory: true } + ] + } + } + ] + } + }; +} + +function assertNoAckedOrFinalDeliveredClaim(result) { + assert.notEqual(result.contract.delivery_state, 'acked'); + assert.notEqual(result.planning.receipt.delivery_state, 'acked'); + assert.notEqual(result.contract.receipt_status, 'acked'); + assert.notEqual(result.planning.receipt.status, 'acked'); + assert.notEqual(result.runtimeExecution?.result?.supervisor?.deliveryState, 'acked'); + assert.notEqual(result.runtimeExecution?.result?.supervisor?.deliveryState, 'final_delivered'); +} + +function assertDeferredTruthState(result) { + assert.equal(result.contract.delivery_state, 'pending_external_send'); + assert.equal(result.planning.receipt.delivery_state, 'pending_external_send'); + assertNoAckedOrFinalDeliveredClaim(result); +} + +const futureTruthStateMatrix = Object.freeze({ + deferred: { + contractDeliveryState: 'pending_external_send', + attempted: true, + terminalClaimForbidden: ['acked', 'final_delivered'] + }, + planningOnly: { + attempted: false, + terminalClaimForbidden: ['acked', 'final_delivered'] + } +}); + test('runtime-integrated route matrix: no runtime stays planning-only', () => { const result = executeRuntimeIntegratedGovernance(createBaseArgs()); @@ -293,8 +349,8 @@ test('runtime-integrated route matrix: degraded preflight still runs queue/bridg assert.equal(result.preflight.status, 'degraded'); assert.equal(result.contract.adapter_actions[0], 'notify_operator'); - assert.equal(result.contract.delivery_state, 'pending_external_send'); - assert.equal(result.runtimeIntegration.attempted, true); + assertDeferredTruthState(result); + assert.equal(result.runtimeIntegration.attempted, futureTruthStateMatrix.deferred.attempted); assert.equal(result.runtimeIntegration.adapter, 'orchestrator'); assert.equal(result.runtimeIntegration.action, 'notify_operator'); assert.equal(result.runtimeExecution.ok, true); @@ -338,6 +394,7 @@ test('runtime-integrated route matrix: matched adapter_action runs orchestrator assert.equal(result.runtimeIntegration.adapter, 'orchestrator'); assert.equal(result.runtimeIntegration.action, 'notify_operator'); assert.equal(result.runtimeIntegration.reason, 'adapter_action notify_operator routed to orchestrator adapter runner'); + assertDeferredTruthState(result); assert.equal(result.runtimeExecution.ok, true); assert.equal(result.runtimeExecution.result.dispatcher.dispatchedCount, 1); assert.equal(result.runtimeExecution.result.supervisor.pendingCount, 1); @@ -352,3 +409,54 @@ test('runtime-integrated route matrix: matched adapter_action runs orchestrator fs.rmSync(root, { recursive: true, force: true }); } }); + + +test('runtime-integrated route matrix: degraded without adapter_action stays not attempted', () => { + const result = executeRuntimeIntegratedGovernance(createBaseArgs({ + capabilityDescriptor: createDegradedDescriptor(), + policyPacks: [createNoAdapterActionPack()], + runtime: createStubRuntime(), + })); + + assert.equal(result.preflight.status, 'degraded'); + assert.deepEqual(result.contract.adapter_actions, []); + assert.deepEqual(result.contract.package_actions, ['emit_event']); + assert.equal(result.runtimeIntegration.attempted, futureTruthStateMatrix.planningOnly.attempted); + assert.equal(result.runtimeIntegration.reason, 'runtime execution not attempted: degraded compatibility preflight produced no adapter_action route'); + assert.equal(result.runtimeExecution, null); + assertNoAckedOrFinalDeliveredClaim(result); +}); + +test('runtime-integrated route matrix: degraded runtime path never claims acked or final delivered', () => { + const root = createFixtureRoot(); + try { + mkdirs(root, ['evidence', 'events', 'queue', 'spool', 'receipts']); + const statePath = writeState(root); + + const result = executeRuntimeIntegratedGovernance(createBaseArgs({ + capabilityDescriptor: createDegradedDescriptor(), + runtime: { + state: statePath, + evidenceDir: path.join(root, 'evidence'), + eventDir: path.join(root, 'events'), + queueDir: path.join(root, 'queue'), + spoolDir: path.join(root, 'spool'), + receiptDir: path.join(root, 'receipts'), + writeState: true, + dryRun: true, + now: '2026-05-07T08:20:00.000Z', + }, + })); + + assert.equal(result.preflight.status, 'degraded'); + assertDeferredTruthState(result); + assert.equal(result.runtimeExecution.result.supervisor.pendingCount, 1); + + const receipt = readSingleJson(path.join(root, 'receipts')); + assert.equal(receipt.state, 'pending_external_send'); + assert.notEqual(receipt.state, 'acked'); + assert.notEqual(receipt.state, 'final_delivered'); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } +});