Repository navigation
feat(rules): target expressions count the rule's guards - #630
ccf-lisa[bot] wants to merge 3 commits into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
gusfcarvalho
left a comment
There was a problem hiding this comment.
ccf-review: COMMENT
1 Should-fix.
Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630
The "event rule's if" case compiled the same ExprWhen expression as the when case and tested nothing new. Drop it and say why if isn't covered separately (there is no if kind; no source accepts event rules). compile now collects guards for every kind that returns bool rather than only ExprWhen, so an if kind gets them when it's added. Also cover a dotted lookup (subject.labels.owner) guarded in when. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2cbab75 to
784809d
Compare
gusfcarvalho
left a comment
There was a problem hiding this comment.
ccf-review: APPROVE
no findings.
Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630
What
A rule's target expression only runs for subjects its condition holds for, so the map-key guards in the condition now count for the target's unguarded-lookup warnings. With
the target no longer warns about
subject.labels["owner"].rules.Compiledkeeps its unguarded lookups by key (m["k"]and the dottedm.k), and a condition (any expression kind that returnsbool, today onlywhen) also records the guards that hold whenever it's true.Compiled.WarningsGiven(condition)drops the lookups the condition guards. CachedCompiledvalues stay independent of any condition, and a target compiled alone (Warnings, orWarningsGiven(nil)) behaves as before."k" in mandhas(m.k)reached through top-level&&only:a && (b && "k" in m)counts. A guard under||,!, a ternary, a macro (exists,all, ...) or any other call doesn't, because it may be false while the condition is true. Guards inside the target expression itself count as before (anywhere in it).POST /api/rulesandPOST /api/rules/previewuse the request'swhen;POST/PUT /api/rules/{id}/actions[/{actionId}]use the saved rule'swhen.PUT /api/rules/{id}now also returns the saved actions' target warnings under the newwhen, so dropping a guard the targets relied on shows up.ifplays the same role (ruleConditionsays where it plugs in). No source accepts event rules yet,Rulestores onlywhen_expr, and there is noifexpression kind, soifisn't tested separately.compilecollects guards for every kind that returnsboolrather than onlyExprWhen, so anifkind gets them when it's added.triggers.md(validation on save) anduser-interface.md(when an expression fails, the validation table) say the condition's guards count.Tests
rules.TestTargetWarningsGivenCondition: guarded inwhen(also nested in&&, and viahas()) → no warning; a dotted target lookup (subject.labels.owner) guarded inwhenbyinorhas()→ no warning, by another key → warning; guard only under||, under!, in a ternary, inside a macro, or for another key → warning; a target with two lookups keeps the warning for the key the condition doesn't guard; the cached target's ownWarningsare unchanged.TestRulesApi/TestTargetWarningsCountTheConditionsGuards: a saved rule whosewhenguardsownerreturns no target warnings on create and preview; an action added to it doesn't warn, one looking upteamdoes;PUT /api/rules/{id}with awhenthat drops the guard returns the three target warnings, and restoring it leaves onlyteam; a preview with the guard under||warns onactions[0].target.expr.TestCreateAndGetnow expects no warnings forvalidRule(itswhenguardsowner).Why
User decision for the effectors stack: a target is evaluated only for subjects matching the rule's condition, so a guard there makes the target's lookup safe, and the warning on
"slack-handle:" + subject.labels["owner"]under"owner" in subject.labels && …was a false positive.Gate
On this branch:
go build ./...pass; golangci-lint v2.15.0 0 new issues (default config: only the 6 pre-existing issues in untouchedworkflows/workerfiles; the shared CI config reports nothing in the changed files);make testpass;go vet -tags integration ./...pass;make swagno diff;go mod tidyno diff;go test -tags integration -p 1 -count=1on./internal/service/rules/...and./internal/api/handler/...pass.Size
Counted: 350 lines (added + removed, tests and docs included; no generated files changed).
🤖 Generated with Claude Code