Skip to content

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

fix(showcase): preserve retained profiles and recognize CLI aliases

tt-a1icb6e8551ec18
diff --git a/scripts/build-readme-showcase.mjs b/scripts/build-readme-showcase.mjs
index c518772b..4ca966fd 100644
--- a/scripts/build-readme-showcase.mjs
+++ b/scripts/build-readme-showcase.mjs
@@ -6,6 +6,7 @@ import os from 'node:os';
import path from 'node:path';
import { spawn, spawnSync } from 'node:child_process';
import { fileURLToPath, pathToFileURL } from 'node:url';
+import { sameEntry } from '../archify/renderers/shared/path-semantics.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(__dirname, '..');
@@ -277,7 +278,9 @@ async function stopChrome(chrome, profileRoot, timeoutMs = 5000) {
forcedDelay.cancel();
releaseChildStreams(chrome);
if (!forced && !settled) {
- throw new Error(`Chrome did not exit; profile retained at ${profileRoot}`);
+ const error = new Error(`Chrome did not exit; profile retained at ${profileRoot}`);
+ error.retainProfile = true;
+ throw error;
}
}
@@ -376,6 +379,20 @@ function buildGif(ffmpeg, framesRoot) {
if (result.status !== 0) throw new Error(`ffmpeg failed:\n${result.stderr || result.stdout}`);
}
+// The owner of the temporary root must honor Chrome shutdown failure too.
+export async function withCaptureDirectory(capture) {
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-readme-showcase-'));
+ let retainProfile = false;
+ try {
+ return await capture(tempRoot);
+ } catch (error) {
+ retainProfile = error.retainProfile === true;
+ throw error;
+ } finally {
+ if (!retainProfile) fs.rmSync(tempRoot, { recursive: true, force: true });
+ }
+}
+
async function main() {
for (const scene of scenes) {
const artifact = path.join(repoRoot, scene.artifact);
@@ -384,8 +401,7 @@ async function main() {
const chromePath = findChrome();
if (!chromePath) throw new Error('Chrome or Chromium is required. Set ARCHIFY_CHROME to its executable path.');
const ffmpeg = requireCommand('ffmpeg', 'Install it with your system package manager.');
- const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-readme-showcase-'));
- try {
+ await withCaptureDirectory(async (tempRoot) => {
const { framesRoot, frameCount } = await captureFrames(chromePath, tempRoot);
buildGif(ffmpeg, framesRoot);
const receipt = {
@@ -413,13 +429,11 @@ async function main() {
console.log(`README showcase ${frameCount} frames / ${receipt.durationSeconds.toFixed(1)}s / ${receipt.bytes} bytes`);
console.log(outputPath);
console.log(receiptPath);
- } finally {
- fs.rmSync(tempRoot, { recursive: true, force: true });
- }
+ });
}
const invokedDirectly = process.argv[1]
- && import.meta.url === pathToFileURL(process.argv[1]).href;
+ && sameEntry(fileURLToPath(import.meta.url), process.argv[1]).status === 'match';
if (invokedDirectly) {
main().catch(error => {
console.error(error.stack || error.message);
diff --git a/test/readme-showcase.test.mjs b/test/readme-showcase.test.mjs
index 4a19c82b..618bac27 100644
--- a/test/readme-showcase.test.mjs
+++ b/test/readme-showcase.test.mjs
@@ -1,6 +1,6 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { execFileSync } from 'node:child_process';
+import { execFileSync, spawnSync } from 'node:child_process';
import { EventEmitter } from 'node:events';
import { PassThrough } from 'node:stream';
import crypto from 'node:crypto';
@@ -514,3 +514,46 @@ test('Star History publishing advances the data branch without a force push', ()
fs.rmSync(fixture, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
}
});
+
+
+test('showcase CLI runs through a filesystem alias while imports remain inert', (t) => {
+ const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-showcase-alias-'));
+ t.after(() => fs.rmSync(scratch, {recursive:true, force:true}));
+ const script = path.join(repoRoot, 'scripts/build-readme-showcase.mjs');
+ const alias = path.join(scratch, 'showcase.mjs');
+ try { fs.symlinkSync(script, alias, 'file'); }
+ catch (error) {
+ if (process.platform === 'win32' && ['EPERM','EACCES'].includes(error.code)) {
+ t.skip('Windows host does not permit creating file symlinks'); return;
+ }
+ throw error;
+ }
+ // A deliberately empty tool search path makes actual main() fail quickly,
+ // without launching a browser or generating a GIF.
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toLowerCase() !== 'path'));
+ env.PATH = '';
+ const direct = spawnSync(process.execPath, [script], {env, encoding:'utf8'});
+ const linked = spawnSync(process.execPath, [alias], {env, encoding:'utf8'});
+ assert.equal(direct.status, 1, direct.stderr);
+ assert.equal(linked.status, 1, 'alias must execute main, not silently succeed');
+ assert.match(linked.stderr, /ffmpeg|Chrome or Chromium is required/);
+ const imported = spawnSync(process.execPath, ['--input-type=module','--eval', `await import(${JSON.stringify(pathToFileURL(alias).href)})`], {env,encoding:'utf8'});
+ assert.equal(imported.status, 0, imported.stderr);
+});
+
+
+test('outer capture cleanup retains a live Chrome profile and cleans ordinary failures', async () => {
+ const showcase = await import(pathToFileURL(path.join(repoRoot, 'scripts/build-readme-showcase.mjs')).href);
+ let retained;
+ await assert.rejects(showcase.withCaptureDirectory(async root => {
+ retained = root;
+ const profile = path.join(root, 'profile'); fs.mkdirSync(profile);
+ await showcase.stopChrome(fakeChrome(), profile, 5);
+ }), /Chrome did not exit; profile retained/);
+ try { assert.equal(fs.existsSync(path.join(retained, 'profile')), true); }
+ finally { fs.rmSync(retained, {recursive:true, force:true}); }
+ let removed;
+ const original = new Error('capture failed');
+ await assert.rejects(showcase.withCaptureDirectory(async root => {removed=root; throw original;}), error => error===original);
+ assert.equal(fs.existsSync(removed), false);
+});