Skip to content

Commit 9524e35

Browse files
use static fake provider fixture
1 parent ce150cf commit 9524e35

1 file changed

Lines changed: 2 additions & 30 deletions

File tree

global-template/docgen/test/semantic-index.test.mjs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,9 @@ function catalogFixture(root) {
3636

3737
function installFakeProvider(root) {
3838
const p = projectPaths(root); const dir = path.join(p.base, 'test-bin'); fs.mkdirSync(dir, { recursive: true });
39+
const source = path.join(testDir, 'fixtures', 'fake-provider.mjs');
3940
const file = path.join(dir, 'fake-provider.mjs');
40-
fs.writeFileSync(file, `#!/usr/bin/env node
41-
import fs from 'node:fs';
42-
import path from 'node:path';
43-
const prompt=fs.readFileSync(0,'utf8');
44-
const stage=process.env.DOCGEN_STAGE;
45-
const cwd=process.cwd();
46-
const tick=String.fromCharCode(96);
47-
const between=(text,start,end)=>{const tail=text.split(start)[1];return tail?tail.split(end)[0]:null;};
48-
const target=between(prompt,'Write exactly one JSON file: '+tick,tick);
49-
const write=(rel,value)=>{if(!rel)throw new Error('missing output path for '+stage);const file=path.join(cwd,rel);fs.mkdirSync(path.dirname(file),{recursive:true});fs.writeFileSync(file,JSON.stringify(value,null,2)+'\n');};
50-
if(stage==='modelCore'){
51-
write(target,{system:{components:[{id:'resource',kind:'component',name:'Resource',statement:'HTTP resource',classification:'FACT',confidence:1,evidence:[{path:'src/Resource.java',startLine:1}]}],relationships:[],workflows:[],unknowns:[]},business:{actors:[],capabilities:[],concepts:[],businessRules:[],decisions:[],branchConditions:[],lifecycles:[],invariants:[],useCases:[],unknowns:[]},flows:{businessFlows:[],controlFlows:[],requestFlows:[],trafficFlows:[],dataFlows:[],eventFlows:[]},catalogs:{endpoints:[],messageHandlers:[],externalDependencies:[],dataStores:[],scheduledJobs:[]}});
52-
}else if(stage==='modelEnterprise'){
53-
write(target,{security:{unknowns:[]},operations:{unknowns:[]},testing:{unknowns:[]},'data-governance':{unknowns:[]},decisions:{unknowns:[]},configuration:{unknowns:[]},'change-impact':{unknowns:[]},ownership:{unknowns:[]}});
54-
}else if(stage==='plan'){
55-
write(target,{schemaVersion:'2.0',metadata:{description:'Fixture docs'},pages:[{id:'overview',title:'System Overview',summary:'Fixture overview.',category:'orientation',mode:'explanation',type:'overview',order:1,audience:['engineer'],coverageTags:['architecture'],query:'resource architecture',requiredSections:[],risk:'low',relatedPages:[]}]});
56-
}else if(stage==='generate'){
57-
const json=between(prompt,'Page contracts:\n','\n\nFor every contract:');
58-
const contracts=JSON.parse(json);
59-
for(const contract of contracts){
60-
const page=contract.page;
61-
const md='---\ntitle: '+JSON.stringify(page.title)+'\ndescription: '+JSON.stringify(page.summary)+'\npageId: '+JSON.stringify(page.id)+'\ncategory: '+JSON.stringify(page.category)+'\nmode: '+JSON.stringify(page.mode)+'\ntype: '+JSON.stringify(page.type)+'\norder: '+page.order+'\n---\n# '+page.title+'\n\n'+page.summary+'\n\nThe repository exposes an HTTP resource.\n';
62-
const output=path.join(cwd,contract.outputPath);fs.mkdirSync(path.dirname(output),{recursive:true});fs.writeFileSync(output,md);
63-
write(contract.traceabilityPath,{schemaVersion:'2.0',pageId:page.id,pagePath:contract.outputPath,claims:[{id:page.id+':resource',section:page.title,statement:'The repository exposes an HTTP resource.',classification:'FACT',confidence:1,evidence:[{path:'src/Resource.java',startLine:1}],sourceModelRefs:['system:resource']}]});
64-
}
65-
}else if(stage==='audit'){
66-
const output=between(prompt,'report: '+tick,tick)||'.docgen/audit/llm-risk.json';write(output,{schemaVersion:'2.0',pages:[]});
67-
}else{process.exitCode=2;console.error('unexpected stage '+stage);}
68-
`);
69-
fs.chmodSync(file, 0o755);
41+
fs.copyFileSync(source, file); fs.chmodSync(file, 0o755);
7042
const check = spawnSync(process.execPath, ['--check', file], { encoding: 'utf8' });
7143
assert.equal(check.status, 0, check.stderr || check.stdout);
7244
return file;

0 commit comments

Comments
 (0)