From 69dba4e2cb5a2df5ea62450b3b6fe2c903ce9093 Mon Sep 17 00:00:00 2001 From: Younes Abouelnagah Date: Thu, 5 Nov 2026 09:56:46 -0500 Subject: [PATCH] test(mcp): build both targets inside test so a stale dist cannot pass The tests run the built artifacts (dist/server/index.js, dist/view.html and the Workers bundle), but `pnpm mcp test` ran them without building. With a source change and an old dist/, every test passed against the old build: with src/node/index.ts throwing on import, the old command passed 154/154, and the new one fails. `test` now runs build and build:worker first. Turbo's test task drops its separate build dependencies, and `verify` drops its build steps, so nothing builds twice. test:browser now runs after test, and test declares dist/ and dist-worker/ as outputs, so one Turbo run never builds in two tasks at once and a cache hit restores the build. Answers ansari#335 Q5. Co-Authored-By: Claude Opus 5.5 --- apps/mcp/README.md | 4 +++- apps/mcp/package.json | 4 ++-- apps/mcp/turbo.json | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/mcp/README.md b/apps/mcp/README.md index 344f2aad..6f027629 100644 --- a/apps/mcp/README.md +++ b/apps/mcp/README.md @@ -64,6 +64,8 @@ pnpm mcp start `build` writes `dist/view.html` and a bundled `dist/server/index.js`. No API/auth/frontend build or SDK source checkout is needed. `dev` runs the Node entry source (`src/node/index.ts`) after `build`. The synthetic browser harness is test-only and uses no credentials or live answers. +`test` runs `build` and `build:worker` itself before any test, because the tests run the built artifacts: without a fresh build they pass against a stale `dist/`. `test:browser` reads `dist/view.html` without building, so run it after `test` (as `verify` and the Turbo task order do). + ### Two hosting targets, one application The same Hono application and official MCP handler (`src/server/fetch-app.ts`) run on Node/Docker and on Cloudflare Workers. Each target is a thin entry that supplies configuration, logging and the built card explicitly: `src/node/` (`index.ts` and `http-server.ts`: environment, filesystem read at start, listener, signals) and `src/worker/index.ts` (Worker bindings, console, the card bundled at build time). Both adapters import the shared code in `src/server/`; shared modules import neither adapter and read no file, environment or process object. @@ -76,7 +78,7 @@ The same Hono application and official MCP handler (`src/server/fetch-app.ts`) r ```sh # Clean frozen installation, then both artifacts and every check (Node, Workers and browser): pnpm install --frozen-lockfile --strict-peer-dependencies --filter ansari-mcp... -pnpm mcp verify # typecheck, build, build:worker, test, test:browser +pnpm mcp verify # lint, typecheck, test (which builds both targets first), test:browser # Run the Worker in Wrangler's local runtime under one declared environment (dev, beta or production). Its local secrets are `.dev.vars.` only (git-ignored, and excluded from the Docker build context, together with `.wrangler/` and `dist-worker/`). The script refuses a generic `.dev.vars`, which Wrangler would read for every environment, and turns off Wrangler's `.env` fallback. pnpm dev:worker:dev --var ANSARI_RELEASE:local-1 diff --git a/apps/mcp/package.json b/apps/mcp/package.json index 3033653b..e5752e5e 100644 --- a/apps/mcp/package.json +++ b/apps/mcp/package.json @@ -13,9 +13,9 @@ "start": "node dist/server/index.js", "dev": "tsx src/node/index.ts", "typecheck": "tsc --noEmit", - "test": "tsx --test test/*.test.ts", + "test": "pnpm build && pnpm build:worker && tsx --test test/*.test.ts", "test:browser": "tsx test/browser.ts", - "verify": "pnpm lint && pnpm typecheck && pnpm build && pnpm build:worker && pnpm test && pnpm test:browser", + "verify": "pnpm lint && pnpm typecheck && pnpm test && pnpm test:browser", "check:release": "node scripts/check-release.mjs", "build:worker": "tsx scripts/build.ts worker", "guard:dev-vars": "test ! -e .dev.vars || { echo 'A generic .dev.vars is read by every environment: rename it to .dev.vars. for the one environment it belongs to.' >&2; exit 1; }", diff --git a/apps/mcp/turbo.json b/apps/mcp/turbo.json index e3d96abd..e08ed7ec 100644 --- a/apps/mcp/turbo.json +++ b/apps/mcp/turbo.json @@ -10,14 +10,15 @@ "dependsOn": [] }, "test": { - "dependsOn": [ - "build", - "build:worker" + "dependsOn": [], + "outputs": [ + "dist/**", + "dist-worker/**" ] }, "test:browser": { "dependsOn": [ - "build" + "test" ], "cache": false },