Skip to content

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

test(showcase): exercise Windows command lookup and ffmpeg errors

杨嘉伟cb20293f14ec
diff --git a/scripts/build-readme-showcase.mjs b/scripts/build-readme-showcase.mjs
index 8527e7e0..c18d77c5 100644
--- a/scripts/build-readme-showcase.mjs
+++ b/scripts/build-readme-showcase.mjs
@@ -68,20 +68,33 @@ function executable(file) {
}
}
-function commandPath(command) {
+function commandPath(command, spawnCommand = spawnSync) {
if (process.platform === 'win32') {
- const result = spawnSync('where.exe', [command], {
+ const result = spawnCommand('where.exe', [command], {
encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
});
- return result.status === 0 ? result.stdout.trim().split(/\r?\n/)[0] : null;
+ if (result.error || result.status !== 0) return null;
+ return result.stdout.trim().split(/\r?\n/).find(Boolean) || null;
}
- const result = spawnSync('sh', ['-c', 'command -v "$1"', 'archify-showcase', command], {
+ const result = spawnCommand('sh', ['-c', 'command -v "$1"', 'archify-showcase', command], {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
});
- return result.status === 0 ? result.stdout.trim() : null;
+ if (result.error || result.status !== 0) return null;
+ return result.stdout.trim() || null;
}
+function launchFfmpeg(ffmpeg, args, spawnCommand = spawnSync) {
+ const result = spawnCommand(ffmpeg, args, { encoding: 'utf8' });
+ if (result.error || result.status !== 0) {
+ const detail = result.error?.message || String(result.stderr || result.stdout || '').trim() || `exited ${result.status ?? 'without a status'}`;
+ throw new Error(`ffmpeg failed:\n${detail}`);
+ }
+ return result;
+}
+
+export { commandPath, requireCommand, launchFfmpeg };
+
function findChrome() {
const candidates = [
process.env.ARCHIFY_CHROME,
@@ -316,12 +329,11 @@ function buildGif(ffmpeg, framesRoot) {
'[s0]palettegen=max_colors=112:stats_mode=diff[p]',
'[s1][p]paletteuse=dither=bayer:bayer_scale=3:diff_mode=rectangle',
].join(';');
- const result = spawnSync(ffmpeg, [
+ launchFfmpeg(ffmpeg, [
'-y', '-loglevel', 'error', '-framerate', String(fps),
'-i', path.join(framesRoot, 'frame-%04d.png'),
'-filter_complex', filter, '-loop', '0', outputPath,
- ], { encoding: 'utf8' });
- if (result.status !== 0) throw new Error(`ffmpeg failed:\n${result.error?.message || result.stderr || result.stdout}`);
+ ]);
}
async function main() {
@@ -366,7 +378,10 @@ async function main() {
}
}
-main().catch(error => {
- console.error(error.stack || error.message);
- process.exitCode = 1;
-});
+const invokedDirectly = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
+if (invokedDirectly) {
+ main().catch(error => {
+ console.error(error.stack || error.message);
+ process.exitCode = 1;
+ });
+}
diff --git a/test/readme-showcase.test.mjs b/test/readme-showcase.test.mjs
index 305c0c92..9da4bbd7 100644
--- a/test/readme-showcase.test.mjs
+++ b/test/readme-showcase.test.mjs
@@ -5,7 +5,7 @@ import crypto from 'node:crypto';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
-import { fileURLToPath } from 'node:url';
+import { fileURLToPath, pathToFileURL } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const skillRoot = path.resolve(__dirname, '..', 'archify');
@@ -142,9 +142,6 @@ test('README motion proof is compact, looping, and backed by current gallery art
assert.match(builder, /\?embed=1&theme=dark\$\{scene\.hash\}/);
assert.doesNotMatch(builder, /play=1|#view=/);
assert.match(builder, /path\.relative\(from, to\)\.split\(path\.sep\)\.join\('\/'\)/);
- assert.match(builder, /process\.platform === 'win32'/);
- assert.match(builder, /spawnSync\('where\.exe', \[command\]/);
- assert.match(builder, /result\.error\?\.message/);
const buffer = fs.readFileSync(assetPath);
const receipt = JSON.parse(fs.readFileSync(receiptPath, 'utf8'));
const inspected = inspectGif(buffer);
@@ -170,6 +167,29 @@ test('README motion proof is compact, looping, and backed by current gallery art
}
});
+test('Windows command lookup and ffmpeg launch keep their boundary diagnostics', async () => {
+ const showcase = await import(pathToFileURL(path.join(repoRoot, 'scripts', 'build-readme-showcase.mjs')).href);
+ const selected = String.raw`C:\Tools\ffmpeg.EXE`;
+ const lookup = showcase.commandPath('ffmpeg', () => ({
+ status: 0,
+ stdout: `\r\n${selected}\r\nC:\\Other\\ffmpeg.exe\r\n`,
+ }));
+ assert.equal(lookup, selected);
+ assert.equal(showcase.commandPath('ffmpeg', () => ({
+ status: 1,
+ stdout: '',
+ error: new Error('where failed'),
+ })), null);
+ assert.throws(
+ () => showcase.launchFfmpeg(selected, ['-version'], () => ({
+ status: null,
+ stderr: '',
+ error: Object.assign(new Error('spawn ENOENT'), { code: 'ENOENT' }),
+ })),
+ /ffmpeg failed:\s*spawn ENOENT/,
+ );
+});
+
test('every README header links to the other languages', () => {
const languageLinks = [];
for (const { href, label } of readmeLanguages) {