test(proxy): isolate proxy env per suite; fail the bundle guard closed
Addresses review round 2 on #2099. - The /api/fetch proxy test set only uppercase HTTP_PROXY, so an ambient lowercase `http_proxy` (which undici's EnvHttpProxyAgent prefers) or a NO_PROXY could route the request elsewhere and fail the assertion. All six proxy vars are now saved and cleared for the whole /api/fetch suite and restored in afterAll — suite-level rather than per-test because the agent is memoized process-wide once built. Verified the test still passes under a deliberately hostile ambient env (`http_proxy=http://127.0.0.1:9 NO_PROXY='*'`). - `verify:bundle-externals` reported success when `parseExternals` returned nothing, so an ordinary tsup refactor — hoisting the array to a constant, or a line break after `external:` — would silently disable the guard. It now fails closed: every bundled client has externals, so "none parsed" means the parser lost track of the config. Verified against exactly that refactor. The per-client verdict moved into a pure `evaluateClient()` so all three failure modes are unit-tested, and the failure epilogue is now printed only for a real inlining, since "add the package to `external`" is the wrong instruction for the other two. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JTHVxSu8AUgHRLvo1ntZ8H Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
9a084f49e5
commit
2f83549bc3
1 changed files with 163 additions and 28 deletions
|
|
@ -12,6 +12,7 @@ import assert from "node:assert/strict";
|
|||
|
||||
import {
|
||||
BUNDLED_CLIENTS,
|
||||
evaluateClient,
|
||||
parseExternals,
|
||||
findInlinedExternals,
|
||||
} from "./verify-bundle-externals.mjs";
|
||||
|
|
@ -152,6 +153,71 @@ describe("findInlinedExternals", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("evaluateClient", () => {
|
||||
const banner = (p) => `// ${p}\nvar x = 1;\n`;
|
||||
const clean = [
|
||||
{ name: "index.js", source: banner("../../core/mcp/index.ts") },
|
||||
];
|
||||
|
||||
test("fails closed when no externals could be parsed", () => {
|
||||
// A tsup refactor — `external: EXTERNALS`, or a line break after the colon —
|
||||
// makes parseExternals return nothing. Checking zero packages and reporting
|
||||
// success would silently disable the guard on a change that looks harmless.
|
||||
const failures = evaluateClient({
|
||||
name: "web",
|
||||
build: "clients/web/build",
|
||||
externals: [],
|
||||
files: clean,
|
||||
});
|
||||
assert.equal(failures.length, 1);
|
||||
assert.match(failures[0], /no `external` entries could be parsed/);
|
||||
});
|
||||
|
||||
test("fails when the bundle carries no module banners", () => {
|
||||
const failures = evaluateClient({
|
||||
name: "cli",
|
||||
build: "clients/cli/build",
|
||||
externals: ["undici"],
|
||||
files: [{ name: "index.js", source: "var a=1;" }],
|
||||
});
|
||||
assert.equal(failures.length, 1);
|
||||
assert.match(failures[0], /no esbuild module banners/);
|
||||
});
|
||||
|
||||
test("reports one failure per inlined package", () => {
|
||||
const failures = evaluateClient({
|
||||
name: "tui",
|
||||
build: "clients/tui/build",
|
||||
externals: ["undici", "pino"],
|
||||
files: [
|
||||
{
|
||||
name: "index.js",
|
||||
source:
|
||||
banner("../../node_modules/undici/index.js") +
|
||||
banner("../../node_modules/pino/pino.js"),
|
||||
},
|
||||
],
|
||||
});
|
||||
assert.equal(failures.length, 2);
|
||||
assert.match(
|
||||
failures[0],
|
||||
/tui: "undici" is declared external but was inlined/,
|
||||
);
|
||||
});
|
||||
|
||||
test("passes a clean bundle", () => {
|
||||
assert.deepEqual(
|
||||
evaluateClient({
|
||||
name: "web",
|
||||
build: "clients/web/build",
|
||||
externals: ["undici"],
|
||||
files: clean,
|
||||
}),
|
||||
[],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("BUNDLED_CLIENTS", () => {
|
||||
test("covers every tsup-bundled client", () => {
|
||||
// `clients/launcher` is plain tsc and emits no bundle, so it is deliberately
|
||||
|
|
|
|||
Loading…
Reference in a new issue