H-A-66: the indexer's revision verb, first views and seat-list part keep no callers
Every account may call every verb: the verb revision answers every caller, so its callers list and the node-engine account's mapping go; the first-view tools take no callers list and the tools bundle's env carries none; the seat-list part is made without one. Red only from the contract removals C1 and C3 (I7's manifest events, the gate's pin events, the entry's pull), followed in the next commits. Builds: design 47 H §752, §764 (every seat contract: callers); H-A-41, H-A-66 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -311,7 +311,7 @@ func main() {
|
||||
tools = append(tools, catalogTools(trunk.State, kept, watched)...)
|
||||
// The seat mesh-catalog's verb revision, a first view of the catalog half answered in this runtime of its own to exactly
|
||||
// the parts whose entry declares it (novox/hq ADR 0663).
|
||||
tools = append(tools, index.RevisionTool(revisions, kept, os.Getenv(stdio.ServedAs)), index.EntryTool(revisions, keptRead{stdio.State(index.EntryIndexState)}), index.EntriesTool(revisions, keptRead{stdio.State(index.EntryIndexState)}, keptRead{stdio.State(index.NamedState)}), index.VersionsTool(keptRead{stdio.State(index.VersionsState)}),
|
||||
tools = append(tools, index.RevisionTool(revisions, kept), index.EntryTool(revisions, keptRead{stdio.State(index.EntryIndexState)}), index.EntriesTool(revisions, keptRead{stdio.State(index.EntryIndexState)}, keptRead{stdio.State(index.NamedState)}), index.VersionsTool(keptRead{stdio.State(index.VersionsState)}),
|
||||
index.OutdatedTool(&index.Indexer{Versions: keptRead{stdio.State(index.VersionsState)}, Heard: keptRead{stdio.State(index.HeardState)}, Revisions: revisions}),
|
||||
index.InputsReadTool(keptRead{stdio.State(index.InputsState)}, stateobjects.ForState(index.InputsState).Objects))
|
||||
tools = append(tools, index.CatalogRevisionTools(revisions, asks, time.Now, func(what, why string) error {
|
||||
|
||||
@@ -14,16 +14,15 @@ import (
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// viewTools are the indexer's first-view tools (ADR 0621 §1, ADR 0622 §1), each answering only the callers its manifest
|
||||
// writes into its env value (views.CallersEnv), and its ordinary read tools (design 25 § 12.2). Every one reads only the
|
||||
// viewTools are the indexer's first-view tools (ADR 0621 §1, ADR 0622 §1), each answering every caller (design 47 H
|
||||
// §752, H-A-66), and its ordinary read tools (design 25 § 12.2). Every one reads only the
|
||||
// indexer's own states, so it answers as soon as the runtime of its own is connected (ADR 0621 §3).
|
||||
func viewTools(getenv func(string) string, state func(string) views.Source, now func() time.Time) []stdio.Tool {
|
||||
module := getenv(stdio.ServedAs) // the module the runtime serves the tools as, never a constant (design 47 G A-296)
|
||||
marks := state(views.MarksState)
|
||||
var out []stdio.Tool
|
||||
for _, t := range index.FirstViewTools {
|
||||
out = append(out, views.FirstViewTool(module, t.Tool, t.State, t.Words,
|
||||
views.ParseCallers(getenv(views.CallersEnv(t.Tool))), state(t.State), marks, now))
|
||||
out = append(out, views.FirstViewTool(module, t.Tool, t.State, t.Words, state(t.State), marks, now))
|
||||
}
|
||||
for _, t := range index.ReadTools {
|
||||
out = append(out, views.ReadTool(module, t.Tool, t.State, t.Words, state(t.State), marks, now))
|
||||
|
||||
@@ -112,7 +112,7 @@ func (b *seatBus) said(c index.SeatDefinitionChanged) {
|
||||
// subject (ADR 0437 §4), and its list is its own state seat-definitions, which indexer_seat_definition and the seat's verb
|
||||
// seat-definitions read. It returns the part, whose status the indexer's health can show.
|
||||
func followSeatList(bus *seatBus, say func(context.Context, index.SeatDefinitionChanged) error, logf func(string, ...any), changed func()) (*seatlist.Part, func(context.Context, index.SeatDefinitionChanged) error) {
|
||||
part := seatlist.NewPart(toolPrefix, nil)
|
||||
part := seatlist.NewPart(toolPrefix)
|
||||
part.Follow(bus, changed, logf)
|
||||
return part, func(ctx context.Context, c index.SeatDefinitionChanged) error {
|
||||
if err := say(ctx, c); err != nil {
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestTheSeatListIsReadAgainWhenItsStatesAreBound(t *testing.T) {
|
||||
t.Fatal("the list was read with its states missing")
|
||||
}
|
||||
// A-179, A-186: the definition the verb input's callers are checked against is the list's once read, none before.
|
||||
if _, ok := seatlist.Definition(seatlist.NewPart(toolPrefix, nil).Reader, seatlist.Seat)(); ok {
|
||||
if _, ok := seatlist.Definition(seatlist.NewPart(toolPrefix).Reader, seatlist.Seat)(); ok {
|
||||
t.Error("a definition is answered before the seat list's reader started")
|
||||
}
|
||||
if _, ok := seatlist.Definition(part.Reader, seatlist.Seat)(); ok {
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
t.Errorf("said %+v, want main 1, then the escaped branch 1 and 2", said)
|
||||
}
|
||||
answer := func(branch string, revision int64) meshcatalog.RevisionAnswer {
|
||||
a, err := Revision(ctx, ix.Revisions, nil, "indexer", "reader", meshcatalog.RevisionInput{Branch: branch, Revision: revision})
|
||||
a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Revision: revision})
|
||||
if err != nil {
|
||||
t.Fatalf("revision of %q: %v", branch, err)
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
// A-205: `source` answers the branch's revision taken in from that source revision; a candidate's group alone answers its
|
||||
// newest revision, whatever its heads.
|
||||
bySource := func(branch string, source int64) (meshcatalog.RevisionAnswer, error) {
|
||||
return Revision(ctx, ix.Revisions, nil, "indexer", "reader", meshcatalog.RevisionInput{Branch: branch, Source: source})
|
||||
return Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Source: source})
|
||||
}
|
||||
if a, err := bySource("main", 5); err != nil || a.Revision.Revision != 1 || a.Entries[0].Commit != "c1" {
|
||||
t.Errorf("main's source 5 answered %+v (%v)", a.Revision, err)
|
||||
@@ -89,44 +89,24 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if a, err := Revision(ctx, ix.Revisions, nil, "indexer", "reader", meshcatalog.RevisionInput{Group: "run-ab"}); err != nil || a.Revision.Revision != 4 || a.Revision.Heads != "h2" || a.Entries[0].Commit != "c9" {
|
||||
if a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Group: "run-ab"}); err != nil || a.Revision.Revision != 4 || a.Revision.Heads != "h2" || a.Entries[0].Commit != "c9" {
|
||||
t.Errorf("a group alone answered %+v (%v), want its newest revision 4", a.Revision, err)
|
||||
}
|
||||
if _, err := Revision(ctx, ix.Revisions, nil, "indexer", "reader", meshcatalog.RevisionInput{Group: "run-none"}); err == nil {
|
||||
if _, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Group: "run-none"}); err == nil {
|
||||
t.Error("a candidate never kept was answered")
|
||||
}
|
||||
}
|
||||
|
||||
// A-450: a node-engine's call is proved as node.<machine>; it is answered as the module whose entry serves the seat node-engine
|
||||
// (a part of the revision, so on the list as its own call would be), and refused when the revision holds no such module or the
|
||||
// account is no node's.
|
||||
func TestTheNodeEngineReadsTheRevisionAsTheModuleHoldingItsSeat(t *testing.T) {
|
||||
// H-A-66 (design 47 H §752): the verb revision answers every caller, even one the runtime proved none for and whose module
|
||||
// declares no invokes.
|
||||
func TestTheRevisionAnswersEveryCaller(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
invokes []string
|
||||
caller string
|
||||
want bool
|
||||
}{
|
||||
{"the engine's module declares the verb", []string{RevisionInvoke}, "node.novox", true},
|
||||
{"no module of the revision serves the seat node-engine", nil, "node.novox", false},
|
||||
{"a caller with a dot after the machine is no engine's account", []string{RevisionInvoke}, "node.novox.extra", false},
|
||||
{"a module that serves no engine seat is no engine", []string{RevisionInvoke}, "node.", false},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)}
|
||||
engine := meshcatalog.CatalogEntry{Module: "mesh-host", Repository: "novox/h", Commit: "c1", Manifest: map[string]any{},
|
||||
Serves: []string{"seat:node-engine.compose", "seat:node-engine.compose-candidate"}, Invokes: c.invokes}
|
||||
if c.name == "no module of the revision serves the seat node-engine" {
|
||||
engine.Serves = nil
|
||||
}
|
||||
if err := ix.KeepBranchEntries(ctx, "main", 5, map[string]meshcatalog.CatalogEntry{"mesh-host": engine}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err := Revision(ctx, ix.Revisions, nil, "indexer", c.caller, meshcatalog.RevisionInput{Branch: "main"})
|
||||
if (err == nil) != c.want {
|
||||
t.Errorf("caller %q: err %v, want answered %v", c.caller, err, c.want)
|
||||
}
|
||||
})
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)}
|
||||
engine := meshcatalog.CatalogEntry{Module: "mesh-host", Repository: "novox/h", Commit: "c1", Manifest: map[string]any{}}
|
||||
if err := ix.KeepBranchEntries(ctx, "main", 5, map[string]meshcatalog.CatalogEntry{"mesh-host": engine}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a, err := RevisionTool(ix.Revisions, nil).Run(map[string]any{"branch": "main"}); err != nil || a.(meshcatalog.RevisionAnswer).NoneYet {
|
||||
t.Errorf("an unproven caller answered %+v, %v; want the revision", a, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,58 +17,15 @@ import (
|
||||
// part reads the catalog half (novox/hq ADR 0663 §2).
|
||||
const RevisionInvoke = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbRevision
|
||||
|
||||
// RevisionCallers are the parts the newest trunk revision's entries say declare the verb revision in their invokes,
|
||||
// sorted, the holder itself never among them (ADR 0663 §2: granted to exactly the parts that declare it). A single `*`
|
||||
// in invokes declares every seat verb, as the grants part reads it (A-390).
|
||||
//
|
||||
// Lead answer A-395: every part the newest trunk revision holds may read it, and so may the tool runner, which reads the
|
||||
// catalog half for each module it serves on that module's or its own account, the holder's own tools too (A-401).
|
||||
func RevisionCallers(entries []meshcatalog.CatalogEntry, holder string) stdio.Callers {
|
||||
out := stdio.Callers{ToolRunner}
|
||||
for _, e := range entries {
|
||||
if !slices.Contains(out, e.Module) {
|
||||
out = append(out, e.Module)
|
||||
}
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// nodeEngineSeat is the seat whose holder's calls come as the account of a node, not of a module process.
|
||||
const nodeEngineSeat = "node-engine"
|
||||
|
||||
// CallerModule is the caller a callers list is checked against (design 47 G A-450; ADR 0621 §2, ADR 0663 §2): the proof of a
|
||||
// node-engine's call is the account `node.<machine>` (one dot), which no list entry names, so it stands for the module whose
|
||||
// entry of the revision serves the seat node-engine, the part that declares the verb. Any other caller is its own. Every verb
|
||||
// of the seat mesh-catalog the indexer holds that checks its caller reads it through this one function.
|
||||
func CallerModule(entries []meshcatalog.CatalogEntry, caller string) string {
|
||||
machine, ok := strings.CutPrefix(caller, "node.")
|
||||
if !ok || machine == "" || strings.Contains(machine, ".") {
|
||||
return caller
|
||||
}
|
||||
for _, e := range entries {
|
||||
for _, word := range e.Serves {
|
||||
if strings.HasPrefix(word, "seat:"+nodeEngineSeat+".") {
|
||||
return e.Module
|
||||
}
|
||||
}
|
||||
}
|
||||
return caller
|
||||
}
|
||||
|
||||
// ToolRunner is the module of every node's tool runner, the runtime every module's tools run in (A-395).
|
||||
const ToolRunner = "node-tools"
|
||||
|
||||
// Revision answers the seat mesh-catalog's verb revision from the indexer's own objects (ADR 0663 §1, §3): one catalog
|
||||
// graph revision, the trunk's newest when the input names none, a kept trunk revision by its number, or a candidate's by
|
||||
// its group and heads, with one page of its entries whole, by module name. The caller is the runtime's proof: it is
|
||||
// answered only when the newest trunk revision's entry of its module declares the verb in invokes, and the holder is
|
||||
// refused too. With no trunk revision kept yet the answer is `none-yet` alone (design 47 G §530), never an empty
|
||||
// its group and heads, with one page of its entries whole, by module name. Every caller is answered (design 47 H §752,
|
||||
// H-A-66: every account may call every verb). With no trunk revision kept yet the answer is `none-yet` alone (design 47 G §530), never an empty
|
||||
// catalog and never an error.
|
||||
//
|
||||
// kept, when not nil, is the trunk's newest revision held in memory: the trunk's newest answers from it with no read of
|
||||
// the bucket (A-487c); a candidate, a branch and an older number read the bucket.
|
||||
func Revision(ctx context.Context, o Objects, kept *KeptTrunk, holder, caller string, in meshcatalog.RevisionInput) (meshcatalog.RevisionAnswer, error) {
|
||||
func Revision(ctx context.Context, o Objects, kept *KeptTrunk, in meshcatalog.RevisionInput) (meshcatalog.RevisionAnswer, error) {
|
||||
var out meshcatalog.RevisionAnswer
|
||||
var newest meshcatalog.CatalogRevision
|
||||
var ok bool
|
||||
@@ -86,10 +43,6 @@ func Revision(ctx context.Context, o Objects, kept *KeptTrunk, holder, caller st
|
||||
// An answer is told by its fields (design 47 G §530): no trunk revision kept yet is `none-yet`, no error.
|
||||
return meshcatalog.RevisionAnswer{NoneYet: true}, nil
|
||||
}
|
||||
caller = CallerModule(trunkEntries, caller)
|
||||
if err := views.Refusal(meshcatalog.Seat+"."+meshcatalog.VerbRevision, RevisionCallers(trunkEntries, holder), caller); err != nil {
|
||||
return out, fmt.Errorf("%w (novox/hq ADR 0663 §2: a part reads it by declaring %s in invokes)", err, RevisionInvoke)
|
||||
}
|
||||
// A watched branch other than the first keeps its own revisions (A-85); the first's are the trunk's. The branch is
|
||||
// named as a key name is escaped, so it is read back to the branch's own name.
|
||||
branch, err := keys.UnescapeName(in.Branch)
|
||||
@@ -161,13 +114,13 @@ func Revision(ctx context.Context, o Objects, kept *KeptTrunk, holder, caller st
|
||||
|
||||
// RevisionTool is the verb revision as the tool mesh-catalog.revision of the indexer's own runtime (ADR 0663 §1): the
|
||||
// tool runner describes it with the seat's definition, so it carries no description or input of its own.
|
||||
func RevisionTool(o Objects, kept *KeptTrunk, holder string) stdio.Tool {
|
||||
func RevisionTool(o Objects, kept *KeptTrunk) stdio.Tool {
|
||||
return stdio.Tool{Name: meshcatalog.Seat + "." + meshcatalog.VerbRevision, Run: func(args map[string]any) (any, error) {
|
||||
var in meshcatalog.RevisionInput
|
||||
if raw, err := json.Marshal(args); err == nil {
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
}
|
||||
return Revision(context.Background(), o, kept, holder, stdio.CallerOf(args), in)
|
||||
return Revision(context.Background(), o, kept, in)
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// FirstViewTools are the indexer's first-view tools (ADR 0621 §1, ADR 0622 §1, ADR 0631 §1): the tool, the state it answers, and
|
||||
// the words of what that state holds. Each answers only its callers list (CallersEnv), which the manifest writes. Which
|
||||
// the words of what that state holds. Each answers every caller (design 47 H §752, H-A-66). Which
|
||||
// modules exist is the seat mesh-catalog's verb revision (ADR 0663 §1, RevisionTool), granted by declaration, not by a
|
||||
// list; the first view modules stays beside it, in its form before milestone G and answered from the newest trunk
|
||||
// revision (TrunkStates), until the grants part reads the catalog half (design 47 G A-354).
|
||||
|
||||
@@ -273,33 +273,10 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
|
||||
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
||||
t.Errorf("runs-as = %q, secrets-owner %q: the tools bundle runs on the indexer's own account (ADR 0621 §1)", m.RunsAs, m.SecretsOwner)
|
||||
}
|
||||
// ADR 0621 §2, ADR 0622 §1, ADR 0631 §1: each first-view tool answers exactly its readers; the indexer is on none, and
|
||||
// graph answers the assigner alone.
|
||||
// ADR 0663 §2: revision has no callers list; it answers the parts whose entry declares it.
|
||||
// Design 47 G A-354: modules answers its readers as before milestone G.
|
||||
callers := map[string]string{"manifests": "mesh-grants,node-tools,mesh-delivery-assigner", "modules": "mesh-grants,node-tools,mesh-delivery-assigner", "verdicts": "mesh-grants",
|
||||
"graph": "mesh-delivery-assigner"}
|
||||
// H-A-66 (design 47 H §752): no first-view tool keeps a callers list, so the tools bundle carries none in its env.
|
||||
for _, a := range m.Build.Artifacts {
|
||||
if a.Name != "tools" {
|
||||
continue
|
||||
}
|
||||
if len(a.Env) != len(callers) {
|
||||
t.Errorf("tools env = %v, want only the four callers lists", a.Env)
|
||||
}
|
||||
for tool, list := range callers {
|
||||
if got := a.Env[views.CallersEnv(tool)]; got != list {
|
||||
t.Errorf("%s callers = %q, want %q", tool, got, list)
|
||||
}
|
||||
if views.ParseCallers(a.Env[views.CallersEnv(tool)]).Allows("n1." + m.Module) {
|
||||
t.Errorf("%s answers the indexer itself", tool)
|
||||
}
|
||||
}
|
||||
// ADR 0631 How it is checked: graph refuses every caller but the assigner, the indexer itself included.
|
||||
graphCallers := views.ParseCallers(a.Env[views.CallersEnv("graph")])
|
||||
for caller, refused := range map[string]bool{"n1.mesh-delivery-assigner": false, "n1.mesh-grants": true, "n1.node-tools": true, "n1." + m.Module: true} {
|
||||
if err := views.Refusal("graph", graphCallers, caller); (err != nil) != refused {
|
||||
t.Errorf("graph to %s: refused %v, want refused %v", caller, err, refused)
|
||||
}
|
||||
if a.Name == "tools" && len(a.Env) != 0 {
|
||||
t.Errorf("tools env = %v, want no callers list", a.Env)
|
||||
}
|
||||
}
|
||||
// ADR 0635 §5: its views family is its ordinary events, `views.<state>` among its emits, and its one stream is the
|
||||
|
||||
@@ -242,13 +242,7 @@
|
||||
"binary": "mesh-delivery-indexer-tools",
|
||||
"loads": [
|
||||
"mesh-delivery-indexer-tools"
|
||||
],
|
||||
"env": {
|
||||
"MESH_VIEW_CALLERS_MANIFESTS": "mesh-grants,node-tools,mesh-delivery-assigner",
|
||||
"MESH_VIEW_CALLERS_MODULES": "mesh-grants,node-tools,mesh-delivery-assigner",
|
||||
"MESH_VIEW_CALLERS_VERDICTS": "mesh-grants",
|
||||
"MESH_VIEW_CALLERS_GRAPH": "mesh-delivery-assigner"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user