Skip to content

Commit 55ad7ab

Browse files
cliffhallclaude
andcommitted
chore: handle PR #1792 round-3 follow-ups in-place (format-coverage guard, uniform globs, theme gate)
Rather than defer these to tickets, fold them into this PR: - Obs 2: widen every client + root format glob to a uniform *.{ts,tsx,mts,cts,js,jsx,mjs,cjs} so a future .mts/.cjs/.tsx top-level file can't silently slip the gate. - Obs 1: add scripts/verify-format-coverage.mjs (wired into `validate`) — it parses the format:check globs out of every package.json, enumerates all tracked source files, and fails listing any not covered by a glob. The durable, standing version of #1789's one-shot audit; negative-tested. - Obs 3: bring src/theme/** under the coverage gate (21/23 files were already ≥90 transitively; add Paper.test.tsx for the one laggard, Paper.ts). src/App.tsx (~4.5k lines, ~42% branches) is converted from a silent omission into an explicit, documented exclusion (comment on the coverage `include` + AGENTS.md) — gating it is a dedicated effort, not a whitelist tweak. npm run ci green (the new guard reports 885/885 tracked source files gated). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent b4d0424 commit 55ad7ab

9 files changed

Lines changed: 225 additions & 15 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ The top-level **`src/types/`** is a sibling of both and is not the place for new
255255

256256
Cross-directory imports point **one way, `lib → utils`** (infra depends on pure helpers, never the reverse). Keep it that way: if a `utils/` module needs a type currently exported from a `lib/` module, declare the type in `utils/` and re-export it from `lib/` (as `pendingReauth` owns `OAuthResumeAuthKind` and `oauthResume` re-exports it), rather than importing "up" from `utils` into `lib`.
257257

258-
Nothing **enforces** the boundary: no path alias keys off it, and the coverage `include` in `clients/web/vite.config.ts` lists **both** `src/lib/**` and `src/utils/**`, so a move between them is coverage-neutral (this is why the refactor was gate-safe). It's a human-legible signal at import time, valuable in a codebase this test-heavy (the ≥90% per-file gate). Note that `include` is a **whitelist** — it names `components`/`hooks`/`lib`/`utils`/`server` (plus the `core/*` runtime; `hooks` was added in #1787), so a module placed **outside** those directories (`theme/`, `types/`, `App.tsx`, or a brand-new grab-bag) falls out of the ≥90 gate entirely, silently. When adding a module, place it by the rule and keep it inside a gated directory; when it genuinely mixes both (e.g. `downloadFile` bundles DOM-side-effect helpers with a couple of pure ones), keep it whole on its dominant side (`lib`) rather than splitting hairs.
258+
Nothing **enforces** the boundary: no path alias keys off it, and the coverage `include` in `clients/web/vite.config.ts` lists **both** `src/lib/**` and `src/utils/**`, so a move between them is coverage-neutral (this is why the refactor was gate-safe). It's a human-legible signal at import time, valuable in a codebase this test-heavy (the ≥90% per-file gate). Note that `include` is a **whitelist** — it names `components`/`hooks`/`theme`/`lib`/`utils`/`server` (plus the `core/*` runtime; `hooks` and `theme` were added in #1787), so a module placed **outside** those directories (`types/`, `App.tsx`, or a brand-new grab-bag) falls out of the ≥90 gate entirely, silently. The one **deliberate, documented** exception is `src/App.tsx` — a ~4.5k-line composition root at ~42% branch coverage, whose omission is called out in a comment on the `include` array itself (gating it is a dedicated testing/decomposition effort, not a whitelist tweak) rather than left silent. When adding a module, place it by the rule and keep it inside a gated directory; when it genuinely mixes both (e.g. `downloadFile` bundles DOM-side-effect helpers with a couple of pure ones), keep it whole on its dominant side (`lib`) rather than splitting hairs.
259259

260260
## React instructions
261261
- UI Components

‎clients/cli/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"test:cli-metadata": "vitest run metadata.test.ts",
2929
"pretest": "npm run test-servers:build && npm run build",
3030
"lint": "eslint .",
31-
"format": "prettier --write src __tests__ \"*.{ts,js}\"",
32-
"format:check": "prettier --check src __tests__ \"*.{ts,js}\""
31+
"format": "prettier --write src __tests__ \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
32+
"format:check": "prettier --check src __tests__ \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\""
3333
},
3434
"dependencies": {
3535
"@modelcontextprotocol/client": "2.0.0-beta.5",

‎clients/launcher/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"build": "tsc",
1616
"postbuild": "node scripts/make-executable.js",
1717
"lint": "eslint .",
18-
"format": "prettier --write src __tests__ scripts \"*.{ts,js}\"",
19-
"format:check": "prettier --check src __tests__ scripts \"*.{ts,js}\"",
18+
"format": "prettier --write src __tests__ scripts \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
19+
"format:check": "prettier --check src __tests__ scripts \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
2020
"test": "vitest run",
2121
"test:coverage": "vitest run --coverage",
2222
"validate": "npm run format:check && npm run lint && npm run build && npm run test"

‎clients/tui/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"test": "vitest run",
2424
"test:coverage": "vitest run --coverage",
2525
"lint": "eslint .",
26-
"format": "prettier --write src __tests__ \"*.{ts,tsx,js}\"",
27-
"format:check": "prettier --check src __tests__ \"*.{ts,tsx,js}\""
26+
"format": "prettier --write src __tests__ \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
27+
"format:check": "prettier --check src __tests__ \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\""
2828
},
2929
"dependencies": {
3030
"@modelcontextprotocol/client": "2.0.0-beta.5",

‎clients/web/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"test:integration:watch": "npm run test-servers:build && vitest --project=integration",
2727
"test-servers:build": "tsc -p ../../test-servers --noCheck",
2828
"lint": "eslint .",
29-
"format": "prettier --write src server .storybook \"*.{ts,js}\"",
30-
"format:check": "prettier --check src server .storybook \"*.{ts,js}\"",
29+
"format": "prettier --write src server .storybook \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
30+
"format:check": "prettier --check src server .storybook \"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
3131
"preview": "vite preview",
3232
"storybook": "storybook dev -p 6006"
3333
},
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, it, expect } from "vitest";
2+
import { Paper } from "@mantine/core";
3+
import { renderWithMantine } from "../test/renderWithMantine";
4+
5+
// The theme's ThemePaper.extend is applied transitively when components render a
6+
// Paper, but no single component exercises every variant — the `code`,
7+
// `contained`, and `panel` branches of its classNames/styles callbacks were
8+
// uncovered. Render each variant (plus the default) under the project theme so
9+
// both callbacks run for every branch. See #1787 (theme/** brought under the
10+
// coverage gate).
11+
12+
const VARIANTS = ["code", "contained", "panel"] as const;
13+
14+
describe("ThemePaper variants", () => {
15+
it("renders the default variant (no variant-specific styles)", () => {
16+
const { getByText } = renderWithMantine(<Paper>default</Paper>);
17+
expect(getByText("default")).toBeTruthy();
18+
});
19+
20+
for (const variant of VARIANTS) {
21+
it(`renders the "${variant}" variant`, () => {
22+
const { getByText } = renderWithMantine(
23+
<Paper variant={variant}>{variant}</Paper>,
24+
);
25+
expect(getByText(variant)).toBeTruthy();
26+
});
27+
}
28+
29+
it('applies the paper-code class only to the "code" variant', () => {
30+
const { getByText } = renderWithMantine(<Paper variant="code">c</Paper>);
31+
// classNames returns { root: "paper-code" } for the code variant.
32+
expect(getByText("c").className).toContain("paper-code");
33+
});
34+
});

‎clients/web/vite.config.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,16 @@ export default defineConfig(({ command }) => {
167167
coverage: {
168168
provider: "v8",
169169
reporter: ["text", "html", "json-summary"],
170+
// Whitelist of gated directories. NOTE: `src/App.tsx` is deliberately
171+
// NOT listed — it is a ~4.5k-line composition root at ~42% branch
172+
// coverage, so gating it is a dedicated testing/decomposition effort,
173+
// not a whitelist tweak. Its omission is intentional and documented
174+
// here (and in AGENTS.md) rather than silent. Every *other* src
175+
// directory is gated; add new ones here as they appear.
170176
include: [
171177
"src/components/**/*.{ts,tsx}",
172178
"src/hooks/**/*.{ts,tsx}",
179+
"src/theme/**/*.{ts,tsx}",
173180
"src/lib/**/*.{ts,tsx}",
174181
"src/utils/**/*.{ts,tsx}",
175182
"clients/web/server/**/*.{ts,tsx}",

‎package.json‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@
4040
"ci": "npm run validate && npm run coverage && npm run verify:build-gate && npm run smoke && npm run ci:storybook",
4141
"ci:storybook": "cd clients/web && npx playwright install chromium && npm run test:storybook",
4242
"verify:build-gate": "node scripts/verify-build-gate.mjs",
43-
"validate": "npm run validate:core && npm run validate:web && npm run validate:cli && npm run validate:tui && npm run validate:launcher",
43+
"validate": "npm run verify:format-coverage && npm run validate:core && npm run validate:web && npm run validate:cli && npm run validate:tui && npm run validate:launcher",
44+
"verify:format-coverage": "node scripts/verify-format-coverage.mjs",
4445
"validate:core": "npm run format:check:core && npm run format:check:scripts && npm run format:check:shared && npm run lint:core && npm run lint:shared",
4546
"lint:core": "eslint \"core/**/*.{ts,tsx}\"",
46-
"lint:shared": "eslint \"test-servers/src/**/*.ts\" vitest.shared.mts eslint.config.js",
47+
"lint:shared": "eslint \"test-servers/src/**/*.{ts,tsx,mts,cts}\" vitest.shared.mts eslint.config.js",
4748
"format:core": "prettier --write \"core/**/*.{ts,tsx}\"",
4849
"format:check:core": "prettier --check \"core/**/*.{ts,tsx}\"",
49-
"format:scripts": "prettier --write \"scripts/**/*.{mjs,js,cjs,ts}\"",
50-
"format:check:scripts": "prettier --check \"scripts/**/*.{mjs,js,cjs,ts}\"",
51-
"format:shared": "prettier --write \"test-servers/src/**/*.ts\" vitest.shared.mts eslint.config.js",
52-
"format:check:shared": "prettier --check \"test-servers/src/**/*.ts\" vitest.shared.mts eslint.config.js",
50+
"format:scripts": "prettier --write \"scripts/**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
51+
"format:check:scripts": "prettier --check \"scripts/**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}\"",
52+
"format:shared": "prettier --write \"test-servers/src/**/*.{ts,tsx,mts,cts}\" vitest.shared.mts eslint.config.js",
53+
"format:check:shared": "prettier --check \"test-servers/src/**/*.{ts,tsx,mts,cts}\" vitest.shared.mts eslint.config.js",
5354
"format": "npm run format:core && npm run format:scripts && npm run format:shared && cd clients/web && npm run format && cd ../cli && npm run format && cd ../tui && npm run format && cd ../launcher && npm run format",
5455
"validate:cli": "cd clients/cli && npm run validate",
5556
"validate:tui": "cd clients/tui && npm run validate",

‎scripts/verify-format-coverage.mjs‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env node
2+
// Durable guard for the "every first-party source file is format-gated" invariant
3+
// that #1789 established by a one-shot manual audit (PR #1792). A prettier
4+
// `format`/`format:check` glob that stops covering a file fails silently — the
5+
// file is simply skipped, not reported — so a nested dir (`.storybook/`, a
6+
// client `scripts/`) or a new extension can re-open the gap unnoticed. This is
7+
// the format-coverage analog of `verify:build-gate`: it enumerates every tracked
8+
// source file and asserts each is matched by at least one `prettier --check`
9+
// glob declared across the repo's `package.json`s. Exits non-zero, listing the
10+
// offenders, on any miss.
11+
//
12+
// Source of truth is the `format:check*` scripts themselves — this parser reads
13+
// the globs out of them, so widening/narrowing a glob is reflected here with no
14+
// second list to keep in sync.
15+
16+
import { readFileSync } from "node:fs";
17+
import { execFileSync } from "node:child_process";
18+
import path from "node:path";
19+
import { fileURLToPath } from "node:url";
20+
21+
const repoRoot = path.resolve(
22+
path.dirname(fileURLToPath(import.meta.url)),
23+
"..",
24+
);
25+
26+
// File extensions prettier formats as first-party source here. Kept in sync with
27+
// the union of the format globs; a file with one of these extensions that no
28+
// glob matches is the failure this guard exists to catch.
29+
const SOURCE_EXTENSIONS = [
30+
"ts",
31+
"tsx",
32+
"mts",
33+
"cts",
34+
"js",
35+
"jsx",
36+
"mjs",
37+
"cjs",
38+
];
39+
40+
// The `package.json`s whose `format:check*` scripts define the gate. The root
41+
// carries the split `format:check:core|scripts|shared`; each client carries a
42+
// single `format:check`. Paths are relative to the repo root; each glob resolves
43+
// relative to its manifest's directory (prettier's cwd for that script).
44+
const MANIFESTS = [
45+
".",
46+
"clients/web",
47+
"clients/cli",
48+
"clients/tui",
49+
"clients/launcher",
50+
];
51+
52+
/** Split a shell-ish command string into args, honoring double quotes. */
53+
function tokenize(command) {
54+
const tokens = [];
55+
const re = /"([^"]*)"|(\S+)/g;
56+
let m;
57+
while ((m = re.exec(command)) !== null) {
58+
tokens.push(m[1] !== undefined ? m[1] : m[2]);
59+
}
60+
return tokens;
61+
}
62+
63+
/** Extract the path/glob args from every `prettier --check …` in a manifest. */
64+
function prettierCheckArgs(scripts) {
65+
const args = [];
66+
for (const value of Object.values(scripts ?? {})) {
67+
if (typeof value !== "string" || !value.includes("prettier --check"))
68+
continue;
69+
// A manifest may chain `prettier --check …` inside a larger script; take the
70+
// segment starting at each occurrence up to the next `&&`/`||`/`;`.
71+
for (const segment of value.split(/&&|\|\||;/)) {
72+
const trimmed = segment.trim();
73+
if (!trimmed.startsWith("prettier --check")) continue;
74+
const tokens = tokenize(trimmed).slice(2); // drop `prettier` `--check`
75+
for (const t of tokens) {
76+
if (t.startsWith("-")) continue; // a flag, not a path
77+
args.push(t);
78+
}
79+
}
80+
}
81+
return args;
82+
}
83+
84+
const GLOB_CHARS = /[*?{}[\]]/;
85+
86+
/** Convert a prettier glob to an anchored RegExp over repo-relative POSIX paths. */
87+
function globToRegExp(glob) {
88+
let re = "";
89+
for (let i = 0; i < glob.length; i++) {
90+
const c = glob[i];
91+
if (c === "*") {
92+
if (glob[i + 1] === "*") {
93+
// `**` (optionally `**/`) crosses path separators.
94+
if (glob[i + 2] === "/") {
95+
re += "(?:.*/)?";
96+
i += 2;
97+
} else {
98+
re += ".*";
99+
i += 1;
100+
}
101+
} else {
102+
re += "[^/]*"; // `*` stays within a segment
103+
}
104+
} else if (c === "?") {
105+
re += "[^/]";
106+
} else if (c === "{") {
107+
re += "(?:";
108+
} else if (c === "}") {
109+
re += ")";
110+
} else if (c === ",") {
111+
re += "|";
112+
} else if (".+^$()|\\/".includes(c)) {
113+
re += "\\" + c;
114+
} else {
115+
re += c;
116+
}
117+
}
118+
return new RegExp("^" + re + "$");
119+
}
120+
121+
/** Build the set of coverage predicates from all manifests' format globs. */
122+
function buildMatchers() {
123+
const matchers = [];
124+
for (const manifestDir of MANIFESTS) {
125+
const manifestPath = path.join(repoRoot, manifestDir, "package.json");
126+
const pkg = JSON.parse(readFileSync(manifestPath, "utf8"));
127+
for (const arg of prettierCheckArgs(pkg.scripts)) {
128+
const rel = manifestDir === "." ? arg : path.posix.join(manifestDir, arg);
129+
if (GLOB_CHARS.test(arg)) {
130+
const re = globToRegExp(rel);
131+
matchers.push((f) => re.test(f));
132+
} else {
133+
// A bare path: a directory prettier recurses into, or an exact file.
134+
matchers.push((f) => f === rel || f.startsWith(rel + "/"));
135+
}
136+
}
137+
}
138+
return matchers;
139+
}
140+
141+
function trackedSourceFiles() {
142+
const out = execFileSync(
143+
"git",
144+
["ls-files", ...SOURCE_EXTENSIONS.map((e) => `*.${e}`)],
145+
{ cwd: repoRoot, encoding: "utf8" },
146+
);
147+
return out.split("\n").filter(Boolean);
148+
}
149+
150+
const matchers = buildMatchers();
151+
const files = trackedSourceFiles();
152+
const ungated = files.filter((f) => !matchers.some((m) => m(f)));
153+
154+
if (ungated.length > 0) {
155+
console.error(
156+
`verify:format-coverage — ${ungated.length} tracked source file(s) are not covered by any prettier format glob:\n`,
157+
);
158+
for (const f of ungated) console.error(" " + f);
159+
console.error(
160+
"\nAdd the file's directory (or a matching glob) to the relevant `format`/`format:check` script,",
161+
);
162+
console.error("or widen the extension set. See AGENTS.md.");
163+
process.exit(1);
164+
}
165+
166+
console.log(
167+
`verify:format-coverage — OK: all ${files.length} tracked source files are format-gated.`,
168+
);

0 commit comments

Comments
 (0)