Skip to content

Commit a58288a

Browse files
cliffhallclaude
andcommitted
chore: address review feedback on #1689
- Add a root `format` script chaining format:core + each client's format, so the documented "npm run format" works from the root; note it in README + AGENTS (review #1). - Soften the cli/tui tsconfig comments: they mirror web's module/lib *resolution* only, not its extra strictness flags — so cli/tui src is checked slightly more loosely than web src (review #2). - Guard schemaToForm against a non-object property value (malformed server schema `properties: { foo: null }`) instead of throwing on `.title`; add a test (review #3). - Add optional `secretStore` injection to loadRunnerClientConfig and use an InMemorySecretStore + vi.stubEnv in its tests so the result no longer depends on the developer's real OS keychain / env (review #4, #5). - Justify remote.test.ts's `as unknown as Response` double cast inline per the AGENTS rule (review #5). - Widen the core lint/format globs and the root eslint `files` to `{ts,tsx}` so a future core/**/*.tsx can't silently escape (review #6). - Update README's quality-gate table for validate:core + cli/tui typecheck (review #7). Also merges origin/v2/main into the branch. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent 5763666 commit a58288a

11 files changed

Lines changed: 83 additions & 36 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ gh project item-edit --project-id PVT_kwDOCt2Azc4BJVxt --id "$ITEM_ID" --field-i
209209
- after making the changes, respond to each review comment with what was done (or why it was ignored)
210210

211211
### Mandatory pre-push gate
212-
- ALWAYS do `npm run format` before committing — it auto-fixes any Prettier issues. `validate` runs `format:check` (the non-fixing variant) and will fail in CI on any unformatted file, so always run the auto-fixer first rather than letting `format:check` catch it.
212+
- ALWAYS do `npm run format` before committing — the **root** `format` auto-fixes `core/` (`format:core`) and every client's scope in one shot. `validate` runs `format:check` (the non-fixing variant, including `format:check:core`) and will fail in CI on any unformatted file, so always run the auto-fixer first rather than letting `format:check` catch it.
213213
- **`npm run ci` is the mandatory pre-push command** — it mirrors `.github/workflows/main.yml` (minus `npm install`): `validate` → `coverage` → `smoke` → Storybook play-function tests (installs Playwright chromium if needed). It now runs **`npm run coverage`**, the per-file ≥90 gate (lines/statements/functions/branches) that CI enforces — so `npm run ci` is a true superset of GitHub CI, and passing it locally means CI's gates will pass. Expect several minutes. **`npm run validate`** remains the fast inner-loop check during development (unit tests only — no coverage gate, no smoke, no Storybook), but it is **NOT** an acceptable substitute for `npm run ci` before pushing: `validate` runs `test`, not `test:coverage`, so it does **zero** coverage gating. Skipping the gate is how a push passes every fast local check and still fails CI (this exact gap broke PR #1601 on a function-coverage regression).
214214
- ALWAYS do `npm run format` before committing, then **`npm run ci`** before pushing. From the repo root, `validate` runs the **`core/` gate first** (`validate:core`) and then chains the four per-client validations (`validate:web` → `validate:cli` → `validate:tui` → `validate:launcher`); each client delegates to its own `npm run validate` in its own folder (no coverage — fast). Every client is self-validating and the top level just chains them, building each client's bundle along the way (no cross-client build dependencies).
215215
- **`validate:core` is the shared-code format + lint gate (#1689).** Each client's `prettier`/`eslint` is scoped to its own dir, so nothing reached `core/` before — `validate:core` closes that: it runs `format:check:core` (`prettier --check "core/**/*.ts"`) + `lint:core` (`eslint "core/**/*.ts"` via the **root** `eslint.config.js`). Use `npm run format:core` to auto-fix. The root carries prettier/eslint as devDependencies for this; `core/` is isomorphic (browser + Node globals, no JSX). The root `eslint.config.js` honors an `_`-prefix as the intentionally-unused marker (`argsIgnorePattern`/`varsIgnorePattern`/`caughtErrorsIgnorePattern: '^_'`).

‎README.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ Individual clients: `build:web`, `build:cli`, `build:tui`, `build:launcher`. The
138138

139139
Each client self-validates from its own folder; the root scripts chain them. There is **no** aggregate root `test` script — use `validate` (fast) or `coverage` (the gate).
140140

141-
| Script | What it does |
142-
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143-
| `npm run validate` | `format:check` + `lint` + `build` + fast unit tests, per client. The quick inner-loop check. |
144-
| `npm run coverage` | The **per-file ≥90% gate** (lines/statements/functions/branches) under v8 instrumentation, per client. CI-enforced. For web this also runs the integration project. |
145-
| `npm run smoke` | End-to-end smokes through the built launcher (`--help` dispatch + prod cli/tui/web). |
146-
| `npm run ci` | **Mandatory pre-push command.** `validate` → `coverage` → `smoke` → Storybook. A true superset of GitHub CI. |
147-
| `npm run pack:verify` | Publish smoke — see [Publishing](#publishing). |
148-
149-
Per-client scripts exist too (`validate:web`, `coverage:cli`, `smoke:tui`, …). Run `npm run format` (per client) before committing — `validate` runs the non-fixing `format:check` and fails CI on any unformatted file.
141+
| Script | What it does |
142+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143+
| `npm run validate` | Runs `validate:core` (the shared `core/` `format:check` + `lint` gate) first, then per client: `format:check` + `lint` + **`typecheck`** (cli/tui only) + `build` + fast unit tests. The quick inner-loop check. |
144+
| `npm run coverage` | The **per-file ≥90% gate** (lines/statements/functions/branches) under v8 instrumentation, per client. CI-enforced. For web this also runs the integration project and covers the shared `core/` runtime (including `core/json` and `core/client`). |
145+
| `npm run smoke` | End-to-end smokes through the built launcher (`--help` dispatch + prod cli/tui/web). |
146+
| `npm run ci` | **Mandatory pre-push command.** `validate` → `coverage` → `smoke` → Storybook. A true superset of GitHub CI. |
147+
| `npm run pack:verify` | Publish smoke — see [Publishing](#publishing). |
148+
149+
Per-client scripts exist too (`validate:web`, `coverage:cli`, `smoke:tui`, …), plus root `validate:core` / `format:core` for the shared `core/` package. Run `npm run format` before committing — the root `format` fixes `core/` and every client; `validate` runs the non-fixing `format:check` and fails CI on any unformatted file.
150150

151151
For the full testing rules — the ≥90% per-file gate, where test files live, the unit vs. integration vs. storybook projects, and the `v8 ignore` policy — see [`AGENTS.md`](./AGENTS.md).
152152

‎clients/cli/tsconfig.json‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"noEmit": true,
5-
// Mirror clients/web/tsconfig.app.json's effective options so this
6-
// typecheck validates the imported `core/` sources against the exact
7-
// config web's own gate already uses (web's app config does not extend
8-
// tsconfig.base, so it has no `noUncheckedIndexedAccess`; re-enabling it
9-
// here would surface core issues web never gates). DOM lib + bundler
10-
// resolution are what core/ (browser-side auth, DOM types) expects.
5+
// Match clients/web/tsconfig.app.json's module/lib *resolution* options so
6+
// the imported `core/` sources are validated the same way web's own gate
7+
// validates them: DOM lib + bundler resolution are what core/ (browser-side
8+
// auth, DOM types) expects, and `noUncheckedIndexedAccess` is off because
9+
// web's app config does not extend tsconfig.base — re-enabling it here would
10+
// flag core/ issues web never gates. This does NOT mirror web's extra
11+
// strictness flags (noUnusedLocals, verbatimModuleSyntax, ES2023 target,
12+
// …), so cli/tui's own src is checked slightly more loosely than web's src.
1113
"lib": ["ES2023", "DOM", "DOM.Iterable"],
1214
"types": ["node"],
1315
"moduleResolution": "bundler",

‎clients/tui/__tests__/schemaToForm.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ describe("schemaToForm", () => {
1313
expect(form.sections[0]?.fields).toEqual([]);
1414
});
1515

16+
it("treats a non-object property value as an empty schema instead of throwing", () => {
17+
// A malformed server schema whose property value is null/primitive must not
18+
// crash — the field degrades to a plain string input labelled by its key.
19+
const form = schemaToForm(
20+
{ properties: { bad: null, worse: 42 } },
21+
"malformed",
22+
);
23+
const fields = form.sections[0]?.fields ?? [];
24+
expect(fields).toHaveLength(2);
25+
expect(
26+
fields.map((f) => ({ name: f.name, type: f.type, label: f.label })),
27+
).toEqual([
28+
{ name: "bad", type: "string", label: "bad" },
29+
{ name: "worse", type: "string", label: "worse" },
30+
]);
31+
});
32+
1633
it("maps each JSON Schema type to the matching ink-form field type", () => {
1734
const form = schemaToForm(
1835
{

‎clients/tui/src/utils/schemaToForm.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ export function schemaToForm(
6565
const required = schema.required || [];
6666

6767
for (const [key, prop] of Object.entries(properties)) {
68-
const property = prop as JsonSchemaProperty;
68+
// `properties` values are `unknown` (the SDK schema admits anything), so
69+
// guard before treating a value as a schema object — a malformed server
70+
// schema with e.g. `properties: { foo: null }` must not throw on `.title`.
71+
const property = (
72+
typeof prop === "object" && prop !== null ? prop : {}
73+
) as JsonSchemaProperty;
6974
const baseField = {
7075
name: key,
7176
label: property.title || key,

‎clients/tui/tsconfig.json‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
"compilerOptions": {
44
"noEmit": true,
55
"jsx": "react-jsx",
6-
// Mirror clients/web/tsconfig.app.json's effective options so this
7-
// typecheck validates the imported `core/` sources against the exact
8-
// config web's own gate already uses (web's app config does not extend
9-
// tsconfig.base, so it has no `noUncheckedIndexedAccess`; re-enabling it
10-
// here would surface core issues web never gates). DOM lib + bundler
11-
// resolution are what core/ (browser-side auth, DOM types) expects; the
12-
// `react` path redirect lets core/ source resolve its bare `react` import
13-
// from this client's node_modules.
6+
// Match clients/web/tsconfig.app.json's module/lib *resolution* options so
7+
// the imported `core/` sources are validated the same way web's own gate
8+
// validates them: DOM lib + bundler resolution are what core/ (browser-side
9+
// auth, DOM types) expects, `noUncheckedIndexedAccess` is off because web's
10+
// app config does not extend tsconfig.base (re-enabling it would flag core/
11+
// issues web never gates), and the `react` path redirect lets core/ source
12+
// resolve its bare `react` import from this client's node_modules. This does
13+
// NOT mirror web's extra strictness flags (noUnusedLocals, verbatimModule-
14+
// Syntax, ES2023 target, …), so tui's own src is checked slightly more
15+
// loosely than web's src.
1416
"lib": ["ES2023", "DOM", "DOM.Iterable"],
1517
"types": ["node"],
1618
"moduleResolution": "bundler",

‎clients/web/src/test/core/client/remote.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ const validConfig: ClientConfig = {
1515
},
1616
};
1717

18-
/** Build a minimal `Response`-like stub for the mocked fetch. */
18+
/**
19+
* Build a minimal `Response`-like stub for the mocked fetch. The code under
20+
* test only reads `.ok`, `.status`, and `.json()`, so the stub implements just
21+
* those. The double cast is unavoidable here: `Response` has ~20 required
22+
* members (`headers`, `body`, `arrayBuffer`, `blob`, `clone`, …), so a direct
23+
* `as Response` is a TS2352 error and there is no lighter alternative than
24+
* asserting through `unknown` for a deliberately-partial test double.
25+
*/
1926
function fakeResponse(init: {
2027
ok: boolean;
2128
status: number;

‎clients/web/src/test/core/client/runner.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { describe, it, expect, afterEach } from "vitest";
1+
import { describe, it, expect, afterEach, vi } from "vitest";
22
import * as fs from "node:fs/promises";
33
import * as os from "node:os";
44
import * as path from "node:path";
5+
import { InMemorySecretStore } from "@inspector/core/auth/node/secret-store.js";
56
import {
67
buildRunnerClientAuthOptions,
78
isOAuthCapableServerConfig,
@@ -126,12 +127,14 @@ describe("loadRunnerClientConfig", () => {
126127
if (tmpDir) {
127128
await fs.rm(tmpDir, { recursive: true, force: true });
128129
}
129-
delete process.env.MCP_CLIENT_CONFIG_PATH;
130+
vi.unstubAllEnvs();
130131
});
131132

132133
it("reads client.json from an explicit path (empty when absent)", async () => {
133134
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "runner-client-"));
134135
const filePath = path.join(tmpDir, "client.json");
136+
// No injected store here → exercises the default `new KeyringSecretStore()`
137+
// path (its get() tolerates keychain unavailability, returning {}).
135138
expect(
136139
await loadRunnerClientConfig({ clientConfigPath: filePath }),
137140
).toEqual({});
@@ -150,8 +153,12 @@ describe("loadRunnerClientConfig", () => {
150153
}),
151154
"utf-8",
152155
);
153-
process.env.MCP_CLIENT_CONFIG_PATH = filePath;
154-
const config = await loadRunnerClientConfig();
156+
vi.stubEnv("MCP_CLIENT_CONFIG_PATH", filePath);
157+
// Inject an in-memory store so the result never depends on the developer's
158+
// real OS keychain.
159+
const config = await loadRunnerClientConfig({
160+
secretStore: new InMemorySecretStore(),
161+
});
155162
expect(config.cimd?.clientMetadataUrl).toBe(
156163
"https://example.com/oauth/client.json",
157164
);

‎core/client/runner.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
* for Node runners (TUI, CLI).
44
*/
55

6-
import { KeyringSecretStore } from "../auth/node/secret-store.js";
6+
import {
7+
KeyringSecretStore,
8+
type SecretStore,
9+
} from "../auth/node/secret-store.js";
710
import type {
811
InspectorClientOptions,
912
InspectorServerSettings,
@@ -18,6 +21,9 @@ import {
1821
export interface LoadRunnerClientConfigOptions {
1922
/** Explicit path from `--client-config` (or MCP_CLIENT_CONFIG_PATH when unset). */
2023
clientConfigPath?: string;
24+
/** Secret store for the IdP clientSecret; defaults to the OS keychain. Tests
25+
* inject an in-memory store for determinism. */
26+
secretStore?: SecretStore;
2127
}
2228

2329
/** Load install-level client.json with keychain-backed IdP secrets. */
@@ -28,7 +34,7 @@ export async function loadRunnerClientConfig(
2834
options?.clientConfigPath?.trim() ||
2935
process.env.MCP_CLIENT_CONFIG_PATH?.trim() ||
3036
undefined;
31-
const secretStore = new KeyringSecretStore();
37+
const secretStore = options?.secretStore ?? new KeyringSecretStore();
3238
return loadClientConfig({ filePath: customPath, secretStore });
3339
}
3440

‎eslint.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { defineConfig, globalIgnores } from "eslint/config";
1111
export default defineConfig([
1212
globalIgnores(["core/**/build/**", "core/**/dist/**"]),
1313
{
14-
files: ["core/**/*.ts"],
14+
files: ["core/**/*.{ts,tsx}"],
1515
extends: [js.configs.recommended, tseslint.configs.recommended],
1616
languageOptions: {
1717
ecmaVersion: 2022,

0 commit comments

Comments
 (0)