Skip to content

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

test: reduce fixture costs and parallelize regression gates

tt-a1i6fa9f7c368d5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5f349356..2873f334 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -72,14 +72,57 @@ jobs:
- name: Install renderer dependencies
if: needs.scope.outputs.scope == 'full'
run: npm ci && npm --prefix archify ci
- - name: Golden-file + schema tests
- if: needs.scope.outputs.scope == 'full'
+ - name: Complete regression suite on canonical Node
+ if: needs.scope.outputs.scope == 'full' && matrix.node-version == 22
run: npm test
+ - name: Supported Node runtime compatibility
+ if: needs.scope.outputs.scope == 'full' && matrix.node-version != 22
+ run: npm run test:compat
- name: Verify community Hermes adapter
if: needs.scope.outputs.scope == 'full' && matrix.node-version == 22
run: node --test integrations/hermes-agent/test/plugin-contract.test.mjs
- webm-artifact:
+ browser-regression:
+ needs: scope
+ if: always() && !cancelled()
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [1, 2]
+ steps:
+ - name: Require successful scope checks
+ env:
+ SCOPE_RESULT: ${{ needs.scope.result }}
+ CI_SCOPE: ${{ needs.scope.outputs.scope }}
+ shell: bash
+ run: |
+ test "$SCOPE_RESULT" = success
+ case "$CI_SCOPE" in docs|full) ;; *) exit 1 ;; esac
+ - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
+ if: needs.scope.outputs.scope == 'full'
+ - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
+ if: needs.scope.outputs.scope == 'full'
+ with:
+ node-version: 22
+ - name: Provision a known Chrome runtime
+ if: needs.scope.outputs.scope == 'full'
+ id: setup-chrome
+ uses: browser-actions/setup-chrome@48ad923757ca74d66703209fe939badbdf80f2f4 # v2.2.0
+ with:
+ chrome-version: stable
+ install-dependencies: true
+ - name: Install browser test dependencies
+ if: needs.scope.outputs.scope == 'full'
+ run: npm ci --ignore-scripts --no-audit --no-fund && npm --prefix archify ci --ignore-scripts
+ - name: Run shared browser regression gate
+ if: needs.scope.outputs.scope == 'full'
+ run: npm run test:browser -- --shard=${{ matrix.shard }}/2
+ env:
+ ARCHIFY_CHROME: ${{ steps.setup-chrome.outputs.chrome-path }}
+ ARCHIFY_CHROME_NO_SANDBOX: '1'
+
+ webm-decode:
needs: scope
if: always() && !cancelled()
runs-on: ubuntu-latest
@@ -114,15 +157,24 @@ jobs:
run: npm run test:webm
env:
ARCHIFY_CHROME: ${{ steps.setup-chrome.outputs.chrome-path }}
- - name: Install browser test dependencies
- if: needs.scope.outputs.scope == 'full'
- run: npm ci --ignore-scripts --no-audit --no-fund && npm --prefix archify ci --ignore-scripts
- - name: Run shared browser regression gate
- if: needs.scope.outputs.scope == 'full'
- run: npm run test:browser
+
+ webm-artifact:
+ needs: [scope, browser-regression, webm-decode]
+ if: always() && !cancelled()
+ runs-on: ubuntu-latest
+ steps:
+ - name: Require every browser and WebM gate to succeed
env:
- ARCHIFY_CHROME: ${{ steps.setup-chrome.outputs.chrome-path }}
- ARCHIFY_CHROME_NO_SANDBOX: '1'
+ SCOPE_RESULT: ${{ needs.scope.result }}
+ CI_SCOPE: ${{ needs.scope.outputs.scope }}
+ BROWSER_RESULT: ${{ needs.browser-regression.result }}
+ WEBM_RESULT: ${{ needs.webm-decode.result }}
+ shell: bash
+ run: |
+ test "$SCOPE_RESULT" = success
+ case "$CI_SCOPE" in docs|full) ;; *) exit 1 ;; esac
+ test "$BROWSER_RESULT" = success
+ test "$WEBM_RESULT" = success
zip-freshness:
needs: scope
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index d9eff074..b927e7a0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -52,7 +52,7 @@ jobs:
archify/package-lock.json
- name: Install renderer dependencies
run: npm ci && npm --prefix archify ci
- - name: Tests must pass before releasing
+ - name: Complete regression suite on canonical Node before releasing
run: npm test
- name: Provision a known Chrome runtime
id: setup-chrome
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 27184746..c3e80c40 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -83,9 +83,30 @@ Nested tests follow Node's filtering rules: include their parent test names in
the pattern as well. Check the reported pass/skip counts for the intended cases.
`npm test` still runs all generated-output checks, golden comparisons, and every
-discovered test suite. Both test runners accept `--concurrency=N` to tune the
-number of simultaneous test files on Node 18.19+, for example
-`npm test -- --concurrency=4`. The default remains 2.
+discovered test suite. CI runs that complete suite once on canonical Node 22.
+The Node 18, 20, and 24 checks run `npm run test:compat`: all golden comparisons
+across the ten diagram types, followed by the maintained whole suites for CLI,
+schema compatibility, processes, paths, atomic output, preview, update, and
+diagnostics. The compatibility inventory is in
+`scripts/compat-test-inventory.mjs`; it also retains the complete package-gate
+suite for filesystem failures and noncanonical archive-toolchain rejection.
+Repository content, generator, and installation regressions remain in the
+complete Node 22 run. This preserves every regression in its owning gate while
+testing the maintained Node runtimes; it does not repeat every regression on
+every Node major. Tags retain the complete Node 22 suite, and both workflows
+retain their real Windows path, browser, WebM, and package gates.
+
+Use `npm run test:compat -- --list` to inspect the compatibility suites without
+running them; a normal compatibility run also runs the golden harness first.
+Exact file and test-name selections are supported through the shared runner,
+but a selected pass covers only that selection plus the golden harness.
+`test:focus` remains the development command that omits the golden pass.
+
+The test runners accept `--concurrency=N` to tune the number of simultaneous
+test files on Node 18.19+, for example `npm test -- --concurrency=4`. Headless
+repository and compatibility runs default to the available CPU count, capped
+at 4. Setting `ARCHIFY_CHROME` or running `test:browser` keeps the default at 2.
+Older Node versions that lack this concurrency option retain Node's default.
Compare timing and results on the same machine before increasing concurrency;
browser tests can become slower or unstable under CPU contention.
@@ -115,11 +136,20 @@ suites there so both workflows keep the same coverage. Ordinary `npm test`
retains optional browser skips. Real WebM decoding and site-language integration
remain in the separate `npm run test:webm` gate used by both workflows.
+PR CI divides the maintained browser inventory into two disjoint file shards
+with `npm run test:browser -- --shard=1/2` and `--shard=2/2`. Both run alongside
+the independent WebM gate; the required `webm-artifact` check succeeds only
+after both browser shards, WebM, and scope checks succeed. Tag releases and an
+unqualified `npm run test:browser` still run the complete browser inventory.
+`--list --shard=1/2` lists a shard without requiring Chrome. Shards cannot be
+combined with explicit files or test-name filtering; every maintained file runs
+in exactly one shard, and every executing shard still requires Chrome.
+
Only set `ARCHIFY_CHROME` for the browser run when you also plan to run the full
browser gate: many browser suites are included in `npm test` and would otherwise
-execute again. The ordinary CI Node matrix and required browser gate retain
-their existing coverage. Reuse the applicable final-head CI results instead of
-repeating an unchanged full suite locally.
+execute again. The canonical regression suite, Node compatibility matrix, and
+required browser gate establish their respective coverage. Reuse the applicable
+final-head CI results instead of repeating an unchanged full suite locally.
## Packages and generated artifacts
diff --git a/package.json b/package.json
index ad2417e3..4621e5c6 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"scripts": {
"test": "npm --prefix archify run check:viewer && npm --prefix archify run check:brand-marks && npm --prefix archify run check:validators && npm --prefix archify run check:release-identity && node test/golden.mjs && node scripts/run-tests.mjs",
"test:focus": "node scripts/run-tests.mjs --require-files",
+ "test:compat": "node scripts/run-compat-tests.mjs",
"test:browser": "node scripts/run-browser-tests.mjs",
"test:webm": "node test/webm-artifact.smoke.mjs && node --test test/site-language-integration.mjs"
},
diff --git a/scripts/compat-test-inventory.mjs b/scripts/compat-test-inventory.mjs
new file mode 100644
index 00000000..dd060176
--- /dev/null
+++ b/scripts/compat-test-inventory.mjs
@@ -0,0 +1,70 @@
+import fs from 'node:fs';
+import path from 'node:path';
+
+// The complete regression suite runs on canonical Node 22. Other maintained
+// Node lanes repeat goldens and these process, filesystem, schema and CLI
+// contracts; do not infer compatibility coverage from changed source paths.
+export const compatibilityTestFiles = Object.freeze([
+ 'test/artifact-receipt-flush.test.mjs',
+ 'test/atomic-output-recovery.test.mjs',
+ 'test/base-input-compatibility.test.mjs',
+ 'test/brand-content-encoding.test.mjs',
+ 'test/brand-marks.test.mjs',
+ 'test/chrome-pipe-transport.test.mjs',
+ 'test/cli-output-types.test.mjs',
+ 'test/cli.test.mjs',
+ 'test/compatibility-gate.test.mjs',
+ 'test/delivery-contract.test.mjs',
+ 'test/delivery-sidecar-path.test.mjs',
+ 'test/delivery-update.test.mjs',
+ 'test/finalize-browser-lifecycle.test.mjs',
+ 'test/finalize-paths.test.mjs',
+ 'test/finalize.test.mjs',
+ 'test/generate-validators.test.mjs',
+ 'test/meta-output-contract.test.mjs',
+ 'test/native-output-path.test.mjs',
+ 'test/open-artifact.test.mjs',
+ 'test/output-path.test.mjs',
+ 'test/path-boundary-contract.test.mjs',
+ 'test/path-semantics.test.mjs',
+ 'test/portable-path.test.mjs',
+ 'test/preview-contract.test.mjs',
+ 'test/preview-force-stop.test.mjs',
+ 'test/preview.test.mjs',
+ 'test/release-package-gates.test.mjs',
+ 'test/render-failure-diagnostics.test.mjs',
+ 'test/render-output-checks.test.mjs',
+ 'test/renderer-atomic-write.test.mjs',
+ 'test/renderer-diagnostic-boundary.test.mjs',
+ 'test/renderer-import-isolation.test.mjs',
+ 'test/repair-receipt.test.mjs',
+ 'test/repair-rounds.test.mjs',
+ 'test/repository-evidence-replacement.test.mjs',
+ 'test/repository-evidence-types.test.mjs',
+ 'test/repository-evidence.test.mjs',
+ 'test/repository-test-runner.test.mjs',
+ 'test/sidecar-path-length.test.mjs',
+ 'test/temp-cleanup.test.mjs',
+ 'test/update-contract.test.mjs',
+ 'test/update-notifier.test.mjs',
+ 'test/v1-compatibility.test.mjs',
+ 'test/validate-next-action.test.mjs',
+ 'test/visual-check.test.mjs',
+ 'test/workflow-migration.test.mjs',
+]);
+
+export function validateCompatibilityInventory(repoRoot, files = compatibilityTestFiles) {
+ if (files.length === 0) throw new Error('Compatibility inventory must not be empty');
+ const seen = new Set();
+ for (const file of files) {
+ if (typeof file !== 'string' || !/^test\/[a-z0-9-]+\.test\.mjs$/.test(file)) {
+ throw new Error(`Invalid compatibility test file: ${file}`);
+ }
+ if (seen.has(file)) throw new Error(`Duplicate compatibility test file: ${file}`);
+ seen.add(file);
+ if (!fs.existsSync(path.join(repoRoot, file)) || !fs.statSync(path.join(repoRoot, file)).isFile()) {
+ throw new Error(`Missing compatibility test file: ${file}`);
+ }
+ }
+ return files;
+}
diff --git a/scripts/generate-viewer.mjs b/scripts/generate-viewer.mjs
index 506cc482..01858674 100644
--- a/scripts/generate-viewer.mjs
+++ b/scripts/generate-viewer.mjs
@@ -4,8 +4,7 @@ import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
-const output = path.join(root, 'archify/assets/template.html');
+const defaultRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
// Each fragment maps a marker in `viewer/template.source.html` to a file in
// `viewer/`. The optional indent re-prefixes every non-empty source line so
// the inlined block sits inside the surrounding `<style>` / `<script>` tags at
@@ -40,11 +39,8 @@ function reindent(source, spaces) {
.join('\n');
}
-try {
- const args = process.argv.slice(2);
- if (args.length > 1 || (args.length === 1 && args[0] !== '--check')) {
- throw new Error('Usage: node scripts/generate-viewer.mjs [--check]');
- }
+export function generateViewer({ root = defaultRoot, check = false } = {}) {
+ const output = path.join(root, 'archify/assets/template.html');
let generated = fs.readFileSync(path.join(root, 'viewer/template.source.html'), 'utf8');
for (const [marker, file, indent = 0] of fragments) {
const source = fs.readFileSync(path.join(root, 'viewer', file), 'utf8');
@@ -67,7 +63,7 @@ try {
// including characters with String.replace semantics.
generated = parts[0] + reindent(source, indent) + tail;
}
- if (args[0] === '--check') {
+ if (check) {
if (!fs.existsSync(output) || fs.readFileSync(output, 'utf8') !== generated) {
throw new Error('Viewer template is stale — run npm run generate:viewer from archify/.');
}
@@ -79,9 +75,19 @@ try {
} finally {
fs.rmSync(temporary, { force: true });
}
- console.log('generated archify/assets/template.html');
}
-} catch (error) {
- console.error(error.message);
- process.exitCode = 1;
+}
+
+if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ try {
+ const args = process.argv.slice(2);
+ if (args.length > 1 || (args.length === 1 && args[0] !== '--check')) {
+ throw new Error('Usage: node scripts/generate-viewer.mjs [--check]');
+ }
+ generateViewer({ check: args[0] === '--check' });
+ if (args.length === 0) console.log('generated archify/assets/template.html');
+ } catch (error) {
+ console.error(error.message);
+ process.exitCode = 1;
+ }
}
diff --git a/scripts/run-browser-tests.mjs b/scripts/run-browser-tests.mjs
index 4bf4fc45..959b827a 100644
--- a/scripts/run-browser-tests.mjs
+++ b/scripts/run-browser-tests.mjs
@@ -8,6 +8,7 @@ import { testRunnerOptions } from './test-runner-options.mjs';
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
// Shared by PR CI and tag releases. WebM decoding stays in test:webm.
+// Adjacent heavy suites use opposite indices for CI's two modulo shards.
const testFiles = [
'finalize-browser.test.mjs',
'desktop-reader-browser.test.mjs',
@@ -21,10 +22,10 @@ const testFiles = [
'compact-header-clearance.test.mjs',
'architecture-reading-size-browser.test.mjs',
'export-cleanup-browser.test.mjs',
- 'offline-font-browser.test.mjs',
'i18n.test.mjs',
- 'semantic-radar.test.mjs',
+ 'offline-font-browser.test.mjs',
'viewer-chrome-layout.test.mjs',
+ 'semantic-radar.test.mjs',
'viewer-camera-browser.test.mjs',
'motion-governor-browser.test.mjs',
'finder-browser.test.mjs',
@@ -43,9 +44,34 @@ const testFiles = [
];
let options;
+let shard;
try {
- options = testRunnerOptions(process.argv.slice(2), {
- repoRoot, testFiles: testFiles.map(file => path.join('test', file)),
+ if (new Set(testFiles).size !== testFiles.length) throw new Error('Browser inventory contains duplicate files');
+ const runnerArguments = [];
+ for (const argument of process.argv.slice(2)) {
+ if (argument.startsWith('--shard')) {
+ if (shard) throw new Error('--shard may be specified only once');
+ const match = /^--shard=([1-9]\d*)\/([1-9]\d*)$/.exec(argument);
+ if (!match) throw new Error('Use --shard=<index>/<count> with positive integers');
+ const index = Number(match[1]);
+ const count = Number(match[2]);
+ if (!Number.isSafeInteger(index) || !Number.isSafeInteger(count) || index > count) {
+ throw new Error('--shard index must be a safe integer within the shard count');
+ }
+ if (count > testFiles.length) throw new Error('--shard count would create empty browser shards');
+ shard = { index, count };
+ } else {
+ runnerArguments.push(argument);
+ }
+ }
+ if (shard && runnerArguments.some(argument => !argument.startsWith('--') || argument.startsWith('--test-name-pattern='))) {
+ throw new Error('--shard cannot be combined with explicit files or a test-name selection');
+ }
+ const inventory = shard
+ ? testFiles.filter((_, index) => index % shard.count === shard.index - 1)
+ : testFiles;
+ options = testRunnerOptions(runnerArguments, {
+ repoRoot, testFiles: inventory.map(file => path.join('test', file)),
});
} catch (error) {
console.error(error.message);
@@ -62,7 +88,7 @@ if (!chrome) {
process.exit(1);
}
-console.error(`Browser tests: ${options.files.length} files, concurrency ${options.concurrency}`);
+console.error(`Browser tests: ${options.files.length} files, concurrency ${options.concurrency}${shard ? `, shard ${shard.index}/${shard.count}` : ''}`);
const result = spawnSync(process.execPath, options.args, {
cwd: repoRoot,
env: { ...process.env, ARCHIFY_CHROME: chrome },
@@ -70,4 +96,4 @@ const result = spawnSync(process.execPath, options.args, {
});
if (result.error) throw result.error;
if (result.signal) console.error(`browser test runner terminated by ${result.signal}`);
-process.exitCode = result.status ?? 1;
+process.exitCode = result.signal ? 1 : (result.status ?? 1);
diff --git a/scripts/run-compat-tests.mjs b/scripts/run-compat-tests.mjs
new file mode 100644
index 00000000..4969f3ef
--- /dev/null
+++ b/scripts/run-compat-tests.mjs
@@ -0,0 +1,40 @@
+#!/usr/bin/env node
+
+import { spawnSync } from 'node:child_process';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { validateCompatibilityInventory } from './compat-test-inventory.mjs';
+import { testRunnerOptions } from './test-runner-options.mjs';
+
+const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const argv = process.argv.slice(2);
+let options;
+try {
+ options = testRunnerOptions(argv, {
+ repoRoot, testFiles: validateCompatibilityInventory(repoRoot),
+ });
+} catch (error) {
+ console.error(error.message);
+ process.exit(1);
+}
+if (options.list) {
+ console.log(options.files.join('\n'));
+ process.exit(0);
+}
+
+console.error(`Compatibility tests: golden outputs plus ${options.files.length} runtime suites`);
+// Delegate to the existing runner so compatibility tests have the same option
+// handling, isolated update cache, cleanup and child-failure behavior.
+const runnerFlags = argv.filter(argument => argument.startsWith('--'));
+for (const args of [
+ ['test/golden.mjs'],
+ ['scripts/run-tests.mjs', ...runnerFlags, ...options.files],
+]) {
+ const result = spawnSync(process.execPath, args, { cwd: repoRoot, stdio: 'inherit' });
+ if (result.error) throw result.error;
+ if (result.signal) console.error(`compatibility test runner terminated by ${result.signal}`);
+ if (result.signal || result.status !== 0) {
+ process.exitCode = result.signal ? 1 : (result.status ?? 1);
+ break;
+ }
+}
diff --git a/scripts/run-tests.mjs b/scripts/run-tests.mjs
index a93049b1..8c51dc61 100644
--- a/scripts/run-tests.mjs
+++ b/scripts/run-tests.mjs
@@ -16,7 +16,11 @@ const testFiles = fs.readdirSync(testRoot)
let options;
try {
- options = testRunnerOptions(process.argv.slice(2), { repoRoot, testFiles, allowRequireFiles: true });
+ // Node-only files benefit from independent CPU slots. Keep Chrome's lower
+ // ceiling when a full run explicitly enables browser cases.
+ const parallelism = os.availableParallelism?.() ?? os.cpus().length;
+ const defaultConcurrency = process.env.ARCHIFY_CHROME ? 2 : Math.max(1, Math.min(4, parallelism));
+ options = testRunnerOptions(process.argv.slice(2), { repoRoot, testFiles, allowRequireFiles: true, defaultConcurrency });
} catch (error) {
console.error(error.message);
process.exit(1);
diff --git a/scripts/test-runner-options.mjs b/scripts/test-runner-options.mjs
index d37607b5..2a9a6cdc 100644
--- a/scripts/test-runner-options.mjs
+++ b/scripts/test-runner-options.mjs
@@ -1,8 +1,8 @@
import path from 'node:path';
// Both runners accept exact files, never infer coverage from changed sources.
-export function testRunnerOptions(argv, { repoRoot, testFiles, allowRequireFiles = false }) {
- let concurrency = 2;
+export function testRunnerOptions(argv, { repoRoot, testFiles, allowRequireFiles = false, defaultConcurrency = 2 }) {
+ let concurrency = defaultConcurrency;
let explicitConcurrency = false;
let list = false;
let requireFiles = false;
diff --git a/test/architecture-compare-recovery.test.mjs b/test/architecture-compare-recovery.test.mjs
index 823e4f30..bd8ac6dc 100644
--- a/test/architecture-compare-recovery.test.mjs
+++ b/test/architecture-compare-recovery.test.mjs
@@ -9,8 +9,6 @@ import { fileURLToPath } from 'node:url';
const skillRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'archify');
const cli = path.join(skillRoot, 'bin/archify.mjs');
-const base = path.join(skillRoot, 'examples/checkout-platform.base.architecture.json');
-const head = path.join(skillRoot, 'examples/checkout-platform.head.architecture.json');
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
const cases = [
{ name: 'successful replacement cleans staging', failures: [] },
@@ -30,6 +28,23 @@ const cases = [
function fixture(t) {
const root = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'archify-compare-recovery-')));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
+ // Recovery exercises publication and file identity, not checkout-platform layout.
+ // Keep real CLI-rendered artifacts while minimizing each old/candidate render.
+ const base = path.join(root, 'base.json');
+ const head = path.join(root, 'head.json');
+ const graph = {
+ schema_version: 1, diagram_type: 'architecture',
+ meta: { title: 'Recovery fixture', output: 'review.html' },
+ components: [
+ { id: 'api', type: 'backend', label: 'API', pos: [80, 80], size: [160, 80] },
+ { id: 'store', type: 'database', label: 'Store', pos: [380, 80], size: [160, 80] },
+ ],
+ connections: [{ id: 'write', from: 'api', to: 'store', label: 'write' }],
+ };
+ fs.writeFileSync(base, JSON.stringify(graph));
+ const candidate = structuredClone(graph);
+ candidate.components[1].label = 'Updated store';
+ fs.writeFileSync(head, JSON.stringify(candidate));
const targets = { html: path.join(root, 'review.html'), receipt: path.join(root, 'review.receipt.json') };
const run = (preload, newHead = head, json = true) => spawnSync(process.execPath, [
...(preload ? ['--require', preload] : []), cli, 'compare', 'architecture', base, newHead,
@@ -41,13 +56,13 @@ function fixture(t) {
assert.equal(initial.status, 0, initial.stderr || initial.stdout);
const old = Object.fromEntries(Object.entries(targets).map(([key, file]) => [key, fs.readFileSync(file)]));
assert.equal(JSON.parse(old.receipt).artifact.sha256, hash(old.html));
- return { root, targets, old, run };
+ return { root, targets, old, run, head };
}
test('compare recovery: human diagnostics identify the retained backup and target', { timeout: 70000 }, (t) => {
const data = fixture(t);
const { preload } = inject(data, ['commit-receipt', 'restore-html']);
- const result = data.run(preload, head, false);
+ const result = data.run(preload, data.head, false);
assert.ifError(result.error);
assert.equal(result.status, 1);
assert.equal(result.stdout.trim(), '');
diff --git a/test/architecture-delta-literals.test.mjs b/test/architecture-delta-literals.test.mjs
index 5237c3b1..ef638f0a 100644
--- a/test/architecture-delta-literals.test.mjs
+++ b/test/architecture-delta-literals.test.mjs
@@ -12,25 +12,38 @@ const attr = (node, name) => node.attrs?.find((entry) => entry.name === name)?.v
const descendants = (node) => [node, ...(node.childNodes || []).flatMap(descendants)];
const textContent = (node) => node.nodeName === '#text' ? node.value : (node.childNodes || []).map(textContent).join('');
-function fixtures(kind, operation, label) {
+const labels = ['PID $$', 'Match $&', 'Before $`', "After $'"];
+
+function fixtures(kind, operation) {
const base = {
schema_version: 1, diagram_type: 'architecture', meta: { title: 'Literal labels', output: 'literal-labels.html' },
- components: [
- { id: 'keep', type: 'backend', label: 'Keep', pos: [80, 80], size: [160, 80] },
- { id: 'target', type: 'database', label: kind === 'node' ? label : 'Target', pos: [380, 80], size: [160, 80] },
- ],
- connections: kind === 'edge' ? [{ id: 'link', from: 'keep', to: 'target', label }] : [],
- boundaries: kind === 'boundary' ? [{ kind: 'region', label, wraps: ['target'], pad: 30 }] : [],
+ components: [], connections: [], boundaries: [],
};
+ // Independent rows batch the tokens without overlapping nodes, routes, or frames.
+ for (const [index, label] of labels.entries()) {
+ const y = 80 + index * 320;
+ base.components.push(
+ { id: `keep-${index}`, type: 'backend', label: 'Keep', pos: [80, y], size: [160, 80] },
+ { id: `target-${index}`, type: 'database', label: kind === 'node' ? label : 'Target', pos: [380, y], size: [160, 80] },
+ );
+ if (kind === 'edge') base.connections.push({ id: `link-${index}`, from: `keep-${index}`, to: `target-${index}`, label });
+ if (kind === 'boundary') base.boundaries.push({ kind: 'region', label, wraps: [`target-${index}`], pad: 30 });
+ }
const head = structuredClone(base);
if (operation === 'removed') {
- if (kind === 'node') head.components.pop();
+ if (kind === 'node') head.components = head.components.filter(({ id }) => id.startsWith('keep-'));
if (kind === 'edge') head.connections = [];
if (kind === 'boundary') head.boundaries = [];
} else if (kind === 'edge') {
- Object.assign(head.connections[0], { fromSide: 'bottom', toSide: 'bottom', via: [[160, 240], [460, 240]] });
- } else if (kind === 'boundary') head.boundaries[0].pad = 40;
- else head.components[1].pos = [380, 280];
+ for (const [index, connection] of head.connections.entries()) {
+ const y = 240 + index * 320;
+ Object.assign(connection, { fromSide: 'bottom', toSide: 'bottom', via: [[160, y], [460, y]] });
+ }
+ } else if (kind === 'boundary') {
+ for (const boundary of head.boundaries) boundary.pad = 40;
+ } else {
+ for (const component of head.components.filter(({ id }) => id.startsWith('target-'))) component.pos[0] = 680;
+ }
return [base, head];
}
@@ -39,41 +52,49 @@ for (const kind of ['node', 'edge', 'boundary']) {
test(`compare preserves literal replacement tokens in ${operation} ${kind} labels`, (t) => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-delta-literals-'));
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
- for (const label of ['PID $$', 'Match $&', 'Before $`', "After $'"]) {
- const inputs = fixtures(kind, operation, label).map((value, index) => {
- const file = path.join(dir, `${index}.json`);
- fs.writeFileSync(file, JSON.stringify(value));
- return file;
- });
- const output = path.join(dir, 'delta.html');
- const run = spawnSync(process.execPath, [path.join(skillRoot, 'bin/archify.mjs'),
- 'compare', 'architecture', ...inputs, output, '--quality', 'standard', '--json'],
- { cwd: skillRoot, encoding: 'utf8', timeout: 30000 });
- assert.ifError(run.error);
- assert.equal(run.status, 0, `${label}: ${run.stderr || run.stdout}`);
- const document = parse(fs.readFileSync(output, 'utf8'));
- const section = descendants(document).find((node) => attr(node, 'data-view') === 'delta');
- assert.ok(section, 'delta section exists');
- const nodes = descendants(section);
- const state = operation === 'removed' ? 'removed' : 'moved-from';
+ const inputs = fixtures(kind, operation).map((value, index) => {
+ const file = path.join(dir, `${index}.json`);
+ fs.writeFileSync(file, JSON.stringify(value));
+ return file;
+ });
+ const output = path.join(dir, 'delta.html');
+ const run = spawnSync(process.execPath, [path.join(skillRoot, 'bin/archify.mjs'),
+ 'compare', 'architecture', ...inputs, output, '--quality', 'standard', '--json'],
+ { cwd: skillRoot, encoding: 'utf8', timeout: 30000 });
+ assert.ifError(run.error);
+ assert.equal(run.status, 0, run.stderr || run.stdout);
+ const document = parse(fs.readFileSync(output, 'utf8'));
+ const section = descendants(document).find((node) => attr(node, 'data-view') === 'delta');
+ assert.ok(section, 'delta section exists');
+ const nodes = descendants(section);
+ const state = operation === 'removed' ? 'removed' : 'moved-from';
+ if (kind === 'boundary') {
+ for (const node of nodes.filter((node) => attr(node, 'data-delta-boundary-key') !== undefined)) {
+ const label = attr(node, 'data-composition-frame-label') ?? textContent(node);
+ assert.ok(labels.includes(label), 'every navigation key belongs to a literal boundary');
+ assert.equal(attr(node, 'data-delta-boundary-key'), `region:${label}`);
+ }
+ }
+ for (const [index, label] of labels.entries()) {
let texts;
if (kind === 'node') {
- const group = nodes.find((node) => attr(node, 'data-node-id') === 'target' && attr(node, 'data-delta-state') === state);
+ const group = nodes.find((node) => attr(node, 'data-node-id') === `target-${index}` && attr(node, 'data-delta-state') === state);
assert.ok(group, 'baseline node exists');
assert.equal(attr(group, 'data-node-label'), label);
texts = descendants(group).filter((node) => node.tagName === 'text');
} else if (kind === 'edge') {
- const group = nodes.find((node) => node.tagName === 'g' && attr(node, 'data-edge-id') === 'link' && attr(node, 'data-delta-state') === state);
+ const group = nodes.find((node) => node.tagName === 'g' && attr(node, 'data-edge-id') === `link-${index}` && attr(node, 'data-delta-state') === state);
assert.ok(group, 'baseline relationship label exists');
texts = descendants(group).filter((node) => node.tagName === 'text');
} else {
- const frame = nodes.find((node) => attr(node, 'data-graph-role') === 'structural-frame' && attr(node, 'data-delta-state') === state);
+ const frame = nodes.find((node) => attr(node, 'data-graph-role') === 'structural-frame' && attr(node, 'data-composition-frame-label') === label && attr(node, 'data-delta-state') === state);
assert.ok(frame, 'baseline boundary exists');
assert.equal(attr(frame, 'data-composition-frame-label'), label);
- const keyed = nodes.filter((node) => attr(node, 'data-delta-boundary-key') !== undefined);
+ assert.equal(attr(frame, 'data-delta-boundary-key'), `region:${label}`);
+ const keyed = nodes.filter((node) => attr(node, 'data-delta-boundary-key') === `region:${label}`);
assert.ok(keyed.length >= 2, 'boundary frame and label have navigation keys');
- for (const node of keyed) assert.equal(attr(node, 'data-delta-boundary-key'), `region:${label}`);
- texts = nodes.filter((node) => node.tagName === 'text' && attr(node, 'data-boundary-label') !== undefined && attr(node, 'data-delta-state') === state);
+ texts = nodes.filter((node) => node.tagName === 'text' && attr(node, 'data-boundary-label') !== undefined && attr(node, 'data-delta-state') === state && textContent(node) === label);
+ for (const node of texts) assert.equal(attr(node, 'data-delta-boundary-key'), `region:${label}`);
}
assert.ok(texts.some((node) => textContent(node) === label), `${kind} visible label must preserve ${label}`);
}
diff --git a/test/browser-gate.test.mjs b/test/browser-gate.test.mjs
index 2d6040bb..a61e0087 100644
--- a/test/browser-gate.test.mjs
+++ b/test/browser-gate.test.mjs
@@ -5,6 +5,7 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import { parse } from 'yaml';
const skillRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'archify');
const repoRoot = path.dirname(skillRoot);
@@ -121,10 +122,10 @@ test('selected browser execution still requires Chrome', () => {
assert.match(result.stderr, /require an executable Chrome\/Chromium/);
});
-for (const outcome of [{ status: 7, signal: null }, { status: null, signal: 'SIGTERM' }]) {
+for (const outcome of [{ status: 7, signal: null }, { status: null, signal: 'SIGTERM' }, { status: 0, signal: 'SIGTERM' }]) {
test(`browser gate propagates child failure (${outcome.signal || outcome.status})`, (t) => {
const result = interceptedRun(t, outcome);
- assert.equal(result.status, outcome.status ?? 1);
+ assert.equal(result.status, outcome.signal ? 1 : (outcome.status ?? 1));
if (outcome.signal) assert.match(result.stderr, /terminated by SIGTERM/);
});
}
@@ -132,15 +133,109 @@ for (const outcome of [{ status: 7, signal: null }, { status: null, signal: 'SIG
test('CI and release use the same browser command and retain WebM decoding', () => {
const manifest = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
assert.equal(manifest.scripts['test:browser'], 'node scripts/run-browser-tests.mjs');
- for (const workflow of ['ci.yml', 'release.yml']) {
- const source = fs.readFileSync(path.join(repoRoot, '.github/workflows', workflow), 'utf8');
- const gate = source.match(/ {6}- name: Run shared browser regression gate\n([\s\S]*?)(?=\n {6}- name:|\n {2}[\w-]+:|$)/)?.[1];
- assert.ok(gate, `${workflow} must invoke the shared gate`);
- assert.match(gate, /run: npm run test:browser\n/);
- assert.doesNotMatch(gate, /working-directory:/);
- assert.match(gate, /ARCHIFY_CHROME: \$\{\{ steps\.setup-chrome\.outputs\.chrome-path \}\}/);
- assert.match(source, /run: npm run test:webm/);
- assert.doesNotMatch(source, /run: node --test[^\n]*test\/.*browser/);
+ for (const [workflow, browserJob, webmJob, browserCommand] of [
+ ['ci.yml', 'browser-regression', 'webm-decode', 'npm run test:browser -- --shard=${{ matrix.shard }}/2'],
+ ['release.yml', 'release', 'release', 'npm run test:browser'],
+ ]) {
+ const jobs = parse(fs.readFileSync(path.join(repoRoot, '.github/workflows', workflow), 'utf8')).jobs;
+ const gate = jobs[browserJob].steps.find(step => step.name === 'Run shared browser regression gate');
+ assert.equal(gate?.run, browserCommand, `${workflow} must invoke the shared gate`);
+ assert.equal(gate['working-directory'], undefined);
+ assert.equal(gate.env.ARCHIFY_CHROME, '${{ steps.setup-chrome.outputs.chrome-path }}');
+ assert.ok(jobs[webmJob].steps.some(step => step.run === 'npm run test:webm'));
+ }
+});
+
+test('browser shards are deterministic, nonempty, disjoint and cover the full maintained inventory', (t) => {
+ const full = JSON.parse(interceptedRun(t, { status: 0 }).stdout).args.filter(arg => !arg.startsWith('--'));
+ const shards = [1, 2].map(index => {
+ const result = interceptedRun(t, { status: 0 }, [`--shard=${index}/2`]);
+ assert.equal(result.status, 0, result.stderr);
+ assert.match(result.stderr, new RegExp(`shard ${index}/2`));
+ const files = JSON.parse(result.stdout).args.filter(arg => !arg.startsWith('--'));
+ assert.deepEqual(files, full.filter((_, fileIndex) => fileIndex % 2 === index - 1));
+ assert.ok(files.length > 0);
+ return files;
+ });
+ assert.equal(new Set(shards.flat()).size, full.length);
+ assert.equal(shards.flat().length, full.length);
+ assert.deepEqual(shards.flat().sort(), [...full].sort());
+ const owner = file => shards.findIndex(files => files.includes(`test/${file}`));
+ assert.notEqual(owner('desktop-reader-browser.test.mjs'), owner('i18n.test.mjs'));
+ assert.notEqual(owner('viewer-chrome-layout.test.mjs'), owner('reader-layout-browser.test.mjs'));
+});
+
+test('browser shard listing requires neither Chrome nor test execution', () => {
+ const full = spawnSync(process.execPath, [runner, '--list'], {
+ encoding: 'utf8', env: { ...process.env, ARCHIFY_CHROME: '' },
+ }).stdout.trim().split('\n');
+ for (const index of [1, 2]) {
+ const result = spawnSync(process.execPath, [runner, `--shard=${index}/2`, '--list'], {
+ encoding: 'utf8', env: { ...process.env, ARCHIFY_CHROME: '' },
+ });
+ assert.equal(result.status, 0, result.stderr);
+ assert.equal(result.stderr, '');
+ assert.deepEqual(result.stdout.trim().split('\n'), full.filter((_, fileIndex) => fileIndex % 2 === index - 1));
+ }
+});
+
+test('browser shards reject invalid, duplicate, empty or partially selected coverage before launch', (t) => {
+ for (const args of [
+ ['--shard'], ['--shard=0/2'], ['--shard=1/0'], ['--shard=3/2'],
+ ['--shard=01/2'], ['--shard=1/2.0'], ['--shard=1/999'],
+ ['--shard=1/9007199254740992'], ['--shard=1/2', '--shard=2/2'],
+ ['--shard=1/2', 'test/i18n.test.mjs'],
+ ['--shard=1/2', '--test-name-pattern=locale'],
+ ]) {
+ const result = interceptedRun(t, { status: 0 }, args);
+ assert.equal(result.status, 1, result.stderr);
+ assert.equal(result.stdout, '', 'invalid sharding must never start child tests');
+ }
+});
+
+test('sharded browser gates retain Chrome requirements and propagate child failures', (t) => {
+ const unavailable = spawnSync(process.execPath, [runner, '--shard=1/2'], {
+ encoding: 'utf8', env: { ...process.env, ARCHIFY_CHROME: '' },
+ });
+ assert.equal(unavailable.status, 1);
+ assert.match(unavailable.stderr, /require an executable Chrome\/Chromium/);
+ for (const outcome of [{ status: 7 }, { status: null }, { status: 0, signal: 'SIGTERM' }]) {
+ const result = interceptedRun(t, outcome, ['--shard=2/2']);
+ assert.equal(result.status, outcome.signal ? 1 : (outcome.status ?? 1));
+ }
+});
+
+test('CI media aggregate fails closed for either child and keeps docs-only scope validation', () => {
+ const jobs = parse(fs.readFileSync(path.join(repoRoot, '.github/workflows/ci.yml'), 'utf8')).jobs;
+ assert.equal(jobs['browser-regression'].strategy['fail-fast'], false);
+ assert.deepEqual(jobs['browser-regression'].strategy.matrix.shard, [1, 2]);
+ const aggregate = jobs['webm-artifact'];
+ assert.deepEqual(aggregate.needs, ['scope', 'browser-regression', 'webm-decode']);
+ assert.equal(aggregate.if, 'always() && !cancelled()');
+ const step = aggregate.steps[0];
+ assert.equal(step.env.BROWSER_RESULT, '${{ needs.browser-regression.result }}');
+ assert.equal(step.env.WEBM_RESULT, '${{ needs.webm-decode.result }}');
+ const runAggregate = overrides => spawnSync('bash', ['-e', '-u', '-o', 'pipefail', '-c', step.run], {
+ encoding: 'utf8', env: {
+ ...process.env, SCOPE_RESULT: 'success', CI_SCOPE: 'full',
+ BROWSER_RESULT: 'success', WEBM_RESULT: 'success', ...overrides,
+ },
+ });
+ for (const scope of ['full', 'docs']) assert.equal(runAggregate({ CI_SCOPE: scope }).status, 0);
+ for (const key of ['SCOPE_RESULT', 'BROWSER_RESULT', 'WEBM_RESULT']) {
+ for (const result of ['failure', 'skipped', 'cancelled', '']) {
+ assert.notEqual(runAggregate({ [key]: result }).status, 0, `${key}=${result} must fail closed`);
+ }
+ }
+ assert.notEqual(runAggregate({ CI_SCOPE: 'unknown' }).status, 0);
+ for (const name of ['browser-regression', 'webm-decode']) {
+ const job = jobs[name];
+ assert.equal(job.needs, 'scope');
+ assert.equal(job.if, 'always() && !cancelled()');
+ assert.equal(job.steps[0].env.SCOPE_RESULT, '${{ needs.scope.result }}');
+ assert.match(job.steps[0].run, /test "\$SCOPE_RESULT" = success/);
+ assert.match(job.steps[0].run, /docs\|full/);
+ for (const runtimeStep of job.steps.slice(1)) assert.equal(runtimeStep.if, "needs.scope.outputs.scope == 'full'");
}
});
diff --git a/test/compatibility-gate.test.mjs b/test/compatibility-gate.test.mjs
new file mode 100644
index 00000000..e581469c
--- /dev/null
+++ b/test/compatibility-gate.test.mjs
@@ -0,0 +1,160 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+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';
+import { parse } from 'yaml';
+import {
+ compatibilityTestFiles,
+ validateCompatibilityInventory,
+} from '../scripts/compat-test-inventory.mjs';
+
+const repoRoot = fileURLToPath(new URL('../', import.meta.url));
+const runner = path.join(repoRoot, 'scripts/run-compat-tests.mjs');
+const [major, minor] = process.versions.node.split('.').map(Number);
+const supportsConcurrency = major > 18 || (major === 18 && minor >= 19);
+const supportsNamePattern = major > 18 || (major === 18 && minor >= 11);
+
+function interceptedRun(t, args = [], outcomes = [{ status: 0 }, { status: 0 }]) {
+ const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-compat-gate-'));
+ t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
+ const preload = path.join(directory, 'capture.cjs');
+ fs.writeFileSync(preload, `
+const childProcess = require('node:child_process');
+const outcomes = ${JSON.stringify(outcomes)};
+let invocation = 0;
+childProcess.spawnSync = (command, args, options) => {
+ console.log(JSON.stringify({ command, args, cwd: options.cwd }));
+ const result = outcomes[invocation++] || { status: 0 };
+ if (result.error) result.error = new Error(result.error);
+ return result;
+};
+require('node:module').syncBuiltinESMExports();
+`);
+ return spawnSync(process.execPath, ['--require', preload, runner, ...args], {
+ cwd: directory, encoding: 'utf8',
+ });
+}
+
+function calls(result) {
+ return result.stdout.trim() ? result.stdout.trim().split('\n').map(line => JSON.parse(line)) : [];
+}
+
+test('compatibility inventory is nonempty, unique, and names existing regression suites', () => {
+ assert.equal(validateCompatibilityInventory(repoRoot), compatibilityTestFiles);
+ assert.throws(() => validateCompatibilityInventory(repoRoot, []), /must not be empty/);
+ const file = compatibilityTestFiles[0];
+ assert.throws(() => validateCompatibilityInventory(repoRoot, [file, file]), /Duplicate/);
+ assert.throws(() => validateCompatibilityInventory(repoRoot, ['test/missing-compat.test.mjs']), /Missing/);
+ for (const unsafe of ['../test/cli.test.mjs', 'test/golden.mjs', path.join(repoRoot, file)]) {
+ assert.throws(() => validateCompatibilityInventory(repoRoot, [unsafe]), /Invalid/);
+ }
+});
+
+test('compatibility retains whole runtime-sensitive suites and the noncanonical ZIP contract', () => {
+ for (const name of [
+ 'cli', 'preview', 'preview-force-stop', 'update-notifier', 'update-contract',
+ 'finalize', 'finalize-browser-lifecycle', 'renderer-import-isolation',
+ 'renderer-diagnostic-boundary', 'render-failure-diagnostics',
+ 'atomic-output-recovery', 'renderer-atomic-write', 'artifact-receipt-flush',
+ 'path-semantics', 'path-boundary-contract', 'native-output-path', 'output-path',
+ 'portable-path', 'delivery-sidecar-path', 'sidecar-path-length',
+ 'generate-validators', 'v1-compatibility', 'base-input-compatibility',
+ 'workflow-migration', 'release-package-gates',
+ 'brand-marks', 'brand-content-encoding',
+ ]) assert.ok(compatibilityTestFiles.includes(`test/${name}.test.mjs`), `${name} must retain compatibility coverage`);
+});
+
+test('compatibility runs all goldens before delegating its exact inventory from an unrelated cwd', (t) => {
+ const result = interceptedRun(t);
+ assert.equal(result.status, 0, result.stderr);
+ const observed = calls(result);
+ assert.deepEqual(observed.map(call => call.args), [
+ ['test/golden.mjs'], ['scripts/run-tests.mjs', ...compatibilityTestFiles],
+ ]);
+ for (const call of observed) {
+ assert.equal(call.command, process.execPath);
+ assert.equal(fs.realpathSync(call.cwd), fs.realpathSync(repoRoot));
+ }
+ assert.match(result.stderr, /Compatibility tests: golden outputs plus \d+ runtime suites/);
+});
+
+test('compatibility listing starts neither goldens nor child tests', (t) => {
+ const result = interceptedRun(t, ['--list']);
+ assert.equal(result.status, 0, result.stderr);
+ assert.deepEqual(result.stdout.trim().split('\n'), compatibilityTestFiles);
+ assert.equal(result.stderr, '');
+});
+
+test('compatibility rejects unknown suites and invalid options before any execution', (t) => {
+ for (const args of [
+ ['test/gallery.test.mjs'], ['test/missing.test.mjs'], ['--unknown'],
+ ['--concurrency=0'], ['--test-name-pattern='], ['--test-name-pattern=['],
+ ]) {
+ const result = interceptedRun(t, args);
+ assert.equal(result.status, 1, result.stderr);
+ assert.equal(result.stdout, '');
+ }
+});
+
+test('compatibility forwards shared runner options and exact selections without filtering goldens', (t) => {
+ const file = 'test/cli.test.mjs';
+ const flags = [
+ ...(supportsConcurrency ? ['--concurrency=1'] : []),
+ ...(supportsNamePattern ? ['--test-name-pattern=cli: validate'] : []),
+ ];
+ const result = interceptedRun(t, [path.join(repoRoot, file), file, ...flags]);
+ assert.equal(result.status, 0, result.stderr);
+ assert.deepEqual(calls(result).map(call => call.args), [
+ ['test/golden.mjs'], ['scripts/run-tests.mjs', ...flags, file],
+ ]);
+});
+
+for (const stage of [0, 1]) {
+ for (const outcome of [{ status: 7 }, { status: null }, { signal: 'SIGTERM' }, { error: 'spawn failed' }]) {
+ test(`compatibility propagates ${stage === 0 ? 'golden' : 'suite'} failure (${outcome.error || outcome.signal || outcome.status})`, (t) => {
+ const outcomes = [{ status: 0 }, { status: 0 }];
+ outcomes[stage] = outcome;
+ const result = interceptedRun(t, [], outcomes);
+ assert.equal(result.status, outcome.signal || outcome.error ? 1 : (outcome.status ?? 1), result.stderr);
+ assert.equal(calls(result).length, stage + 1, 'a failed golden must not start compatibility suites');
+ if (outcome.signal) assert.match(result.stderr, /terminated by SIGTERM/);
+ if (outcome.error) assert.match(result.stderr, /spawn failed/);
+ });
+ }
+}
+
+test('compatibility goldens cover every advertised diagram type', () => {
+ const source = fs.readFileSync(path.join(repoRoot, 'test/golden.mjs'), 'utf8');
+ const fixtures = source.match(/const GOLDEN = \[([\s\S]*?)\n\];/)?.[1];
+ assert.ok(fixtures, 'golden harness must declare its representative rendered fixtures');
+ const modes = new Set([...fixtures.matchAll(/\['([a-z]+)',/g)].map(match => match[1]));
+ assert.deepEqual([...modes].sort(), [
+ 'architecture', 'class', 'dataflow', 'erd', 'lifecycle',
+ 'sequence', 'timeline', 'tree', 'waterfall', 'workflow',
+ ]);
+});
+
+test('CI keeps all Node check names while separating canonical regressions and compatibility', () => {
+ const manifest = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
+ assert.equal(manifest.scripts['test:compat'], 'node scripts/run-compat-tests.mjs');
+ assert.match(manifest.scripts.test, /check:viewer/);
+ assert.match(manifest.scripts.test, /check:brand-marks/);
+ assert.match(manifest.scripts.test, /check:validators/);
+ assert.match(manifest.scripts.test, /check:release-identity/);
+ assert.match(manifest.scripts.test, /node test\/golden\.mjs/);
+ assert.match(manifest.scripts.test, /node scripts\/run-tests\.mjs$/);
+ const ci = parse(fs.readFileSync(path.join(repoRoot, '.github/workflows/ci.yml'), 'utf8'));
+ const job = ci.jobs.test;
+ assert.deepEqual(job.strategy.matrix['node-version'], [18, 20, 22, 24]);
+ assert.equal(job.name, undefined, 'preserve generated matrix check names');
+ const full = job.steps.find(step => step.run === 'npm test');
+ const compatibility = job.steps.find(step => step.run === 'npm run test:compat');
+ assert.equal(full?.if, "needs.scope.outputs.scope == 'full' && matrix.node-version == 22");
+ assert.equal(compatibility?.if, "needs.scope.outputs.scope == 'full' && matrix.node-version != 22");
+ const release = parse(fs.readFileSync(path.join(repoRoot, '.github/workflows/release.yml'), 'utf8'));
+ assert.equal(release.jobs.release.steps.find(step => step.with?.['node-version'])?.with['node-version'], 22);
+ assert.equal(release.jobs.release.steps.filter(step => step.run === 'npm test').length, 1);
+});
diff --git a/test/generate-viewer.test.mjs b/test/generate-viewer.test.mjs
index e3adf33e..b6b62dc3 100644
--- a/test/generate-viewer.test.mjs
+++ b/test/generate-viewer.test.mjs
@@ -5,6 +5,7 @@ import os from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
+import { generateViewer } from '../scripts/generate-viewer.mjs';
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const marker = '/* ARCHIFY:READER_LAYOUT */';
@@ -108,29 +109,44 @@ test('viewer.css owns the complete main style block', (t) => {
assert.match(css, /\n\}\n$/);
});
-for (const [fragment, slot] of Object.entries(fragments)) {
- for (const failure of ['missing shell', 'missing fragment', 'missing marker', 'duplicate marker', 'empty fragment', ...Object.keys(fragments).map(name => `${name} marker`)]) {
- test(`assembly rejects ${fragment}: ${failure} without overwriting a valid artifact`, (t) => {
- const f = fixture(t);
- const previous = fs.readFileSync(f.output);
- if (failure === 'missing shell') fs.unlinkSync(f.shell);
- if (failure === 'missing fragment') fs.unlinkSync(f[fragment]);
- const owner = fragment === 'cleanup' ? f.export : f.shell;
- if (failure === 'missing marker') fs.writeFileSync(owner, fs.readFileSync(owner, 'utf8').replace(slot, ''));
- if (failure === 'duplicate marker') fs.appendFileSync(owner, slot);
- if (failure === 'empty fragment') fs.writeFileSync(f[fragment], ' \n');
- const embeddedSlot = fragments[failure.replace(/ marker$/, '')];
- if (embeddedSlot) fs.appendFileSync(f[fragment], embeddedSlot);
- for (const args of [[], ['--check']]) {
- const result = f.run(...args);
- assert.equal(result.status, 1, failure);
- assert.match(result.stderr, /ENOENT|marker|empty/);
- assert.deepEqual(fs.readFileSync(f.output), previous);
- assert.deepEqual(fs.readdirSync(path.dirname(f.output)), ['template.html']);
- }
- });
+test('assembly failure matrix preserves a valid artifact', { concurrency: false }, async (t) => {
+ const f = fixture(t);
+ // Marker rejection depends on source structure, not production bundle size.
+ // The CLI tests above and below retain the complete authoritative sources.
+ const shellSlots = Object.values(fragments).filter(slot => slot !== cleanupMarker && slot !== viewerCssMarker);
+ fs.writeFileSync(f.shell, `<style>\n${viewerCssMarker}\n</style><script>\n${shellSlots.join('\n')}\n</script>\n`);
+ for (const fragment of Object.keys(fragments)) {
+ fs.writeFileSync(f[fragment], `/* ${fragment} source */\n${fragment === 'export' ? `${cleanupMarker}\n` : ''}`);
}
-}
+ generateViewer({ root: f.root });
+ // Each case restores its mutations before the next awaited subtest starts.
+ for (const [fragment, slot] of Object.entries(fragments)) {
+ for (const failure of ['missing shell', 'missing fragment', 'missing marker', 'duplicate marker', 'empty fragment', ...Object.keys(fragments).map(name => `${name} marker`)]) {
+ await t.test(`assembly rejects ${fragment}: ${failure} without overwriting a valid artifact`, () => {
+ const previous = fs.readFileSync(f.output);
+ const owner = fragment === 'cleanup' ? f.export : f.shell;
+ const sources = new Map([f.shell, f[fragment], owner].map(file => [file, fs.readFileSync(file)]));
+ try {
+ if (failure === 'missing shell') fs.unlinkSync(f.shell);
+ if (failure === 'missing fragment') fs.unlinkSync(f[fragment]);
+ if (failure === 'missing marker') fs.writeFileSync(owner, fs.readFileSync(owner, 'utf8').replace(slot, ''));
+ if (failure === 'duplicate marker') fs.appendFileSync(owner, slot);
+ if (failure === 'empty fragment') fs.writeFileSync(f[fragment], ' \n');
+ const embeddedSlot = fragments[failure.replace(/ marker$/, '')];
+ if (embeddedSlot) fs.appendFileSync(f[fragment], embeddedSlot);
+ for (const check of [false, true]) {
+ assert.throws(() => generateViewer({ root: f.root, check }), /ENOENT|marker|empty/, failure);
+ assert.deepEqual(fs.readFileSync(f.output), previous);
+ assert.deepEqual(fs.readdirSync(path.dirname(f.output)), ['template.html']);
+ }
+ } finally {
+ for (const [file, bytes] of sources) fs.writeFileSync(file, bytes);
+ fs.writeFileSync(f.output, previous);
+ }
+ });
+ }
+ }
+});
test('assembly preserves literal replacement tokens, Unicode and source line endings', (t) => {
const f = fixture(t);
diff --git a/test/release-package-gates.test.mjs b/test/release-package-gates.test.mjs
index 327dedec..8c11e474 100644
--- a/test/release-package-gates.test.mjs
+++ b/test/release-package-gates.test.mjs
@@ -264,9 +264,13 @@ test('GitHub Pages deploys the verified website artifact only after every reposi
'v4.3.3',
);
assert.match(website, /name: website-dist/);
- const browser = workflowJob(workflow, 'webm-artifact');
+ const browser = workflowJob(workflow, 'browser-regression');
assert.match(browser, /Run shared browser regression gate/);
- assert.match(browser, /npm run test:browser/);
+ assert.match(browser, /npm run test:browser -- --shard=\$\{\{ matrix\.shard \}\}\/2/);
+ const media = workflowJob(workflow, 'webm-artifact');
+ assert.match(media, /needs: \[scope, browser-regression, webm-decode\]/);
+ assert.match(media, /test "\$BROWSER_RESULT" = success/);
+ assert.match(media, /test "\$WEBM_RESULT" = success/);
const renderer = workflowJob(workflow, 'test');
assert.match(renderer, /Verify community Hermes adapter/);
const packageSmoke = workflowJob(workflow, 'package-smoke');
diff --git a/test/repository-evidence-types.test.mjs b/test/repository-evidence-types.test.mjs
index e4196428..995a9518 100644
--- a/test/repository-evidence-types.test.mjs
+++ b/test/repository-evidence-types.test.mjs
@@ -3,7 +3,7 @@ import { execFileSync, spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
-import test from 'node:test';
+import test, { after } from 'node:test';
import { fileURLToPath } from 'node:url';
import { startPreview } from '../archify/bin/preview.mjs';
@@ -42,9 +42,23 @@ function evidencePayload(html) {
return JSON.parse(match[1]);
}
-// A throwaway origin-matched checkout plus the typed diagram that points at it.
-function fixture({ type, collection, example, first }) {
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-evidence-types-'));
+function temporaryDirectory(t, prefix) {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
+ return root;
+}
+
+// Initialize identical source history once. Each test copies the whole checkout,
+// including .git, so changing its origin or index cannot affect another test.
+let sourceSeed;
+let seedRoot;
+after(() => {
+ if (seedRoot) fs.rmSync(seedRoot, { recursive: true, force: true });
+});
+function repositorySeed() {
+ if (sourceSeed) return sourceSeed;
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-evidence-seed-'));
+ seedRoot = root;
fs.mkdirSync(path.join(root, 'src', 'nested'), { recursive: true });
fs.writeFileSync(path.join(root, 'src', 'router.js'), 'export function route(input) {\n return input.kind;\n}\n');
fs.writeFileSync(path.join(root, 'src', 'store.js'), 'export const store = new Map();\n');
@@ -55,6 +69,17 @@ function fixture({ type, collection, example, first }) {
git(root, 'add', '.');
git(root, 'commit', '-m', 'fixture');
const revision = git(root, 'rev-parse', 'HEAD');
+ sourceSeed = { root, revision };
+ return sourceSeed;
+}
+
+// A throwaway origin-matched checkout plus the typed diagram that points at it.
+function fixture(t, { type, collection, example, first }) {
+ const seed = repositorySeed();
+ const root = temporaryDirectory(t, 'archify-evidence-types-');
+ // cpSync copies files rather than hardlinking them or sharing a Git common dir.
+ fs.cpSync(seed.root, root, { recursive: true });
+ const { revision } = seed;
const diagram = JSON.parse(fs.readFileSync(path.join(skillRoot, 'examples', example), 'utf8'));
diagram.meta.repository = { url: 'https://github.com/example/evidence-repo', revision };
@@ -73,8 +98,8 @@ function fixture({ type, collection, example, first }) {
for (const shape of TYPES) {
const { type, collection, first } = shape;
- test(`${type} repository evidence is revision-verified, receipt-backed, and keyed by node id`, () => {
- const data = fixture(shape);
+ test(`${type} repository evidence is revision-verified, receipt-backed, and keyed by node id`, (t) => {
+ const data = fixture(t, shape);
const output = path.join(data.root, `verified.${type}.html`);
const result = run(['deliver', type, data.input, output, '--repo-root', data.root, '--json']);
assert.equal(result.status, 0, result.stderr || result.stdout);
@@ -107,8 +132,8 @@ for (const shape of TYPES) {
assert.doesNotMatch(svg, /src\/router\.js|github\.com\/example\/evidence-repo|source-evidence/);
});
- test(`${type} repository evidence applies every architecture verification`, () => {
- const data = fixture(shape);
+ test(`${type} repository evidence applies every architecture verification`, (t) => {
+ const data = fixture(t, shape);
const output = path.join(data.root, `must-stay.${type}.html`);
fs.writeFileSync(output, 'trusted previous artifact');
const deliver = (...args) => run(['deliver', type, data.input, output, ...args, '--json']);
@@ -184,8 +209,8 @@ for (const shape of TYPES) {
assert.equal(fs.readFileSync(output, 'utf8'), 'trusted previous artifact');
});
- test(`${type} duplicate evidence node IDs cannot replace a trusted artifact`, () => {
- const data = fixture(shape);
+ test(`${type} duplicate evidence node IDs cannot replace a trusted artifact`, (t) => {
+ const data = fixture(t, shape);
const duplicate = structuredClone(data.node);
duplicate.sources = [{ path: 'src/store.js', line: 1 }];
data.diagram[collection].push(duplicate);
@@ -221,8 +246,8 @@ for (const shape of TYPES) {
assert.equal(fs.readFileSync(output, 'utf8'), 'trusted previous artifact');
});
- test(`${type} repository evidence honors Gitee and GitLab links and local-only mode`, () => {
- const data = fixture(shape);
+ test(`${type} repository evidence honors Gitee and GitLab links and local-only mode`, (t) => {
+ const data = fixture(t, shape);
const output = path.join(data.root, `provider.${type}.html`);
data.diagram.meta.repository = { url: 'https://gitee.com/example/evidence-repo', revision: data.revision, provider: 'gitee' };
@@ -262,8 +287,8 @@ for (const shape of TYPES) {
assert.ok(evidence.nodes[first].every((source) => !Object.hasOwn(source, 'href')));
});
- test(`${type} evidence diagnostics point at its own node collection`, () => {
- const data = fixture(shape);
+ test(`${type} evidence diagnostics point at its own node collection`, (t) => {
+ const data = fixture(t, shape);
data.node.sources = [{ path: 'src/missing.js' }];
data.write();
const result = run(['validate', type, data.input, '--repo-root', data.root, '--json']);
@@ -277,8 +302,8 @@ for (const shape of TYPES) {
assert.ok(diagnostic.supportedFixes.length);
});
- test(`${type} sources stay bounded by the shared schema shape`, () => {
- const data = fixture(shape);
+ test(`${type} sources stay bounded by the shared schema shape`, (t) => {
+ const data = fixture(t, shape);
data.node.sources = [
{ path: 'src/router.js' },
{ path: 'src/router.js' },
@@ -297,8 +322,8 @@ for (const shape of TYPES) {
assert.match(result.stderr, /must NOT have additional properties/);
});
- test(`${type} node sources require pinned repository metadata`, () => {
- const data = fixture(shape);
+ test(`${type} node sources require pinned repository metadata`, (t) => {
+ const data = fixture(t, shape);
delete data.diagram.meta.repository;
data.write();
const result = run(['validate', type, data.input, '--repo-root', data.root, '--json']);
@@ -308,8 +333,8 @@ for (const shape of TYPES) {
));
});
- test(`${type} repository metadata requires at least one verified source`, () => {
- const data = fixture(shape);
+ test(`${type} repository metadata requires at least one verified source`, (t) => {
+ const data = fixture(t, shape);
delete data.node.sources;
data.write();
const result = run(['validate', type, data.input, '--repo-root', data.root, '--json']);
@@ -340,9 +365,9 @@ test('repository evidence no longer rejects any supported diagram type', () => {
);
});
-test('ordinary typed artifacts still carry no repository evidence', () => {
+test('ordinary typed artifacts still carry no repository evidence', (t) => {
for (const { type, example } of TYPES) {
- const output = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'archify-no-evidence-types-')), `${type}.html`);
+ const output = path.join(temporaryDirectory(t, 'archify-no-evidence-types-'), `${type}.html`);
const result = run(['render', type, path.join(skillRoot, 'examples', example), output]);
assert.equal(result.status, 0, result.stderr);
const html = fs.readFileSync(output, 'utf8');
@@ -361,9 +386,9 @@ async function waitForState(url, predicate, timeoutMs = 12000) {
assert.fail(`preview did not settle; latest state: ${JSON.stringify(latest)}`);
}
-test('live preview publishes verified evidence for a non-architecture type', { timeout: 20000 }, async () => {
+test('live preview publishes verified evidence for a non-architecture type', { timeout: 20000 }, async (t) => {
const shape = TYPES.find(({ type }) => type === 'lifecycle');
- const data = fixture(shape);
+ const data = fixture(t, shape);
const output = path.join(data.root, 'preview.lifecycle.html');
const preview = await startPreview({
type: shape.type,
@@ -386,8 +411,8 @@ test('live preview publishes verified evidence for a non-architecture type', { t
}
});
-test('workflow migration verifies and preserves pinned source evidence before replacement', () => {
- const data = fixture(TYPES.find(shape => shape.type === 'workflow'));
+test('workflow migration verifies and preserves pinned source evidence before replacement', (t) => {
+ const data = fixture(t, TYPES.find(shape => shape.type === 'workflow'));
const repository = data.diagram.meta.repository;
const legacy = JSON.parse(fs.readFileSync(path.join(skillRoot, '..', 'test', 'fixtures/v1-workflow-explicit-coordinates.workflow.json'), 'utf8'));
legacy.meta.repository = repository;
diff --git a/test/repository-test-runner.test.mjs b/test/repository-test-runner.test.mjs
index f6214408..b69f8b25 100644
--- a/test/repository-test-runner.test.mjs
+++ b/test/repository-test-runner.test.mjs
@@ -11,14 +11,16 @@ const runner = path.join(repoRoot, 'scripts/run-tests.mjs');
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(Number);
const supportsConcurrency = nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 19);
const supportsNamePattern = nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 11);
+const defaultConcurrency = process.env.ARCHIFY_CHROME ? 2 : Math.max(1, Math.min(4, os.availableParallelism?.() ?? os.cpus().length));
-function interceptedRun(t, args = [], outcome = { status: 0 }, nodeVersion = process.versions.node) {
+function interceptedRun(t, args = [], outcome = { status: 0 }, nodeVersion = process.versions.node, runtime = {}) {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-runner-'));
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
const preload = path.join(directory, 'capture.cjs');
fs.writeFileSync(preload, `
const childProcess = require('node:child_process');
const fs = require('node:fs');
+${runtime.parallelism === undefined ? '' : `require('node:os').availableParallelism = () => ${runtime.parallelism};`}
Object.defineProperty(process.versions, 'node', { value: ${JSON.stringify(nodeVersion)} });
childProcess.spawnSync = (command, args, options) => {
const cache = options.env.ARCHIFY_UPDATE_CACHE_DIRECTORY;
@@ -29,7 +31,7 @@ require('node:module').syncBuiltinESMExports();
`);
return spawnSync(process.execPath, ['--require', preload, runner, ...args], {
cwd: directory, encoding: 'utf8',
- env: { ...process.env, ARCHIFY_UPDATE_CACHE_DIRECTORY: path.join(directory, 'user-cache') },
+ env: { ...process.env, ...(runtime.chrome === undefined ? {} : { ARCHIFY_CHROME: runtime.chrome }), ARCHIFY_UPDATE_CACHE_DIRECTORY: path.join(directory, 'user-cache') },
});
}
@@ -58,6 +60,14 @@ test('supported older Node retains default operation and rejects explicit concur
assert.match(override.stderr, /requires Node 18\.19 or newer/);
});
+test('default Node concurrency uses available CPUs with a four-file ceiling and a separate Chrome limit', (t) => {
+ for (const [parallelism, chrome, expected] of [[1, '', 1], [2, '', 2], [8, '', 4], [8, 'chrome', 2]]) {
+ const result = interceptedRun(t, ['test/repository-test-runner.test.mjs'], { status: 0 }, '22.0.0', { parallelism, chrome });
+ assert.equal(result.status, 0, result.stderr);
+ assert.deepEqual(JSON.parse(result.stdout).args, ['--test', `--test-concurrency=${expected}`, 'test/repository-test-runner.test.mjs']);
+ }
+});
+
test('focused runner forwards a validated test name pattern as one child argument', (t) => {
const pattern = '^repository runner .*failure';
const result = interceptedRun(t, ['test/repository-test-runner.test.mjs', `--test-name-pattern=${pattern}`]);
@@ -69,7 +79,7 @@ test('focused runner forwards a validated test name pattern as one child argumen
}
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(JSON.parse(result.stdout).args, [
- '--test', ...(supportsConcurrency ? ['--test-concurrency=2'] : []),
+ '--test', ...(supportsConcurrency ? [`--test-concurrency=${defaultConcurrency}`] : []),
`--test-name-pattern=${pattern}`, 'test/repository-test-runner.test.mjs',
]);
});
@@ -147,7 +157,7 @@ require('node:module').syncBuiltinESMExports();
const invocation = JSON.parse(result.stdout);
const [major, minor] = process.versions.node.split('.').map(Number);
if (major > 18 || (major === 18 && minor >= 19)) {
- assert.ok(invocation.args.includes('--test-concurrency=2'));
+ assert.ok(invocation.args.includes(`--test-concurrency=${defaultConcurrency}`));
}
assert.equal(fs.realpathSync(invocation.cwd), fs.realpathSync(repoRoot));
const expected = fs.readdirSync(path.join(repoRoot, 'test'))
diff --git a/test/viewer-chrome-layout.test.mjs b/test/viewer-chrome-layout.test.mjs
index b5f356a4..d34754b0 100644
--- a/test/viewer-chrome-layout.test.mjs
+++ b/test/viewer-chrome-layout.test.mjs
@@ -13,6 +13,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const skillRoot = path.resolve(__dirname, '..', 'archify');
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-viewer-chrome-layout-'));
const chromePath = process.env.ARCHIFY_CHROME ? findChrome() : null;
+const renderedArtifacts = new Map();
const CASES = {
architecture: 'web-app.architecture.json',
@@ -23,7 +24,9 @@ const CASES = {
};
function render(mode, example) {
- const output = path.join(tmp, `${mode}.html`);
+ const key = JSON.stringify([mode, example]);
+ if (renderedArtifacts.has(key)) return renderedArtifacts.get(key);
+ const output = path.join(tmp, `${mode}-${renderedArtifacts.size}.html`);
execFileSync(process.execPath, [
path.join(skillRoot, 'bin', 'archify.mjs'),
'render',
@@ -31,6 +34,7 @@ function render(mode, example) {
path.join(skillRoot, 'examples', example),
output,
]);
+ renderedArtifacts.set(key, output);
return output;
}