138 lines
5.1 KiB
JavaScript
138 lines
5.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { planDecisionExecution } from '../src/core/decision-runner.mjs';
|
|
|
|
const baseCapabilityDescriptor = {
|
|
capabilities: {
|
|
enforcement: {
|
|
block_transition: { supported: true, level: 'partial' },
|
|
force_checkpoint: { supported: true, level: 'partial' },
|
|
rewrite_message: { supported: false, level: 'none' },
|
|
annotate_placeholder: { supported: false, level: 'none' },
|
|
request_review: { supported: false, level: 'none' },
|
|
downgrade_status: { supported: false, level: 'none' },
|
|
escalate: { supported: true, level: 'full' }
|
|
},
|
|
notification_path: {
|
|
queue_items: { supported: true, level: 'full' },
|
|
spool_handoff: { supported: true, level: 'full' },
|
|
sender_binding: { supported: true, level: 'full' },
|
|
direct_send: { supported: true, level: 'partial' },
|
|
truth_model: {
|
|
delivery_states: ['prepared', 'queued', 'dispatched', 'pending_external_send', 'acked', 'blocked'],
|
|
ack_requires_proven_send: true,
|
|
pending_external_send_supported: true
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
test('planDecisionExecution produces runtime-adapter dispatch intent for force_checkpoint', () => {
|
|
const result = planDecisionExecution({
|
|
decision: {
|
|
decision: 'force_checkpoint',
|
|
policy_id: 'no-silence.missed-checkpoint',
|
|
severity: 'high',
|
|
reason: 'checkpoint overdue',
|
|
rewritten_message: 'Required update.',
|
|
suggested_status: 'in_progress',
|
|
required_actions: [
|
|
{ action: 'notify_operator', target: 'operator_channel', mandatory: true },
|
|
{ action: 'emit_event', target: 'event_stream', mandatory: true }
|
|
],
|
|
operator_notice: {
|
|
required: true,
|
|
channel: 'telegram',
|
|
urgency: 'high',
|
|
message: 'Required update.',
|
|
deadline: '2026-01-01T00:00:00.000Z'
|
|
}
|
|
},
|
|
capabilityDescriptor: baseCapabilityDescriptor
|
|
});
|
|
|
|
assert.equal(result.receipt.delivery_state, 'pending_external_send');
|
|
assert.deepEqual(result.enforcement_intent.runtime_adapter_required, ['notify_operator']);
|
|
assert.ok(result.receipt.notes.some((note) => note.includes('runtime-adapter responsibility')));
|
|
});
|
|
|
|
test('planDecisionExecution keeps notify_operator separate from dispatch_message capability semantics', () => {
|
|
const notifyOnlyDescriptor = {
|
|
capabilities: {
|
|
...baseCapabilityDescriptor.capabilities,
|
|
notification_path: {
|
|
...baseCapabilityDescriptor.capabilities.notification_path,
|
|
sender_binding: { supported: false, level: 'none' },
|
|
direct_send: { supported: false, level: 'none' }
|
|
}
|
|
}
|
|
};
|
|
|
|
const result = planDecisionExecution({
|
|
decision: {
|
|
decision: 'force_checkpoint',
|
|
policy_id: 'no-silence.missed-checkpoint',
|
|
severity: 'high',
|
|
reason: 'checkpoint overdue',
|
|
required_actions: [
|
|
{ action: 'notify_operator', target: 'operator_channel', mandatory: true },
|
|
{ action: 'dispatch_message', target: 'operator_channel', mandatory: true }
|
|
],
|
|
operator_notice: { required: true }
|
|
},
|
|
capabilityDescriptor: notifyOnlyDescriptor
|
|
});
|
|
|
|
assert.deepEqual(result.enforcement_intent.runtime_adapter_required, ['notify_operator']);
|
|
assert.equal(result.enforcement_intent.planned_actions[0].execution_mode, 'runtime_adapter_dispatch_deferred');
|
|
assert.equal(result.enforcement_intent.blocked_actions[0].action, 'dispatch_message');
|
|
assert.ok(result.receipt.notes.some((note) => note.includes('pending_external_send')));
|
|
});
|
|
|
|
test('planDecisionExecution truthfully blocks unsupported package action paths', () => {
|
|
const result = planDecisionExecution({
|
|
decision: {
|
|
decision: 'downgrade_status',
|
|
policy_id: 'verified-completion-only.insufficient-evidence',
|
|
severity: 'high',
|
|
reason: 'completion evidence too weak',
|
|
rewritten_message: null,
|
|
suggested_status: 'pending_verification',
|
|
required_actions: [
|
|
{
|
|
action: 'set_status',
|
|
target: 'task_record',
|
|
mandatory: true,
|
|
details: { to: 'pending_verification' }
|
|
}
|
|
],
|
|
operator_notice: null
|
|
},
|
|
capabilityDescriptor: baseCapabilityDescriptor
|
|
});
|
|
|
|
assert.equal(result.receipt.status, 'degraded');
|
|
assert.equal(result.enforcement_intent.planned_actions.length, 0);
|
|
assert.equal(result.enforcement_intent.blocked_actions[0].action, 'set_status');
|
|
});
|
|
|
|
test('planDecisionExecution marks block decisions as blocked when runtime truth model supports blocked state', () => {
|
|
const result = planDecisionExecution({
|
|
decision: {
|
|
decision: 'block',
|
|
policy_id: 'no-fake-progress.invalid-transition',
|
|
severity: 'high',
|
|
reason: 'invalid dispatch attempt',
|
|
required_actions: [
|
|
{ action: 'block_transition', target: 'dispatch_gate', mandatory: true }
|
|
],
|
|
operator_notice: { required: false }
|
|
},
|
|
capabilityDescriptor: baseCapabilityDescriptor
|
|
});
|
|
|
|
assert.equal(result.receipt.delivery_state, 'blocked');
|
|
assert.deepEqual(result.enforcement_intent.package_core_actions, ['block_transition']);
|
|
});
|