Skip to content

Commit daecf59

Browse files
cliffhallclaude
andcommitted
chore(web): harden dev warning filter per review
- Tighten BENIGN_PAIRS to repo-relative path fragments (not basenames) so an unrelated future UNRESOLVED_IMPORT warning mentioning the same dep + a same-named file isn't silently dropped. Verified Rolldown prints the full repo-relative path. (review #1) - Add a note that the matcher tracks Rolldown's message format and degrades to a safe no-op (warnings return) if that format changes. (review #2) - Export isBenignWarning/BENIGN_PAIRS, guard the stream patching behind !VITEST, add a .d.mts so the pure helper is importable from TS, and add a unit test locking the signature pairs and the over-match guards. (review #3) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 656816b commit daecf59

3 files changed

Lines changed: 83 additions & 7 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Type declarations for the dev-only `quiet-config-warnings.mjs` hook so its
2+
* pure helpers can be imported (and unit-tested) from TypeScript. */
3+
4+
/** (package-quote, repo-relative-source-path) pairs of benign warnings to drop. */
5+
export declare const BENIGN_PAIRS: ReadonlyArray<readonly [string, string]>;
6+
7+
/** True when `text` is a benign node-only UNRESOLVED_IMPORT warning. */
8+
export declare function isBenignWarning(text: string): boolean;

‎clients/web/server/quiet-config-warnings.mjs‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@
1414
* so we drop any write whose text carries the unresolved-import signature for
1515
* one of these known-benign (package, source-file) pairs. Installed via
1616
* `node --import` ahead of the Vite CLI; only affects the dev script.
17+
*
18+
* This matcher is tied to Rolldown's current warning format (the `'pkg'` quote
19+
* style and the repo-relative source path it prints). If these warnings ever
20+
* reappear, check whether Rolldown changed its message format. The failure mode
21+
* is safe: a format change just makes the filter a no-op (the warnings return),
22+
* it never drops anything else.
1723
*/
1824

19-
const BENIGN_PAIRS = [
20-
["'chokidar'", "server.ts"],
21-
["'atomically'", "store-io.ts"],
22-
["'@napi-rs/keyring'", "secret-store.ts"],
25+
// (package, source-file) pairs. The file is a repo-relative path fragment — not
26+
// just a basename — so an unrelated future warning that happens to mention the
27+
// same dep and a same-named file isn't silently dropped.
28+
export const BENIGN_PAIRS = [
29+
["'chokidar'", "core/mcp/remote/node/server.ts"],
30+
["'atomically'", "core/storage/store-io.ts"],
31+
["'@napi-rs/keyring'", "core/auth/node/secret-store.ts"],
2332
];
2433

25-
function isBenignWarning(text) {
34+
export function isBenignWarning(text) {
2635
if (!text.includes("UNRESOLVED_IMPORT")) return false;
2736
return BENIGN_PAIRS.some(
2837
([dep, file]) => text.includes(dep) && text.includes(file),
@@ -48,5 +57,10 @@ function patch(stream) {
4857
};
4958
}
5059

51-
patch(process.stdout);
52-
patch(process.stderr);
60+
// Guard so importing this module (e.g. from a unit test for isBenignWarning)
61+
// doesn't monkey-patch the test runner's streams. Under `npm run dev` VITEST is
62+
// unset, so the patch installs as intended.
63+
if (!process.env.VITEST) {
64+
patch(process.stdout);
65+
patch(process.stderr);
66+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
isBenignWarning,
4+
BENIGN_PAIRS,
5+
} from "../../../server/quiet-config-warnings.mjs";
6+
7+
// A representative Rolldown config-load warning block (header + code frame), as
8+
// captured from `vite dev` startup.
9+
function warning(dep: string, file: string): string {
10+
return (
11+
`${file} (8:36) [UNRESOLVED_IMPORT] Warning: Could not resolve ${dep} in ${file}\n` +
12+
` ╭─[ ${file}:8:37 ]\n` +
13+
` 8 │ import { readFile } from ${dep};\n` +
14+
` ╰─ Module not found, treating it as an external dependency\n`
15+
);
16+
}
17+
18+
describe("quiet-config-warnings / isBenignWarning", () => {
19+
it("matches each benign node-only dep warning", () => {
20+
for (const [dep, file] of BENIGN_PAIRS) {
21+
expect(isBenignWarning(warning(dep, file))).toBe(true);
22+
}
23+
});
24+
25+
it("ignores non-UNRESOLVED output", () => {
26+
expect(isBenignWarning("VITE v8.0.0 ready in 603 ms")).toBe(false);
27+
expect(
28+
isBenignWarning("Sandbox (MCP Apps): http://localhost:61146/sandbox"),
29+
).toBe(false);
30+
});
31+
32+
it("does not drop an UNRESOLVED_IMPORT for a different (real) dependency", () => {
33+
expect(
34+
isBenignWarning(
35+
"src/App.tsx (1:0) [UNRESOLVED_IMPORT] Warning: Could not resolve 'some-real-pkg' in src/App.tsx",
36+
),
37+
).toBe(false);
38+
});
39+
40+
it("requires the matching source path, not just the package name", () => {
41+
// Same dep, but in an unrelated file → not silenced (guards over-matching).
42+
expect(
43+
isBenignWarning(
44+
"src/elsewhere.ts (1:0) [UNRESOLVED_IMPORT] Warning: Could not resolve 'chokidar' in src/elsewhere.ts",
45+
),
46+
).toBe(false);
47+
});
48+
49+
it("uses repo-relative path fragments (not bare basenames)", () => {
50+
for (const [, file] of BENIGN_PAIRS) {
51+
expect(file).toContain("/");
52+
}
53+
});
54+
});

0 commit comments

Comments
 (0)