Files
mesh-delivery/modules/mesh-grants/internal/grants/findings_test.go
T
jschoubben 78825dc580 GR11 (A-51, §388): the grants part's first-view-unanswered, first-view-empty and binding-unlisted through the held finding writer
The part's state `findings`, its finding stream `mesh-grants-findings` and the consume of `mesh-conditions.findings-asked`
are declared in module.json; the process makes mesh-sdk's held writer (Asked from the contract) and starts it once its
state is bound. Its other conditions stay said to the operator channel. gofmt of bus.go and grants_test.go.

Builds: design 47 G §388 (G-8), §529 (G-12), A-51 (G-20)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-11 22:45:48 +01:00

68 lines
2.5 KiB
Go

package grants
import (
"context"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/views"
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
)
type findingsFake struct {
written []mcseat.Finding
cleared [][4]string
}
func (f *findingsFake) Write(_ context.Context, w mcseat.Finding) error {
f.written = append(f.written, w)
return nil
}
func (f *findingsFake) Clear(_ context.Context, scope, id, kind, why string) error {
f.cleared = append(f.cleared, [4]string{scope, id, kind, why})
return nil
}
// Design 47 G §388, §529, A-51: the part's first-view-unanswered, first-view-empty and binding-unlisted are findings of the part's
// module, written while raised and cleared when cleared, never conditions said to the operator channel; any other key is refused.
func TestTheFourKindsAreSaidAsFindings(t *testing.T) {
at := time.Date(2026, 11, 11, 22, 0, 0, 0, time.UTC)
f := &findingsFake{}
say := SayFinding(f, "ace", func() time.Time { return at })
fv := FirstViews[0]
if err := say(unansweredCondition(fv, views.Status{}, true)); err != nil {
t.Fatal(err)
}
if err := say(emptyCondition(fv, true)); err != nil {
t.Fatal(err)
}
if err := say(unlistedCondition("mod-c", "kept", true)); err != nil {
t.Fatal(err)
}
want := []struct{ kind, id string }{
{"first-view-unanswered", "mesh-delivery-assigner.assignments"}, {"first-view-empty", "mesh-delivery-assigner.assignments"}, {"binding-unlisted", "mod-c.kept"}}
if len(f.written) != 3 {
t.Fatalf("written %+v", f.written)
}
for i, w := range want {
got := f.written[i]
if got.Kind != w.kind || got.Scope != "module" || got.Observer != Module || got.Subject.Machine != "ace" || !got.At.Equal(at) ||
got.Severity != mcseat.FindingSeverityWarning || got.Summary == "" || got.Headline == "" {
t.Errorf("finding %d = %+v, want kind %s", i, got, w.kind)
}
}
if err := say(unlistedCondition("mod-c", "kept", false)); err != nil {
t.Fatal(err)
}
if len(f.cleared) != 1 || f.cleared[0][0] != "module" || f.cleared[0][2] != "binding-unlisted" || f.cleared[0][3] == "" {
t.Errorf("cleared %+v", f.cleared)
}
if err := say(oc.Condition{Key: RefusedCondition, State: occ.StateRaised}); err == nil || len(f.written) != 3 {
t.Errorf("a condition that is no finding was taken: %v", err)
}
}