416659ffd8
When glint check runs in single-context mode (--branch, --tag, --source, or --var), jobs that resolve to JobSkipped against that context are now excluded from needs: and dependencies: cross-job checks (GL027-GL031). This eliminates false-positive errors for jobs intentionally gated to specific pipeline events (e.g. a deploy job with rules:if: CI_COMMIT_TAG no longer triggers GL027 on branch pipelines). linter.Lint now accepts a skipped map[string]bool (nil = check all jobs); checkNeeds and checkDependencies skip jobs present in the map. Multi-context mode (--context) passes nil, so all jobs are checked regardless of context. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package linter
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.k3nny.fr/glint/internal/model"
|
|
)
|
|
|
|
// TestCheckNeeds_SkippedJob verifies that a skipped job's needs: violations are suppressed.
|
|
func TestCheckNeeds_SkippedJob(t *testing.T) {
|
|
p := &model.Pipeline{
|
|
Stages: []string{"build", "deploy"},
|
|
Jobs: map[string]model.Job{
|
|
"skipped-job": {
|
|
Name: "skipped-job",
|
|
Stage: "build",
|
|
Script: []any{"echo"},
|
|
Needs: []any{"nonexistent-job"},
|
|
},
|
|
},
|
|
}
|
|
// Without skipping: should report unknown needs.
|
|
withoutSkip := checkNeeds(p, nil)
|
|
if len(withoutSkip) == 0 {
|
|
t.Fatal("expected GL027 without skipped set, got none")
|
|
}
|
|
// With job skipped: no findings.
|
|
withSkip := checkNeeds(p, map[string]bool{"skipped-job": true})
|
|
if len(withSkip) != 0 {
|
|
t.Errorf("expected no findings for skipped job, got %v", withSkip)
|
|
}
|
|
}
|
|
|
|
// TestCheckNeeds_StageOrder verifies that a job needing a job in a later stage
|
|
// produces RuleNeedsStageOrder (line 64-76 in needs.go).
|
|
func TestCheckNeeds_StageOrder(t *testing.T) {
|
|
p := &model.Pipeline{
|
|
Stages: []string{"build", "test", "deploy"},
|
|
Jobs: map[string]model.Job{
|
|
"build-job": {
|
|
Name: "build-job",
|
|
Stage: "build",
|
|
Script: []any{"make"},
|
|
Needs: []any{"deploy-job"},
|
|
},
|
|
"deploy-job": {
|
|
Name: "deploy-job",
|
|
Stage: "deploy",
|
|
Script: []any{"make deploy"},
|
|
},
|
|
},
|
|
}
|
|
findings := checkNeeds(p, nil)
|
|
var gotStageOrder bool
|
|
for _, f := range findings {
|
|
if f.Rule == RuleNeedsStageOrder {
|
|
gotStageOrder = true
|
|
}
|
|
}
|
|
if !gotStageOrder {
|
|
t.Errorf("build-job needing deploy-job (later stage): expected GL025 finding; got: %v", findings)
|
|
}
|
|
}
|