shots check: ligatures no longer read as system-font glyphs (probe spans shaped as one run); --help on every command and group, unknown flags rejected before anything runs

Root cause: the per-character font probes were inline spans side by side, so Chrome shaped f + i into the fi ligature across them and the lone i probe reported no glyph of ours. Each probe is now its own block. The Google Fonts text= subsets keep the GSUB ligatures; regression test with a real Montserrat text= subset.

--help / -h prints the command's usage and exits 0 before any config, render or network; unknown flags exit 2 with the usage (cli/data/flags.json from tools/gen-flags.ts). Command tables moved to cli/commands.ts; ads apple reachable again; shots render --scenes rejects unknown ids at once.
This commit is contained in:
CRTkafa 2026-10-11 21:23:37 +00:00
parent cde9424ce3
commit ee427553bb
12 changed files with 1625 additions and 99 deletions

111
tests/cli-help.test.ts Normal file
View file

@ -0,0 +1,111 @@
// `--help` / `-h` on every command and command group prints the usage and exits 0 before anything runs (no config
// load, no render, no browser, no store call); an unknown --flag exits 2 with the usage, also before anything runs.
// Each command is spawned for real with an empty working folder, a temp HOME, no credentials and
// STOREBOUND_NO_NETWORK=1 (cli/index.ts makes fetch throw), and the folders must stay empty.
// Also: cli/data/flags.json is fresh (tools/gen-flags.ts --check), and every option the MCP / desktop tool lists pass
// to a command is one that command accepts (else the strict flag check would break those tools).
import { afterAll, describe, expect, test } from 'bun:test';
import { mkdtempSync, readdirSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { COMMANDS, PLAIN } from '../cli/commands';
import FLAGS from '../cli/data/flags.json';
import { TOOLS } from '../cli/mcp-tools';
import { DESKTOP_ONLY, OWNER_TOOLS } from '../cli/serve';
const ROOT = join(import.meta.dir, '..');
const CLI = join(ROOT, 'cli', 'index.ts');
const tmp: string[] = [];
const mk = (p: string): string => { const d = mkdtempSync(join(tmpdir(), p)); tmp.push(d); return d; };
afterAll(() => { for (const d of tmp) rmSync(d, { recursive: true, force: true }); });
const env = (home: string): Record<string, string> => {
const e: Record<string, string> = {};
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !/^(ASC_|PLAY_|ANDROID_KEY|REVIEW_DEMO|STOREBOUND_|APPLE_ADS|REVENUECAT|GOOGLE_)/.test(k)) e[k] = v;
// no transpiler cache: Bun would write it under the temp HOME (~/Library/Caches/bun)
return { ...e, HOME: home, STOREBOUND_NO_NETWORK: '1', NO_COLOR: '1', BUN_RUNTIME_TRANSPILER_CACHE_PATH: '0' };
};
async function run(args: string[]): Promise<{ code: number; out: string; err: string; ms: number; cwd: string[]; home: string[] }> {
const cwd = mk('sb-help-cwd-'), home = mk('sb-help-home-');
const t = Date.now();
const p = Bun.spawn([process.execPath, CLI, ...args], { cwd, env: env(home), stdin: 'ignore', stdout: 'pipe', stderr: 'pipe' });
const kill = setTimeout(() => p.kill(), 15_000);
const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]);
clearTimeout(kill);
return { code, out, err, ms: Date.now() - t, cwd: readdirSync(cwd), home: readdirSync(home) };
}
const keys = [...Object.keys(PLAIN), ...Object.keys(COMMANDS)];
const groups = [...new Set(keys.filter(k => k.includes(' ')).map(k => k.split(' ')[0]!))];
describe('cli --help', () => {
test('cli/data/flags.json is fresh', () => {
const r = Bun.spawnSync([process.execPath, join(ROOT, 'tools', 'gen-flags.ts'), '--check'], { cwd: ROOT, stdout: 'pipe', stderr: 'pipe' });
expect(r.stderr.toString()).toBe('');
expect(r.exitCode).toBe(0);
});
test('every command and group: usage on stdout, exit 0, fast, nothing written, no network', async () => {
const cases = [...keys.map(k => [...k.split(' '), '--help']), ...groups.map(g => [g, '--help']), ['shots', 'render', '-h'], ['shots', 'render', '--lang', 'en', '--help'], ['help'], ['--help']];
const bad: string[] = [];
for (let i = 0; i < cases.length; i += 8) {
const rs = await Promise.all(cases.slice(i, i + 8).map(async c => ({ c, r: await run(c) })));
for (const { c, r } of rs) {
const why = [
r.code !== 0 && `exit ${r.code}`,
!/^(usage: |storebound )/.test(r.out) && `stdout ${JSON.stringify(r.out.slice(0, 80))}`,
r.err.trim() && `stderr ${JSON.stringify(r.err.slice(0, 200))}`,
r.ms > 5000 && `${r.ms} ms`,
r.cwd.length && `wrote ${r.cwd.join(', ')}`,
r.home.length && `wrote ~/${r.home.join(', ~/')}`,
].filter(Boolean);
if (why.length) bad.push(`storebound ${c.join(' ')}: ${why.join('; ')}`);
}
}
expect(bad).toEqual([]);
}, 120_000);
test('a command --help names its options; a group lists its commands', async () => {
const r = await run(['shots', 'render', '--help']);
expect(r.out).toContain('usage: storebound shots render');
expect(r.out).toContain('--scenes');
const g = await run(['shots', '--help']);
for (const k of keys.filter(k => k.startsWith('shots '))) expect(g.out).toContain(k);
}, 30_000);
test('an unknown flag: exit 2 with the usage, before anything runs', async () => {
for (const c of [['shots', 'render', '--dyr'], ['doctor', '--jsno'], ['play', 'status', '--x=1']]) {
const r = await run(c);
expect(r.code).toBe(2);
expect(r.err).toContain(`unknown option for storebound ${c.slice(0, -1).join(' ')}: ${c.at(-1)!.split('=')[0]}`);
expect(r.err).toContain('usage: storebound');
expect(r.cwd).toEqual([]);
expect(r.home).toEqual([]);
}
const g = await run(['shots']);
expect(g.code).toBe(2);
expect(g.err).toContain('storebound shots: which command?');
}, 30_000);
});
describe('flag table vs the tool lists', () => {
test('every option an MCP or desktop tool passes is one its command accepts', () => {
const table = FLAGS.commands as Record<string, string[]>;
const bad: string[] = [];
for (const t of [...TOOLS, ...DESKTOP_ONLY, ...OWNER_TOOLS]) {
const words = t.command.filter(w => !w.startsWith('--'));
const key = table[words.slice(0, 2).join(' ')] ? words.slice(0, 2).join(' ') : words[0]!;
const ok = new Set([...FLAGS.global, ...(table[key] ?? [])]);
if (!table[key]) { bad.push(`${t.name}: no command ${key}`); continue; }
const src = t.args?.toString() ?? '';
const used = [
...t.command.filter(w => w.startsWith('--')).map(w => w.slice(2)),
...[...src.matchAll(/'--([a-z][a-z0-9-]*)'/g)].map(m => m[1]!),
...[...src.matchAll(/\b(?:opt|flag)\('([a-z][a-z0-9-]*)'/g)].map(m => m[1]!),
];
for (const f of used) if (!ok.has(f)) bad.push(`${t.name}: storebound ${key} --${f}`);
}
expect(bad).toEqual([]);
});
});

93
tests/fixtures/fonts/Montserrat-OFL.txt vendored Normal file
View file

@ -0,0 +1,93 @@
Copyright 2024 The Montserrat.Git Project Authors (https://github.com/JulietaUla/Montserrat.git)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

View file

@ -0,0 +1,49 @@
// Regression: ligatures must not read as system-font glyphs. STAR DASH's "Outfits, ..." caption failed `shots check`
// with `i drawn with a system font` although Montserrat drew every glyph: the per-character probe spans sat side by
// side, Chrome shaped "f" + "i" into the fi ligature across them and the lone "i" span reported no glyph of ours.
// The fixture is a real Google Fonts css2 `text=` subset of Montserrat (as `shots fonts` downloads it; OFL, see
// fixtures/fonts/Montserrat-OFL.txt); it keeps the GSUB ligatures (ff, fi, ffi). Skips when no Chromium can launch.
import { afterAll, describe, expect, test } from 'bun:test';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { measureFonts } from '../cli/shots/glyphs';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let browser: any = null;
let skipWhy = '';
try {
const { chromium } = await import('playwright-core');
try { browser = await chromium.launch({ headless: true }); } catch { browser = await chromium.launch({ headless: true, channel: 'chrome' }); }
} catch (e) { skipWhy = (e as Error).message.split('\n')[0]!; }
if (!browser) console.warn(`glyph ligature test skipped: no Chromium could launch (${skipWhy}). Run \`bunx playwright install chromium\`.`);
afterAll(async () => { await browser?.close(); }, 30_000);
const font = readFileSync(join(import.meta.dir, 'fixtures', 'fonts', 'montserrat-text-subset.woff2')).toString('base64');
const TEXT = 'Outfits, fit, office, affine';
describe.skipIf(!browser)('shots font usage: ligatures', () => {
for (const weight of [400, 600, 800]) test(`"${TEXT}" in a Montserrat text= subset, weight ${weight}: zero system-font glyphs`, async () => {
const page = await browser.newPage();
try {
await page.setContent(`<style>@font-face { font-family: 'Montserrat'; font-weight: 100 900; font-synthesis: none; src: url(data:font/woff2;base64,${font}) format('woff2'); }
p { font-family: 'Montserrat'; font-weight: ${weight}; font-size: 48px; } small { font-family: 'Montserrat'; font-weight: ${weight}; }</style>
<p class="sub">${TEXT}</p><div><small>mounts and vehicles</small></div>`);
await page.evaluate('document.fonts.ready.then(() => 0)');
// the subset really ligates: the line has fewer glyphs than characters, all from our font
const cdp = await page.context().newCDPSession(page);
await cdp.send('DOM.enable'); await cdp.send('CSS.enable');
const { root } = await cdp.send('DOM.getDocument', { depth: 0 });
const { nodeId } = await cdp.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'p' });
const { fonts } = await cdp.send('CSS.getPlatformFontsForNode', { nodeId }) as { fonts: { isCustomFont: boolean; glyphCount: number }[] };
await cdp.detach();
expect(fonts.every(f => f.isCustomFont)).toBe(true);
expect(fonts.reduce((n, f) => n + f.glyphCount, 0)).toBeLessThan(TEXT.length);
const measured = await measureFonts(page, ['Montserrat']);
expect(measured.map(m => m.el)).toEqual(['p.sub', 'div small']);
for (const m of measured) expect(Object.keys(m.faces)).toEqual(['Montserrat']);
expect(await page.evaluate("document.getElementById('sb-glyph-probes')")).toBeNull();
} finally { await page.close(); }
}, 30_000);
});