chore(store): cover NormalizeBotSetupCodeDefaults validation gates#104
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 20, 2026, 9:55 AM ET / 13:55 UTC. Summary Reproducibility: not applicable. This PR adds characterization coverage rather than fixing a separately reported user-visible failure. The supplied body includes direct test output, but it could not be independently run or inspected here. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: After the checkout is inspectable, compare the full test file with the current validator and nearby store tests, then land the focused regression suite if every assertion matches the existing public validation contract. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds characterization coverage rather than fixing a separately reported user-visible failure. The supplied body includes direct test output, but it could not be independently run or inspected here. Is this the best way to solve the issue? Unclear: direct tests of the exported validator are plausibly the narrowest solution, but the full test file and current implementation could not be compared because read-only checkout commands were unavailable. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against c9cf5ba3691a. Label changesLabel justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Landed via rebase as Maintainer verification:
The landed tree exactly matches the reviewed rebased candidate. This is coverage-only, so no changelog entry was added. |
What Problem This Solves
NormalizeBotSetupCodeDefaults(apps/api/internal/store/setup_code_defaults.go) validates thedefaultspayload carried by every bot setup-code grant. It runs on the mint path of both store backends (internal/store/sqlite/setup_codes.go:85andinternal/store/postgres/setup_codes.go:85), so it sits on the public API boundary. It enforces several non-obvious gates:defaultTois trimmed, then bounded for UTF-8 validity, NUL bytes, and a rune-count length cap (not byte length);allowFromhas a hard entry-count cap, per-entry trim + non-empty check + the same UTF-8/NUL/length validation, and first-seen de-duplication;agentActivity: truerequires the dedicatedagent_activity:writescope.The function shipped with no direct test coverage. A regression in any of these gates — dropping the dedup, measuring the length in bytes instead of runes, or removing the scope requirement — would not be caught before merge.
Why This Change Was Made
Coverage-only. This adds one new file,
apps/api/internal/store/setup_code_defaults_test.go(+162, test-only), pinning the validator's currentmainbehavior. The tests drive the real exportedNormalizeBotSetupCodeDefaultsdirectly (no stubs), including the boundary cases (256-rune multibytedefaultTo, exactly-at-capallowFrom) and the pointer cases (agentActivitynil / true / false).User Impact
No user-visible or runtime change — no production code is touched. For maintainers, the setup-code
defaultsvalidation gates now regress loudly instead of silently: a future edit that breaks the rune-length measure, the de-duplication, the NUL/UTF-8 checks, or theagent_activity:writegate will fail this suite.Evidence
Linux, Go toolchain from
go.mod(1.26.x), branched off currentmain(c9cf5ba).12/12 pass on clean
main:Non-vacuous — each case bites when the target is mutated (mutation applied to
setup_code_defaults.go, suite re-run, then reverted):setup_code_defaults.goutf8.RuneCountInString(value)→len(value)(byte length)DefaultToLengthIsRuneCountfailsallowFromcount cap>→>=AllowFromAtCapPassesfailsTrimsAndDedupesfailsagentActivityscope gate disabledAgentActivityRequiresScopefails>= 0→< 0)gofmt -lreports the file clean;go vet ./internal/store/exits 0; the fullgo test ./internal/store/package is green with the file added.Scope boundary: no production code changed, no new config/defaults, no dependency change — a single new
_test.gounderapps/api/internal/store. Maintainer edits to the branch are welcome.Related: none — coverage mined from the module itself; no linked issue.
AI-assisted contribution.
Generated by Claude Code