Repository navigation
fix: express constant middleware-recipe/cookbook responses via respond - #630
Merged
Merged
Conversation
/api/items, /negotiated and /versioned in the middleware recipe and cookbook
returned the same literal body on every request through a trusted `function:`
handler. `respond: {json: ...}` expresses that directly with no code, matching
the declarative-first direction. Delete the now-unused function modules
(items.mjs, catalog.mjs, status.mjs) from both the recipe and the cookbook,
regenerate examples/cookbook/route-index.json, and update the hardcoded
handler-count assertions in test/context.test.ts to match.
status.mjs was also a fixed answer despite not being flagged by the
constant-response review detector (its body contains the word "state", which
the conservative detector treats as dynamic); convert it too since it is
genuinely constant.
Reword the "Native bodies stay opaque" bullet in docs/MIDDLEWARE-EXAMPLES.md:
that framing only holds for sandbox: true routes, where the guest cannot read
a native response body. These cookbook routes are trusted, so envelope,
negotiate and etag can read and rewrite a respond body the same as a function
response. Also touch up two middleware comments (envelope.mjs, etag.mjs) that
described the body they rewrite as a "function response"/"function output".
Closes #599
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 24, 2026
jimhoyd
added a commit
that referenced
this pull request
Sep 24, 2026
…stant-response heuristic (#650) The constant-response review signal's dynamicHints regex flagged a function as dynamic whenever state/env/secrets/inputs appeared anywhere in the source, including as a bare object-literal key or inside a string value. A genuinely constant handler such as Response.json({service: 'cookbook', state: 'ok'}) was therefore never flagged, even though respond: {json: ...} could express it directly (recipes/middleware/functions/status.mjs, pre-#630). Mask string/template literal contents before testing for these four words, and only treat a remaining match as dynamic when it isn't a bare `word:` object-literal key. The other dynamic hints (await, fetch, Date, process, control flow, ...) are unchanged. Closes #638 Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
Summary
recipes/middleware/functions/items.mjs(/api/items, behindenvelope.mjs),functions/catalog.mjs(/versioned, behindetag.mjs) andfunctions/status.mjs(/negotiated, behindnegotiate.mjs) were trustedfunction:handlers that always returned the same literal body — exactly whatrespond: {json: ...}expresses declaratively, per the declarative-first direction.function:handlers withrespond: {json: ...}inrecipes/middleware/urlcode.yamland the identical routes inexamples/cookbook/routes/middleware.yaml, and deleted the now-unused function modules from both trees (test/recipes.test.tsrequires the two to stay identical for any file that still exists in the recipe).status.mjswas also genuinely constant but wasn't flagged by theconstant-responsereview signal — its body contains the wordstate, which the conservative detector inpackages/core/src/review.tstreats as a dynamic hint. Converted it anyway since it's constant in fact.examples/cookbook/route-index.json(npm run docs:cookbook-index) and trimmedrecipes/middleware/recipe.yaml'sfileslist to match.docs/MIDDLEWARE-EXAMPLES.md: that framing only applies tosandbox: trueroutes, where the guest truly cannot read a native response body. On these trusted cookbook/recipe routes,envelope,negotiateandetagcan read and rewrite arespondbody exactly as they could a function's. Touched up two stale "function response"/"function output" comments inenvelope.mjs/etag.mjsfor the same reason.test/context.test.ts(function10→7,respond16→19,files.functions.length10→7) to match the cookbook's new handler mix.Verification
urlcode test --project recipes/middleware: 64/64 passed (matches the issue's prior manual trial).urlcode test --project examples/cookbook: 99/99 passed.urlcode review --project recipes/middleware: 0 observations (previously 2constant-responsefindings).node --test test/recipes.test.ts test/review.test.ts test/context.test.ts: all green.npm run typecheck,npm run check:docs: clean.npm run verify: full suite passed except 4 unrelated, timing-sensitive tests (cli.test.ts,provider-verification.test.ts,sandbox-pool.test.ts,verify-deployment.test.ts— wall-clock deadline assertions) that failed under heavy concurrent load from other sessions on this shared machine; re-ran them in isolation and they still occasionally miss their wall-clock windows under load, but none touch recipes/cookbook/review/context code and they aren't in the diff's blast radius.npm run test:package: passed (recipes ship in the package).Remaining
constant-responsereview detector's conservativestate/env/etc. word-boundary heuristic still won't flag a genuinely constant handler whose body happens to contain one of those words (that's howstatus.mjsslipped through here). Not fixing the detector itself in this PR — out of scope for this issue, which only asked to convert the three modules and confirm the signal now reports nothing for the recipe.Closes #599
🤖 Generated with Claude Code