Skip to content

[Gap]: middleware recipe and cookbook keep constant-response functions that respond expresses #599

Closed

Description

@jimhoyd

What you were trying to do

Convert recipes to declarative-first for #555, then run the new constant-response review signal (#556) over the shipped recipes.

Where it broke down

urlcode review --project recipes/middleware reports two constant-response observations after #555:

  • recipes/middleware/functions/items.mjs (/api/items, behind envelope.mjs)
  • recipes/middleware/functions/catalog.mjs (/versioned, behind etag.mjs)

functions/status.mjs (/negotiated, behind negotiate.mjs) is also a fixed answer but is not flagged (its body contains the word state, which the conservative detector treats as dynamic).

The same three functions exist in examples/cookbook/functions/ for the same routes in examples/cookbook/routes/middleware.yaml, and test/recipes.test.ts requires the recipe and cookbook modules to stay identical.

These routes are trusted, and on a trusted route the middleware can read a respond body. I replaced the three function: handlers in recipes/middleware/urlcode.yaml with equivalent respond: {json: …} values as a trial: urlcode test --project recipes/middleware passed 64 of 64 fixtures (envelope, ETag/304 and negotiation included). I reverted the trial to keep #555 in scope.

docs/MIDDLEWARE-EXAMPLES.md ("Native bodies stay opaque") says envelope, negotiate and etag rewrite a body only when the downstream response is a function response. That matches sandbox: true routes, not the trusted routes these modules run on. The guest-API framing on the same page is tracked in #558.

Code or YAML you had to write by hand

The three function modules above, which respond expresses.

Suggested change

Replace the three functions with respond in both the recipe and the cookbook, delete the modules, regenerate examples/cookbook/route-index.json, and reword the "Native bodies stay opaque" bullet so it applies only to sandbox: true routes. Check that the constant-response review signal then reports nothing for the recipe.

Verification

Verified: the trial conversion passed the recipe's fixtures. Not verified: the cookbook fixtures with the same conversion.

Activity

  1. added
    ai-first
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-first

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions