Round 2 T2, T3, T4, T5: the tool runner ends G with its merge-base test count; the wait test runs its rows side by side
The tests G added fold into existing ones as subtests (design 47 G §626, A-306: 171 tests down to 154, integration 9 down to 7). TestMeshWaitRefusesLoudlyAndNeverLoops runs its groups of one-second rows as parallel subtests, each on a runtime of its own, 15 s down to 5 s (A-311: the one-second floor of a wait's timeout stands, no clock is injected). The go.mod no longer requires meshconditionsclient, which no package loads (T4). Node names in the lines G adds are role names (T5). Builds: design 47 G §626, design 34 every-event §19, A-306, A-311; review round 2 findings T2, T3, T4, T5 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -3,6 +3,7 @@ package approval
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -506,4 +507,86 @@ func TestTheRefusalsAndAnswers(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) { tc.run(t, newWorld()) })
|
||||
}
|
||||
// Design 46 7-approval-mark §5, §3, §4 and design 34 every-event §33: the marks a module's calls are gated by, derived from
|
||||
// fixture catalog halves and served entries.
|
||||
t.Run("TheMarks", func(t *testing.T) {
|
||||
login := map[string]seatdef.Definition{"node-login-shell": {Seat: "node-login-shell",
|
||||
Verbs: []seatdef.Verb{{Name: "execute", NeedsApproval: true}, {Name: "sessions"}}}}
|
||||
v1 := entry("src2:1", []string{"node-login-shell.execute", "node-login-shell.sessions"},
|
||||
map[string]any{"needs-approval": []any{"wipe"}})
|
||||
v2 := entry("src2:2", []string{"node-login-shell.execute", "node-login-shell.sessions"},
|
||||
map[string]any{"needs-approval": []any{"erase", "node-login-shell.sessions"}})
|
||||
mail := catalogseat.CatalogEntry{Module: "mail", Fp: "src2:m", Manifest: map[string]any{
|
||||
"needs-approval": []any{"mail.received"}, "emits": []any{"mail.received"},
|
||||
"streams": []any{map[string]any{"name": "MAIL", "events": []any{"mail.**"}, "grant": map[string]any{"config": "readers", "events": "mail.{key}.**"}}}}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cat *fakeCatalog
|
||||
module string
|
||||
fp string
|
||||
tools []string
|
||||
verbs map[string]string
|
||||
subjects []string
|
||||
unread bool
|
||||
}{
|
||||
{name: "a seat's mark stands for every holder, and the holder's own adds up", cat: &fakeCatalog{revision: "7",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1}, newest: map[string]catalogseat.CatalogEntry{"shell": v1}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"wipe"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell"}},
|
||||
{name: "a holder's needs-approval cannot unmark its seat's verb, and marks another", cat: &fakeCatalog{revision: "8",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:2": v2}, newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:2", tools: []string{"erase"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}},
|
||||
{name: "across a version change the union stands: a dropped mark is asked while the old bundle runs", cat: &fakeCatalog{revision: "9",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1, "src2:2": v2}, newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"erase", "wipe"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}},
|
||||
{name: "a served entry that cannot be read leaves the newest marks, every marked call refused", cat: &fakeCatalog{revision: "9",
|
||||
newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"erase"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}, unread: true},
|
||||
{name: "a bundle with no fingerprint has no served entry", cat: &fakeCatalog{revision: "9", defs: login},
|
||||
module: "shell", unread: true},
|
||||
{name: "a marked event and a stream with a grant give their subjects and each .>", cat: &fakeCatalog{revision: "3",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:m": mail}, newest: map[string]catalogseat.CatalogEntry{"mail": mail}},
|
||||
module: "mail", fp: "src2:m", subjects: []string{"mesh.mod.mail.event.mail.received", "mesh.mod.mail.event.mail.received.>",
|
||||
"mesh.stream.mail.event.mail.>", "mesh.stream.mail.event.mail.received", "mesh.stream.mail.event.mail.received.>"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
m := gate.Derive(tc.cat, tc.module, tc.fp)
|
||||
if got := keysOf(m.Tools); !reflect.DeepEqual(got, tc.tools) {
|
||||
t.Errorf("tools %v, want %v", got, tc.tools)
|
||||
}
|
||||
if tc.verbs == nil {
|
||||
tc.verbs = map[string]string{}
|
||||
}
|
||||
if !reflect.DeepEqual(m.Verbs, tc.verbs) {
|
||||
t.Errorf("verbs %v, want %v", m.Verbs, tc.verbs)
|
||||
}
|
||||
if got := keysOf(m.Subjects); !reflect.DeepEqual(got, tc.subjects) {
|
||||
t.Errorf("subjects %v, want %v", got, tc.subjects)
|
||||
}
|
||||
if (m.Unread != "") != tc.unread || m.Revision != tc.cat.revision {
|
||||
t.Errorf("unread %q, revision %q", m.Unread, m.Revision)
|
||||
}
|
||||
})
|
||||
}
|
||||
// §4: a bundle whose marks name a tool it does not register is not loaded, its finding mark-unserved raised; a bundle that
|
||||
// serves it clears it, and a catalog without the mark too.
|
||||
t.Run("mark-unserved raised and cleared", func(t *testing.T) {
|
||||
cat := &fakeCatalog{revision: "7", byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1}, newest: map[string]catalogseat.CatalogEntry{"shell": v1}, defs: login}
|
||||
w := &findings{}
|
||||
g := gate.New(gate.Deps{Node: "n1", Runner: "node-tools", Catalog: cat, Findings: Findings(w, "n1", "node-tools", nil)})
|
||||
if got := g.Unserved("shell", "src2:1", []string{"other"}); !reflect.DeepEqual(got, []string{"wipe"}) || w.raised[keys.EscapeName("n1.shell")] != gate.KindMarkUnserved {
|
||||
t.Fatalf("unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
if got := g.Unserved("shell", "src2:1", []string{"wipe"}); got != nil || w.raised[keys.EscapeName("n1.shell")] != "" {
|
||||
t.Fatalf("a bundle serving the mark: unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
_ = g.Unserved("shell", "src2:1", nil)
|
||||
cat.byFp["src2:1"], cat.newest["shell"] = entry("src2:1", nil, nil), entry("src2:1", nil, nil)
|
||||
if got := g.Unserved("shell", "src2:1", nil); got != nil || w.raised[keys.EscapeName("n1.shell")] != "" {
|
||||
t.Fatalf("a catalog without the mark: unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ package approval
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
condseat "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"
|
||||
|
||||
catalogseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -47,89 +44,6 @@ func entry(fp string, serves []string, manifest map[string]any) catalogseat.Cata
|
||||
return catalogseat.CatalogEntry{Module: "shell", Fp: fp, Serves: serves, Manifest: manifest}
|
||||
}
|
||||
|
||||
// Design 46 7-approval-mark §5, §3, §4 and design 34 every-event §33: the marks a module's calls are gated by, derived from
|
||||
// fixture catalog halves and served entries.
|
||||
func TestTheMarks(t *testing.T) {
|
||||
login := map[string]seatdef.Definition{"node-login-shell": {Seat: "node-login-shell",
|
||||
Verbs: []seatdef.Verb{{Name: "execute", NeedsApproval: true}, {Name: "sessions"}}}}
|
||||
v1 := entry("src2:1", []string{"node-login-shell.execute", "node-login-shell.sessions"},
|
||||
map[string]any{"needs-approval": []any{"wipe"}})
|
||||
v2 := entry("src2:2", []string{"node-login-shell.execute", "node-login-shell.sessions"},
|
||||
map[string]any{"needs-approval": []any{"erase", "node-login-shell.sessions"}})
|
||||
mail := catalogseat.CatalogEntry{Module: "mail", Fp: "src2:m", Manifest: map[string]any{
|
||||
"needs-approval": []any{"mail.received"}, "emits": []any{"mail.received"},
|
||||
"streams": []any{map[string]any{"name": "MAIL", "events": []any{"mail.**"}, "grant": map[string]any{"config": "readers", "events": "mail.{key}.**"}}}}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cat *fakeCatalog
|
||||
module string
|
||||
fp string
|
||||
tools []string
|
||||
verbs map[string]string
|
||||
subjects []string
|
||||
unread bool
|
||||
}{
|
||||
{name: "a seat's mark stands for every holder, and the holder's own adds up", cat: &fakeCatalog{revision: "7",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1}, newest: map[string]catalogseat.CatalogEntry{"shell": v1}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"wipe"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell"}},
|
||||
{name: "a holder's needs-approval cannot unmark its seat's verb, and marks another", cat: &fakeCatalog{revision: "8",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:2": v2}, newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:2", tools: []string{"erase"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}},
|
||||
{name: "across a version change the union stands: a dropped mark is asked while the old bundle runs", cat: &fakeCatalog{revision: "9",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1, "src2:2": v2}, newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"erase", "wipe"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}},
|
||||
{name: "a served entry that cannot be read leaves the newest marks, every marked call refused", cat: &fakeCatalog{revision: "9",
|
||||
newest: map[string]catalogseat.CatalogEntry{"shell": v2}, defs: login},
|
||||
module: "shell", fp: "src2:1", tools: []string{"erase"}, verbs: map[string]string{"node-login-shell.execute": "seat node-login-shell",
|
||||
"node-login-shell.sessions": "entry shell src2:2"}, unread: true},
|
||||
{name: "a bundle with no fingerprint has no served entry", cat: &fakeCatalog{revision: "9", defs: login},
|
||||
module: "shell", unread: true},
|
||||
{name: "a marked event and a stream with a grant give their subjects and each .>", cat: &fakeCatalog{revision: "3",
|
||||
byFp: map[string]catalogseat.CatalogEntry{"src2:m": mail}, newest: map[string]catalogseat.CatalogEntry{"mail": mail}},
|
||||
module: "mail", fp: "src2:m", subjects: []string{"mesh.mod.mail.event.mail.received", "mesh.mod.mail.event.mail.received.>",
|
||||
"mesh.stream.mail.event.mail.>", "mesh.stream.mail.event.mail.received", "mesh.stream.mail.event.mail.received.>"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
m := gate.Derive(tc.cat, tc.module, tc.fp)
|
||||
if got := keysOf(m.Tools); !reflect.DeepEqual(got, tc.tools) {
|
||||
t.Errorf("tools %v, want %v", got, tc.tools)
|
||||
}
|
||||
if tc.verbs == nil {
|
||||
tc.verbs = map[string]string{}
|
||||
}
|
||||
if !reflect.DeepEqual(m.Verbs, tc.verbs) {
|
||||
t.Errorf("verbs %v, want %v", m.Verbs, tc.verbs)
|
||||
}
|
||||
if got := keysOf(m.Subjects); !reflect.DeepEqual(got, tc.subjects) {
|
||||
t.Errorf("subjects %v, want %v", got, tc.subjects)
|
||||
}
|
||||
if (m.Unread != "") != tc.unread || m.Revision != tc.cat.revision {
|
||||
t.Errorf("unread %q, revision %q", m.Unread, m.Revision)
|
||||
}
|
||||
})
|
||||
}
|
||||
// §4: a bundle whose marks name a tool it does not register is not loaded, its finding mark-unserved raised; a bundle that
|
||||
// serves it clears it, and a catalog without the mark too.
|
||||
t.Run("mark-unserved raised and cleared", func(t *testing.T) {
|
||||
cat := &fakeCatalog{revision: "7", byFp: map[string]catalogseat.CatalogEntry{"src2:1": v1}, newest: map[string]catalogseat.CatalogEntry{"shell": v1}, defs: login}
|
||||
w := &findings{}
|
||||
g := gate.New(gate.Deps{Node: "n1", Runner: "node-tools", Catalog: cat, Findings: Findings(w, "n1", "node-tools", nil)})
|
||||
if got := g.Unserved("shell", "src2:1", []string{"other"}); !reflect.DeepEqual(got, []string{"wipe"}) || w.raised[keys.EscapeName("n1.shell")] != gate.KindMarkUnserved {
|
||||
t.Fatalf("unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
if got := g.Unserved("shell", "src2:1", []string{"wipe"}); got != nil || w.raised[keys.EscapeName("n1.shell")] != "" {
|
||||
t.Fatalf("a bundle serving the mark: unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
_ = g.Unserved("shell", "src2:1", nil)
|
||||
cat.byFp["src2:1"], cat.newest["shell"] = entry("src2:1", nil, nil), entry("src2:1", nil, nil)
|
||||
if got := g.Unserved("shell", "src2:1", nil); got != nil || w.raised[keys.EscapeName("n1.shell")] != "" {
|
||||
t.Fatalf("a catalog without the mark: unserved %v, findings %v", got, w.raised)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// findings is the runner's held writer as a fixture: each finding raised now, by id.
|
||||
type findings struct {
|
||||
raised map[string]string
|
||||
|
||||
Reference in New Issue
Block a user