const test=require('node:test'); const assert=require('node:assert/strict'); const fs=require('node:fs'); const path=require('node:path'); const C=require('./plan-core.js'); const P=JSON.parse(fs.readFileSync(path.join(__dirname,'plan-data.json'),'utf8')); test('single-owner access requires host passwords with no user-account UI and Ubuntu server target',()=>{ assert.equal(P.accessPolicy.userAccounts,false);assert.equal(P.accessPolicy.passwordRequired,true);assert.equal(P.accessPolicy.controlServerOS,'Ubuntu'); for(const id of ['F80','F81','F82'])assert.ok(P.defaultSelected.includes(id)); const old={...C.initial(P),planVersion:'2026-09-20.4',selected:['F25'],notes:'기존 메모',status:{F25:'doing'}}; const s=C.normalize(P,old);for(const id of ['F80','F81','F82'])assert.ok(s.selected.includes(id)); assert.equal(s.notes,old.notes);assert.equal(s.status.F25,'doing'); assert.match(C.brief(P,s),/가입·로그인·로그아웃은 구현하지 않는다/); assert.match(P.uiAudit.flows.find(f=>f.id==='U31').finding,/로그아웃 UI는 구현하지 않는다/); }); test('catalogue has a valid DAG and complete default dependency closure',()=>{ assert.equal(C.validatePlan(P),true);assert.equal(P.features.length,82);assert.equal(P.defaultSelected.length,30); assert.deepEqual(C.closure(P,P.defaultSelected),P.defaultSelected); for(const f of P.features){assert.ok(f.description&&f.implementation&&f.module);assert.ok(f.acceptance.length>=2)} }); test('selecting a late feature adds all prerequisite levels',()=>{ let s=C.initial(P);s.selected=[];s=C.toggle(P,s,'F33',true); for(const id of ['F33','F32','F31','F28','F25','F01','F06','F10'])assert.ok(s.selected.includes(id)); assert.ok(!s.selected.includes('F44')); }); test('removal cascades through dependent scope, retaining recorded status',()=>{ let s=C.initial(P);s.status.F25='done';s=C.toggle(P,s,'F10',false); assert.ok(!s.selected.includes('F25'));assert.ok(!s.selected.includes('F11')); assert.equal(s.status.F25,'done');assert.ok(s.selected.includes('F09')); }); test('readiness depends on actual prerequisite status, not selected checkboxes',()=>{ let s=C.initial(P);assert.deepEqual(C.summary(P,s).ready.map(f=>f.id),['F01']); s.status.F01='done';assert.ok(C.summary(P,s).ready.some(f=>f.id==='F02')); s.status.F25='done';assert.ok(C.summary(P,s).inconsistent.some(f=>f.id==='F25')); }); test('import validates version, IDs, status, notes; no caller mutation',()=>{ const s=C.initial(P);const clean=C.normalize(P,JSON.parse(JSON.stringify(s)));assert.deepEqual(clean,s); for(const bad of [{...s,schemaVersion:9},{...s,selected:['F999']},{...s,status:{F01:'unknown'}},{...s,notes:'x'.repeat(5001)},{...s,planVersion:'old'}])assert.throws(()=>C.normalize(P,bad)); assert.throws(()=>C.normalize(P,JSON.parse('{"schemaVersion":1,"planVersion":"'+P.planVersion+'","selected":[],"notes":"","status":{"__proto__":"done"}}'))); }); test('handoff includes precisely selected features, constraints and notes',()=>{ let s=C.initial(P);s.selected=['F01'];s.notes='테스트 메모';let text=C.brief(P,s); assert.ok(text.includes('선택 ID: F01'));assert.ok(text.includes('테스트 메모')); assert.ok(!text.includes('- [ ] F02'));assert.ok(text.includes('미검증')); s.selected=[];assert.match(C.brief(P,s),/범위가 비어/); }); test('v5 selections survive and every handoff carries the original-parity contract',()=>{ const old={...C.initial(P),planVersion:'2026-09-20.5',selected:['F24'],settingsSelected:['host_privacy_mode'],status:{F01:'done'},notes:'내 기록'}; const s=C.normalize(P,old),b=C.brief(P,s); assert.equal(s.notes,old.notes);assert.equal(s.status.F01,'done');assert.deepEqual(s.settingsSelected,old.settingsSelected); for(const rule of P.parityPolicy.handoffRules)assert.ok(b.includes(rule)); assert.match(b,/notparsec\.exe/);assert.match(b,/미선택\/MVP는 최종 제외 사유가 아니다/); assert.ok(P.features.every(f=>f.parityReview==='required')); assert.ok(P.settings.settings.every(s=>s.parityReview==='required')); assert.ok(P.uiAudit.flows.every(f=>f.parityReview==='required')); assert.equal(P.uiAudit.flows.find(f=>f.id==='U33').result,'제외·대체 재검토'); }); test('embedded standalone payload matches catalogue and local links exist',()=>{ const html=fs.readFileSync(path.join(__dirname,'notparsec-plan.html'),'utf8'); const embedded=JSON.parse(html.match(/