Skip to content

Commit e18b530

Browse files
leggetterclaude
andcommitted
test(acceptance): cover filter/transform rule order on create, update 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 <noreply@anthropic.com>
1 parent c1c8064 commit e18b530

4 files changed

Lines changed: 180 additions & 0 deletions

File tree

‎test/acceptance/connection_test.go‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,77 @@ func TestConnectionWithTransformRule(t *testing.T) {
13911391
t.Logf("Successfully created and verified connection with transform rule: %s", conn.ID)
13921392
}
13931393

1394+
// TestConnectionCreateRuleOrderFollowsFlags verifies that filter and transform rules
1395+
// are stored in the order their flags were given. Filter, transform and deduplicate
1396+
// rules run in array order, so filter-then-transform must survive the round trip.
1397+
func TestConnectionCreateRuleOrderFollowsFlags(t *testing.T) {
1398+
if testing.Short() {
1399+
t.Skip("Skipping acceptance test in short mode")
1400+
}
1401+
1402+
tests := []struct {
1403+
name string
1404+
flags func(trnName string) []string
1405+
want []string
1406+
}{
1407+
{
1408+
name: "filter before transform",
1409+
flags: func(trnName string) []string {
1410+
return []string{
1411+
"--rule-filter-body", `{"type":"payment"}`,
1412+
"--rule-transform-name", trnName,
1413+
"--rule-transform-code", ruleOrderTransformCode,
1414+
}
1415+
},
1416+
want: []string{"filter", "transform"},
1417+
},
1418+
{
1419+
name: "transform before filter",
1420+
flags: func(trnName string) []string {
1421+
return []string{
1422+
"--rule-transform-name", trnName,
1423+
"--rule-transform-code", ruleOrderTransformCode,
1424+
"--rule-filter-body", `{"type":"payment"}`,
1425+
}
1426+
},
1427+
want: []string{"transform", "filter"},
1428+
},
1429+
}
1430+
1431+
for _, tt := range tests {
1432+
t.Run(tt.name, func(t *testing.T) {
1433+
cli := NewCLIRunner(t)
1434+
timestamp := generateTimestamp()
1435+
trnName := "test-trn-order-" + timestamp
1436+
1437+
// Registered first so it runs after the connection is deleted
1438+
t.Cleanup(func() {
1439+
deleteTransformation(t, cli, trnName)
1440+
})
1441+
1442+
args := []string{
1443+
"gateway", "connection", "create",
1444+
"--name", "test-rule-order-" + timestamp,
1445+
"--source-name", "test-src-order-" + timestamp,
1446+
"--source-type", "WEBHOOK",
1447+
"--destination-name", "test-dst-order-" + timestamp,
1448+
"--destination-type", "CLI",
1449+
"--destination-cli-path", "/webhooks",
1450+
}
1451+
var conn Connection
1452+
err := cli.RunJSON(&conn, append(args, tt.flags(trnName)...)...)
1453+
require.NoError(t, err, "Should create connection with filter and transform rules")
1454+
require.NotEmpty(t, conn.ID, "Connection should have an ID")
1455+
1456+
t.Cleanup(func() {
1457+
deleteConnection(t, cli, conn.ID)
1458+
})
1459+
1460+
assert.Equal(t, tt.want, getConnectionRuleTypes(t, cli, conn.ID), "Rules should follow flag order")
1461+
})
1462+
}
1463+
}
1464+
13941465
// TestConnectionWithDelayRule tests creating a connection with a delay rule
13951466
func TestConnectionWithDelayRule(t *testing.T) {
13961467
if testing.Short() {

‎test/acceptance/connection_update_test.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,50 @@ func TestConnectionUpdateRules(t *testing.T) {
150150
t.Logf("Successfully updated connection rules: %s", connID)
151151
}
152152

153+
// TestConnectionUpdateRuleOrderFollowsFlags verifies that update stores filter and
154+
// transform rules in flag order, and that saving again does not change that order.
155+
func TestConnectionUpdateRuleOrderFollowsFlags(t *testing.T) {
156+
if testing.Short() {
157+
t.Skip("Skipping acceptance test in short mode")
158+
}
159+
160+
cli := NewCLIRunner(t)
161+
trnName := "test-trn-update-order-" + generateTimestamp()
162+
163+
// Registered first so it runs after the connection is deleted
164+
t.Cleanup(func() {
165+
deleteTransformation(t, cli, trnName)
166+
})
167+
168+
connID := createTestConnection(t, cli)
169+
require.NotEmpty(t, connID, "Connection ID should not be empty")
170+
171+
t.Cleanup(func() {
172+
deleteConnection(t, cli, connID)
173+
})
174+
175+
update := func(flags ...string) {
176+
t.Helper()
177+
var updated Connection
178+
args := append([]string{"gateway", "connection", "update", connID}, flags...)
179+
require.NoError(t, cli.RunJSON(&updated, args...), "Should update connection rules")
180+
}
181+
transformFlags := []string{"--rule-transform-name", trnName, "--rule-transform-code", ruleOrderTransformCode}
182+
filterFlags := []string{"--rule-filter-body", `{"type":"payment"}`}
183+
184+
// Start with transform before filter
185+
update(append(append([]string{}, transformFlags...), filterFlags...)...)
186+
assert.Equal(t, []string{"transform", "filter"}, getConnectionRuleTypes(t, cli, connID),
187+
"Rules should follow flag order")
188+
189+
// Reorder to filter before transform, then save the same rules again
190+
for i := 0; i < 2; i++ {
191+
update(append(append([]string{}, filterFlags...), transformFlags...)...)
192+
assert.Equal(t, []string{"filter", "transform"}, getConnectionRuleTypes(t, cli, connID),
193+
"Rules should follow flag order after save %d", i+1)
194+
}
195+
}
196+
153197
// TestConnectionUpdateNotFound tests error handling when updating a non-existent connection
154198
func TestConnectionUpdateNotFound(t *testing.T) {
155199
if testing.Short() {

‎test/acceptance/connection_upsert_test.go‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,54 @@ func TestConnectionUpsertPartialUpdates(t *testing.T) {
743743
})
744744
}
745745

746+
// TestConnectionUpsertRuleOrderFollowsFlags verifies that upsert stores filter and
747+
// transform rules in flag order on create, and keeps that order when upserted again.
748+
func TestConnectionUpsertRuleOrderFollowsFlags(t *testing.T) {
749+
if testing.Short() {
750+
t.Skip("Skipping acceptance test in short mode")
751+
}
752+
753+
cli := NewCLIRunner(t)
754+
timestamp := generateTimestamp()
755+
connName := "test-upsert-order-" + timestamp
756+
trnName := "test-trn-upsert-order-" + timestamp
757+
758+
// Registered first so it runs after the connection is deleted
759+
t.Cleanup(func() {
760+
deleteTransformation(t, cli, trnName)
761+
})
762+
763+
args := []string{
764+
"gateway", "connection", "upsert", connName,
765+
"--source-name", "test-upsert-order-src-" + timestamp,
766+
"--source-type", "WEBHOOK",
767+
"--destination-name", "test-upsert-order-dst-" + timestamp,
768+
"--destination-type", "CLI",
769+
"--destination-cli-path", "/webhooks",
770+
"--rule-filter-body", `{"type":"payment"}`,
771+
"--rule-transform-name", trnName,
772+
"--rule-transform-code", ruleOrderTransformCode,
773+
}
774+
775+
var conn Connection
776+
require.NoError(t, cli.RunJSON(&conn, args...), "Should upsert (create) connection")
777+
require.NotEmpty(t, conn.ID, "Connection should have an ID")
778+
779+
t.Cleanup(func() {
780+
deleteConnection(t, cli, conn.ID)
781+
})
782+
783+
assert.Equal(t, []string{"filter", "transform"}, getConnectionRuleTypes(t, cli, conn.ID),
784+
"Rules should follow flag order on create")
785+
786+
// Upsert again with the same flags: the order must not change on a second save
787+
var again Connection
788+
require.NoError(t, cli.RunJSON(&again, args...), "Should upsert (update) connection")
789+
assert.Equal(t, conn.ID, again.ID, "Second upsert should update the same connection")
790+
assert.Equal(t, []string{"filter", "transform"}, getConnectionRuleTypes(t, cli, conn.ID),
791+
"Rules should follow flag order after a second upsert")
792+
}
793+
746794
// TestConnectionUpsertRejectsEmptySourceWebhookSecret is the connection-side
747795
// regression test for #335. This is the exact command shape that failed in the
748796
// hookdeck/evals benchmark: the provider secret lived in a workspace .env that

‎test/acceptance/helpers.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,3 +1773,20 @@ func RequireCLIAuthenticationOnce(t *testing.T) string {
17731773

17741774
return cachedWhoamiOutput
17751775
}
1776+
1777+
// ruleOrderTransformCode is a pass-through transformation for rule order tests.
1778+
const ruleOrderTransformCode = `addHandler("transform", (request, context) => request);`
1779+
1780+
// getConnectionRuleTypes fetches a connection and returns its rule types in stored order.
1781+
func getConnectionRuleTypes(t *testing.T, cli *CLIRunner, id string) []string {
1782+
t.Helper()
1783+
1784+
var conn Connection
1785+
require.NoError(t, cli.RunJSON(&conn, "gateway", "connection", "get", id), "Should get connection %s", id)
1786+
types := make([]string, 0, len(conn.Rules))
1787+
for _, rule := range conn.Rules {
1788+
ruleType, _ := rule["type"].(string)
1789+
types = append(types, ruleType)
1790+
}
1791+
return types
1792+
}

0 commit comments

Comments
 (0)