#!/usr/bin/env node // ═══════════════════════════════════════════════════════════════════════════ // Vertical Slice: Deployment utan pipeline blockeras (S-003) // Mål: Gå från rött till grönt för ETT test // Princip: "En regel i taget, bevisat genom test" // ═══════════════════════════════════════════════════════════════════════════ import { AgentRuntimeV2 } from './agent-runtime-v2.mjs'; /** * EOS Policy för pipeline-krav * Denna policy ska blockera deployment till produktion utan godkänd pipeline */ function checkPipelinePolicy(task) { // Kontrollera om det är en deployment till produktion const isDeployment = task.type === 'deployment' || task.description?.toLowerCase().includes('deploy'); const isProduction = task.target === 'production' || task.description?.toLowerCase().includes('produktion'); // Kontrollera om pipeline finns const hasPipeline = task.pipeline !== undefined && task.pipeline !== null; if (isDeployment && isProduction && !hasPipeline) { return { passed: false, rule: 'pipeline-required', reason: 'Deployment till produktion kräver godkänd CI/CD-pipeline enligt Engineering Contract §7', severity: 'CRITICAL', action: 'STOP', evidence: { type: task.type, target: task.target, pipeline: task.pipeline } }; } return { passed: true }; } /** * Uppdaterad Agent Runtime med pipeline-kontroll */ class AgentRuntimeDeploySlice extends AgentRuntimeV2 { constructor(task) { super(task); this.policies = [checkPipelinePolicy]; } async runEOSCheck() { const node = this.trace.addNode('EOS', { rules: this.policies.length }); // Kör alla policyer const results = []; for (const policy of this.policies) { const result = policy(this.task); results.push(result); if (!result.passed) { this.trace.blockNode(node.id, result.reason); return { passed: false, blockedBy: result.rule, reason: result.reason, severity: result.severity, evidence: result.evidence }; } } this.trace.completeNode(node.id, { passed: results.length, failed: 0 }); return { passed: true, results }; } } // ═══════════════════════════════════════════════════════════════════════════ // TEST // ═══════════════════════════════════════════════════════════════════════════ async function testDeployBlock() { console.log('═══════════════════════════════════════════════════════════════'); console.log(' VERTICAL SLICE: Deployment utan pipeline blockeras (S-003)'); console.log('═══════════════════════════════════════════════════════════════\n'); const test = { id: 'S-003', name: 'Deployment utan pipeline blockeras', input: { id: 'S-003', description: 'Deploy till produktion', type: 'deployment', target: 'production', pipeline: null } }; console.log(`Test: ${test.name}`); console.log(`Input: ${JSON.stringify(test.input)}\n`); const startTime = Date.now(); try { const runtime = new AgentRuntimeDeploySlice(test.input); const result = await runtime.execute(); const duration = Date.now() - startTime; // Verifiera const passed = result.status === 'blocked'; console.log(`Result: ${result.status}`); console.log(`Reason: ${result.reason}`); console.log(`Duration: ${duration}ms\n`); console.log('Runtime Trace:'); console.log(runtime.getTrace().toText()); if (passed) { console.log('\n✅ PASS — Deployment utan pipeline blockeras korrekt'); console.log('Vertical Slice complete!'); } else { console.log('\n❌ FAIL — Deployment blockades inte'); } return { passed, duration, trace: runtime.getTrace().toJSON() }; } catch (error) { console.log(`\n❌ FAIL — Exception: ${error.message}`); return { passed: false, duration: Date.now() - startTime, error: error.message }; } } // Kör testet endast om filen körs direkt if (process.argv[1] === new URL(import.meta.url).pathname) { import('fs').then(({ writeFileSync }) => { testDeployBlock().then(result => { writeFileSync( '/home/bernt/.openclaw/workspace/EOS/vertical-slice-deploy-result.json', JSON.stringify(result, null, 2) ); process.exit(result.passed ? 0 : 1); }); }); } export { AgentRuntimeDeploySlice, checkPipelinePolicy };