fix(cli): consistent output format, sorted findings, version flag
- Workflow rules now use strict if: evaluation (parse failure → skip rule, not match); fixes premature matching that blocked later rules and injected wrong variables into the context - Single = accepted as alias for == in rules:if: expressions - File/Line preserved through extends: resolution (lost during YAML encode/decode round-trip in the resolver) - Findings sorted by (File, Line, Rule) so same-file issues group together - All warnings use ruff-style path: [warning] message format (includes, extends chains, workflow non-start) - Add --version / -v flag; version shown at top of every --help output - Build injects version via ldflags using git describe Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,12 @@ func TestEvalIf(t *testing.T) {
|
||||
// ── Permissive fallback ───────────────────────────────────────────────
|
||||
{"unparseable returns true", `this is not valid syntax %%%`, true},
|
||||
{"empty expr returns true", ``, true},
|
||||
|
||||
// ── Single = as alias for == ──────────────────────────────────────────
|
||||
{"single eq match", `$CI_COMMIT_BRANCH = "develop"`, true},
|
||||
{"single eq no match", `$CI_COMMIT_BRANCH = "main"`, false},
|
||||
{"single eq in compound", `$CI_COMMIT_BRANCH = "develop" && $CI_PIPELINE_SOURCE = "push"`, true},
|
||||
{"single eq compound false", `$CI_COMMIT_BRANCH = "main" && $CI_PIPELINE_SOURCE = "push"`, false},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
@@ -131,3 +137,48 @@ func TestEvalIf(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalIfStrict(t *testing.T) {
|
||||
vars := func(key string) string {
|
||||
m := map[string]string{
|
||||
"CI_COMMIT_BRANCH": "develop",
|
||||
"CI_PIPELINE_SOURCE": "push",
|
||||
"WORKFLOW": "",
|
||||
}
|
||||
return m[key]
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
expr string
|
||||
want bool
|
||||
}{
|
||||
// Parseable expressions behave identically to EvalIf.
|
||||
{"parseable match", `$CI_COMMIT_BRANCH == "develop"`, true},
|
||||
{"parseable no match", `$CI_COMMIT_BRANCH == "main"`, false},
|
||||
{"single eq match", `$CI_COMMIT_BRANCH = "develop"`, true},
|
||||
// Empty expression: ruleIfMatchesStrict handles the empty→true case
|
||||
// before calling EvalIfStrict, so empty falls through to false here.
|
||||
{"empty expr", ``, false},
|
||||
|
||||
// Unparseable expressions return false (strict) instead of true (permissive).
|
||||
{"unparseable returns false", `this is not valid syntax %%%`, false},
|
||||
|
||||
// The key workflow-rule scenario: a complex condition with an
|
||||
// unevaluable sub-expression should not match (strict=false) so that
|
||||
// later workflow rules can be evaluated.
|
||||
{"workflow rule complex no match", `$WORKFLOW = "gitflow" && $CI_PIPELINE_SOURCE == /(push|web)/`, false},
|
||||
|
||||
// Compound with a bad second operand: strict returns false.
|
||||
{"and with bad rhs strict false", `$CI_COMMIT_BRANCH == "develop" && !(((`, false},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := EvalIfStrict(tc.expr, vars)
|
||||
if got != tc.want {
|
||||
t.Errorf("EvalIfStrict(%q) = %v, want %v", tc.expr, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user