Skip to content

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

fix(cli): record the output-limit delivery failure before releasing staging

zhanhuangchao15fb0d49e5cd
diff --git a/archify.zip b/archify.zip
index 236233eb..ca5d6675 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/bin/archify.mjs b/archify/bin/archify.mjs
index 59db0b0f..2fb68451 100755
--- a/archify/bin/archify.mjs
+++ b/archify/bin/archify.mjs
@@ -4817,7 +4817,7 @@ async function commandDeliver(args) {
if (check.stderr) process.stderr.write(check.stderr);
const outputLimit = checkerOutputLimitDiagnostics(check, checkMaxBuffer);
if (outputLimit) {
- reportDeliveryFailure({
+ await reportDeliveryFailure({
json,
stage: 'check',
type,
diff --git a/archify/test/cli.test.mjs b/archify/test/cli.test.mjs
index a6319b2f..db868804 100644
--- a/archify/test/cli.test.mjs
+++ b/archify/test/cli.test.mjs
@@ -916,6 +916,66 @@ test('cli: deliver reports an output-limit failure distinctly and preserves the
);
});
+test('cli: deliver records the output-limit failure before it releases the delivery', () => {
+ const input = path.join(skillRoot, 'examples/web-app.architecture.json');
+ const out = path.join(tmp, 'output-limit-order.html');
+ const trustedPriorArtifact = '<!doctype html><title>trusted prior artifact</title>\n';
+ fs.writeFileSync(out, trustedPriorArtifact);
+
+ // The failure receipt must be recorded before the delivery releases its
+ // staging. Both steps are observable from the CLI process: the receipt is
+ // published as the `.delivery.json` sidecar (linked into place), and the
+ // staging directory is retired through an `.archify-staging-remove-` quarantine.
+ const orderLog = path.join(tmp, 'output-limit-order.log');
+ const probe = path.join(tmp, 'output-limit-order-probe.mjs');
+ fs.writeFileSync(
+ probe,
+ `import fs from 'node:fs';
+const log = process.env.ARCHIFY_ORDER_LOG;
+// Instrumentation must never change CLI behavior, so a log write failure is ignored.
+const note = (event) => { try { if (log) fs.appendFileSync(log, event + '\\n'); } catch {} };
+const publishesReceipt = (to) => typeof to === 'string' && to.endsWith('.delivery.json');
+const linkSync = fs.linkSync;
+fs.linkSync = function (from, to) {
+ if (publishesReceipt(to)) note('record-failure');
+ return linkSync.apply(this, arguments);
+};
+const renameSync = fs.renameSync;
+fs.renameSync = function (from, to) {
+ if (publishesReceipt(to)) note('record-failure');
+ if (typeof to === 'string' && to.includes('.archify-staging-remove-')) {
+ const retired = String(from).split(/[\\\\/]/).pop();
+ note('release-staging:' + retired);
+ }
+ return renameSync.apply(this, arguments);
+};
+`,
+ );
+ fs.writeFileSync(orderLog, '');
+ const nodeOptions = `${process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} ` : ''}--import=${pathToFileURL(probe).href}`;
+
+ const result = run(['deliver', 'architecture', input, out, '--json'], {
+ env: { ...process.env, ARCHIFY_CHECK_MAX_BUFFER: '1024', ARCHIFY_ORDER_LOG: orderLog, NODE_OPTIONS: nodeOptions },
+ });
+
+ assert.equal(result.status, 1);
+ const failure = JSON.parse(result.stdout);
+ assert.equal(failure.diagnostics[0].code, 'artifact/check-output-limit');
+ assert.equal(fs.readFileSync(out, 'utf8'), trustedPriorArtifact);
+ const order = fs.readFileSync(orderLog, 'utf8').trim().split('\n').filter(Boolean);
+ const recorded = order.indexOf('record-failure');
+ // The delivery staging basename is its mkdtemp name; matching that shape keeps
+ // sibling stagings and `.archify-delivery-lock.json` from colliding with it.
+ const deliveryStaging = /^release-staging:\.archify-delivery-[A-Za-z0-9]{6}$/;
+ const released = order.findIndex((event) => deliveryStaging.test(event));
+ assert.notEqual(recorded, -1, `the failure receipt was not recorded (${order.join(' -> ') || 'no events'})`);
+ assert.notEqual(released, -1, `the delivery staging directory was not released (${order.join(' -> ') || 'no events'})`);
+ assert.ok(
+ recorded < released,
+ `the failure receipt must be recorded before the delivery staging is released (${order.join(' -> ')})`,
+ );
+});
+
test('cli: validate reports an output-limit failure with the same diagnostic', () => {
const input = path.join(skillRoot, 'examples/web-app.architecture.json');
const result = run(['validate', 'architecture', input, '--json'], {
diff --git a/archify/test/finalize.test.mjs b/archify/test/finalize.test.mjs
index e90a9300..ca85aa89 100644
--- a/archify/test/finalize.test.mjs
+++ b/archify/test/finalize.test.mjs
@@ -1123,11 +1123,17 @@ test('runFinalize reads the capture limit from the supplied env, not process.env
// (which inherit the supplied env) pass. The overflow probe below pins
// the lower end of that window: if the echo ever drops under 5 MiB the
// test fails loudly instead of passing without exercising the regression.
+ // Restore, rather than clear, the variables this test overrides so a
+ // preconfigured environment cannot be damaged for later tests.
+ const previousCheckMaxBuffer = process.env.ARCHIFY_CHECK_MAX_BUFFER;
+ const previousChrome = process.env.ARCHIFY_CHROME;
process.env.ARCHIFY_CHECK_MAX_BUFFER = String(5 * 1024 * 1024);
process.env.ARCHIFY_CHROME = missingChrome;
t.after(() => {
- delete process.env.ARCHIFY_CHECK_MAX_BUFFER;
- delete process.env.ARCHIFY_CHROME;
+ if (previousCheckMaxBuffer === undefined) delete process.env.ARCHIFY_CHECK_MAX_BUFFER;
+ else process.env.ARCHIFY_CHECK_MAX_BUFFER = previousCheckMaxBuffer;
+ if (previousChrome === undefined) delete process.env.ARCHIFY_CHROME;
+ else process.env.ARCHIFY_CHROME = previousChrome;
});
const finalized = await runFinalize({