Skip to content

Commit 6d0c7f5

Browse files
committed
fix: clear validationErr on successful retry in stepExprCustomOp
Without clearing, a failed matches regex validation would leave validationErr set, causing an infinite loop when the user retried with a valid regex or switched to a different operator.
1 parent f4226b8 commit 6d0c7f5

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

internal/policywizard/forms.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ func (m *Model) applyFormValues(fv formValues) {
378378
m.exprContext = "flow.tags." + fv.str
379379

380380
case stepExprCustomOp:
381+
m.validationErr = ""
381382
switch fv.operator {
382383
case "exists":
383384
m.storeSubExpr(policy.ExistsExpr(m.exprContext))

internal/policywizard/forms_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,36 @@ func TestApply_ExprCustomOp_MatchesInvalidRegex(t *testing.T) {
424424
assert.Contains(t, m.validationErr, "invalid regex")
425425
}
426426

427+
func TestApply_ExprCustomOp_MatchesValidRetryClears(t *testing.T) {
428+
m := newTestModel()
429+
m.step = stepExprCustomOp
430+
m.exprContext = "flow.name"
431+
432+
// First attempt: invalid regex
433+
m.applyFormValues(formValues{operator: "matches", str: "[unclosed"})
434+
assert.Contains(t, m.validationErr, "invalid regex")
435+
436+
// Second attempt: valid regex should clear error
437+
m.applyFormValues(formValues{operator: "matches", str: "^prod"})
438+
assert.Empty(t, m.validationErr)
439+
require.Len(t, m.pendingExprs, 1)
440+
}
441+
442+
func TestApply_ExprCustomOp_SwitchOperatorClearsError(t *testing.T) {
443+
m := newTestModel()
444+
m.step = stepExprCustomOp
445+
m.exprContext = "flow.name"
446+
447+
// First attempt: invalid regex with matches
448+
m.applyFormValues(formValues{operator: "matches", str: "[unclosed"})
449+
assert.Contains(t, m.validationErr, "invalid regex")
450+
451+
// Switch to == operator should clear error
452+
m.applyFormValues(formValues{operator: "==", str: "prod"})
453+
assert.Empty(t, m.validationErr)
454+
require.Len(t, m.pendingExprs, 1)
455+
}
456+
427457
func TestApply_ExprCustomOp_ExistsStoresPending(t *testing.T) {
428458
m := newTestModel()
429459
m.step = stepExprCustomOp

0 commit comments

Comments
 (0)