Repository navigation
fix(linter,gosqlx): deterministic L006/L009 and Extract* result order (#618, #619) - #625
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ajitpratap0's task in 16s —— View job Review of PR #625 (deterministic L006/L009 and Extract* ordering)I read the diff of the three source files. I did not run the tests or the benchmarks, and I only skimmed the test files. The race-gate and benchstat numbers below come from the PR description. Summary: The changes are small and correct, and I found no blocking issues.
|
…tic (#618) Two linter rules built their output by ranging over Go maps, so results varied between identical runs. - L006 (column alignment): the expected indent was chosen by ranging over the indent-count map, so ties between equally common indents were broken randomly. The selection now scans the continuation-column indents in source order, so the earliest tied indent wins. For "SELECT a,\n b,\n c\nFROM t" it now always reports line 3, column 5. - L009 (aliasing consistency, text fallback): violations were appended by ranging over the table-name map. Table names are now tracked in first-seen order and violations are emitted in that order. Counts, messages and line numbers are unchanged. Adds repeated-run regression tests for both rules and for gosqlx.Lint. The new tests failed (flaky) before the fix. Fixes #618 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZSk1292jPc8ipDboNxeve
…stic sorted order (#619) stringSetToSlice and qualifiedSetToSlice collected map keys in Go's random iteration order, so every Extract* function and ExtractMetadata returned slices whose order changed from call to call. Both helpers now sort before the detach/arena copy: []string results use ascending byte order (slices.Sort) and []QualifiedName results are ordered by Schema, then Table, then Name. The sort runs on every path, including the empty-parts early return, and allocs/op is unchanged. Godoc on Metadata and each Extract* function documents the guarantee and the examples show sorted output. Fixes #619 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UZSk1292jPc8ipDboNxeve
609fa8d to
ddd8521
Compare
|
Merge train (batch 3): rebased onto main after #621 merged (ddd8521). The adversarial + security pass (Opus) found nothing. Answers to the bot review:
|
|
Claude finished @ajitpratap0's task in 14s —— View job Review of PR #625 (deterministic L006/L009 and Extract* ordering)I read the diffs of the source files and checked the one open item from the earlier review. I did not run the tests or benchmarks. The race-gate and benchstat numbers come from the PR description. Verdict: LGTM. I found no blocking issues.
Follow-ups
|
Summary
#618 linter: L006 and text-based L009 results depend on map iteration order
Fixes #618. Two linter rules produced different results on identical runs because they read their results from Go maps, whose iteration order is random. In L006 (column alignment), the expected indent is now chosen by scanning the continuation-column indents in source order, so when indent counts tie the earliest one wins. 'SELECT a,\n b,\n c\nFROM t' now reports line 3, column 5 on every run (100 of 100 CLI runs). The text-fallback path of L009 (aliasing consistency) now lists violations in the order tables first appear in the query; counts, messages and line numbers are unchanged. The new repeated-run tests in the style package and in gosqlx.Lint fail on 61ca6c8 in 5 of 5 runs and pass with -count=5 -race after the fix. The full race gate, go vet and golangci-lint are clean. Deferred, with sound reasons: (a) sorting all violations by position in LintString — optional in the issue, and it would change the existing per-rule grouping; (b) the cfg.Rules map ranged over in pkg/linter/config/config.go, which gives cfg.Warnings a random order — the same kind of bug but not reported in #618, so it should get a follow-up issue; (c) #619 is handled in its own commit on this chain.
#619 gosqlx: ExtractMetadata and Extract* return tables/columns/functions in random map order
ExtractTables, ExtractTablesQualified, ExtractColumns, ExtractColumnsQualified, ExtractFunctions and ExtractMetadata now return their results in sorted order, so repeated calls on the same AST return identical slices (#619). Before, the deduplicated keys came out in Go's random map-iteration order. Strings are now sorted in ascending byte order. QualifiedName results are sorted by Schema, then Table, then Name. The sort runs before the existing detach/arena copy on every path, so input-retention protection and allocs/op are unchanged; ns/op rises about 3-15% on the Extract benchmarks. New regression tests pin the exact output for the issue SQL and other queries over 50 calls, and check that every slice is sorted and that ExtractMetadata matches the individual extractors. The tests fail on the pre-fix code and pass with the fix. Out of scope: first-appearance (source) ordering, rejected in favour of sorting, which the issue allows; case-insensitive ordering; and docs/CHANGELOG updates, which are handled separately.
Commits (2), one implementation commit per issue plus test-only follow-ups:
7 files changed, 350 insertions(+), 19 deletions(-)Test Plan
CGO_ENABLED=1 go test -race -timeout 300s $(go list ./... | grep -v /cbinding)),go vet,golangci-lint, re-ran the reproduction cases on HEAD, and confirmed the new tests fail on the parent commit.benchstat -count=6before/after on the same machine.#618 evidence (validator)
#618 race gate: I ran
CGO_ENABLED=1 go test -race -timeout 300s $(go list ./... | grep -v /cbinding)on HEAD bcf4393. It exited 0 with 44 packages ok and no FAIL lines. I also rango test -count=5 -race ./pkg/linter/rules/style/ ./pkg/gosqlx/and both packages passed (style 1.2s, gosqlx 10.8s).#619 evidence (validator)
#619 race gate: I ran
CGO_ENABLED=1 go test -race -timeout 300s $(go list ./... | grep -v /cbinding)on HEAD 609fa8d. It exited 0: 44 packages ok, no FAIL lines, including pkg/gosqlx (5.9s), pkg/gosqlx/testing and pkg/mcp.CGO_ENABLED=1 go test ./pkg/cbinding/also passed. The targeted race run of TestExtract_DeterministicOrder_Issue619, TestExtract_SortedInvariant, TestExtract_ResultsDoNotRetainInput and TestExtract_RetentionHarnessDetectsAliasing passed.Breaking Changes
Notes
gosqlx formatsilently corrupts many expressions; switch the CLI to pkg/formatter #599-schema/postgres: loader misreports index columns and key flags (column order, INCLUDE, expression and partitioned indexes, read-only roles) #620); later PRs in the train are rebased onto this one after it merges.main.Fixes #618
Fixes #619
Follow-up to #566
🤖 Generated with Claude Code
https://claude.ai/code/session_01UZSk1292jPc8ipDboNxeve