Skip to content

fix(findings): add --insert-at to routing/transformation rule create - #303

Draft
cvkramer wants to merge 1 commit into
mainfrom
fix/routing-rules-insert
Draft

cvkramer wants to merge 1 commit into
mainfrom
fix/routing-rules-insert

Conversation

@cvkramer

Copy link
Copy Markdown

What

findings routing-rules|transformation-rules create --insert-at N makes room for the new rule at priority/evaluation_order N instead of 400ing on a collision: every existing rule at or after N shifts one down first (highest order first, so none collide mid-move), then the new rule is created at N. --insert-at overrides any priority/evaluationOrder already in --body-file. A failure part-way through names exactly which rules already shifted (nothing is rolled back). The plain create path's own collision 400 ("order N is already used by another rule") now points at --insert-at. Shared between routing-rules and transformation-rules via `newFindingRulesCmd's existing per-family parameters.

The list-then-shift sequence needs a read before sendMutationSequence's step count can be known, which the usual withPreReadpattern cannot provide (it validates/transforms one mutation, not a dynamic step list). It lives incmd/mutation.goassendRuleInsertSequence— the one file allowed to read before a write — with acursorGuardExemptions` entry for its one-shot, non-paginated list read.

Why

Bead: global-w291.6

Verification

  • go build ./..., go vet ./...: clean
  • go test ./...: pass
  • go test -count=1 -shuffle=on ./...: pass
  • golangci-lint run --timeout=3m ./...: 0 issues
  • go mod tidy && git diff --exit-code go.mod go.sum: clean
  • gosec -quiet ./...: clean
  • New tests in cmd/findings_rules_insert_test.go confirmed to fail on origin/main (compile/flag errors) before this change and pass after; cover the shift order, partial-failure reporting, --insert-at validation, the collision-error hint, --dry-run, the body-file override, and transformation-rules sharing the same path.
  • A 25-seed -shuffle=on sweep (required since cmd/mutation.go changed) showed failures, but every one is pre-existing: reproduced identically on a clean origin/main checkout (ephemeral-port exhaustion under this shared machine's load, one unrelated setgid filesystem flake) — none touch findings/routing-rules/mutation.go or any new test. A single-process -shuffle=on run and the plain go test ./... both pass cleanly on this branch.

Fixes #299

findings routing-rules|transformation-rules create treats priority/
evaluationOrder as an exact, unique order: creating a rule whose order
collides with an existing one 400s ("order N is already used by
another rule") with no way to insert before another rule.

--insert-at N lists the rule family's existing rules, shifts every one
at or after N down one (highest order first, so no two ever collide
mid-move), then creates the new rule at N. A failure part-way through
names exactly which rules already shifted; nothing is rolled back.
The plain create path's own collision 400 now points at --insert-at.

The list-then-shift sequence needs a read before sendMutationSequence's
step count can be known, so it lives in cmd/mutation.go (the one place
allowed to read before a write) as sendRuleInsertSequence, with a
cursorGuardExemptions entry for its one-shot, non-paginated list read.

Shared between routing-rules (priority) and transformation-rules
(evaluationOrder) via newFindingRulesCmd's existing per-family
parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findings routing-rules create has no insert-before/reorder; priority collision returns opaque 400

2 participants