Skip to content

Commit 8d2dee3

Browse files
committed
fix: not is a prefix operator, not a function
Change NegateExpr to produce "not expr" instead of "not(expr)" to match the policy expression language syntax.
1 parent e7a0f8d commit 8d2dee3

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

internal/policy/expression.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func UnwrapExpr(expr string) string {
7474
return s
7575
}
7676

77-
// NegateExpr wraps a raw (unwrapped) expression with not().
77+
// NegateExpr prefixes a raw (unwrapped) expression with the not operator.
7878
func NegateExpr(raw string) string {
79-
return fmt.Sprintf("not(%s)", raw)
79+
return fmt.Sprintf("not %s", raw)
8080
}

internal/policy/expression_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ func TestUnwrapExpr_AlreadyRaw(t *testing.T) {
9090

9191
func TestNegateExpr(t *testing.T) {
9292
result := NegateExpr(`flow.name == "prod"`)
93-
assert.Equal(t, `not(flow.name == "prod")`, result)
93+
assert.Equal(t, `not flow.name == "prod"`, result)
9494
}
9595

9696
func TestCombineAndNegate(t *testing.T) {
9797
a := UnwrapExpr(FlowNameExpr("prod"))
9898
b := NegateExpr(UnwrapExpr(ArtifactNameMatchExpr("^datadog:.*")))
9999
result := CombineExprs("and", a, b)
100-
assert.Equal(t, `${{ flow.name == "prod" and not(matches(artifact.name, "^datadog:.*")) }}`, result)
100+
assert.Equal(t, `${{ flow.name == "prod" and not matches(artifact.name, "^datadog:.*") }}`, result)
101101
}

internal/policywizard/forms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (m *Model) buildForm() *huh.Form {
175175

176176
case stepExprNegate:
177177
f = confirmForm("Negate this condition?",
178-
"Wrap with not() — e.g. not(flow.name == \"prod\")")
178+
"Prefix with not — e.g. not flow.name == \"prod\"")
179179

180180
case stepExprCombineConfirm:
181181
f = confirmForm("Combine with another condition?",

internal/policywizard/forms_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func TestApply_ExprNegate_Yes_NegatesLastPending(t *testing.T) {
436436
m.applyFormValues(formValues{confirm: true})
437437

438438
require.Len(t, m.pendingExprs, 1)
439-
assert.Equal(t, `not(flow.name == "prod")`, m.pendingExprs[0])
439+
assert.Equal(t, `not flow.name == "prod"`, m.pendingExprs[0])
440440
}
441441

442442
func TestApply_ExprNegate_No_LeavesUnchanged(t *testing.T) {
@@ -576,7 +576,7 @@ func TestCombineFlow_NegatedExprWithOr(t *testing.T) {
576576

577577
require.Len(t, m.Policy.Artifacts.TrailCompliance.Exceptions, 1)
578578
assert.Equal(t,
579-
`${{ not(flow.name == "staging") or exists(flow) }}`,
579+
`${{ not flow.name == "staging" or exists(flow) }}`,
580580
m.Policy.Artifacts.TrailCompliance.Exceptions[0].If,
581581
)
582582
}

0 commit comments

Comments
 (0)