Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix(cli): reject checker spawn errors even with status zero (#748)
outlier27-cell4c8256672d49
diff --git a/archify.zip b/archify.zipindex 9943d9e0..8802a28b 100644Binary files a/archify.zip and b/archify.zip differdiff --git a/archify/bin/archify.mjs b/archify/bin/archify.mjsindex f2ca6a4b..5a32f157 100755--- a/archify/bin/archify.mjs+++ b/archify/bin/archify.mjs@@ -2258,9 +2258,12 @@ function runNode(args, options = {}) {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;+ // spawnSync can report a system failure after a child has exited zero. A+ // truncated renderer or checker result is never a successful invocation.+ if (result.error && result.status === 0) {+ result.archifyRawStatus = result.status;+ result.status = 1;+ }return result;}@@ -2288,7 +2291,7 @@ function checkerOutputLimitDiagnostics(check, limitBytes) {evidence: {systemCode: check.error.code,...(check.signal ? { signal: check.signal } : {}),- status: check.status ?? null,+ status: check.archifyRawStatus ?? check.status ?? null,limitBytes,receivedBytes,},@@ -4322,10 +4325,6 @@ function writeDeliveryFailureReceipt(options) {return recorded;}-function reportValidateFailure(options) {- reportArtifactFailure({ ...options, command: 'validate' });-}-function reportArtifactArgumentFailure(command, error) {const details = error.archifyArgument || {};reportArtifactFailure({@@ -6824,6 +6823,7 @@ async function commandMigrate(args) {// attributed to the command the caller actually invoked.async function commandValidate(args, invocation = {}) {const invokingCommand = invocation.command || 'validate';+ const reportFailure = (options) => reportArtifactFailure({ ...options, command: invokingCommand });const qualityArgs = extractQualityArgs(args);const repoArgs = extractRepoRootArgs(qualityArgs.rest);args = repoArgs.rest;@@ -6867,7 +6867,7 @@ async function commandValidate(args, invocation = {}) {else validateAuthoredOutputPath(document.meta.output);} catch (error) {const diagnostics = error.archifyDiagnostics || [inputDiagnostic(error, inputPath)];- reportValidateFailure({+ reportFailure({json,stage: diagnostics.some((entry) => entry.code.startsWith('input/')) ? 'input' : 'render',type,@@ -6887,19 +6887,21 @@ async function commandValidate(args, invocation = {}) {env: rendererEnv(quality, repoRoot, true),});if (result.status !== 0) {- try {- const receipt = JSON.parse(result.stdout);- if (receipt?.contract && Array.isArray(receipt.diagnostics)) {- process.stdout.write(`${JSON.stringify(receipt, null, 2)}\n`);- process.exitCode = result.status ?? 1;- return;+ if (!result.error) {+ try {+ const receipt = JSON.parse(result.stdout);+ if (receipt?.contract && Array.isArray(receipt.diagnostics)) {+ process.stdout.write(`${JSON.stringify(receipt, null, 2)}\n`);+ process.exitCode = result.status ?? 1;+ return;+ }+ } catch {+ // Fall through to the renderer failure contract when no compiler+ // receipt was produced (for example, input JSON could not be read).}- } catch {- // Fall through to the renderer failure contract when no compiler- // receipt was produced (for example, input JSON could not be read).}const failure = rendererFailure(result);- reportValidateFailure({+ reportFailure({json,stage: failure.diagnostics.some((entry) => entry.code.startsWith('input/')) ? 'input' : 'render',type,@@ -6930,7 +6932,7 @@ async function commandValidate(args, invocation = {}) {});if (render.status !== 0) {const failure = rendererFailure(render);- report = () => reportValidateFailure({+ report = () => reportFailure({json,stage: failure.diagnostics.some((entry) => entry.code.startsWith('input/')) ? 'input' : 'render',type,@@ -6953,7 +6955,7 @@ async function commandValidate(args, invocation = {}) {exitCode = check.status ?? 1;const outputLimit = checkerOutputLimitDiagnostics(check, checkMaxBuffer);if (outputLimit) {- report = () => reportValidateFailure({+ report = () => reportFailure({json,stage: 'check',type,@@ -6970,7 +6972,7 @@ async function commandValidate(args, invocation = {}) {} catch {checker = { ok: false, diagnostic: 'Artifact checker failed without a parseable receipt.' };}- report = () => reportValidateFailure({+ report = () => reportFailure({json,stage: 'check',type,@@ -7031,7 +7033,7 @@ async function commandValidate(args, invocation = {}) {await temporary.cleanup();} catch (error) {exitCode = 1;- report = () => reportValidateFailure({+ report = () => reportFailure({json,stage: 'cleanup',type,diff --git a/test/cli.test.mjs b/test/cli.test.mjsindex 24600641..340ba64c 100644--- a/test/cli.test.mjs+++ b/test/cli.test.mjs@@ -1064,6 +1064,82 @@ test('cli: compare reports an output-limit failure with the same diagnostic', ()assert.equal(failure.diagnostics[0].evidence.systemCode, 'ENOBUFS');});+for (const command of ['validate', 'deliver', 'migrate', 'compare', 'check']) {+ test(`cli: ${command} rejects checker ENOBUFS with status zero`, () => {+ const input = path.join(skillRoot, 'examples/web-app.architecture.json');+ const out = path.join(tmp, `spawn-error-${command}.html`);+ const prior = '<!doctype html><title>trusted artifact</title>\n';+ fs.writeFileSync(out, prior);+ const args = command === 'validate' ? ['validate', 'architecture', input, '--json']+ : command === 'deliver' ? ['deliver', 'architecture', input, out, '--json']+ : command === 'migrate' ? ['migrate', 'workflow', path.join(__dirname, 'fixtures/v1-workflow-700x400.workflow.json'), path.join(tmp, 'spawn-error.workflow.json'), '--to-schema', '2', '--json']+ : command === 'compare' ? ['compare', 'architecture', input, input, out, '--json']+ : ['check', out];+ const wrapper = path.join(tmp, `spawn-error-${command}.mjs`);+ fs.writeFileSync(wrapper, `+import childProcess from 'node:child_process';+import { syncBuiltinESMExports } from 'node:module';+const original = childProcess.spawnSync;+childProcess.spawnSync = (executable, args, options) => {+ if (String(args?.[0]).endsWith('check-render-output.mjs')) {+ return { status: 0, signal: null, stdout: '{"ok":true}', stderr: '', error: Object.assign(new Error('buffer exceeded'), { code: 'ENOBUFS' }) };+ }+ return original(executable, args, options);+};+syncBuiltinESMExports();+process.argv = [process.execPath, ${JSON.stringify(cli)}, ...${JSON.stringify(args)}];+await import(${JSON.stringify(pathToFileURL(cli).href)});+`);+ const result = spawnSync(process.execPath, [wrapper], { cwd: skillRoot, encoding: 'utf8' });+ assert.equal(result.status, 1, result.stderr || result.stdout);+ const receipt = JSON.parse(result.stdout);+ assert.equal(receipt.ok, false);+ const entry = receipt.diagnostics.find(({ code }) => code === 'artifact/check-output-limit');+ assert.ok(entry, result.stdout);+ assert.equal(entry.evidence.systemCode, 'ENOBUFS');+ assert.equal(entry.evidence.status, 0);+ assert.equal(entry.evidence.receivedBytes, Buffer.byteLength('{"ok":true}'));+ if (command === 'deliver' || command === 'compare') assert.equal(fs.readFileSync(out, 'utf8'), prior);+ });+}++for (const [command, args] of [+ ['inspect', ['inspect', 'architecture', path.join(skillRoot, 'examples/web-app.architecture.json'), '--json']],+ ['validate', ['validate', 'architecture', path.join(skillRoot, 'examples/web-app.architecture.json'), '--layout-json', '--json']],+]) {+ test(`cli: ${command} rejects renderer ENOBUFS with status zero in layout mode`, () => {+ const wrapper = path.join(tmp, `renderer-spawn-error-${command}.mjs`);+ fs.writeFileSync(wrapper, `+import childProcess from 'node:child_process';+import { syncBuiltinESMExports } from 'node:module';+const original = childProcess.spawnSync;+childProcess.spawnSync = (executable, childArgs, options) => {+ if (String(childArgs?.[0]).endsWith('render-architecture.mjs')) {+ return {+ status: 0,+ signal: null,+ stdout: JSON.stringify({ contract: 'archify.renderer.failure.v1', diagnostics: [] }),+ stderr: '',+ error: Object.assign(new Error('buffer exceeded'), { code: 'ENOBUFS' }),+ };+ }+ return original(executable, childArgs, options);+};+syncBuiltinESMExports();+process.argv = [process.execPath, ${JSON.stringify(cli)}, ...${JSON.stringify(args)}];+await import(${JSON.stringify(pathToFileURL(cli).href)});+`);+ const result = spawnSync(process.execPath, [wrapper], { cwd: skillRoot, encoding: 'utf8' });+ assert.equal(result.status, 1, result.stderr || result.stdout);+ const receipt = JSON.parse(result.stdout);+ assert.equal(receipt.ok, false);+ assert.equal(receipt.command, command);+ assert.equal(receipt.stage, 'render');+ assert.equal(receipt.diagnostics[0].code, 'internal/renderer-process');+ assert.equal(receipt.contract, undefined);+ });+}+test('cli: check reports an output-limit failure with a classified receipt', () => {const input = path.join(skillRoot, 'examples/web-app.architecture.json');const artifact = path.join(tmp, 'check-output-limit.html');