feat: wire minimal governance contract path
This commit is contained in:
@@ -68,12 +68,14 @@ test('package root export resolves public package surface only', () => {
|
||||
packageName: plugin.packageName,
|
||||
hasRunWatchdogChain: typeof plugin.runWatchdogChain,
|
||||
hasPlanDecisionExecution: typeof plugin.planDecisionExecution,
|
||||
hasExecuteGovernanceContract: typeof plugin.executeGovernanceContract,
|
||||
}));
|
||||
`);
|
||||
|
||||
assert.equal(result.packageName, '@openclaw/plugin-reporting-governance');
|
||||
assert.equal(result.hasRunWatchdogChain, 'function');
|
||||
assert.equal(result.hasPlanDecisionExecution, 'function');
|
||||
assert.equal(result.hasExecuteGovernanceContract, 'function');
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { executeGovernanceContract } from '../src/core/execute-governance-contract.mjs';
|
||||
import capabilityDescriptor from '../capabilities/openclaw-watchdog-reference.json' with { type: 'json' };
|
||||
|
||||
const noSilencePack = {
|
||||
metadata: { id: 'no-silence', severity_default: 'high' },
|
||||
spec: {
|
||||
evaluation_mode: 'any_rule_match',
|
||||
rules: [
|
||||
{
|
||||
id: 'no-silence.missed-checkpoint',
|
||||
title: 'Missed checkpoint requires visible recovery',
|
||||
intent: 'Prevent overdue checkpoints from becoming invisible.',
|
||||
triggers: { event_types: ['silence_timeout'] },
|
||||
conditions: {
|
||||
all: [
|
||||
{ fact: 'checkpoint.is_overdue', equals: true }
|
||||
]
|
||||
},
|
||||
decision_output: {
|
||||
decision: 'force_checkpoint',
|
||||
severity: 'high',
|
||||
reason: 'checkpoint overdue triggered forced operator-visible recovery',
|
||||
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: checkpoint overdue.',
|
||||
deadline: '2026-01-01T00:00:00.000Z'
|
||||
}
|
||||
},
|
||||
operator_message_templates: {
|
||||
checkpoint_forced: 'Required update: task exceeded allowed silence window.'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
test('capability descriptor -> policy evaluation -> decision planning yields adapter-compatible contract', () => {
|
||||
const result = executeGovernanceContract({
|
||||
event: {
|
||||
type: 'silence_timeout',
|
||||
payload: {
|
||||
checkpoint_overdue: true,
|
||||
result_available: true,
|
||||
result_forwarded: false,
|
||||
}
|
||||
},
|
||||
evidence: [
|
||||
{ id: 'ev-watchdog', quality: 'moderate', is_new: true }
|
||||
],
|
||||
capabilityDescriptor,
|
||||
policyPacks: [noSilencePack],
|
||||
context: {
|
||||
signals: ['checkpoint_overdue'],
|
||||
operator_context: { report_anchor_present: true }
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(result.evaluation.decision.decision, 'force_checkpoint');
|
||||
assert.equal(result.planning.receipt.delivery_state, 'pending_external_send');
|
||||
assert.deepEqual(result.contract.adapter_actions, ['notify_operator']);
|
||||
assert.deepEqual(result.contract.package_actions, ['emit_event']);
|
||||
assert.deepEqual(result.contract.blocked_actions, []);
|
||||
assert.equal(result.contract.receipt_status, 'planned');
|
||||
assert.equal(result.contract.runtime, 'openclaw-watchdog-reference');
|
||||
});
|
||||
|
||||
test('contract truthfully degrades when capability descriptor cannot satisfy mandatory action', () => {
|
||||
const limitedDescriptor = {
|
||||
...capabilityDescriptor,
|
||||
metadata: {
|
||||
...capabilityDescriptor.metadata,
|
||||
id: 'limited-openclaw-watchdog-reference'
|
||||
},
|
||||
capabilities: {
|
||||
...capabilityDescriptor.capabilities,
|
||||
enforcement: {
|
||||
...capabilityDescriptor.capabilities.enforcement,
|
||||
force_checkpoint: { supported: false, level: 'none' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = executeGovernanceContract({
|
||||
event: {
|
||||
type: 'silence_timeout',
|
||||
payload: { checkpoint_overdue: true }
|
||||
},
|
||||
capabilityDescriptor: limitedDescriptor,
|
||||
policyPacks: [noSilencePack],
|
||||
context: {
|
||||
signals: ['checkpoint_overdue']
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(result.evaluation.decision.decision, 'force_checkpoint');
|
||||
assert.deepEqual(result.contract.adapter_actions, []);
|
||||
assert.deepEqual(result.contract.blocked_actions, ['notify_operator']);
|
||||
assert.equal(result.contract.receipt_status, 'degraded');
|
||||
});
|
||||
Reference in New Issue
Block a user