Files
ARTEX/report/report_test.go
T
BaaRai 101c92d516 Coverage ledger: review fixes (one-line capped fields, framed gap lines, per-run end_reason)
Normalise and length-check ledger fields in db.RecordCoverage, frame the planner gap lines in the data envelope, cap the wrap-up (25) and report (200) gap lists, cap current rows at 2000 per task. Replace the activity budget marker with tasks.end_reason, written with the guarded terminal status and cleared on revive. Generic 500 message in taskCoverage; early return on an empty ledger in the planner block.
2026-11-12 20:48:34 +01:00

50 lines
1.7 KiB
Go

package report
import (
"strings"
"testing"
"github.com/Autumn-27/artex/db"
)
// The exported report carries the coverage gaps and the completeness caveat;
// nothing is added when the task's coverage feature is off (nil ledger).
func TestMarkdownCoverageGaps(t *testing.T) {
l := db.BuildCoverageLedger([]db.CoverageEntry{{Surface: "/a", RiskArea: "xss", Outcome: db.OutcomeNeedsFollowUp}},
[]string{"sqli"}, db.CoverageCompletenessFor("timeout", false, false, true))
cases := []struct {
name string
l *db.CoverageLedger
want []string
}{
{"ledger", l, []string{"## Coverage gaps", "timeout", "Incomplete scan", "open gaps: 2", "- unrecorded_risk_class sqli", "- needs_follow_up /a xss"}},
{"coverage off", nil, nil},
}
for _, c := range cases {
md := Markdown(Input{Title: "t", Coverage: c.l})
if c.want == nil && strings.Contains(md, "Coverage gaps") {
t.Fatalf("%s: unexpected coverage section", c.name)
}
for _, w := range c.want {
if !strings.Contains(md, w) {
t.Errorf("%s: missing %q in\n%s", c.name, w, md)
}
}
}
}
// The report lists at most reportMaxGaps gaps, then a count line.
func TestMarkdownCoverageGapsCap(t *testing.T) {
var entries []db.CoverageEntry
for i := 0; i < reportMaxGaps+30; i++ {
entries = append(entries, db.CoverageEntry{Surface: "/p", RiskArea: "xss", Outcome: db.OutcomeNeedsFollowUp})
}
md := Markdown(Input{Title: "t", Coverage: db.BuildCoverageLedger(entries, nil, db.CoverageCompleteness{})})
if n := strings.Count(md, "\n- needs_follow_up /p xss"); n != reportMaxGaps {
t.Fatalf("listed %d gaps, want %d", n, reportMaxGaps)
}
if !strings.Contains(md, "- and 30 more (see the coverage API)") {
t.Fatalf("missing count line in\n%s", md)
}
}