Skip to content

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

fix(workflow): apply shared cross-collection contracts in the compiler

zhanhuangchaod12d0eeea997
diff --git a/archify.zip b/archify.zip
index 7fb71656..9f943839 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/shared/cli.mjs b/archify/renderers/shared/cli.mjs
index 86e954c1..d3fe4365 100644
--- a/archify/renderers/shared/cli.mjs
+++ b/archify/renderers/shared/cli.mjs
@@ -62,8 +62,7 @@ export function loadDiagram({ rendererDir, diagramType, defaultExample, argv = p
const authoredOutput = diagram?.meta?.output;
if (authoredOutput !== undefined) validateAuthoredOutputPath(authoredOutput);
validateSchema(diagramType, diagram);
- validateGuidedViews(diagramType, diagram);
- validateRelationshipIds(diagramType, diagram);
+ validateCrossCollectionContracts(diagramType, diagram);
validateEngineeringProfile(diagramType, diagram);
const sourceEvidence = verifyRepositoryEvidence(diagramType, diagram, process.env.ARCHIFY_REPO_ROOT);
const template = fs.readFileSync(path.join(skillRoot, 'assets/template.html'), 'utf8');
@@ -361,6 +360,13 @@ export function validateGuidedViews(diagramType, diagram) {
}
}
+// Share relationship-ID and guided-view semantic checks between the loader
+// and workflow compiler without performing filesystem operations (see #429).
+export function validateCrossCollectionContracts(diagramType, diagram) {
+ validateGuidedViews(diagramType, diagram);
+ validateRelationshipIds(diagramType, diagram);
+}
+
// Accessible name for the generated diagram SVG.
export function svgRootAttrs(meta, explicitQualityProfile) {
const animation = meta.animation === 'trace' ? ' data-animation="trace"' : '';
diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjs
index 883a2cfb..6bc01ea4 100644
--- a/archify/renderers/workflow/workflow-compiler.mjs
+++ b/archify/renderers/workflow/workflow-compiler.mjs
@@ -1,5 +1,13 @@
import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';
-import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';
+import {
+ animateAttr,
+ focusEdgeAttrs,
+ focusNodeAttrs,
+ focusNodeTitle,
+ svgAccessibleText,
+ svgRootAttrs,
+ validateCrossCollectionContracts,
+} from '../shared/cli.mjs';
import {
throwDiagnosticError,
throwDiagnosticProblems,
@@ -824,6 +832,7 @@ function compileWorkflowInternal({
let inputDiagnostics = [];
try {
validateSchema('workflow', qualityResolvedWorkflow);
+ validateCrossCollectionContracts('workflow', qualityResolvedWorkflow);
} catch (error) {
inputDiagnostics = Array.isArray(error?.archifyDiagnostics)
? error.archifyDiagnostics.map((diagnostic) => ({
diff --git a/archify/test/workflow-compiler-hard-contract.test.mjs b/archify/test/workflow-compiler-hard-contract.test.mjs
index f1e697be..1344d229 100644
--- a/archify/test/workflow-compiler-hard-contract.test.mjs
+++ b/archify/test/workflow-compiler-hard-contract.test.mjs
@@ -2,6 +2,11 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { compileWorkflow } from '../renderers/workflow/workflow-compiler.mjs';
+import { spawnSync } from 'node:child_process';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
function clone(value) {
return JSON.parse(JSON.stringify(value));
@@ -1957,6 +1962,65 @@ test('compileWorkflow enforces the canonical workflow schema at its public bound
}
});
+function validationParityWorkflow() {
+ return workflow({
+ lanes: [{ id: 'main', label: 'Main' }],
+ nodes: ['a', 'b', 'c'].map((id, index) => ({
+ id, lane: 'main', col: index * 2, type: 'backend', label: id,
+ })),
+ edges: [
+ { id: 'first', from: 'a', to: 'b' },
+ { id: 'second', from: 'b', to: 'c' },
+ ],
+ });
+}
+
+test('compileWorkflow applies the shared cross-collection contracts the renderer enforces', (t) => {
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-compiler-parity-'));
+ t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
+ for (const { expectedCode, mutate } of [
+ {
+ expectedCode: 'relationship/duplicate-id',
+ mutate: (document) => { document.edges[1].id = document.edges[0].id; },
+ },
+ {
+ expectedCode: 'guided-view/invalid',
+ mutate: (document) => {
+ document.meta.views = [{ id: 'view', label: 'View', focus: ['missing'] }];
+ },
+ },
+ ]) {
+ const document = validationParityWorkflow();
+ mutate(document);
+ const input = path.join(directory, 'input.json');
+ fs.writeFileSync(input, JSON.stringify(document));
+ const rendered = spawnSync(process.execPath, [
+ fileURLToPath(new URL('../renderers/workflow/render-workflow.mjs', import.meta.url)),
+ input, path.join(directory, 'output.html'),
+ ], {
+ encoding: 'utf8',
+ env: { ...process.env, ARCHIFY_DIAGNOSTIC_FORMAT: 'json', ARCHIFY_QUALITY_PROFILE: 'standard' },
+ });
+ assert.equal(rendered.status, 1, rendered.stderr);
+ assert.deepEqual(JSON.parse(rendered.stderr).diagnostics.map(({ code }) => code), [expectedCode]);
+
+ const result = compileWorkflow({ workflow: document, qualityProfile: 'standard' });
+ assert.equal(result.ok, false);
+ assert.equal(result.svg, undefined);
+ assert.equal(result.receipt.contract, 'readable-v2');
+ assert.deepEqual(
+ result.diagnostics.map(({ code }) => code),
+ [expectedCode],
+ JSON.stringify(result.diagnostics, null, 2),
+ );
+ assert.ok(result.diagnostics.every(({ code }) => code !== 'internal/unclassified'));
+ assert.ok(result.diagnostics.every(({ supportedFixes }) => (
+ Array.isArray(supportedFixes) && supportedFixes.length === 0
+ )));
+ assert.deepEqual(result.receipt.diagnostics, result.diagnostics);
+ }
+});
+
test('readable-v2 rejects a negative absolute label pin without an explicit viewBox', () => {
const document = oneLaneWorkflow([{
id: 'ab', from: 'a', to: 'b', label: 'pinned', labelAt: [-20, 80],