Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix: reject checker capture errors even after a zero exit

tt-a1i8f30743e738d
diff --git a/archify.zip b/archify.zip
index dd53e282..2425cbfa 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/bin/archify.mjs b/archify/bin/archify.mjs
index 9a796a2d..8cc30c12 100755
--- a/archify/bin/archify.mjs
+++ b/archify/bin/archify.mjs
@@ -2246,13 +2246,17 @@ function rendererPath(type) {
const DEFAULT_MAX_BUFFER = 64 * 1024 * 1024;
function runNode(args, options = {}) {
- return spawnSync(process.execPath, args, {
+ const result = spawnSync(process.execPath, args, {
cwd: options.cwd || process.cwd(),
encoding: 'utf8',
stdio: options.stdio || 'inherit',
maxBuffer: options.maxBuffer ?? DEFAULT_MAX_BUFFER,
env: options.env ? { ...process.env, ...options.env } : process.env,
});
+ // The child can exit before a piped-output overflow is observed. A capture
+ // error still means the operation failed, even when its exit status is zero.
+ if (result.error && result.status === 0) result.status = 1;
+ return result;
}
// The artifact checker prints its whole receipt on stdout; a dense,
diff --git a/scripts/generate-viewer.mjs b/scripts/generate-viewer.mjs
index 01858674..62d81450 100644
--- a/scripts/generate-viewer.mjs
+++ b/scripts/generate-viewer.mjs
@@ -3,6 +3,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import { sameEntry } from '../archify/renderers/shared/path-semantics.mjs';
const defaultRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
// Each fragment maps a marker in `viewer/template.source.html` to a file in
@@ -78,7 +79,7 @@ export function generateViewer({ root = defaultRoot, check = false } = {}) {
}
}
-if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
+if (process.argv[1] && sameEntry(process.argv[1], fileURLToPath(import.meta.url)).status === 'match') {
try {
const args = process.argv.slice(2);
if (args.length > 1 || (args.length === 1 && args[0] !== '--check')) {
diff --git a/test/cli.test.mjs b/test/cli.test.mjs
index 73a18e25..8872ee4d 100644
--- a/test/cli.test.mjs
+++ b/test/cli.test.mjs
@@ -1044,6 +1044,71 @@ test('cli: check reports an output-limit failure with a classified receipt', ()
assert.equal(receipt.diagnostic, receipt.diagnostics[0].message);
});
+test('cli: checker output-limit errors remain failures when the child exits zero', async (t) => {
+ const input = path.join(skillRoot, 'examples/web-app.architecture.json');
+ const artifact = path.join(tmp, 'zero-exit-output-limit.html');
+ assert.equal(run(['render', 'architecture', input, artifact]).status, 0);
+ const checker = path.join(skillRoot, 'scripts/check-render-output.mjs');
+ const preload = path.join(tmp, 'zero-exit-output-limit.cjs');
+ const log = path.join(tmp, 'zero-exit-output-limit.log');
+ fs.writeFileSync(preload, `
+const fs = require('node:fs');
+const childProcess = require('node:child_process');
+const spawnSync = childProcess.spawnSync;
+childProcess.spawnSync = function (executable, args, options) {
+ const result = spawnSync(executable, args, options);
+ if (args[0] === ${JSON.stringify(checker)}) {
+ if (result.error?.code !== 'ENOBUFS') throw new Error('Expected a real checker buffer overflow');
+ // Reproduce the real race: stdout exceeds the limit after the child exits.
+ result.status = 0;
+ result.signal = null;
+ fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({
+ status: result.status, error: result.error.code, bytes: Buffer.byteLength(result.stdout),
+ }) + '\\n');
+ }
+ return result;
+};
+require('node:module').syncBuiltinESMExports();
+`);
+ const source = path.join(__dirname, 'fixtures/v1-workflow-700x400.workflow.json');
+ const outputs = Object.fromEntries(['migrate', 'deliver', 'compare'].map(command => [
+ command, path.join(tmp, `zero-exit-output-limit-${command}.${command === 'migrate' ? 'workflow.json' : 'html'}`),
+ ]));
+ const cases = {
+ migrate: ['migrate', 'workflow', source, outputs.migrate, '--to-schema', '2', '--json'],
+ validate: ['validate', 'architecture', input, '--json'],
+ deliver: ['deliver', 'architecture', input, outputs.deliver, '--json'],
+ compare: ['compare', 'architecture', input, input, outputs.compare, '--json'],
+ check: ['check', artifact],
+ };
+ for (const [command, args] of Object.entries(cases)) {
+ await t.test(`${command} preserves its output-limit diagnostic`, () => {
+ const previous = 'trusted previous output\n';
+ if (outputs[command]) fs.writeFileSync(outputs[command], previous);
+ fs.writeFileSync(log, '');
+ const result = spawnSync(process.execPath, ['--require', preload, cli, ...args], {
+ cwd: skillRoot,
+ encoding: 'utf8',
+ env: { ...process.env, ARCHIFY_CHECK_MAX_BUFFER: '1024' },
+ });
+ const witness = JSON.parse(fs.readFileSync(log, 'utf8').trim().split('\n')[0]);
+ assert.equal(witness.status, 0);
+ assert.equal(witness.error, 'ENOBUFS');
+ assert.ok(witness.bytes > 1024);
+ assert.equal(result.status, 1, result.stderr || result.stdout);
+ const failure = JSON.parse(result.stdout);
+ assert.equal(failure.ok, false);
+ assert.equal(failure.command, command);
+ const entry = failure.diagnostics.find(diagnosticEntry => diagnosticEntry.code === 'artifact/check-output-limit');
+ assert.ok(entry, `missing output-limit diagnostic for ${command}`);
+ assert.equal(entry.evidence.systemCode, 'ENOBUFS');
+ assert.equal(entry.evidence.limitBytes, 1024);
+ assert.equal(entry.evidence.receivedBytes, witness.bytes);
+ if (outputs[command]) assert.equal(fs.readFileSync(outputs[command], 'utf8'), previous);
+ });
+ }
+});
+
test('cli: finalize captures a near-limit check receipt with provenance', { timeout: 180000 }, () => {
const input = path.join(tmp, 'near-limit-finalize.architecture.json');
fs.writeFileSync(input, JSON.stringify(bipartiteArchitectureSpec(11)));
diff --git a/test/generate-viewer.test.mjs b/test/generate-viewer.test.mjs
index b6b62dc3..a22bca27 100644
--- a/test/generate-viewer.test.mjs
+++ b/test/generate-viewer.test.mjs
@@ -4,7 +4,7 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
-import { fileURLToPath } from 'node:url';
+import { fileURLToPath, pathToFileURL } from 'node:url';
import { generateViewer } from '../scripts/generate-viewer.mjs';
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
@@ -30,6 +30,8 @@ function fixture(t) {
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.mkdirSync(path.join(root, 'scripts'));
fs.mkdirSync(path.join(root, 'archify/assets'), { recursive: true });
+ fs.mkdirSync(path.join(root, 'archify/renderers/shared'), { recursive: true });
+ fs.copyFileSync(path.join(repoRoot, 'archify/renderers/shared/path-semantics.mjs'), path.join(root, 'archify/renderers/shared/path-semantics.mjs'));
fs.cpSync(path.join(repoRoot, 'viewer'), path.join(root, 'viewer'), { recursive: true });
fs.copyFileSync(path.join(repoRoot, 'scripts/generate-viewer.mjs'), path.join(root, 'scripts/generate-viewer.mjs'));
const output = path.join(root, 'archify/assets/template.html');
@@ -72,6 +74,43 @@ test('the committed Viewer rebuilds deterministically outside the repository wor
assert.equal(fs.statSync(f.output).mtimeMs, beforeCheck, '--check must not rewrite output');
});
+test('Viewer generation runs through a preserved symlink entry', (t) => {
+ const f = fixture(t);
+ const script = path.join(f.root, 'scripts/generate-viewer.mjs');
+ const alias = path.join(f.root, 'scripts/generate-viewer-alias.mjs');
+ try {
+ fs.symlinkSync(script, alias);
+ } catch (error) {
+ if (['EPERM', 'EACCES', 'ENOTSUP'].includes(error?.code)) {
+ t.skip(`symlinks unavailable: ${error.code}`);
+ return;
+ }
+ throw error;
+ }
+ const previous = fs.readFileSync(f.output);
+ fs.unlinkSync(f.output);
+ const result = spawnSync(process.execPath, ['--preserve-symlinks-main', alias], {
+ cwd: os.tmpdir(), encoding: 'utf8',
+ });
+ assert.equal(result.status, 0, result.stderr);
+ assert.equal(result.stdout.trim(), 'generated archify/assets/template.html');
+ assert.deepEqual(fs.readFileSync(f.output), previous);
+});
+
+test('importing the generator with an unavailable entry path does not run or throw', (t) => {
+ const f = fixture(t);
+ const previous = fs.readFileSync(f.output);
+ const moduleUrl = pathToFileURL(path.join(f.root, 'scripts/generate-viewer.mjs')).href;
+ const missingEntry = path.join(f.root, 'scripts/missing-entry.mjs');
+ const result = spawnSync(process.execPath, ['--input-type=module', '-e',
+ `process.argv[1] = ${JSON.stringify(missingEntry)}; await import(${JSON.stringify(moduleUrl)}); console.log('imported');`], {
+ cwd: os.tmpdir(), encoding: 'utf8',
+ });
+ assert.equal(result.status, 0, result.stderr);
+ assert.equal(result.stdout.trim(), 'imported');
+ assert.deepEqual(fs.readFileSync(f.output), previous);
+});
+
test('editing any authoritative source requires explicit regeneration', (t) => {
const f = fixture(t);
for (const input of [f.shell, f.viewerCss, f.export, f.reader, f.cleanup, f.chrome, f.camera, f.radar, f.motion, f.finder, f.outline, f.tree, f.intent, f.lens, f.route, f.focus]) {