fix(runner): the MCP guard tested for real, and the MCP routes tested at all (DEV-2501) - #201
Open
danielzytohoc wants to merge 1 commit into
Open
fix(runner): the MCP guard tested for real, and the MCP routes tested at all (DEV-2501)#201danielzytohoc wants to merge 1 commit into
danielzytohoc wants to merge 1 commit into
Conversation
…DEV-2501) The coverage audit's two worst findings, closed. G1 — the containment guard was asserted against a copy of itself. The "only demos the MCP created are updatable through it" test declared its own local `fromMcp` predicate instead of importing the route's check, so deleting the guard from index.ts left the test green — a test of a security control that cannot fail when the control goes away. The predicate now lives in mcp-create.ts as isMcpCreated() (the containment control from the PR #177 security review), the route calls it, the test imports it, and a source-grep test (theme-codegen.test.mjs style) pins the route to the exported predicate so an inline check cannot drift back in. G2 — nothing imported the router, so every route-level promise of the MCP endpoints (status codes, response shapes) was untested. pipeline/mcp-routes.test.mjs now drives the real default export of workers/api/src/index.ts under plain `node --test`, via module hooks (fixtures/worker-hooks.mjs) that map the worker's ".js" specifiers onto its ".ts" sources and stand a structural stub in for @cloudflare/sandbox (its "cloudflare:" imports only exist inside workerd). Bindings are in-memory fakes covering exactly what the two routes touch; the create path takes createDemo()'s build-cache-hit branch, so no test ever boots a container. Covered end to end: the required-description 400 (with no D1 write), the 201 create shape (all four links + createdBy), the stored owner matching the "My demos" listing query, both 403s (foreign owner; browser-made demo), 410 for revoked, and 404 for unknown. Verified both layers bite: re-inlining the forked_from check fails the source-grep test, and neutering the guard behind `false &&` (invisible to grep) fails the route-level 403 test.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c697206. Configure here.
| assert.ok(start > -1, "the MCP update route exists in index.ts"); | ||
| const end = source.indexOf('parts[1] === "demos"', start); | ||
| const route = source.slice(start, end > -1 ? end : undefined); | ||
| assert.match(route, /isMcpCreated\(/, "the route must gate on the exported predicate"); |
There was a problem hiding this comment.
Hollow MCP guard source-grep
Medium Severity
The structural check that the PATCH MCP route still calls isMcpCreated( also matches the nearby comment that already contains that same text. Removing the real call while leaving the comment keeps this assertion green, which is the hollow-control failure mode this PR set out to close for the containment guard.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c697206. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes the two worst findings of the DEV-2501 coverage audit on the MCP endpoints (
POST /api/mcp/demos,PATCH /api/mcp/demos/:id— PRs #170/#177, ADR-0033).G1 — a security control asserted against a copy of itself
The test "only demos the MCP created are updatable through it" declared its own local predicate:
and asserted against that, not against the route. Deleting the containment guard from
index.tsleft the test green — the test could not fail when the control it names went away, which is the defining property of a hollow test.Fixed in three layers:
isMcpCreated()inworkers/api/src/mcp-create.ts, with JSDoc naming it as the containment control from the PR feat(runner): update a demo in place from the MCP (DEV-2501) #177 security review (a leaked shared secret must never reach demos built in the browser).PATCH /api/mcp/demos/:idroute calls it, and the rewritten test imports it (same cases as before:mcp:javascript/mcp:reactpass;catalog:javascript,null/undefined,{}refuse).pipeline/theme-codegen.test.mjs) asserts the route's source matches/isMcpCreated\(/and does not match an inlineforked_from?.startsWith— so the check cannot silently drift back to a re-inlined copy that diverges from what the tests import.G2 — no route-level tests at all
Nothing imported the router (
workers/api/src/index.ts), so every status code and response shape it promises was untested. New specpipeline/mcp-routes.test.mjsdrives the real default export — request in,Responseout — under the existing plainnode --testrunner.How it loads:
module.register()hooks (pipeline/fixtures/worker-hooks.mjs) map the worker's.jsimport specifiers onto its.tssources, and stand a structural stub in for@cloudflare/sandbox, whosecloudflare:scheme imports only exist inside workerd.node --testisolates each spec in its own process, so the hooks never touch other specs. Bindings are in-memory fakes for exactly what the two routes use (D1 with a recorded write log, KV, R2); the create path is steered throughcreateDemo()'s build-cache-hit branch — itself production code — so no test boots a container, and the sandbox stub throws if one is ever requested.Acceptance criteria now proven at route level:
{id, url, embedUrl, editUrl, shareUrl, createdBy}withurl === /d/:idetc. — this one looked unreachable (createDemo runs a container build) but the build-cache branch made it testable without any product change;created_by = <asserted author>andforked_fromstartingmcp:, and that row matchesdemoListQuery("mine", …)— the audit's G5-router variant;/edit/:id;Nothing on the list had to be skipped.
Verification
pnpm test— 417/417 green (was 410);pnpm typecheck— clean.forked_fromcheck fails the source-grep test; neutering the guard behindfalse &&(invisible to grep) fails the route-level 403 test. Both mutations reverted.npx wrangler deploy --dry-run --containers-rollout=noneinworkers/api— passes. The bare--dry-runstops at the container image build because Docker isn't installed on this machine; identical error on untouchedmaster, i.e. pre-existing and environmental, and the Worker bundle itself builds either way.Note
Low Risk
Production change is a refactor of an existing MCP update guard to a shared helper; risk is low and offset by new route-level tests.
Overview
Closes DEV-2501 audit gaps on MCP create/update by making the containment guard (
forked_frommust start withmcp:) a sharedisMcpCreated()inmcp-create.ts, wiringPATCH /api/mcp/demos/:idto call it instead of an inline check, and fixingmcp-create.test.mjsso it imports that predicate plus a source-grep that the route still callsisMcpCreated()—so removing the guard can fail tests.Adds
mcp-routes.test.mjs, the first spec that drives the realindex.tsrouter viaworker.fetch, usingworker-hooks.mjs(.js→.tsresolution,@cloudflare/sandboxstub) and fake D1/KV/R2. It covers create validation (400 without description, no writes), 201 response contract, owner/forked_fromstamping, and update refusals (403 wrong owner or browser demo, 410 revoked, 404 missing id).Reviewed by Cursor Bugbot for commit c697206. Bugbot is set up for automated code reviews on this repo. Configure here.