Skip to content

fix(connection): build rules in flag order - #464

Open
leggetter wants to merge 4 commits into
mainfrom
fix/connection-rule-flag-order
Open

leggetter wants to merge 4 commits into
mainfrom
fix/connection-rule-flag-order

Conversation

@leggetter

@leggetter leggetter commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

--rule-* flags always built rules as deduplicate → transform → filter → delay → retry. Filter, transform and deduplicate run in rules[] order, so --rule-filter-body … --rule-transform-name … silently produced transform → filter on create, update and upsert.

  • Rules now follow the position of each rule type's first flag, as AGENTS.md ("Ordered Array Configurations") already specifies
  • --rules / --rules-file are unchanged and keep the array as given
  • The MCP connections tool's rules description now says order matters
  • README note on flag ordering

Behaviour change: anyone passing --rule-filter-* before --rule-transform-* and relying on transform running first will now get filter first. That's the order they wrote, but it is a change.

Implementation
  • addConnectionRuleFlags wraps each rule flag's pflag.Value in orderTrackingValue. On Set, it records the flag's rule type in connectionRuleFlags.ruleOrder (first occurrence wins).
  • buildConnectionRules builds rules into a map by type, then emits them using ruleOrder followed by defaultRuleOrder. Types with no recorded position, such as when the struct is populated directly in tests, keep the old order.
  • Flag help text is unchanged, so there's no reference regeneration.
Tests
  • New pkg/cmd/connection_rule_order_test.go:
    • flag order through real cobra parsing (filter/transform both ways, first flag wins, all five types, retry positioned by a non-strategy flag)
    • the struct-literal fallback order
    • create, update and upsert commands each record order
  • Confirmed the flag-order tests fail against the previous connection_common.go
  • go test ./... passes
Context

A customer's agent saw filter → transform flipped to transform → filter on every connection save. Their trigger was the REST API's pre-2025-07-01 versions, where transformations always run before filters. This CLI bug produces the same symptom. Related: hookdeck/agent-skills#29.

🤖 Generated with Claude Code

leggetter and others added 4 commits October 1, 2026 11:55
Rules built from --rule-<type>-* flags were always ordered
deduplicate -> transform -> filter -> delay -> retry. Filter, transform
and deduplicate run in rules array order, so filter-before-transform
could not be expressed with flags, and every create, update or upsert
with both flags produced transform -> filter.

Each rule flag now records its rule type when set, and rules are emitted
in the order of each type's first flag, as AGENTS.md describes. Types
with no recorded position fall back to the previous order.

Also state in the MCP connections tool that rule order matters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TestConnectionWithMultipleRules passes filter, retry and delay flags and
asserted the old fixed order (filter, delay, retry). Rules now follow
flag order, so assert filter, retry, delay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and upsert

The only acceptance check for flag order used retry and delay, which
don't affect execution. Add end-to-end checks for the filter/transform
case:

- create: filter-then-transform and transform-then-filter are stored as given
- update: reorder transform-then-filter to filter-then-transform, then
  save again, and the order holds
- upsert: create with filter-then-transform, upsert again, order holds

Transformations get unique names and are deleted after the connection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@leggetter
leggetter marked this pull request as ready for review October 2, 2026 09:27
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.

1 participant