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:
85
coverage-gate/main_test.go
Normal file
85
coverage-gate/main_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRun_FailsWhenBelowThreshold(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmp := t.TempDir()
|
||||
policyPath := filepath.Join(tmp, "policy.json")
|
||||
profilePath := filepath.Join(tmp, "coverage.out")
|
||||
|
||||
policy := `{
|
||||
"minimum_statement_coverage": 80,
|
||||
"critical_packages": []
|
||||
}`
|
||||
if err := os.WriteFile(policyPath, []byte(policy), 0600); err != nil {
|
||||
t.Fatalf("write policy: %v", err)
|
||||
}
|
||||
|
||||
profile := "mode: set\n" +
|
||||
"git.hrafn.xyz/aether/cue/service/llm/validator.go:1.1,2.1 10 0\n"
|
||||
if err := os.WriteFile(profilePath, []byte(profile), 0600); err != nil {
|
||||
t.Fatalf("write profile: %v", err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
var errOut bytes.Buffer
|
||||
exit := run(
|
||||
[]string{"--profile", profilePath, "--policy", policyPath, "--src-root", "."},
|
||||
&out,
|
||||
&errOut,
|
||||
func(_ string) ([]string, error) {
|
||||
return []string{"git.hrafn.xyz/aether/cue/service/llm"}, nil
|
||||
},
|
||||
)
|
||||
if exit != 1 {
|
||||
t.Fatalf("expected exit 1, got %d\nstdout: %s\nstderr: %s", exit, out.String(), errOut.String())
|
||||
}
|
||||
if !strings.Contains(errOut.String(), "below threshold") {
|
||||
t.Fatalf("expected threshold error, got: %s", errOut.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun_PassesWhenAllMeetThreshold(t *testing.T) {
|
||||
t.Parallel()
|
||||
tmp := t.TempDir()
|
||||
policyPath := filepath.Join(tmp, "policy.json")
|
||||
profilePath := filepath.Join(tmp, "coverage.out")
|
||||
|
||||
policy := `{
|
||||
"minimum_statement_coverage": 80,
|
||||
"critical_packages": []
|
||||
}`
|
||||
if err := os.WriteFile(policyPath, []byte(policy), 0600); err != nil {
|
||||
t.Fatalf("write policy: %v", err)
|
||||
}
|
||||
|
||||
profile := "mode: set\n" +
|
||||
"git.hrafn.xyz/aether/cue/service/llm/validator.go:1.1,2.1 10 1\n"
|
||||
if err := os.WriteFile(profilePath, []byte(profile), 0600); err != nil {
|
||||
t.Fatalf("write profile: %v", err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
var errOut bytes.Buffer
|
||||
exit := run(
|
||||
[]string{"--profile", profilePath, "--policy", policyPath, "--src-root", "."},
|
||||
&out,
|
||||
&errOut,
|
||||
func(_ string) ([]string, error) {
|
||||
return []string{"git.hrafn.xyz/aether/cue/service/llm"}, nil
|
||||
},
|
||||
)
|
||||
if exit != 0 {
|
||||
t.Fatalf("expected exit 0, got %d\nstdout: %s\nstderr: %s", exit, out.String(), errOut.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "all in-scope packages meet threshold") {
|
||||
t.Fatalf("expected success summary, got: %s", out.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user