Files
boc/EOS/test-decision-replay.mjs
T

79 lines
3.3 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
// ═══════════════════════════════════════════════════════════════════════════
// Testa Decision Replay
// ═══════════════════════════════════════════════════════════════════════════
import { AgentRuntimeV6 } from './agent-runtime-v6.mjs';
async function testDecisionReplay() {
console.log('═══════════════════════════════════════════════════════════════');
console.log(' TEST: Decision Replay');
console.log('═══════════════════════════════════════════════════════════════\n');
// Test 1: Blockerat beslut
const task1 = {
id: 'TEST-001',
description: 'SSH:a in i produktion',
type: 'infrastructure',
action: 'ssh',
target: 'production'
};
const runtime1 = new AgentRuntimeV6(task1);
const result1 = await runtime1.execute();
console.log('Test 1: SSH till produktion');
console.log(`Result: ${result1.status}`);
console.log(`Decision ID: ${result1.decisionId}`);
// Spela upp beslutet
const replay1 = runtime1.getDecisionReplay().replayDecision(result1.decisionId);
console.log(`Replayable: ${replay1.original?.replayable || false}`);
console.log(`Operation: ${replay1.original?.canonicalOperation?.operation}`);
console.log(`Decision: ${replay1.original?.policyResult?.passed ? 'ALLOW' : 'BLOCK'}`);
// Test 2: Tillåtet beslut
const task2 = {
id: 'TEST-002',
description: 'Ändra text i README',
type: 'documentation'
};
const runtime2 = new AgentRuntimeV6(task2);
const result2 = await runtime2.execute();
console.log('\nTest 2: Ändra README');
console.log(`Result: ${result2.status}`);
console.log(`Decision ID: ${result2.decisionId}`);
const replay2 = runtime2.getDecisionReplay().replayDecision(result2.decisionId);
console.log(`Replayable: ${replay2.original?.replayable || false}`);
console.log(`Operation: ${replay2.original?.canonicalOperation?.operation}`);
console.log(`Decision: ${replay2.original?.policyResult?.passed ? 'ALLOW' : 'BLOCK'}`);
// Generera rapport
const allDecisions = [
...runtime1.getDecisionReplay().exportDecisions(),
...runtime2.getDecisionReplay().exportDecisions()
];
console.log('\n=== DECISION REPLAY RAPPORT ===');
console.log(`Totalt antal beslut: ${allDecisions.length}`);
console.log(`Beslut med replay-stöd: ${allDecisions.filter(d => d.replayable).length}`);
console.log(`Reproducerbara: ${allDecisions.filter(d => d.replayable).length}/${allDecisions.length}`);
// Spara beslut
const fs = await import('fs');
fs.writeFileSync(
'/home/bernt/.openclaw/workspace/EOS/decision-replay-test.json',
JSON.stringify({
timestamp: new Date().toISOString(),
decisions: allDecisions
}, null, 2)
);
console.log('\n✅ Decision Replay fungerar!');
}
testDecisionReplay().catch(console.error);