Files
mesh-catalog/modules/mesh-self-check/cmd/mesh-self-check/findings.go
T
2026-11-11 21:47:00 +01:00

53 lines
2.1 KiB
Go

package main
// The self-check's findings are the generated finding of the seat mesh-conditions, written through mesh-sdk's finding
// writer (design 47 G §461, §689); the probes build them with these two helpers.
import (
"strings"
meshconditions "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/views"
)
// Finding, and the writer's other three bodies, are the seat mesh-conditions' own types.
type (
Finding = meshconditions.Finding
FindingCleared = meshconditions.FindingCleared
FindingsStated = meshconditions.FindingsStated
FindingsAsked = meshconditions.FindingsAskedEvent
FindingsWriter = views.Writer[Finding, FindingCleared, FindingsStated, FindingsAsked]
)
// idOf is a finding's id: the id of what it is about, and a ref that tells findings of one kind on one id apart after it
// (`<id>.<ref>`, each escaped as a name of a key is; design 47 G A-14).
func idOf(id, ref string) string {
if ref == "" {
return keys.EscapeName(id)
}
return keys.EscapeName(id) + "." + keys.EscapeName(ref)
}
// finding is f about scope and id (with ref when findings of one kind on one id need telling apart), on machine: it sets
// the key's scope and id and the subject's scope and id equal (design 47 G A-14).
func finding(scope, id, ref, machine string, f Finding) Finding {
f.Scope, f.ID = scope, idOf(id, ref)
f.Subject = meshconditions.Subject{Scope: scope, ID: f.ID, Machine: machine}
return f
}
// said is the one observation a finding keeps as evidence; its moment is the finding's own (`at`), so that a finding
// that says the same is not written again.
func said(s string) []meshconditions.Evidence {
return []meshconditions.Evidence{{Said: strings.TrimSpace(s)}}
}
// keyOf is where f is kept: `<scope>.<id>.<kind>`.
func keyOf(f Finding) string { return views.FindingKey(f.Scope, f.ID, f.Kind) }
// findingKey is the key of the finding of kind about scope and id with ref, as finding makes it.
func findingKey(scope, id, ref, kind string) string {
return views.FindingKey(scope, idOf(id, ref), kind)
}