import test from 'node:test'; import assert from 'node:assert/strict'; import policyModule from '../src/shared/deployment-policy.cjs'; const { evaluateDeploymentPolicy } = policyModule; test('deployment freeze and maintenance windows fail closed with reasoned overrides', () => { const profile = { deploymentPolicy: { frozen: true, freezeReason: 'Incident', requireNote: true, maintenanceWindows: [{ days: [1], start: '09:00', end: '10:00' }] } }; const now = new Date(2026, 6, 28, 12, 0); // Tuesday assert.throws(() => evaluateDeploymentPolicy(profile, { now, note: 'Release' }), (error) => error.code === 'DEPLOYMENT_POLICY_BLOCKED'); assert.throws(() => evaluateDeploymentPolicy(profile, { now, note: 'Release', override: true }), /override reason/i); const result = evaluateDeploymentPolicy(profile, { now, note: 'Release', override: true, reason: 'Emergency recovery' }); assert.equal(result.overridden, true); assert.equal(result.violations.length, 2); }); test('deployment policy accepts an in-window release with required note', () => { const now = new Date(2026, 6, 27, 9, 30); // Monday const profile = { deploymentPolicy: { requireNote: true, maintenanceWindows: [{ days: [1], start: '09:00', end: '10:00' }] } }; assert.equal(evaluateDeploymentPolicy(profile, { now, note: 'Version 1.2' }).allowed, true); assert.throws(() => evaluateDeploymentPolicy(profile, { now }), /release note/i); }); test('overnight maintenance windows continue into the following day', () => { const profile = { deploymentPolicy: { maintenanceWindows: [{ days: [1], start: '22:00', end: '02:00' }] } }; assert.equal(evaluateDeploymentPolicy(profile, { now: new Date(2026, 6, 27, 23, 0) }).allowed, true); assert.equal(evaluateDeploymentPolicy(profile, { now: new Date(2026, 6, 28, 1, 0) }).allowed, true); assert.throws(() => evaluateDeploymentPolicy(profile, { now: new Date(2026, 6, 28, 3, 0) }), /outside/); });