diff --git a/modules/mesh-grants/cmd/mesh-grants/integration_test.go b/modules/mesh-grants/cmd/mesh-grants/integration_test.go index d84b24ee..225309db 100644 --- a/modules/mesh-grants/cmd/mesh-grants/integration_test.go +++ b/modules/mesh-grants/cmd/mesh-grants/integration_test.go @@ -32,7 +32,6 @@ import ( "git.novox.be/novox/mesh-sdk/go/membership" "git.novox.be/novox/mesh-sdk/go/process" "git.novox.be/novox/mesh-sdk/go/seal" - "git.novox.be/novox/mesh-sdk/go/seatlist" "git.novox.be/novox/mesh-sdk/go/views" "mesh-grants/internal/buscompose" @@ -108,8 +107,6 @@ func TestTheGrantsPartWhole(t *testing.T) { put(grants.ReadManifests, digest, meshcatalog.ManifestsByDigestValue{V: keys.Version, Module: module, Manifest: raw}) put(grants.ReadModules, module, meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), Manifest: digest, Repository: "novox/x", Commit: "c"}) - verdict, _ := meshcatalogclient.EncodeVerdict(meshcatalog.VerdictsByDigestValue{Module: module, State: meshcatalogclient.VerdictAccepted, Judge: "j", At: new(time.Now())}) - put(grants.ReadVerdicts, digest, json.RawMessage(verdict)) } manifest("nats", `{"module":"nats","version":"1","claims":[{"name":"mesh-broker"}],"own-secrets":{"broker":"/var/lib/nats/broker"},`+ `"emits":["created","done","dropped","recreated"],"streams":[{"name":"broker-events","events":["created","dropped","recreated"],"max-age-days":30,"max-mib":256}]}`) @@ -543,16 +540,6 @@ func TestTheGrantsPartWhole(t *testing.T) { t.Errorf("the bucket %s: %v, want none", bucket, err) } } - // Issue 1966: the seat list's again tool answers an operator's session, which the mesh MCP server proves as its - // machine's tool runner (issue 627), and the healers; no other module. - t.Run("the seat list's again tool answers an operator's session", func(t *testing.T) { - for caller, refused := range map[string]bool{"person.jochen": false, "shanks.node-tools": false, "ace.mesh-healers": false, - "ace.messenger": true} { - if err := seatlist.Refusal(grants.ToolSeatListAgain, seatListAgainCallers, caller); (err != nil) != refused { - t.Errorf("%s: refused=%v, err %v", caller, refused, err) - } - } - }) // ADR 0640 §5: the real additions change the subjects and the filters and nothing else, and recreate nothing. t.Run("adding subjects and filters changes only those", func(t *testing.T) { stream, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "ADDS", Subjects: []string{"a.>"}, MaxAge: time.Hour, MaxMsgs: 100, diff --git a/modules/mesh-grants/cmd/mesh-grants/testdata/nats.module.json b/modules/mesh-grants/cmd/mesh-grants/testdata/nats.module.json index af929ebe..a73846ef 100644 --- a/modules/mesh-grants/cmd/mesh-grants/testdata/nats.module.json +++ b/modules/mesh-grants/cmd/mesh-grants/testdata/nats.module.json @@ -57,7 +57,7 @@ "mesh-delivery-indexer.indexer_bus_state" ], "consumes": [ - "mesh-catalog.manifest-accepted" + "mesh-catalog.catalog-revision" ], "uses": [ "operator-channel" diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index ce7f8560..1e45fdc3 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -300,12 +300,6 @@ func (b *fakeBus) put(state, key string, v any) { b.states[state] = map[string][]byte{} } b.states[state][key] = raw - // A modules value that carries no verdict is accepted by the indexer's verdict on its digest, as the indexer writes it; - // a row that wants the window before the judge deletes that key. - if m, ok := v.(meshcatalog.ModulesByModuleValue); ok && state == grants.ReadModules && m.Verdict == "" && m.Manifest != "" { - verdict, _ := meshcatalogclient.EncodeVerdict(meshcatalog.VerdictsByDigestValue{Module: key, State: meshcatalogclient.VerdictAccepted, Judge: "j", At: new(time.Now())}) - b.put(grants.ReadVerdicts, m.Manifest, json.RawMessage(verdict)) - } } func (b *fakeBus) Keys(state string) ([]string, error) { @@ -484,11 +478,11 @@ func (b *fakeBus) manifestOf(module, raw string) { b.put(grants.ReadModules, module, meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), Manifest: digest, Repository: "novox/x", Commit: "c"}) } -// refuse marks the indexer's refusal of module's manifest in its value (novox/hq ADR 0578 §1). -func (b *fakeBus) refuse(module, raw, problem string) { +// unreadable writes module's value naming a manifest the indexer's manifests do not hold, so the part cannot read it and +// holds the module (inputs.go, Refused): no verdict holds a manifest any more (design 47 H §745, H-A-79). +func (b *fakeBus) unreadable(module, raw string) { b.put(grants.ReadModules, module, meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), - Manifest: meshcatalogclient.ManifestDigest([]byte(raw)), Repository: "novox/x", Commit: "c", Verdict: meshcatalogclient.VerdictRefused, - Problems: []string{problem}}) + Manifest: meshcatalogclient.ManifestDigest([]byte(raw + " (not held)")), Repository: "novox/x", Commit: "c"}) } // assign places module on node in the seat's assignments, the one place the part reads it (ADR 0549 §5; issue 774). @@ -738,7 +732,7 @@ func TestGrants(t *testing.T) { digest := meshcatalogclient.ManifestDigest([]byte(built)) b.put(grants.ReadManifests, digest, meshcatalog.ManifestsByDigestValue{V: keys.Version, Module: "mod-x", Manifest: built}) fp := "src2:" + strings.Repeat("cd", 32) - b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp, Composed: "sha256:" + strings.Repeat("ef", 32)}) + b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp}) b.entry(fp, digest) }, []string{"a.mod-x", "a.nats", "b.mod-y", "node.a", "node.b"}, "people"}, // Issue 1966: refused, each module is placed where its have says it runs (the bootstrap fallback); a has nats. @@ -883,12 +877,11 @@ func TestGrants(t *testing.T) { if slices.Contains(web.Publish, "$JS.API.DIRECT.GET.KV_mesh-knowledge_sections.>") { t.Error("the object bucket's read is granted as a state's") } - // ADR 0601 clause 3: the owner's trunk manifest now waits for a field; its running build's manifest still declares the - // bucket, so web keeps its object grant. + // ADR 0601 clause 3: the owner's trunk manifest cannot be read (its value names a manifest the indexer does not hold); + // its running build's manifest still declares the bucket, so web keeps its object grant. fp := "src2:" + strings.Repeat("cd", 32) b.put(grants.ReadModules, "mesh-knowledge", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), - Manifest: meshcatalogclient.ManifestDigest([]byte(`{"module":"mesh-knowledge","version":"2"}`)), Repository: "novox/x", Commit: "c", - Verdict: meshcatalogclient.VerdictRefused, Problems: []string{"it waits"}, Unknown: []string{"core-credentials"}}) + Manifest: meshcatalogclient.ManifestDigest([]byte(`{"module":"mesh-knowledge","version":"2"}`)), Repository: "novox/x", Commit: "c"}) b.put(grants.ReadHave, "a.mesh-knowledge", nodeengine.HaveByNodeModuleValue{V: keys.Version, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK, Fp: fp}) b.entry(fp, meshcatalogclient.ManifestDigest([]byte(knowledge))) if heldWeb := (func() grants.User { @@ -989,10 +982,10 @@ func TestGrants(t *testing.T) { b.assign("a", "messenger") b.assign("b", "telegram") if held { - // The trunk's manifest waits for a field; the build that runs was judged on the manifest before. + // The trunk's manifest cannot be read (its value names a manifest the indexer does not hold); the build that runs + // carries the manifest before. b.put(grants.ReadModules, "messenger", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), - Manifest: meshcatalogclient.ManifestDigest([]byte(`{"module":"messenger","version":"2"}`)), Repository: "novox/x", Commit: "c", - Verdict: meshcatalogclient.VerdictRefused, Problems: []string{"it waits"}, Unknown: []string{"core-credentials"}}) + Manifest: meshcatalogclient.ManifestDigest([]byte(`{"module":"messenger","version":"2"}`)), Repository: "novox/x", Commit: "c"}) if runs { fp := "src2:" + strings.Repeat("cd", 32) digest := meshcatalogclient.ManifestDigest([]byte(router)) @@ -1122,14 +1115,14 @@ func TestGrants(t *testing.T) { t.Run("a predefined-key fallback is read with no list; every refused manifest listed", func(t *testing.T) { // mod-p's value falls back to a predefined key, as claude-code's managed_settings does, and no list is on the bus - // (issue 1945); mod-z's manifest the indexer's judge refused (ADR 0578 §3), and mod-z is assigned nowhere. + // (issue 1945); mod-z's manifest the part cannot read (no verdict holds one, design 47 H H-A-79), and mod-z is assigned nowhere. const pManifest = `{"module":"mod-p","version":"1","own-secrets":{"broker":"/var/lib/p/broker"},` + `"config":{"size":{"type":"number","description":"The size text shows in, in points.","predefined":"font-size","default":12,"runtime":true}}}` const zManifest = `{"module":"mod-z","version":"1","no-such-key":true}` b := fixture() b.manifestOf("mod-p", pManifest) b.manifestOf("mod-z", zManifest) - b.refuse("mod-z", zManifest, "it carries no-such-key") + b.unreadable("mod-z", zManifest) b.assign("b", "mod-p") // mesh-wireguard is provided by the mesh, not read from a repository: no manifest in the indexer, none refused, // no gap, and its manifest is the one mesh-sdk provides (issue 1945). @@ -1181,7 +1174,7 @@ func TestGrants(t *testing.T) { `"provides":[{"name":"smtp","scope":"mesh"}],"serves":{"smtp":{"port":587,"domain":"${config:domain}"}}}`) bt.assign("b", "mod-s") runsFP := "src2:" + strings.Repeat("cd", 32) - bt.put(grants.ReadWants, "want.b.mod-s", meshwantsclient.Want{V: keys.Version, Fp: runsFP, Composed: "sha256:" + strings.Repeat("ef", 32)}) + bt.put(grants.ReadWants, "want.b.mod-s", meshwantsclient.Want{V: keys.Version, Fp: runsFP}) bt.entry(runsFP, oldDigest) for _, u := range shadowOf(t, bt) { if u.User == "node.a" && !slices.Contains(u.Publish, served) { @@ -1320,10 +1313,15 @@ func TestGrants(t *testing.T) { // the loaded list says none, as nats_users answers today, on a user whose grants differ: it cannot be compared. denied := slices.Clone(shadow) denied[x].PublishDeny = []string{"mesh.seat.node-launcher.tool.secret"} + // Every account is granted every seat's verbs (design 47 H §752, H-A-113), so every module's user carries the denies + // that allow reaches: the loaded list says each user's own, a.mod-x's empty; and in unsaid it says none for a.mod-x. readable := slices.Clone(fewer) for i := range readable { - readable[i].PublishDeny = []string{} + readable[i].PublishDeny = append([]string{}, shadow[i].PublishDeny...) } + readable[x].PublishDeny = []string{} + unsaid := slices.Clone(fewer) + unsaid[x].PublishDeny = nil // A subscribe the shadow withholds (design 46 approval mark §6) where the loaded list withholds none, as on the first // composition after the release: a narrowing, no right lost. Its reverse, a node gaining approval-mark/1: a right added. withheld := slices.Clone(shadow) @@ -1371,7 +1369,7 @@ func TestGrants(t *testing.T) { {"grants differ", changed, nil, nil, nil, []string{"a.mod-x"}, false, nil, []string{"a.mod-x"}, 1}, {"only a right added", fewer, nil, nil, nil, []string{"a.mod-x"}, false, nil, nil, 1}, {"a deny added refuses", readable, nil, nil, nil, []string{"a.mod-x"}, false, nil, []string{"a.mod-x"}, 1}, - {"a deny the loaded list cannot say refuses a user whose grants differ", fewer, nil, nil, nil, []string{"a.mod-x"}, false, nil, []string{"a.mod-x"}, 1}, + {"a deny the loaded list cannot say refuses a user whose grants differ", unsaid, nil, nil, nil, []string{"a.mod-x"}, false, nil, []string{"a.mod-x"}, 1}, {"a subscribe withheld passes as no right lost", shadow, nil, nil, nil, []string{"a.mod-x"}, false, nil, nil, 0}, {"a subscribe no longer withheld is a right added", withheld, nil, nil, nil, []string{"a.mod-x"}, false, nil, nil, 1}, {"captured 21:19: only added rights", nil, nil, nil, nil, nil, false, captured(nil), nil, 41}, @@ -2895,7 +2893,7 @@ func TestGrants(t *testing.T) { }, ""}, // The ledger of a held module stays with its module's users, whatever the seat list (held.go). {"the ledger of a module whose manifest is refused", func(b *fakeBus, p *grants.Part) { - b.refuse("mod-x", ledgerX, "it is held") + b.unreadable("mod-x", ledgerX) }, ""}, // The union cannot give a login a loaded user has no hash for: held, naming it. {"a loaded user with no hash, the seat list unread", func(b *fakeBus, p *grants.Part) { @@ -3695,10 +3693,10 @@ func TestGrants(t *testing.T) { } }) - // DLV-F4r, DLV-R1 (novox/hq ADR 0615 §4 to §6, ADR 0622; design 25 § 12.2): the five owners' states are read by their + // DLV-F4r, DLV-R1 (novox/hq ADR 0615 §4 to §6, ADR 0622; design 25 § 12.2): the four owners' states are read by their // first views; an answer empty at revision 0 drops no login and raises first-view-empty with the operator's step until an // answer above 0; an owner down past the bound raises first-view-unanswered, cleared by its answer; an event applies a - // change with no ask; grants_first_view_again refuses a state that is none of the five and records the hand act. + // change with no ask; grants_first_view_again refuses a state that is none of the four and records the hand act. t.Run("first views: the owners' states by their first views, an empty answer at revision 0 dropping no login", func(t *testing.T) { b := fixture() b.loaded = shadowOf(t, b) @@ -3707,7 +3705,7 @@ func TestGrants(t *testing.T) { empty.Store(true) owner := func(tool string) func(context.Context, string) (views.Answer, error) { return func(context.Context, string) (views.Answer, error) { - if down.Load() && strings.HasSuffix(tool, ".verdicts") { + if down.Load() && strings.HasSuffix(tool, ".wants") { return views.Answer{}, errors.New("no responders") } for _, fv := range grants.FirstViews { @@ -3754,7 +3752,7 @@ func TestGrants(t *testing.T) { down.Store(true) fv.Start(ctx, func() {}) for _, f := range fv.Followers { - if f.Tool != grants.IndexerModule+".verdicts" { + if f.Tool != grants.AssignerModule+".wants" { <-f.Ready() } } @@ -3774,7 +3772,7 @@ func TestGrants(t *testing.T) { p.Read, p.Views, p.Say, p.SayFinding = fv, fv, say, say before := p.Compose() // The raise the condition keeper did not take was said again by the pass. - if !raised(grants.FirstViewUnanswered+".mesh-delivery-indexer.verdicts", occ.StateRaised) { + if !raised(grants.FirstViewUnanswered+".mesh-delivery-assigner.wants", occ.StateRaised) { t.Fatalf("the refused raise was not said again at the pass: %+v", said) } // Not answered above revision 0, the modules are placed by the node-engines' haves (issue 1966), said as its gap. @@ -3793,7 +3791,7 @@ func TestGrants(t *testing.T) { } waitFor(t, func() bool { return fv.Followers[grants.ReadAssignments].Status().Revision == 7 }) waitFor(t, func() bool { - return raised(grants.FirstViewUnanswered+".mesh-delivery-indexer.verdicts", occ.StateCleared) + return raised(grants.FirstViewUnanswered+".mesh-delivery-assigner.wants", occ.StateCleared) }) after := p.Compose() if slices.ContainsFunc(after.UserList.Gaps, func(g grants.Gap) bool { return g.Input == grants.ReadAssignments }) || @@ -3813,61 +3811,16 @@ func TestGrants(t *testing.T) { if _, found, _ := fv.Get(grants.ReadAssignments, "c.node"); !found || fv.Followers[grants.ReadAssignments].Status().Asks != asksBefore { t.Error("the event did not reach the picture, or asked") } - // The verdicts follow the indexer's manifest-accepted and manifest-refused at the revision each carries (ADR 0622 §2): - // the next revision changes the picture with no ask; one already in it is passed over; one carrying no revision, or - // past the next, asks the first view once more. - verdicts := fv.Followers[grants.ReadVerdicts] - digest := strings.Repeat("ab", 32) - heard := func(event string, body any) { - t.Helper() - raw, _ := json.Marshal(body) - if err := fv.HearVerdict(ctx, event, raw, t.Logf); err != nil { - t.Fatalf("%s: %v", event, err) - } - } - verdictOf := func() meshcatalog.VerdictsByDigestValue { - raw, _, _ := fv.Get(grants.ReadVerdicts, digest) - v, _ := meshcatalogclient.DecodeVerdict(raw) - return v - } - asked := verdicts.Status().Asks - heard(meshcatalog.EventManifestAccepted, meshcatalog.ManifestAcceptedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Revision: 8}) - if v := verdictOf(); v.State != meshcatalogclient.VerdictAccepted || v.Module != "mod-z" || verdicts.Status().Revision != 8 { - t.Errorf("manifest-accepted at the next revision: %+v at %d", v, verdicts.Status().Revision) - } - heard(meshcatalog.EventManifestRefused, meshcatalog.ManifestRefusedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Problems: []string{"p"}, Revision: 9}) - heard(meshcatalog.EventManifestAccepted, meshcatalog.ManifestAcceptedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Revision: 9}) - if v := verdictOf(); !meshcatalogclient.VerdictRefuses(v) || !slices.Equal(v.Problems, []string{"p"}) || verdicts.Status().Asks != asked { - t.Errorf("manifest-refused, then a revision already held: %+v, asks %d (was %d)", v, verdicts.Status().Asks, asked) - } - // A revision below the picture's (ADR 0615 §5; the verdicts made again restart low): the same verdict again is a - // redelivery, passed over; another verdict asks the first view once more. - heard(meshcatalog.EventManifestRefused, meshcatalog.ManifestRefusedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Problems: []string{"p"}, Revision: 3}) - if verdicts.Status().Asks != asked { - t.Errorf("a held verdict redelivered at a lower revision asked: asks %d (was %d)", verdicts.Status().Asks, asked) - } - heard(meshcatalog.EventManifestAccepted, meshcatalog.ManifestAcceptedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Revision: 2}) - waitFor(t, func() bool { return verdicts.Status().Asks > asked }) - waitFor(t, func() bool { s := verdicts.Status(); return !s.Answered.Before(s.Asked) }) - asked = verdicts.Status().Asks - heard(meshcatalog.EventManifestAccepted, meshcatalog.ManifestAcceptedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j"}) - waitFor(t, func() bool { return verdicts.Status().Asks > asked }) - asked = verdicts.Status().Asks - heard(meshcatalog.EventManifestAccepted, meshcatalog.ManifestAcceptedEvent{V: 1, Module: "mod-z", Digest: digest, Judge: "j", Revision: 12}) - waitFor(t, func() bool { return verdicts.Status().Asks > asked }) - if err := fv.HearVerdict(ctx, "manifest-judged", []byte("{}"), t.Logf); err == nil { - t.Error("an event that is no verdict was taken") - } - // The tools: a state that is none of the five is refused; one is asked with its hand act. + // The tools: a state that is none of the four is refused; one is asked with its hand act. var acts []string record := func(what, why string) error { acts = append(acts, what+": "+why); return nil } if _, err := p.AskFirstViewAgain("jochen@shanks", "builds", "x", record); err == nil || len(acts) != 0 { t.Errorf("a state that is no first view was asked: %v %v", err, acts) } - if _, err := p.AskFirstViewAgain("jochen@shanks", "verdicts", "after the take-in", record); err != nil || len(acts) != 1 { - t.Errorf("verdicts again: %v %v", err, acts) + if _, err := p.AskFirstViewAgain("jochen@shanks", "modules", "after the take-in", record); err != nil || len(acts) != 1 { + t.Errorf("modules again: %v %v", err, acts) } - if got, err := p.FirstViewsOf(); err != nil || !strings.Contains(fmt.Sprint(got), "mesh-delivery-indexer.verdicts") { + if got, err := p.FirstViewsOf(); err != nil || !strings.Contains(fmt.Sprint(got), "mesh-delivery-indexer.modules") { t.Errorf("grants_first_views = %v, %v", got, err) } }) @@ -4514,10 +4467,10 @@ func TestGrants(t *testing.T) { } }) - // Clause 3 of the record on a release's Approve (issue 774): a module whose manifest waits for a judge that knows a field - // of it, or is refused, and whose want names no build, keeps its users of the list in force and is said in a condition; - // the rest of the list is written as ever, and the users go the day the manifest is accepted and the module unassigned. - t.Run("a module whose manifest waits or is refused keeps its users of the list in force", func(t *testing.T) { + // Clause 3 of the record on a release's Approve (issue 774): a module whose manifest the part cannot read, and whose want + // names no build, keeps its users of the list in force and is said in a condition; the rest of the list is written as + // ever, and the users go the day the manifest is read and the module unassigned. No verdict holds one (design 47 H H-A-79). + t.Run("a module whose manifest cannot be read keeps its users of the list in force; a verdict holds none", func(t *testing.T) { b := fixture() const ctl = `{"module":"mod-r","version":"1","own-secrets":{"broker":"/var/lib/r/broker","broker-mod-r-tools":"${dir:tools-secret}/broker-mod-r-tools"},` + `"resources":[{"id":"tools-secret","type":"directory","path":"/var/lib/mesh/mod-r-tools","mode":"0711"}],"build":{"artifacts":[{"name":"tools",` + @@ -4554,38 +4507,40 @@ func TestGrants(t *testing.T) { if !ok || len(said) != 1 || said[0].State != occ.StateCleared { t.Fatalf("the list in force keeps no grants of b.mod-r.mod-r-tools (%v), or a held module was said before: %+v", ok, said) } - for gen, held := range []struct{ name, unknown string }{{"waits", "core-credentials"}, {"refused", ""}} { + // No verdict holds a manifest (design 47 H §745, H-A-79): a module in the revision is accepted by being there, so a value + // whose verdict field an indexer of the earlier form wrote as refused is composed as ever and raises no hold. + b.put(grants.ReadModules, "mod-r", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), + Manifest: meshcatalogclient.ManifestDigest([]byte(ctl)), Repository: "novox/x", Commit: "c", Verdict: meshcatalogclient.VerdictRefused, + Problems: []string{"it is held"}, Unknown: []string{"core-credentials"}}) + if res := p.Compose(); len(res.Refused) != 0 || said[len(said)-1].State != occ.StateCleared { + t.Errorf("a verdict of the earlier form held the manifest: refused %v, said %+v", res.Refused, said[len(said)-1]) + } + // A manifest the part cannot read (the value names a digest the indexer's manifests do not hold) is held: its module's + // users stay as the list in force holds them, said, and the rest of the list is written. + { // Another user's hash changes in the same pass, so a list that is written shows the held module did not hold it. - b.put(grants.ReadAccounts, "a.mod-x", map[string]any{"user": "a.mod-x", "hash": fmt.Sprintf("$2a$10$gen%d", gen), "generation": gen + 2, "fingerprint": fmt.Sprintf("sha256:%d", gen+2)}) + b.put(grants.ReadAccounts, "a.mod-x", map[string]any{"user": "a.mod-x", "hash": "$2a$10$gen0", "generation": 2, "fingerprint": "sha256:2"}) was, _, _ := p.Sealed() - var unknown []string - if held.unknown != "" { - unknown = []string{held.unknown} - } - b.put(grants.ReadModules, "mod-r", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), - Manifest: meshcatalogclient.ManifestDigest([]byte(ctl)), Repository: "novox/x", Commit: "c", Verdict: meshcatalogclient.VerdictRefused, - Problems: []string{"it is held"}, Unknown: unknown}) + b.unreadable("mod-r", ctl) b.put(grants.ReadModules, "mod-q", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), Manifest: meshcatalogclient.ManifestDigest([]byte(ctl)), Repository: "novox/x", Commit: "c"}) res := p.Compose() now, _, _ := p.Sealed() after, _, ok, _ := b.ownGet(grants.StateUserList, grants.SealedUserKey(now.Digest, "b.mod-r.mod-r-tools")) if now.Digest == was.Digest || slices.ContainsFunc(res.Errors, func(e string) bool { return strings.Contains(e, "composed whole") }) { - t.Errorf("%s: a held module held the whole list: sealed %+v", held.name, res.Sealed) + t.Errorf("a held module held the whole list: sealed %+v", res.Sealed) } if !ok || string(after) != string(before) || len(res.PrincipalsRefused) != 0 { - t.Errorf("%s: b.mod-r.mod-r-tools did not keep its grants of the list in force: %s, was %s", held.name, after, before) + t.Errorf("b.mod-r.mod-r-tools did not keep its grants of the list in force: %s, was %s", after, before) } if last := said[len(said)-1]; last.State != occ.StateRaised || !strings.Contains(last.Summary, "b.mod-r.mod-r-tools (stays in the list") { - t.Errorf("%s: the kept user was not said: %+v", held.name, last) + t.Errorf("the kept user was not said: %+v", last) } } // A held module that runs no build the part can read declares nothing to anyone: only its own users stay as the list in // force holds them, said unreadable; the others move (ADR 0614 §8). delete(b.states[grants.ReadHave], "b.mod-r") - b.put(grants.ReadModules, "mod-r", meshcatalog.ModulesByModuleValue{V: keys.Version, Fp2: "src2:" + strings.Repeat("ab", 32), - Manifest: meshcatalogclient.ManifestDigest([]byte(ctl)), Repository: "novox/x", Commit: "c", Verdict: meshcatalogclient.VerdictRefused, - Problems: []string{"it is held"}, Unknown: []string{"core-credentials"}}) + b.unreadable("mod-r", ctl) b.put(grants.ReadAccounts, "a.mod-x", map[string]any{"user": "a.mod-x", "hash": "$2a$10$gen9", "generation": 9, "fingerprint": "sha256:9"}) wasList, _, _ := p.Sealed() res := p.Compose() @@ -4599,24 +4554,10 @@ func TestGrants(t *testing.T) { if last := said[len(said)-1]; last.State != occ.StateRaised || !strings.Contains(last.Summary, "the manifest of mod-r is unreadable") { t.Errorf("the unreadable manifest was not said: %+v", last) } - // The window before the judge: the indexer wrote a changed manifest's value and no verdict on its digest yet. Only that - // module's users stay (named unreadable); the others move. - b.manifestOf("mod-r", ctl) - delete(b.states[grants.ReadVerdicts], meshcatalogclient.ManifestDigest([]byte(ctl))) - b.put(grants.ReadAccounts, "a.mod-x", map[string]any{"user": "a.mod-x", "hash": "$2a$10$gen11", "generation": 11, "fingerprint": "sha256:11"}) - wasList, _, _ = p.Sealed() - res = p.Compose() - nowList, _, _ = p.Sealed() - if nowList.Digest == wasList.Digest || strings.Contains(fmt.Sprint(res.Sealed), "kept while a read") { - t.Errorf("a manifest with no verdict yet held the whole list: %+v", res.Sealed) - } - if last := said[len(said)-1]; last.State != occ.StateRaised || !strings.Contains(last.Summary, "no verdict on this manifest yet") { - t.Errorf("a manifest with no verdict yet was not said: %+v", last) - } - // Accepted again: the users compose from the manifest and the condition clears. + // Readable again: the users compose from the manifest and the condition clears. b.manifestOf("mod-r", ctl) if p.Compose(); said[len(said)-1].State != occ.StateCleared { - t.Errorf("the condition was not cleared once the manifest is accepted: %+v", said[len(said)-1]) + t.Errorf("the condition was not cleared once the manifest is readable: %+v", said[len(said)-1]) } // ADR 0601 §4: a tool runner whose manifest does not say so yet (an older build's) keeps its user as the list in force // holds it, known by what it runs (it says the runner is alive), and the held condition says so; never composed as a @@ -4910,7 +4851,7 @@ func TestPassBeforeTheCatalogHalfsFirstViews(t *testing.T) { digest := meshcatalogclient.ManifestDigest([]byte(built)) b.put(grants.ReadManifests, digest, meshcatalog.ManifestsByDigestValue{V: keys.Version, Module: "mod-x", Manifest: built}) fp := "src2:" + strings.Repeat("cd", 32) - b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp, Composed: "sha256:" + strings.Repeat("ef", 32)}) + b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp}) b.entry(fp, digest) waiting(b) in := grants.ReadInputs(b, &grants.Manifests{}) @@ -5223,20 +5164,18 @@ func TestPassBeforeTheCatalogHalfComposesFromTheTrunkToo(t *testing.T) { name string entry bool // the want's entry is answered (the older build); else it is not answered wantsOld bool - newest string // "entry": the want names a newest build whose entry is answered; "none": it names one with no entry + noEntry bool // the want names a build no entry holds: a want names that build alone (design 47 H §750, H-A-37) }{ - {"the want's entry is not answered", false, false, ""}, - {"the want names an entry that is asked", false, false, ""}, - {"the want's entry is an older build", true, true, ""}, - // A-414: a running build with no entry composes from its want's newest build's entry; with neither entry it carries as today. - {"no entry for the fingerprint but one for newest", false, true, "entry"}, - {"neither entry", false, false, "none"}, + {"the want's entry is not answered", false, false, false}, + {"the want names an entry that is asked", false, false, false}, + {"the want's entry is an older build", true, true, false}, + {"no entry for the want's build", false, false, true}, } for _, row := range rows { t.Run(row.name, func(t *testing.T) { b := fixture() if strings.Contains(row.name, "asked") { - b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: "src2:" + strings.Repeat("cd", 32), Composed: "sha256:" + strings.Repeat("ef", 32)}) + b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: "src2:" + strings.Repeat("cd", 32)}) b.put(grants.ReadHave, "a.mod-x", nodeengine.HaveByNodeModuleValue{V: keys.Version, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK, Fp: "src2:" + strings.Repeat("cd", 32)}) b.entriesAsked = true @@ -5245,17 +5184,11 @@ func TestPassBeforeTheCatalogHalfComposesFromTheTrunkToo(t *testing.T) { digest := meshcatalogclient.ManifestDigest([]byte(older)) b.put(grants.ReadManifests, digest, meshcatalog.ManifestsByDigestValue{V: keys.Version, Module: "mod-x", Manifest: older}) fp := "src2:" + strings.Repeat("cd", 32) - b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp, Composed: "sha256:" + strings.Repeat("ef", 32)}) + b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp}) b.entry(fp, digest) } - if row.newest != "" { - fp, newest := "src2:"+strings.Repeat("cd", 32), "src2:"+strings.Repeat("ab", 32) - b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: fp, Newest: newest, Rule: meshwantsclient.RuleStep, Composed: "sha256:" + strings.Repeat("ef", 32)}) - if row.newest == "entry" { - digest := meshcatalogclient.ManifestDigest([]byte(older)) - b.put(grants.ReadManifests, digest, meshcatalog.ManifestsByDigestValue{V: keys.Version, Module: "mod-x", Manifest: older}) - b.entry(newest, digest) - } + if row.noEntry { + b.put(grants.ReadWants, "want.a.mod-x", meshwantsclient.Want{V: keys.Version, Fp: "src2:" + strings.Repeat("cd", 32)}) } b.mu.Lock() b.catalogWaited = []string{"the catalog half of the branch main"} @@ -5264,10 +5197,10 @@ func TestPassBeforeTheCatalogHalfComposesFromTheTrunkToo(t *testing.T) { if in.CatalogUnread == "" { t.Fatal("the catalog half is not unread") } - if row.newest == "none" && !slices.ContainsFunc(in.Gaps, func(g grants.Gap) bool { - return g.Input == "wanted manifests" && strings.Contains(g.Why, "newest build is not held") + if row.noEntry && !slices.ContainsFunc(in.Gaps, func(g grants.Gap) bool { + return g.Input == "wanted manifests" && strings.Contains(g.Why, "the running build has no catalog entry") }) { - t.Errorf("no gap says why the want's newest build was not taken: %+v", in.Gaps) + t.Errorf("no gap says the want's build has no entry: %+v", in.Gaps) } // An entry asked and not answered is no failed read while the catalog half is unread: the trunk's manifest composes the // account and the list is not held for it. @@ -5403,7 +5336,7 @@ func TestAKeptAccountGainsTheRightEveryAccountCarries(t *testing.T) { u.Publish = slices.DeleteFunc(slices.Clone(u.Publish), func(s string) bool { return s == names }) b.own[grants.StateUserList][key], _ = json.Marshal(u) // Its manifest is now held, the catalog half is unread, and the list changes (mod-x runs on b too). - b.refuse("mod-y", yManifest, "held for the test") + b.unreadable("mod-y", yManifest) b.mu.Lock() b.catalogWaited = []string{"the catalog half of the branch main"} b.mu.Unlock() @@ -5470,7 +5403,7 @@ func TestAHeldRunnerIsWrittenAsTheUnionOfTheListInForceAndWhatIsComposed(t *test fp := "src2:" + strings.Repeat("cd", 32) b.put(grants.ReadHave, "a.node-tools", nodeengine.HaveByNodeModuleValue{V: keys.Version, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK, Fp: fp}) b.entry(fp, digest) - b.refuse("node-tools", runner, "held for the test") + b.unreadable("node-tools", runner) b.mu.Lock() b.catalogWaited = []string{"the catalog half of the branch main"} b.mu.Unlock()