feat: extract coverage-gate action from Cue for reuse across projects
- Move coveragegate tool from cue/tools to vociferate/coverage-gate - Create composite action with JSON metrics output for CI - Update tool to export passes/total_coverage/packages_checked/packages_failed - Support per-package threshold policy via JSON configuration - Change module path to git.hrafn.xyz/aether/vociferate/coverage-gate
This commit is contained in:
88
coverage-gate/parse_test.go
Normal file
88
coverage-gate/parse_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseCoverProfile_AppliesExclusions(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmp := t.TempDir()
|
||||
profile := filepath.Join(tmp, "coverage.out")
|
||||
content := "mode: set\n" +
|
||||
"git.hrafn.xyz/aether/cue/api/graph/generated.go:1.1,2.1 2 1\n" +
|
||||
"git.hrafn.xyz/aether/cue/api/graph/resolver.go:1.1,2.1 2 1\n" +
|
||||
"git.hrafn.xyz/aether/cue/service/llm/validator.go:1.1,2.1 2 0\n"
|
||||
if err := os.WriteFile(profile, []byte(content), 0600); err != nil {
|
||||
t.Fatalf("write profile: %v", err)
|
||||
}
|
||||
|
||||
policy := Policy{
|
||||
MinimumStatementCoverage: 80,
|
||||
CriticalPackages: []PackagePolicy{
|
||||
{Package: "git.hrafn.xyz/aether/cue/api/graph", Include: true, Exclusions: []string{"generated.go"}},
|
||||
},
|
||||
}
|
||||
|
||||
got, err := ParseCoverProfile(profile, policy)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseCoverProfile() error = %v", err)
|
||||
}
|
||||
|
||||
api := got["git.hrafn.xyz/aether/cue/api/graph"]
|
||||
if api.Total != 2 || api.Covered != 2 {
|
||||
t.Fatalf("api coverage mismatch: got %+v", api)
|
||||
}
|
||||
llm := got["git.hrafn.xyz/aether/cue/service/llm"]
|
||||
if llm.Total != 2 || llm.Covered != 0 {
|
||||
t.Fatalf("llm coverage mismatch: got %+v", llm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateCoverage_UsesPolicyThresholds(t *testing.T) {
|
||||
t.Parallel()
|
||||
pkgs := []string{
|
||||
"git.hrafn.xyz/aether/cue/service/llm",
|
||||
"git.hrafn.xyz/aether/cue/service/orchestrator",
|
||||
}
|
||||
byPkg := map[string]Coverage{
|
||||
"git.hrafn.xyz/aether/cue/service/llm": {Covered: 8, Total: 10},
|
||||
"git.hrafn.xyz/aether/cue/service/orchestrator": {Covered: 3, Total: 10},
|
||||
}
|
||||
policy := Policy{
|
||||
MinimumStatementCoverage: 80,
|
||||
CriticalPackages: []PackagePolicy{
|
||||
{Package: "git.hrafn.xyz/aether/cue/service/orchestrator", MinimumStatementCoverage: 30, Include: true},
|
||||
},
|
||||
}
|
||||
|
||||
results := EvaluateCoverage(pkgs, byPkg, policy)
|
||||
if len(results) != 2 {
|
||||
t.Fatalf("expected 2 results, got %d", len(results))
|
||||
}
|
||||
if !results[0].Pass {
|
||||
t.Fatalf("expected llm to pass at default threshold: %+v", results[0])
|
||||
}
|
||||
if !results[1].Pass {
|
||||
t.Fatalf("expected orchestrator to pass at overridden threshold: %+v", results[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateCoverage_NoStatementsPasses(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pkg := "git.hrafn.xyz/aether/cue/repository/vector"
|
||||
results := EvaluateCoverage(
|
||||
[]string{pkg},
|
||||
map[string]Coverage{pkg: {Covered: 0, Total: 0}},
|
||||
Policy{MinimumStatementCoverage: 80},
|
||||
)
|
||||
|
||||
if len(results) != 1 {
|
||||
t.Fatalf("expected 1 result, got %d", len(results))
|
||||
}
|
||||
if !results[0].Pass {
|
||||
t.Fatalf("expected pass for no-statement package, got %+v", results[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user