'use strict';
const test=require('node:test'),a=require('node:assert/strict'),fs=require('node:fs'),cp=require('node:child_process'),api=require('./lab.js'),u=require('./content.cjs')[0],cases=u.cases,base=()=>({...cases[0].draft});
test('eight authored examples match declared field-level expectations, without semantic scoring',()=>{a.equal(cases.length,8);for(const c of cases){const r=api.analyze(c.draft);a(r.ok);a.equal(r.state,c.expected.state,c.id);a.deepEqual(r.issues.map(x=>x.field),c.expected.issue_fields,c.id);}});
test('unknown scope stays incomplete while closed or active scope asks to reframe the chosen variant',()=>{for(const phase of ['', 'unknown'])a.equal(api.analyze({...base(),phase}).state,'incomplete');for(const phase of ['during','closed'])a.equal(api.analyze({...base(),phase}).state,'revise');const r=api.analyze({...base(),phase:'closed',plan:''});a.equal(r.state,'revise');a(r.issues.some(x=>x.field==='plan'));});
test('fully empty optional rows are omitted and partial rows retain every missing field',()=>{const x=api.analyze(base());a.deepEqual(x.rows.map(r=>r.id),['R1']);const y=api.analyze({...base(),R2_owner:'Rol por confirmar'});a.deepEqual(y.rows.map(r=>r.id),['R1','R2']);a.deepEqual(y.issues.map(r=>r.field),['R2_reason','R2_change','R2_review']);const blank=api.analyze(api.empty());a.equal(blank.rows.length,0);a(blank.issues.some(x=>x.field==='board'));});
test('priority does not create a concern and pending is distinct from a completed vote',()=>{const r=api.analyze({...base(),priority:'R3'});a.equal(r.state,'incomplete');a.deepEqual(r.rows.map(x=>x.id),['R1']);a(api.priorityText(r).includes('sin preocupación'));const x=api.analyze({...base(),priority:'R1'});a.equal(x.state,'review');a(api.priorityText(x).includes('no es una votación'));a(api.analyze(base()).unresolved_priority);});
test('contract validates limits and controls without executing or semantically classifying text',()=>{for(const raw of [null,{},[],{...base(),extra:'x'},{...base(),phase:'external'},{...base(),priority:'R4'},{...base(),facilitation:'external'},{...base(),plan:1}])a.equal(api.analyze(raw).ok,false);for(const f of api.textFields){const limit={...base(),[f.id]:'x'.repeat(f.max)};a(api.analyze(limit).ok);a.equal(api.analyze({...limit,[f.id]:'x'.repeat(f.max+1)}).ok,false);}});
test('literal Unicode,text and notes survive report while HTML rendering escapes markup',()=>{const text=' & revisión 🧭\nlínea2 ',r=api.analyze({...base(),plan:text,R1_reason:text}),note='nota & literal\nfin';a.equal(r.data.plan,text);a(api.sessionGuide(r).includes('Plan y alcance: '+text));a(api.exportText(r,note).includes(note));const t=api.table('c',['h'],[[text]]);a(t.includes('<img'));a(!t.includes('
x.field==='plan'));});
test('source fields and examples stay immutable and generation is deterministic',()=>{const before=JSON.stringify(cases),raw=Object.freeze(base()),one=api.analyze(raw),two=api.analyze(raw);a.deepEqual(one,two);a.equal(api.exportText(one,'n'),api.exportText(two,'n'));a.equal(JSON.stringify(cases),before);});
test('all draft states remain hypothetical and do not certify meeting,risks or acceptance',()=>{for(const c of cases){const r=api.analyze(c.draft),t=api.sessionGuide(r);a.equal(r.human_review_pending,true);a.equal(r.meeting_executed,false);a.equal(r.risks_verified,false);a(t.includes('NO ES ACTA NI DIAGNÓSTICO'));a(t.includes('TEXTO PARA EL ESCENARIO HIPOTÉTICO'));a(t.includes('aceptación por confirmar')||r.rows.length===0);a(t.includes('sin una probabilidad')||t.includes('no tiene una probabilidad'));}});
test('eight native worked drafts and the human criterion are available before the course invitation',()=>{const h=fs.readFileSync(__dirname+'/'+u.slug+'.html','utf8');a.equal((h.match(/data-native-case=/g)||[]).length,8);a.equal((h.match(/data-native-guide/g)||[]).length,8);a.equal((h.match(/