feat: add reporting governance preflight contract
This commit is contained in:
@@ -104,6 +104,47 @@ const verifiedCompletionPack = {
|
||||
}
|
||||
};
|
||||
|
||||
const structurePack = {
|
||||
metadata: { id: 'mandatory-checkpoint-structure', severity_default: 'medium' },
|
||||
spec: {
|
||||
evaluation_mode: 'any_rule_match',
|
||||
rules: [
|
||||
{
|
||||
id: 'mandatory-checkpoint-structure.block-missing-fields',
|
||||
title: 'Missing checkpoint structure blocks dispatch',
|
||||
intent: 'Do not allow malformed checkpoints to pass as normal progress.',
|
||||
triggers: {
|
||||
event_types: ['task_checkpoint_sent'],
|
||||
claim_types: ['progress']
|
||||
},
|
||||
conditions: {
|
||||
all: [
|
||||
{ fact: 'message.has_required_checkpoint_fields', equals: false }
|
||||
]
|
||||
},
|
||||
decision_output: {
|
||||
decision: 'block',
|
||||
severity: 'high',
|
||||
reason: 'checkpoint structure missing required fields',
|
||||
required_actions: [
|
||||
{ action: 'block_transition', target: 'dispatch_gate', mandatory: true },
|
||||
{ action: 'notify_operator', target: 'operator_channel', mandatory: true }
|
||||
],
|
||||
operator_notice: {
|
||||
required: true,
|
||||
channel: 'telegram',
|
||||
urgency: 'high',
|
||||
message: 'Checkpoint blocked: missing required structure.'
|
||||
}
|
||||
},
|
||||
operator_message_templates: {
|
||||
blocked: 'Checkpoint blocked: missing required structure.'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
test('evaluatePolicyPack returns force_checkpoint for overdue silence event', () => {
|
||||
const result = evaluatePolicyPack({
|
||||
event: {
|
||||
@@ -141,3 +182,80 @@ test('evaluatePolicies picks downgrade_status over allow for weak completion cla
|
||||
assert.equal(result.decision.suggested_status, 'pending_verification');
|
||||
assert.equal(result.evaluations[0].decision.policy_id, 'verified-completion-only.insufficient-evidence');
|
||||
});
|
||||
|
||||
test('evaluatePolicies gives block precedence over allow-like outcomes when checkpoint structure is invalid', () => {
|
||||
const result = evaluatePolicies({
|
||||
event: {
|
||||
type: 'task_checkpoint_sent',
|
||||
payload: {}
|
||||
},
|
||||
evidence: [
|
||||
{ id: 'ev-2', quality: 'moderate', is_new: true }
|
||||
],
|
||||
capabilityDescriptor,
|
||||
policyPacks: [noSilencePack, structurePack],
|
||||
context: {
|
||||
message: { has_required_checkpoint_fields: false }
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(result.decision.decision, 'block');
|
||||
assert.equal(result.decision.policy_id, 'mandatory-checkpoint-structure.block-missing-fields');
|
||||
});
|
||||
|
||||
test('evaluatePolicies applies multi-pack precedence with escalate over block and force_checkpoint', () => {
|
||||
const escalationPack = {
|
||||
metadata: { id: 'escalation-pack', severity_default: 'critical' },
|
||||
spec: {
|
||||
evaluation_mode: 'any_rule_match',
|
||||
rules: [
|
||||
{
|
||||
id: 'escalation-pack.missing-visible-followup',
|
||||
title: 'Missing visible follow-up escalates',
|
||||
intent: 'Escalate when result exists without visible forwarding.',
|
||||
triggers: { event_types: ['silence_timeout'] },
|
||||
conditions: {
|
||||
all: [
|
||||
{ fact: 'forwarding.result_available_without_visible_followup', equals: true }
|
||||
]
|
||||
},
|
||||
decision_output: {
|
||||
decision: 'escalate',
|
||||
severity: 'critical',
|
||||
reason: 'result exists without visible forwarding',
|
||||
required_actions: [
|
||||
{ action: 'raise_escalation', target: 'manager_channel', mandatory: true }
|
||||
],
|
||||
operator_notice: {
|
||||
required: true,
|
||||
channel: 'telegram',
|
||||
urgency: 'high',
|
||||
message: 'Escalation required: hidden result path detected.'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const result = evaluatePolicies({
|
||||
event: {
|
||||
type: 'silence_timeout',
|
||||
payload: {
|
||||
checkpoint_overdue: true,
|
||||
result_available: true,
|
||||
result_forwarded: false
|
||||
}
|
||||
},
|
||||
evidence: [{ id: 'ev-3', quality: 'moderate', is_new: true }],
|
||||
capabilityDescriptor,
|
||||
policyPacks: [noSilencePack, structurePack, escalationPack],
|
||||
context: {
|
||||
signals: ['checkpoint_overdue'],
|
||||
message: { has_required_checkpoint_fields: false }
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(result.decision.decision, 'escalate');
|
||||
assert.equal(result.decision.policy_id, 'escalation-pack.missing-visible-followup');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user