feat: add reporting governance preflight contract
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { executeGovernanceContract } from '../src/core/execute-governance-contract.mjs';
|
||||
import { executeGovernanceContract, runCompatibilityPreflight } from '../src/core/index.mjs';
|
||||
import capabilityDescriptor from '../capabilities/openclaw-watchdog-reference.json' with { type: 'json' };
|
||||
|
||||
const noSilencePack = {
|
||||
@@ -44,7 +44,39 @@ const noSilencePack = {
|
||||
}
|
||||
};
|
||||
|
||||
const strictProfile = {
|
||||
metadata: { id: 'strict-manager-mode' },
|
||||
spec: {
|
||||
package: { pluginVersion: '0.1.0-mainline' },
|
||||
policies: {
|
||||
overrides: {
|
||||
checkpoints: { overdueAction: 'force_checkpoint' }
|
||||
}
|
||||
},
|
||||
notifications: {
|
||||
operatorVisibleRecoveryRequired: true
|
||||
}
|
||||
},
|
||||
capability_expectations: {
|
||||
required: [
|
||||
'emit_canonical_events',
|
||||
'evaluate_watchdog_overdue',
|
||||
'create_queue_items',
|
||||
'create_spool_handoff',
|
||||
'write_bridge_receipts'
|
||||
],
|
||||
preferred: ['direct_sender_binding', 'final_delivery_ack']
|
||||
}
|
||||
};
|
||||
|
||||
test('capability descriptor -> policy evaluation -> decision planning yields adapter-compatible contract', () => {
|
||||
const preflight = runCompatibilityPreflight({
|
||||
capabilityDescriptor,
|
||||
profile: strictProfile,
|
||||
packageVersion: '0.1.0-mainline'
|
||||
});
|
||||
assert.equal(preflight.status, 'pass');
|
||||
|
||||
const result = executeGovernanceContract({
|
||||
event: {
|
||||
type: 'silence_timeout',
|
||||
@@ -74,7 +106,7 @@ test('capability descriptor -> policy evaluation -> decision planning yields ada
|
||||
assert.equal(result.contract.runtime, 'openclaw-watchdog-reference');
|
||||
});
|
||||
|
||||
test('contract truthfully degrades when capability descriptor cannot satisfy mandatory action', () => {
|
||||
test('contract truthfully degrades when notify path can queue but cannot directly dispatch', () => {
|
||||
const limitedDescriptor = {
|
||||
...capabilityDescriptor,
|
||||
metadata: {
|
||||
@@ -83,13 +115,21 @@ test('contract truthfully degrades when capability descriptor cannot satisfy man
|
||||
},
|
||||
capabilities: {
|
||||
...capabilityDescriptor.capabilities,
|
||||
enforcement: {
|
||||
...capabilityDescriptor.capabilities.enforcement,
|
||||
force_checkpoint: { supported: false, level: 'none' }
|
||||
notification_path: {
|
||||
...capabilityDescriptor.capabilities.notification_path,
|
||||
sender_binding: { supported: false, level: 'none' },
|
||||
direct_send: { supported: false, level: 'none' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const preflight = runCompatibilityPreflight({
|
||||
capabilityDescriptor: limitedDescriptor,
|
||||
profile: strictProfile,
|
||||
packageVersion: '0.1.0-mainline'
|
||||
});
|
||||
assert.equal(preflight.status, 'degraded');
|
||||
|
||||
const result = executeGovernanceContract({
|
||||
event: {
|
||||
type: 'silence_timeout',
|
||||
@@ -103,7 +143,48 @@ test('contract truthfully degrades when capability descriptor cannot satisfy man
|
||||
});
|
||||
|
||||
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');
|
||||
assert.deepEqual(result.contract.adapter_actions, ['notify_operator']);
|
||||
assert.deepEqual(result.contract.blocked_actions, []);
|
||||
assert.equal(result.contract.receipt_status, 'planned');
|
||||
assert.ok(result.planning.receipt.notes.some((note) => note.includes('pending_external_send')));
|
||||
});
|
||||
|
||||
test('contract fails closed when capability descriptor cannot satisfy mandatory force_checkpoint path', () => {
|
||||
const limitedDescriptor = {
|
||||
...capabilityDescriptor,
|
||||
metadata: {
|
||||
...capabilityDescriptor.metadata,
|
||||
id: 'hard-limited-openclaw-watchdog-reference'
|
||||
},
|
||||
capabilities: {
|
||||
...capabilityDescriptor.capabilities,
|
||||
enforcement: {
|
||||
...capabilityDescriptor.capabilities.enforcement,
|
||||
force_checkpoint: { supported: false, level: 'none' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const preflight = runCompatibilityPreflight({
|
||||
capabilityDescriptor: limitedDescriptor,
|
||||
profile: strictProfile,
|
||||
packageVersion: '0.1.0-mainline'
|
||||
});
|
||||
assert.equal(preflight.status, 'fail_closed');
|
||||
|
||||
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, ['notify_operator']);
|
||||
assert.equal(result.contract.receipt_status, 'planned');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user