storebound/tools/ci.ts
CRT 08eb314196 Desktop: never a blank window (frozen-prototype fix, error screens, logs, state migration, boot check)
The signed release showed only its background colour and never started the sidecar. Tauri's freezePrototype
freezes Object.prototype before the bundle runs; d3-color and d3-format (under the visx charts) assign
`constructor` / `toString` on plain objects while loading, which throws on a frozen prototype, so the bundle
stopped before React drew anything. The saved state was not the cause.

- build/freeze-safe.ts: Vite plugin that rewrites those assignments in dependencies into a helper that defines
  the property when the frozen prototype would refuse it
- error boundaries for the window, each screen and each app tab (Copy details, Reload, Reset saved state with a
  backup); public/boot.js shows the same panel when the bundle fails or the window stays empty
- logs/host.log (start, saved state, sidecar start/stop, panics) and logs/webview.log (log_webview), rotated,
  home as ~, keys, tokens and e-mail addresses replaced
- state.json `version` 2 with an explicit 1 -> 2 migration (original kept as state.json.v1.bak), per-entry
  tolerant parsing, partial settings keep their fields, unreadable files kept aside
- folders that are gone: "Folder not found" with Locate... (project_locate) / Remove; portfolio reads skip them
- tools/desktop-boot-check.ts: the built window with the release CSP and the frozen prototype, a mocked host from
  the state fixtures (empty, D1 with folders gone, D3) and the real sidecar, through every screen; in bun run ci,
  the Forgejo CI workflow and the macOS release
2026-10-11 01:36:34 +00:00

43 lines
2.9 KiB
TypeScript

#!/usr/bin/env bun
// Everything CI runs, in order; stops at the first failure. bun run ci
// `bun test` covers the CLI and the desktop webview (apps/desktop/tests: model, i18n, theme contrast, webview rules),
// the desktop boot check (tools/desktop-boot-check.ts: the built window in headless Chromium, needs playwright's
// browser or Google Chrome), and the no-hand-written-SVG guard (tests/no-handmade-svg.test.ts: visx charts, Phosphor icons, simple-icons store marks, Mermaid diagrams).
// The desktop Rust host (cargo test, clippy
// with warnings as errors) runs when cargo is installed; set STOREBOUND_CI_RUST=0 to skip it on a machine without Rust.
import { join } from 'node:path';
const root = new URL('..', import.meta.url).pathname;
const tauri = join(root, 'apps/desktop/src-tauri');
const cargo = process.env.STOREBOUND_CI_RUST === '0' ? null : Bun.which('cargo');
const steps: [string, string[], string?][] = [
['adapters', ['bun', 'tools/gen-adapters.ts', '--check']],
// one desktop version: package.json desktopVersion = apps/desktop/package.json = tauri.conf.json = Cargo.toml / .lock
['desktop version', ['bun', 'tools/desktop-version.ts']],
['tests', ['bun', 'test']],
['typecheck', ['bunx', 'tsc', '--noEmit']],
['desktop i18n', ['bun', 'tools/i18n-check.ts']],
['desktop typecheck', ['bunx', 'tsc', '--noEmit', '-p', 'apps/desktop']],
['desktop build', ['bun', 'run', '--cwd', 'apps/desktop', 'build']],
// the release bundle must not carry the dev fixture mode (apps/desktop/tests/webview.test.ts checks dist/ when present)
['desktop bundle check', ['bun', 'test', 'apps/desktop/tests/webview.test.ts']],
// the built window boots (release CSP, Tauri's frozen Object.prototype, mocked host + real sidecar) on an empty, a
// D1 (folders gone) and a full D3 saved state, through every screen: no uncaught error, never an empty window
['desktop boot check', ['bun', 'tools/desktop-boot-check.ts']],
...(cargo ? [
// tauri's build script needs the host sidecar binary (gitignored), so a clean checkout builds it first
['desktop sidecar (host)', ['bun', 'tools/build-sidecars.ts', '--host']],
['desktop rust tests', [cargo, 'test', '--quiet'], tauri],
['desktop clippy', [cargo, 'clippy', '--all-targets', '--quiet', '--', '-D', 'warnings'], tauri],
] as [string, string[], string][] : []),
['scrub', ['bun', 'tools/scrub.ts']],
];
if (!cargo) console.log('ci: cargo not found (or STOREBOUND_CI_RUST=0): desktop Rust tests and clippy skipped');
for (const [name, cmd, cwd] of steps) {
const t = Date.now();
console.log(`\n== ${name}: ${cmd.join(' ')}`);
const r = Bun.spawnSync(cmd, { cwd: cwd ?? root, stdout: 'inherit', stderr: 'inherit' });
if (r.exitCode !== 0) { console.error(`\nci: ${name} failed (exit ${r.exitCode})`); process.exit(1); }
console.log(`== ${name} ok (${((Date.now() - t) / 1000).toFixed(1)}s)`);
}
console.log('\nci: all green');