Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified archify.zip
Binary file not shown.
8 changes: 6 additions & 2 deletions archify/scripts/check-render-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ try {

if (isExplainerHtml(html)) {
const result = checkExplainerHtml(html, { file: htmlPath });
console.log(JSON.stringify(result, null, 2));
process.exit(result.ok ? 0 : 1);
// Piped stdout is asynchronous on macOS. Exit only after the full receipt
// has flushed, and keep the diagram path below from emitting a second one.
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`, () => {
process.exit(result.ok ? 0 : 1);
});
await new Promise(() => {});
}

const checks = [];
Expand Down
23 changes: 23 additions & 0 deletions test/explainer-check.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,26 @@ test('scanner line locations include skipped raw payload lines without recountin
const html='<!doctype html>\n<style>\ntext{fill:red}\n</style>\n<script type="application/json">\n{"content":"<p>not an element</p>"}\n</script>\n<p id="last">Text</p>\n<a href="#last">Link</a>';
const scan=scanHtml(html);assert.deepEqual(scan.elements.map(e=>[e.tag,e.line]),[['style',2],['script',5],['p',8],['a',9]]);
});

for (const valid of [true, false]) {
test(`large explainer receipt flushes through a pipe (${valid ? 'success' : 'failure'})`,()=>{
const native=fs.readFileSync(new URL('../archify/examples/erd-orders-rendered.html',import.meta.url),'utf8');
const child={html:native,sha256:hash(native),bytes:Buffer.byteLength(native)};
const children=Object.fromEntries(Array.from({length:20},(_,i)=>[`diagram-${i}`,child]));
let html=fixture({children});
if (!valid) html=html.replace('</main>','<a href="#missing">Missing</a></main>');
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'explainer-flush-'));
try {
const file=path.join(dir,'page.html');fs.writeFileSync(file,html);
const run=spawnSync(process.execPath,['archify/scripts/check-render-output.mjs',file],{encoding:'utf8',maxBuffer:4*1024*1024,timeout:30000});
assert.ifError(run.error);
assert.equal(run.status,valid?0:1,run.stderr);
const receipt=JSON.parse(run.stdout); // Reject truncated JSON or a second receipt.
assert.ok(Buffer.byteLength(run.stdout)>65536,'exercise a receipt larger than a pipe buffer');
assert.equal(receipt.ok,valid);
assert.equal(receipt.family,'explainer');
assert.equal(receipt.composition.nativeDiagrams.length,20);
assert.ok(receipt.composition.nativeDiagrams.every(c=>c.receipt.ok&&c.receipt.artifact.sha256===child.sha256));
}finally{fs.rmSync(dir,{recursive:true,force:true});}
});
}
Loading