Repository navigation
test(purchase): lex SQL before the idempotency_key writer scan - #1878
Merged
Merged
Conversation
The single-writer scan read a SET clause with ad hoc quote and paren toggles, so a SQL comment before the target hid a write (`SET /* k */ idempotency_key = $1`), and $$...$$, $tag$...$tag$ and E'...' strings desynced it. maskSQL now lexes the statement once and the existing logic runs on its output. - Comments (line and nested block) become a space; every literal body becomes an empty literal; a double-quoted identifier is kept only for idempotency_key and is otherwise emitted as "x". - Fail closed: an unterminated literal, comment or identifier, or a literal body that mentions purchase_executions (a DO block or EXECUTE string), makes the statement unverifiable, which counts as dynamic and fails the test. - 25 fixtures; 14 fail on the previous scan, the rest guard the lexing rules (dollar-quote and E-prefix start rules, a parameter is not a tag, quoted identifiers). - known-issues.md records the limits that remain: schema-qualified or quoted table names, U&'...' strings, standard_conforming_strings off. Closes #1853 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 6 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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 #1853.
Problem
The single-writer scan for
purchase_executions.idempotency_key(TestIdempotencyKeyCopyHasSingleWriter) split a SET clause with ad hoc quote and paren toggles. A SQL comment before the target hid a write (SET /* k */ idempotency_key = $1), and$$...$$,$tag$...$tag$andE'...'strings desynced it. A write hidden that way is a way for the guard to fail open. This was found by qa-ui-4 reviewing #1849 and documented there as a limitation.Change (test-only,
internal/purchase/idempotency_key_writers_test.go, plusknown-issues.md)maskSQLlexes the statement once and the existing scan runs on its output:idempotency_keyand otherwise emitted as"x".$byte, so$1and$1$2are never tags;E/eis an escape-string prefix only after a non-word, non-$byte, and only then does a backslash escape; a plain'...'takes a backslash literally.purchase_executions(aDO $$ ... $$block or anEXECUTE '...'string), makes the statement unverifiable. It counts asdynamic, which already fails the test.known-issues.mdrecords what remains: schema-qualified or quoted table names,U&'...'strings, andstandard_conforming_strings = off.Verification
maskSQL(comments, nesting, E-string backslash, dollar quotes,--inside a literal, unterminated input,$1as a tag, quoted identifiers, the literal-body table check, the E prefix rule) each fail a fixture.go test -run IdempotencyKey ./internal/purchase/passes, and the module-wide scan still reports exactly 1 insert, 0 updates and 0 dynamic. No production code changes.🤖 Generated with Claude Code