Separate observation from evaluation in blacklist sources

Each source's Query() method previously set r.Listed and r.Severity,
embedding verdict logic inside the prober. Evaluation now lives in a
dedicated Evaluate(SourceResult) (bool, string) method per source,
keeping Query() as pure observation.

A package-level EvaluateResult() helper looks up the source by ID and
delegates to its Evaluate method; rules.go, report.go, types.go, and
provider.go all call this instead of reading pre-set r.Listed/r.Severity
values. An unknownSource sentinel handles results whose source is no
longer registered.
This commit is contained in:
nemunaire 2026-05-15 18:04:10 +08:00
commit c437339bda
13 changed files with 123 additions and 44 deletions

View file

@ -101,7 +101,7 @@ func diagnose(d *BlacklistData) []Diagnosis {
var out []Diagnosis
for _, r := range d.Results {
if !r.Listed {
if listed, _ := EvaluateResult(r); !listed {
continue
}
if s, ok := byID[r.SourceID]; ok {
@ -189,7 +189,7 @@ func buildSections(d *BlacklistData) []sourceSection {
// subject sources have at most one). Plain sources skip this.
if dr, ok := byID[id].(DetailRenderer); ok {
for _, r := range results {
if !r.Listed && len(r.Details) == 0 {
if listed, _ := EvaluateResult(r); !listed && len(r.Details) == 0 {
continue
}
html, err := dr.RenderDetail(r)
@ -210,7 +210,7 @@ func sectionStatus(results []SourceResult) (string, string) {
if r.Enabled {
enabled++
}
if r.Listed {
if l, _ := EvaluateResult(r); l {
listed++
} else if r.Error != "" {
errs++
@ -238,11 +238,12 @@ func subjectStatusLabel(r SourceResult) string {
switch {
case !r.Enabled:
return "Disabled"
case r.Listed:
return "LISTED"
case r.Error != "":
return "Error"
}
if listed, _ := EvaluateResult(r); listed {
return "LISTED"
}
return "Clean"
}
@ -250,11 +251,12 @@ func subjectStatusClass(r SourceResult) string {
switch {
case !r.Enabled:
return "muted"
case r.Listed:
return r.Severity
case r.Error != "":
return "warn"
}
if listed, severity := EvaluateResult(r); listed {
return severity
}
return "ok"
}