Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
test: keep incidents as the review eval and name gates by path
youxi7984f44cb3677c1
diff --git a/AGENTS.md b/AGENTS.mdindex af286b4d..78a58466 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -146,6 +146,7 @@ Oracles per row live under `tests/unit/` (for example `event-link-guard.test.js`- The shared download HTTP client pools connections without a cookie jar. Redirects must re-read the calling window's cookies for each HTTP(S) target, progressively narrow Referer, and never restore it after an HTTPS downgrade. Accept page context only from the calling window's actual origin, strip URL credentials, and flush asynchronous file writes before reporting success. Wry 0.54.2 misses macOS literal-IP cookies; only that branch reads the window's full cookie store, with exact IP, Path, Secure and expiry filtering. Keep normal hostnames and other platforms on `cookies_for_url`. Validate the real WebView's User-Agent, Referer, HttpOnly session cookie and wrong-Path exclusion in `tests/integration/ipc-security.mjs`.- macOS menu navigation must keep working on blank error pages: Reload uses native `WebviewWindow::reload`, Go Home uses `navigate` + `resolve_home_url`, Back/Forward use the platform WKWebView history API rather than page `eval`. Copy URL reads `window.url()` so it does not depend on a live JS document.- Not every green CI step is evidence. The old `Test CLI Integration (smoke)` step ended with `|| true` and, because `timeout` took `PAKE_CREATE_APP=1` as the program name, never ran the CLI on any OS; it was removed rather than repaired. The steps that actually fail on regressions are `Run Fast Test Suite` (all three platforms) and `Full Tauri Build` (real `pnpm test` with a build, push and dispatch only). Cite those when claiming a change is verified, and check for `|| true` and `continue-on-error` before treating any other step as proof. `Rust Code Quality` also runs `cargo test --lib`, the only CI gate for the Rust unit tests; its Linux job runs clippy without `-D warnings`, so only the Windows job (`-D warnings`, default features plus `runtime-template,native-download-probe`) fails on lint warnings, and only for Windows cfg arms.+- Incidents are the review eval set. A fix for a defect that reached users through a published npm version or a released app adds its `docs/incidents.md` row in the same commit: the fix commit, the introducing commit when confirmed, the earliest layer that should have caught it, and the test that catches it now. `scripts/check-incidents.mjs` fails a row whose commit does not resolve, whose layer is unknown, or whose catcher is not a test or file in the repository; `tests/unit/check-incidents.test.ts` runs it, so `npx vitest run` in `release:check` and the CI fast suite gate it, and CI's one-commit checkout only shape-checks commits. Verification follows the paths a change touches, not its author: `node scripts/risk-tier.mjs [paths]` prints, as advice, the extra gates for the publish, public workflow, CI, IPC permission, bundle and CLI artifact tiers, and `--self-check` (locked by `tests/unit/risk-tier.test.ts`) fails when a rename leaves a tier pattern matching no file.- `setup-env` in build mode shares one rust-cache key per OS, and the first job to save wins it: every later restore is a full match and never saves again. A job that installs Rust but does not compile the app (fast lane, clippy) must pass `rust-cache-save: false`, or it seeds an empty target and every release recompiles from scratch. A healthy `v0-rust-pake-build-*` entry is about 1.1 GB and a poisoned one about 109 MB; check `gh cache list --key v0-rust-pake-build` before trusting release timings. Release builds reuse it because the CLI keeps `CARGO_TARGET_DIR` at `src-tauri/target` even inside its private workspace.- `.github/workflows/pake-cli.yaml` and `single-app.yaml` are public build surfaces that external users trigger from their own forks (see `docs/github-actions-usage*.md`). Changes there ship to outside users on push to `main`, independent of `V*` releases; treat them like public API, not internal CI. Their `run:` scripts take inputs through `env:`, never `${{ inputs.* }}` interpolated into bash or pwsh (gated by `tests/integration/workflow-paths.test.js`); on Windows an empty variable is unset, so test it with `IsNullOrEmpty`.- Jobs that compile the app on Linux pin `ubuntu-24.04` instead of `ubuntu-latest` (moving to Ubuntu 26 from 2026-10-19): release `.deb`/`.AppImage` link against the runner's glibc and WebKitGTK, so a runner bump raises the minimum distro for users. Move the pin deliberately, and keep the `matrix.build == 'linux'` conditions in `single-app.yaml` rather than matching the runner label.diff --git a/docs/incidents.md b/docs/incidents.mdnew file mode 100644index 00000000..c339ef56--- /dev/null+++ b/docs/incidents.md@@ -0,0 +1,33 @@+# Incidents++Defects that reached a user through a published npm version or a released app, kept as the eval set for every review layer ("incidents are the eval", from the Claude Code team's code review write-up). A row is added in the same change that fixes the defect: the fix commit, the commit that introduced it when known, the earliest layer that should have caught it, and the test or gate that catches it now. `scripts/check-incidents.mjs` fails a row whose commit does not resolve, whose layer is not one of the names below, or whose catcher is not defined in the code; `tests/unit/check-incidents.test.ts` runs it, so `npx vitest run` in `pnpm run release:check` and the CI fast suite fail on a broken row.++A catcher is written in backticks and is one of: the exact title of a Vitest or `node:test` case under `tests/` or `bin/`, a Rust `#[test]` function under `src-tauri/src`, or the repository path of a test file or gate script (for example `tests/browser/fullscreen.mjs`). A title that holds a `|` or a backtick cannot sit in this table; rename the test.++Layers, earliest first:++- `write-time`: the author's own check before committing, a sweep of same-shape sites.+- `unit`: `npx vitest run` and `cargo test --lib`.+- `cli-build`: `pnpm run cli:build` (Rollup plus the TypeScript check).+- `ci`: the Quality & Testing workflow (`Run Fast Test Suite`, `Rust Code Quality`, `Full Tauri Build`, Docker packaging).+- `review`: a diff review against the Review Hard Stops and Current Risk Areas in `AGENTS.md`.+- `release-check`: `pnpm run release:check` and the release workflows before a tag.+- `native`: a real build run on the affected OS or WebView (the `tests/integration` and `tests/browser` probes, a bundled app).+- `field`: only a real user's machine, desktop environment or input method shows it.++When a review skill, its prompt or the model running it changes, rerun it on the files each fix touched as they were at `<Fixed>^` and record which rows it finds. `Introduced` is a commit only when it was confirmed by reading the history, otherwise `unknown`.++## Incidents++| ID | Reported | Symptom | Introduced | Fixed | Layer | Caught by |+| ---- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------- |+| I-01 | 2026-06-29 | `--zoom 99.5` passed the CLI range check and produced a `pake.json` the app could not load (#1274); the same value later still passed through `--config` | unknown | 7edf2af4 | unit | `rejects malformed zoom values instead of truncating them`, `rejects fractional zoom like the --zoom flag` |+| I-02 | 2026-07-13 | Apps started at login on Windows showed a blank taskbar icon (#1323) | unknown | 83a1c476 | field | `reapplies the icon after every explicit window show`, `targets the large taskbar icon instead of only the small window icon` |+| I-03 | 2026-08-01 | A SPA link under `/assets/` was intercepted as a download and a 403 response was toasted as a successful download (#1339) | unknown | f61b3267 | unit | `navigates SPA routes under /assets/ instead of treating them as downloads`, `rejects non-success HTTP responses before writing the file` |+| I-04 | 2026-08-08 | On Windows a window hidden with `--hide-on-close` could never be restored from the tray (#1343) | unknown | 4ba7e65d | native | `acts on one edge of the click, not both`, `treats a minimized window as not on screen` |+| I-05 | 2026-08-10 | Apps built with `--new-window` aborted (SIGABRT) on Cmd+click or `target=_blank` links on macOS 26 (#1347) | unknown | 71dccbb5 | native | `uses WebKit's target configuration with a fresh user content controller` |+| I-06 | 2026-09-10 | Fullscreen video on Windows lost its captions, progress bar and player controls (#1373) | unknown | f671ded1 | native | `preserves WebView2 native fullscreen and keeps the other platform polyfill`, `tests/browser/fullscreen.mjs` |+| I-07 | 2026-09-20 | Playing a video crashed apps on Wayland with WebKitGTK 2.52 after the 3.17.1 fix had covered only X11 (#1386, #1374) | unknown | 3c978e1e | field | `modern_wayland_uses_shm_instead_of_disabling_compositing`, `shm_preserves_legacy_webkit_niri_and_explicit_modes` |+| I-08 | 2026-09-25 | `window.print()` failed with "webview.print not allowed" because the capability lacked the print permission (#1396) | unknown | 187cabb1 | review | `window_print_reaches_the_webview_only_from_trusted_contexts` |+| I-09 | 2026-09-28 | `--windows-toolchain gnu --keep-binary` left a raw `.exe` that would not start without `WebView2Loader.dll` beside it (#1402) | 1fe55a88 | 3e906e81 | unit | `copies WebView2Loader.dll beside the raw binary for gnu`, `records the DLL as an artifact after the binary with --keep-binary` |+| I-10 | 2026-10-15 | On macOS the Enter that confirms a Chinese input method candidate reached the page and sent the message early (#1415) | unknown | f4b4e3cb | field | `keeps the candidate-confirming Enter (keyCode 229) away from the page` |diff --git a/scripts/check-incidents.mjs b/scripts/check-incidents.mjsnew file mode 100644index 00000000..5b0fb2dd--- /dev/null+++ b/scripts/check-incidents.mjs@@ -0,0 +1,218 @@+#!/usr/bin/env node+// Every row of docs/incidents.md names real commits, a known layer and a+// catcher the code defines.+//+// node scripts/check-incidents.mjs+//+// The incident table is the eval set for the review layers (docs/incidents.md+// says why and what each layer means). A row fails when its ID repeats, its+// Reported cell is not a date, its Fixed commit is missing or does not+// resolve, its Introduced commit is neither `unknown` nor a commit, its layer+// is not one of LAYERS, or a backticked catcher is defined nowhere: not a+// Vitest or node:test title under tests/ or bin/, not a Rust #[test] function+// under src-tauri/src, and not a file in this repository.+//+// In a shallow clone (CI checks out one commit) the commits cannot be resolved+// and are only shape-checked, which the output says. tests/unit/+// check-incidents.test.ts runs the same check, so `npx vitest run` (in+// release:check and the CI fast suite) fails on a broken row.++import { spawnSync } from "node:child_process";+import fs from "node:fs";+import path from "node:path";+import { fileURLToPath } from "node:url";++export const ROOT = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ "..",+);+export const LEDGER = path.join(ROOT, "docs", "incidents.md");+export const LAYERS = [+ "write-time",+ "unit",+ "cli-build",+ "ci",+ "review",+ "release-check",+ "native",+ "field",+];+export const COLUMNS = [+ "ID",+ "Reported",+ "Symptom",+ "Introduced",+ "Fixed",+ "Layer",+ "Caught by",+];+const SHA = /^[0-9a-f]{7,40}$/;+const JS_TITLE =+ /\b(?:it|test|describe)(?:\.(?:only|skip|concurrent|each\([^)]*\)))?\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|`([^`$]*)`)/g;+const RUST_TEST = /#\[test\]\s*(?:#\[[^\]]*\]\s*)*fn\s+([A-Za-z0-9_]+)\s*\(/g;+const SKIP_DIRS = new Set(["node_modules", "target", ".git", "dist"]);++function* walk(dir, extensions) {+ let entries;+ try {+ entries = fs.readdirSync(dir, { withFileTypes: true });+ } catch {+ return;+ }+ for (const entry of entries) {+ const full = path.join(dir, entry.name);+ if (entry.isDirectory()) {+ if (!SKIP_DIRS.has(entry.name)) yield* walk(full, extensions);+ } else if (extensions.some((ext) => entry.name.endsWith(ext))) {+ yield full;+ }+ }+}++const unescape = (title) => title.replace(/\\(.)/g, "$1");++export function definedCatchers(root = ROOT) {+ const names = new Set();+ for (const dir of ["tests", "bin"]) {+ for (const file of walk(path.join(root, dir), [".js", ".mjs", ".ts"])) {+ const text = fs.readFileSync(file, "utf8");+ for (const match of text.matchAll(JS_TITLE)) {+ names.add(unescape(match[1] ?? match[2] ?? match[3]));+ }+ }+ }+ for (const file of walk(path.join(root, "src-tauri", "src"), [".rs"])) {+ const text = fs.readFileSync(file, "utf8");+ for (const match of text.matchAll(RUST_TEST)) names.add(match[1]);+ }+ return names;+}++export function isDefined(catcher, defined, root = ROOT) {+ if (defined.has(catcher)) return true;+ // A test file or gate script named by its repository path.+ return (+ catcher.includes("/") &&+ fs.existsSync(path.join(root, catcher)) &&+ fs.statSync(path.join(root, catcher)).isFile()+ );+}++// The table under '## Incidents' as [line number, cells], header and rule+// excluded. Cells are trimmed, so Prettier's column padding is harmless.+export function* rows(text) {+ let section = false;+ const lines = text.split("\n");+ for (let i = 0; i < lines.length; i += 1) {+ const line = lines[i];+ if (line.startsWith("## ")) {+ section = line.trim() === "## Incidents";+ continue;+ }+ if (!section || !line.startsWith("|")) continue;+ const cells = line+ .trim()+ .replace(/^\||\|$/g, "")+ .split("|")+ .map((cell) => cell.trim());+ if (cells.join("|") === COLUMNS.join("|")) continue;+ if (/^[-:\s]*$/.test(cells.join(""))) continue;+ yield [i + 1, cells];+ }+}++export function isShallow(root = ROOT) {+ const out = spawnSync(+ "git",+ ["-C", root, "rev-parse", "--is-shallow-repository"],+ { encoding: "utf8" },+ );+ return out.stdout.trim() === "true";+}++export function resolves(sha, root = ROOT) {+ return (+ spawnSync("git", ["-C", root, "cat-file", "-e", `${sha}^{commit}`])+ .status === 0+ );+}++export function problems(+ text,+ {+ label = "docs/incidents.md",+ defined,+ checkCommits,+ resolve = resolves,+ root = ROOT,+ },+) {+ const found = [];+ const seen = new Set();+ for (const [number, cells] of rows(text)) {+ const where = `${label}:${number}`;+ if (cells.length !== COLUMNS.length) {+ found.push(+ `${where}: expected ${COLUMNS.length} cells, found ${cells.length}`,+ );+ continue;+ }+ const row = Object.fromEntries(COLUMNS.map((name, i) => [name, cells[i]]));+ if (seen.has(row.ID)) found.push(`${where}: ${row.ID} repeats`);+ seen.add(row.ID);+ if (!/^\d{4}-\d{2}-\d{2}$/.test(row.Reported)) {+ found.push(`${where}: Reported is not a date: ${row.Reported}`);+ }+ for (const [column, optional] of [+ ["Fixed", false],+ ["Introduced", true],+ ]) {+ const value = row[column];+ if (optional && value === "unknown") continue;+ if (!SHA.test(value)) {+ found.push(`${where}: ${column} is not a commit: ${value}`);+ } else if (checkCommits && !resolve(value)) {+ found.push(`${where}: ${column} ${value} does not resolve`);+ }+ }+ if (!LAYERS.includes(row.Layer)) {+ found.push(+ `${where}: layer ${row.Layer} is not one of ${LAYERS.join(", ")}`,+ );+ }+ const catchers = [...row["Caught by"].matchAll(/`([^`]+)`/g)].map(+ (match) => match[1],+ );+ if (catchers.length === 0) found.push(`${where}: no catcher named`);+ for (const name of catchers) {+ if (!isDefined(name, defined, root)) {+ found.push(+ `${where}: catcher \`${name}\` is not a test or gate in this repository`,+ );+ }+ }+ }+ return found;+}++export function checkLedger(ledger = LEDGER) {+ const shallow = isShallow();+ const text = fs.readFileSync(ledger, "utf8");+ const found = problems(text, {+ label: path.relative(ROOT, ledger),+ defined: definedCatchers(),+ checkCommits: !shallow,+ });+ return { found, shallow, count: [...rows(text)].length };+}++if (+ process.argv[1] &&+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)+) {+ const { found, shallow, count } = checkLedger();+ for (const line of found) console.log(line);+ const note = shallow ? ", commits shape-checked only (shallow clone)" : "";+ console.log(`incidents: ${count} rows, ${found.length} problems${note}`);+ process.exit(found.length ? 1 : 0);+}diff --git a/scripts/risk-tier.mjs b/scripts/risk-tier.mjsnew file mode 100644index 00000000..5cc72f03--- /dev/null+++ b/scripts/risk-tier.mjs@@ -0,0 +1,175 @@+#!/usr/bin/env node+// Name the verification a change needs from the paths it touches, not from+// who wrote it.+//+// node scripts/risk-tier.mjs [path ...]+// node scripts/risk-tier.mjs --self-check+//+// With no paths it reads the change not yet on the upstream branch: commits+// since the merge base with @{upstream} (origin/main when there is none) plus+// staged, unstaged and untracked files. It prints one line per tier the change+// reaches, highest first, and nothing when only the default checks apply. It+// is advice, never a failure: the gates it names need a real OS, the release+// workflows or the maintainer, where a local script cannot prove they ran.+// Pass your own files when the worktree holds other work.+//+// --self-check exits 1 when a tier pattern matches no tracked file: a rename+// would otherwise drop that file to the default tier without anyone noticing.+// tests/unit/risk-tier.test.ts runs it.++import { spawnSync } from "node:child_process";+import path from "node:path";+import { fileURLToPath } from "node:url";++export const ROOT = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ "..",+);++// Highest first. A path takes every tier it matches. Patterns are literal+// paths, or end in `/*` to cover every file below that directory.+export const TIERS = [+ {+ name: "publish",+ gates:+ "the maintainer's review of the diff; Trusted Publishing kept (id-token: write, the canonical repository URL, " ++ "scripts/check-release-version.mjs; AGENTS.md Review Hard Stops); pnpm run release:check; " ++ "the changed workflow green at the exact SHA before any tag or npm-only dispatch",+ patterns: [+ ".github/workflows/npm-publish.yml",+ ".github/workflows/release.yml",+ "scripts/check-release-version.mjs",+ "default_app_list.json",+ ],+ },+ {+ name: "public-workflow",+ gates:+ "inputs reach run: scripts through env: only (tests/integration/workflow-paths.test.js, " ++ "tests/unit/action-input-security.test.ts); pake-cli.yaml and single-app.yaml reach fork users on push to main, " ++ "action.yml reaches v3 users only after the release moves the v3 tag",+ patterns: [+ "action.yml",+ ".github/workflows/pake-cli.yaml",+ ".github/workflows/single-app.yaml",+ ],+ },+ {+ name: "ci",+ gates:+ "no new `|| true` or continue-on-error on a gating step; a changed gate red-run once on a known-bad sample; " ++ "Run Fast Test Suite and Rust Code Quality green at the exact pushed SHA",+ patterns: [+ ".github/workflows/quality-and-test.yml",+ ".github/actions/*",+ "tests/index.js",+ "scripts/check-incidents.mjs",+ "scripts/risk-tier.mjs",+ ],+ },+ {+ name: "ipc-permission",+ gates:+ "cargo test --lib (with and without --features runtime-template); node tests/integration/ipc-security.mjs " ++ "on a real macOS WebView; every app command in the build.rs manifest with only its required permissions",+ patterns: [+ "src-tauri/build.rs",+ "src-tauri/capabilities/*",+ "src-tauri/src/app/invoke.rs",+ "src-tauri/src/app/config.rs",+ "src-tauri/src/inject/event.js",+ "src-tauri/src/inject/frame_links.js",+ "src-tauri/src/inject/link_policy.js",+ "src-tauri/src/inject/fullscreen.js",+ "src-tauri/src/inject/title_bar.js",+ "src-tauri/src/inject/theme_refresh.js",+ ],+ },+ {+ name: "bundle",+ gates:+ "a real build in a fresh output directory on each affected OS (pnpm test, not --no-build), checking the CLI " ++ "JSON output path and the installer payload; Docker packaging for Linux bundles; restore build churn in tracked " ++ "Tauri config before committing",+ patterns: [+ "src-tauri/tauri.conf.json",+ "src-tauri/tauri.macos.conf.json",+ "src-tauri/tauri.windows.conf.json",+ "src-tauri/tauri.linux.conf.json",+ "src-tauri/Cargo.toml",+ "src-tauri/Info.plist",+ "src-tauri/entitlements.plist",+ "bin/builders/*",+ "Dockerfile",+ ],+ },+ {+ name: "cli-artifact",+ gates:+ "pnpm run cli:build and commit the regenerated dist/cli.js (Rollup inlines package.json); " ++ "npm pack --dry-run --ignore-scripts",+ patterns: ["package.json", "rollup.config.js"],+ },+];++export function matches(file, pattern) {+ return pattern.endsWith("/*")+ ? file.startsWith(pattern.slice(0, -1))+ : file === pattern;+}++function git(...args) {+ const out = spawnSync("git", ["-C", ROOT, ...args], { encoding: "utf8" });+ return out.status === 0 ? out.stdout.split("\n").filter(Boolean) : [];+}++export function pendingPaths() {+ const base =+ (git("merge-base", "HEAD", "@{upstream}")[0] ??+ git("merge-base", "HEAD", "origin/main")[0]) ||+ "";+ const paths = new Set(base ? git("diff", "--name-only", base) : []);+ for (const file of git("ls-files", "--others", "--exclude-standard")) {+ paths.add(file);+ }+ return [...paths].sort();+}++export function tiersFor(paths) {+ return TIERS.map((tier) => ({+ ...tier,+ matched: paths.filter((file) =>+ tier.patterns.some((pattern) => matches(file, pattern)),+ ),+ })).filter((tier) => tier.matched.length > 0);+}++export function deadPatterns(+ tracked = git("ls-files", "--cached", "--others", "--exclude-standard"),+) {+ return TIERS.flatMap((tier) =>+ tier.patterns+ .filter((pattern) => !tracked.some((file) => matches(file, pattern)))+ .map((pattern) => `${tier.name}: ${pattern}`),+ );+}++if (+ process.argv[1] &&+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)+) {+ const args = process.argv.slice(2);+ if (args.length === 1 && args[0] === "--self-check") {+ const dead = deadPatterns();+ for (const row of dead) console.log(`${row} matches no tracked file`);+ process.exit(dead.length ? 1 : 0);+ }+ const paths = args.length ? args : pendingPaths();+ for (const tier of tiersFor(paths)) {+ const more =+ tier.matched.length > 1 ? ` and ${tier.matched.length - 1} more` : "";+ console.log(+ `risk: ${tier.name} (${tier.matched[0]}${more}) needs ${tier.gates}`,+ );+ }+}diff --git a/tests/unit/check-incidents.test.ts b/tests/unit/check-incidents.test.tsnew file mode 100644index 00000000..1ff3bd4a--- /dev/null+++ b/tests/unit/check-incidents.test.ts@@ -0,0 +1,142 @@+import { describe, it, expect } from 'vitest';+import fs from 'node:fs';+import path from 'node:path';+import {+ ROOT,+ LEDGER,+ problems,+ definedCatchers,+ isShallow,+ rows,+} from '../../scripts/check-incidents.mjs';++const HEADER = [+ '## Incidents',+ '',+ '| ID | Reported | Symptom | Introduced | Fixed | Layer | Caught by |',+ '| --- | --- | --- | --- | --- | --- | --- |',+];+const GOOD = [+ 'I-01',+ '2026-01-02',+ 'Something broke',+ 'unknown',+ 'abc1234',+ 'unit',+ '`a known test`',+];+const defined = new Set(['a known test']);+const resolve = (sha: string) => sha === 'abc1234' || sha === 'def5678';++function ledger(...table: string[][]) {+ return [...HEADER, ...table.map((cells) => `| ${cells.join(' | ')} |`)].join(+ '\n',+ );+}++function check(text: string, checkCommits = true) {+ return problems(text, { defined, checkCommits, resolve });+}++function withCell(index: number, value: string) {+ const cells = [...GOOD];+ cells[index] = value;+ return cells;+}++describe('incident ledger', () => {+ it('keeps every row of docs/incidents.md valid', () => {+ const text = fs.readFileSync(LEDGER, 'utf8');+ expect([...rows(text)].length).toBeGreaterThan(0);+ expect(+ problems(text, {+ defined: definedCatchers(),+ checkCommits: !isShallow(),+ }),+ ).toEqual([]);+ });++ it('accepts a well-formed row and a confirmed introducing commit', () => {+ expect(check(ledger(GOOD))).toEqual([]);+ expect(check(ledger(withCell(3, 'def5678')))).toEqual([]);+ });++ it('ignores Prettier column padding and tables outside the section', () => {+ const padded = `| ${GOOD.map((cell) => cell.padEnd(20)).join(' | ')} |`;+ const other = '## Other\n\n| x | y |\n| - | - |\n| bad | row |';+ expect(check(`${other}\n${HEADER.join('\n')}\n${padded}`)).toEqual([]);+ });++ it.each([+ ['a repeated ID', ledger(GOOD, GOOD), /I-01 repeats/],+ [+ 'a Reported cell that is not a date',+ ledger(withCell(1, 'July')),+ /Reported is not a date/,+ ],+ [+ 'an Introduced cell that is not a commit',+ ledger(withCell(3, 'maybe')),+ /Introduced is not a commit/,+ ],+ [+ 'an Introduced commit that does not resolve',+ ledger(withCell(3, 'fff9999')),+ /Introduced fff9999 does not resolve/,+ ],+ [+ 'a Fixed cell that is not a commit',+ ledger(withCell(4, 'unknown')),+ /Fixed is not a commit/,+ ],+ [+ 'a Fixed commit that does not resolve',+ ledger(withCell(4, 'fff9999')),+ /Fixed fff9999 does not resolve/,+ ],+ ['an unknown layer', ledger(withCell(5, 'qa')), /layer qa is not one of/],+ ['no catcher', ledger(withCell(6, 'a test somewhere')), /no catcher named/],+ [+ 'an undefined catcher',+ ledger(withCell(6, '`a missing test`')),+ /catcher `a missing test` is not a test or gate/,+ ],+ ['a missing cell', ledger(GOOD.slice(0, 6)), /expected 7 cells, found 6/],+ ])('fails on %s and nothing else', (_name, text, message) => {+ const found = check(text);+ expect(found).toHaveLength(1);+ expect(found[0]).toMatch(message);+ });++ it('only shape-checks commits in a shallow clone', () => {+ expect(check(ledger(withCell(4, 'fff9999')), false)).toEqual([]);+ expect(check(ledger(withCell(4, 'HEAD')), false)).toHaveLength(1);+ });++ it('finds Vitest, node:test and Rust test names and repository paths', () => {+ const names = definedCatchers();+ expect(names.has('keeps every row of docs/incidents.md valid')).toBe(true);+ expect(+ names.has(+ "uses WebKit's target configuration with a fresh user content controller",+ ),+ ).toBe(true);+ expect(+ names.has(+ 'native fullscreen preserves the player subtree and F11 exits its top layer',+ ),+ ).toBe(true);+ expect(names.has('dmabuf_renderer_stays_disabled_outside_niri')).toBe(true);+ const text = ledger(withCell(6, '`tests/browser/fullscreen.mjs`'));+ expect(problems(text, { defined: names, checkCommits: false })).toEqual([]);+ expect(+ problems(ledger(withCell(6, '`tests/browser`')), {+ defined: names,+ checkCommits: false,+ }),+ ).toHaveLength(1);+ expect(fs.existsSync(path.join(ROOT, 'tests/browser/fullscreen.mjs'))).toBe(+ true,+ );+ });+});diff --git a/tests/unit/risk-tier.test.ts b/tests/unit/risk-tier.test.tsnew file mode 100644index 00000000..d058ded2--- /dev/null+++ b/tests/unit/risk-tier.test.ts@@ -0,0 +1,56 @@+import { describe, it, expect } from 'vitest';+import {+ TIERS,+ tiersFor,+ deadPatterns,+ matches,+} from '../../scripts/risk-tier.mjs';++const names = (paths: string[]) => tiersFor(paths).map((tier) => tier.name);++describe('risk tiers', () => {+ it('matches every tier pattern against a tracked file', () => {+ expect(deadPatterns()).toEqual([]);+ });++ it('reports a pattern that a rename left behind', () => {+ expect(deadPatterns(['README.md'])).toContain(+ 'publish: .github/workflows/npm-publish.yml',+ );+ });++ it.each([+ ['.github/workflows/npm-publish.yml', 'publish'],+ ['scripts/check-release-version.mjs', 'publish'],+ ['action.yml', 'public-workflow'],+ ['.github/workflows/single-app.yaml', 'public-workflow'],+ ['.github/workflows/quality-and-test.yml', 'ci'],+ ['.github/actions/setup-env/action.yml', 'ci'],+ ['src-tauri/capabilities/default.json', 'ipc-permission'],+ ['src-tauri/src/inject/event.js', 'ipc-permission'],+ ['src-tauri/tauri.conf.json', 'bundle'],+ ['bin/builders/WinBuilder.ts', 'bundle'],+ ['package.json', 'cli-artifact'],+ ])('puts %s in the %s tier', (file, tier) => {+ expect(names([file])).toEqual([tier]);+ });++ it('leaves ordinary source, tests and docs at the default checks', () => {+ expect(+ names(['bin/utils/url.ts', 'tests/unit/url.test.ts', 'docs/faq.md']),+ ).toEqual([]);+ });++ it('lists every tier a change reaches, highest first', () => {+ expect(+ names(['package.json', 'action.yml', '.github/workflows/release.yml']),+ ).toEqual(['publish', 'public-workflow', 'cli-artifact']);+ expect(TIERS.map((tier) => tier.name)[0]).toBe('publish');+ });++ it('matches a directory pattern only below that directory', () => {+ expect(matches('bin/builders/MacBuilder.ts', 'bin/builders/*')).toBe(true);+ expect(matches('bin/builders.ts', 'bin/builders/*')).toBe(false);+ expect(matches('xaction.yml', 'action.yml')).toBe(false);+ });+});