Repository navigation
fix(core): distinguish identifier references from literal data in constant-response heuristic - #650
Merged
Conversation
…stant-response heuristic
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
constant-responsereview signal inpackages/core/src/review.tsused a word-boundary regex (dynamicHints) to guess whether a function body is dynamic. It flagged a body as dynamic wheneverstate,env,secretsorinputsappeared anywhere in the source — including as a bare object-literal key ({state: 'ok'}) or as a substring inside a string value — not only as an actual identifier reference (context.state,process.env.X).Response.json({service: 'cookbook', state: 'ok'})was therefore never flagged as anative-alternativetorespond, even though it's a fixed answer that could be expressed declaratively. This was confirmed withrecipes/middleware/functions/status.mjsprior to its conversion in fix: express constant middleware-recipe/cookbook responses via respond #630.word:object-literal key. The other dynamic hints (await,fetch,Date,process, control flow, etc.) are unchanged, and a genuine identifier reference (e.g. a bareenv/statevariable, orprocess.env.X, which is still caught via the unrelatedprocesshint) still correctly keeps the handler out of the signal.Test plan
test/review.test.tsreproducing the exact blind spots from constant-response review detector's word-boundary heuristic has blind spots #638: an unquoted object-literal key (status.mjs'sstate: 'ok'), a string value containing one of the words as a substring, and quoted object keys — all now correctly flagged asconstant-response.state/env/secrets/inputs(not as an object-literal key) is still correctly kept out of theconstant-responsesignal.node --test test/review.test.ts— 32/32 pass.npm run verify(full pipeline: lint, typecheck, build, all workspace tests) — passes.Closes #638
🤖 Generated with Claude Code