From 4b6d76d3dd281df3588e8df70e945f9ef36b19fd Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:51:03 +0100 Subject: [PATCH 1/4] gitea: the state fingerprints is in KEPT, so it is announced and its tools read it (review r1 finding 1) Builds: design 47 H2 H-A-589 (2), G A-287 --- modules/gitea/kept.ts | 1 + modules/gitea/test/kept.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/gitea/kept.ts b/modules/gitea/kept.ts index deba4f89d..d39c1abc9 100644 --- a/modules/gitea/kept.ts +++ b/modules/gitea/kept.ts @@ -9,6 +9,7 @@ export const KEPT: readonly { readonly name: string; readonly readable?: boolean { name: "calls" }, { name: "bound", readable: true }, { name: "findings", readable: true }, + { name: "fingerprints" }, { name: "failed-steps" }, { name: "first-views" }, { name: "idle" }, diff --git a/modules/gitea/test/kept.test.ts b/modules/gitea/test/kept.test.ts index 5595321c0..7d254630c 100644 --- a/modules/gitea/test/kept.test.ts +++ b/modules/gitea/test/kept.test.ts @@ -16,8 +16,8 @@ test("the states the module announces are the states its manifest declares", asy test("the announcement has the layout mesh-sdk's go/announce reads: version 1, the module, the node, the states sorted by name", async () => { const { statesAnnouncement } = await import("../kept.ts"); - assert.deepEqual(statesAnnouncement("gitea", "ace"), { v: 1, module: "gitea", node: "ace", states: [{ name: "announced" }, { name: "bound", readable: true }, { name: "calls" }, { name: "failed-steps" }, { name: "findings", readable: true }, { name: "first-views" }, { name: "idle" }, { name: "taken" }, { name: "token-lease" }, { name: "transfers" }] }); - assert.deepEqual(statesAnnouncement("gitea", undefined), { v: 1, module: "gitea", states: [{ name: "announced" }, { name: "bound", readable: true }, { name: "calls" }, { name: "failed-steps" }, { name: "findings", readable: true }, { name: "first-views" }, { name: "idle" }, { name: "taken" }, { name: "token-lease" }, { name: "transfers" }] }); + assert.deepEqual(statesAnnouncement("gitea", "ace"), { v: 1, module: "gitea", node: "ace", states: [{ name: "announced" }, { name: "bound", readable: true }, { name: "calls" }, { name: "failed-steps" }, { name: "findings", readable: true }, { name: "fingerprints" }, { name: "first-views" }, { name: "idle" }, { name: "taken" }, { name: "token-lease" }, { name: "transfers" }] }); + assert.deepEqual(statesAnnouncement("gitea", undefined), { v: 1, module: "gitea", states: [{ name: "announced" }, { name: "bound", readable: true }, { name: "calls" }, { name: "failed-steps" }, { name: "findings", readable: true }, { name: "fingerprints" }, { name: "first-views" }, { name: "idle" }, { name: "taken" }, { name: "token-lease" }, { name: "transfers" }] }); }); test("index.ts says the announcement as the event `states` before the tools are served", () => { From 1dbc2b6f88b5e5d85984195751c45a9927559853 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:52:49 +0100 Subject: [PATCH 2/4] gitea: the token lists are read before the retirement of the admin's old token, and the two missing rows of the token files' test (review r1 findings 4, 5) Builds: design 47 H2 H-A-699 (2), H-A-699 how checked --- modules/gitea/test/token.test.ts | 37 ++++++++++++++++++++++++++++++++ modules/gitea/token.ts | 2 ++ 2 files changed, 39 insertions(+) diff --git a/modules/gitea/test/token.test.ts b/modules/gitea/test/token.test.ts index bfe5da014..18e5b6d1b 100644 --- a/modules/gitea/test/token.test.ts +++ b/modules/gitea/test/token.test.ts @@ -17,6 +17,7 @@ import { join } from "node:path"; import { collectTools } from "@novox/mesh-sdk/tools"; import { AdminRefused, MintedToken, TOKEN_NAME, TOKEN_SCOPES, leaseOverState, openValue, vaultOverBus, vaultValue, type MintedTokenOptions } from "../dist/token.js"; import { TOKEN_FILE_UNREVOKED, passOver, type ForgeTokens, type ListedToken } from "../dist/tokenfiles.js"; +import { PACKAGES_TOKEN_NAME, PACKAGES_TOKEN_SCOPES } from "../dist/packages-account.js"; import { tokenLeaseTool } from "../dist/tools/tokenlease.js"; import { fakeBus } from "./fakebus.ts"; import { GiteaClient } from "../dist/client.js"; @@ -41,6 +42,8 @@ interface Forge { /** Plant a token by name, beside any other of the same name, as a raced mint would. */ plant(name: string, sha1?: string, scopes?: string[]): void; scopesOf: Map; + /** The account the last mint was for; while it is the tools' account the admin's own list reads empty. */ + mintedFor: string; admins: Map; pullState: string; pullTitle: string; @@ -237,6 +240,8 @@ function fakeForge(): Promise { url: `http://127.0.0.1:${port}`, get mints() { return forge.mints; }, get lastScopes() { return forge.lastScopes; }, + get mintedFor() { return forge.mintedFor; }, + set mintedFor(v: string) { forge.mintedFor = v; }, get pullState() { return forge.pullState; }, get pullTitle() { return forge.pullTitle; }, get branchDeleted() { return forge.branchDeleted; }, @@ -704,6 +709,29 @@ test("a start ends the token files: the lists are read before the first mint dro assert.deepEqual(ORDER, [`own-put ${VAULT} 1`, `delete ${TOKEN_NAME}`], "the own-put, then the drop of the old name"); assert.ok(logs.some((l) => l.includes("token.tmp") && l.includes("no whole token")), logs.join("\n")); assert.ok(logs.every((l) => !l.includes(HEX) && !l.includes(vaulted(bus))), "no line names a token"); + + // A `.tmp` holding a whole token goes with its pair: revoked at the forge by its id, then deleted (H-A-699). + const HEX2 = "fedcba9876543210fedcba9876543210fedcba98"; + forge.tokens.clear(); + forge.plant("kept-by-the-tmp", HEX2, SCOPES); + await leftFiles(env, { "token.tmp": HEX2 + "\n", "token.scopes": SCOPES_LINE + "\n" }); + forge.deletedBy.length = 0; + await minted(env, logs, { stateDir: env.MESH_GITEA_STATE_DIR, tokenFile: "token", findings, listAccounts: async () => ["mesh-tools"] }).listRepos(); + assert.deepEqual(await left(env), [], logs.join("\n")); + assert.equal(forge.tokens.has("kept-by-the-tmp"), false, "the .tmp's token is revoked at the forge"); + + // Both pairs, the tools' `token` and the packages' `packages-token`, go at a first mint, each by its own source. + const env2 = (await delivered(forge)).env; + forge.tokens.clear(); + forge.plant(TOKEN_NAME, HEX, SCOPES); + forge.plant(PACKAGES_TOKEN_NAME, HEX2, PACKAGES_TOKEN_SCOPES); + await leftFiles(env2, { token: HEX + "\n", "token.scopes": SCOPES_LINE + "\n", "packages-token": HEX2 + "\n", "packages-token.scopes": "write:package for mesh-packages\n" }); + const both = { stateDir: env2.MESH_GITEA_STATE_DIR, tokenFile: "token", findings, listAccounts: async () => ["mesh-tools", "mesh-packages"] }; + await new GiteaClient(env2.MESH_GITEA_URL!, source(env2, logs, both)).listRepos(); + await source(env2, logs, { ...both, account: "mesh-packages", oldName: PACKAGES_TOKEN_NAME, + scopes: PACKAGES_TOKEN_SCOPES, tokenFile: "packages-token" }).current(); + assert.deepEqual(await left(env2), [], logs.join("\n")); + assert.equal(forge.tokens.has(PACKAGES_TOKEN_NAME), false, "the packages file's token is revoked at the forge"); }); test("a token file stays when the vault refuses the own-put, and when the forge refuses the revocation or matches nothing: said, written as a finding, cleared once the pair goes", async () => { @@ -759,4 +787,13 @@ test("a start with the vault holding a token and a file left runs the pass; with const failing = { ...options, listAccounts: async () => { throw new Error("no lists without files"); } }; await new GiteaClient(env.MESH_GITEA_URL!, source(env, quiet, failing)).listRepos(); assert.ok(quiet.every((l) => !l.includes("no lists")), quiet.join("\n")); + + // With a retire file left too, the lists are read before the admin's old token goes, so a file holding that token ends (H-A-699 (2)). + forge.mintedFor = ""; // the admin's own list holds the old token, as the forge would list it + forge.plant(TOKEN_NAME, HEX, SCOPES); + await leftFiles(env, { token: HEX + "\n", "token.scopes": SCOPES_LINE + "\n", "mesh-tools.retire-admin": "now\n" }); + const retiring: string[] = []; + await new GiteaClient(env.MESH_GITEA_URL!, source(env, retiring, { ...options, findings: sink() })).listRepos(); + assert.ok(retiring.some((l) => l.includes(`deleted 1 token(s) named "${TOKEN_NAME}"`)), retiring.join("\n")); + assert.deepEqual(await left(env), [], retiring.join("\n")); }); diff --git a/modules/gitea/token.ts b/modules/gitea/token.ts index 52eb09991..edbd7593f 100644 --- a/modules/gitea/token.ts +++ b/modules/gitea/token.ts @@ -380,6 +380,8 @@ export class MintedToken implements TokenSource { } if (this.held === null) { this.log(`reusing the token the vault keeps as ${vaultName(this.opts.account)} (generation ${kept.generation})`); + // The forge's token lists are read before this start deletes any token (H-A-699 (2)). + await this.readFileLists(); // A retirement of the admin's old token that failed after the mint is tried again, once a process. if (this.retireFile && existsSync(this.retireFile)) await this.retireAdmin().catch((err) => this.log(`${err}`)); } From 1ebb59a9d7d5fe081fa1b4c24df4f2ba8e85eb78 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:55:13 +0100 Subject: [PATCH 3/4] mesh-config, mesh-provisioner: Unread is asked in the verb and tool handlers only, the module's own start keeps the waiting read (review r1 finding 3) Builds: design 47 H2 H-A-708 (2) --- modules/mesh-config/cmd/mesh-config/main.go | 32 +++++++++++++++++-- .../mesh-config/cmd/mesh-config/ownstates.go | 31 ++++++++++++------ .../mesh-config/cmd/mesh-config/quiet_test.go | 17 +++++++--- .../cmd/mesh-provisioner/holder.go | 31 ++++++++++++------ .../cmd/mesh-provisioner/holder_test.go | 12 +++++-- .../cmd/mesh-provisioner/holdertools.go | 6 ++++ 6 files changed, 103 insertions(+), 26 deletions(-) diff --git a/modules/mesh-config/cmd/mesh-config/main.go b/modules/mesh-config/cmd/mesh-config/main.go index 1447b5062..3d1a2d9d5 100644 --- a/modules/mesh-config/cmd/mesh-config/main.go +++ b/modules/mesh-config/cmd/mesh-config/main.go @@ -58,6 +58,30 @@ func (r runtimeStore) Get(state, key string) (*Entry, error) { return &Entry{Key: e.Key, Value: e.Value, Revision: e.Revision}, nil } +// Away is the fault `away` while a copy of this module's own states is not read yet: a verb or tool handler asks it +// (asking), the module's own start never does (design 47 H2 H-A-708 (2)). The first views of the owners stay the fault +// `away` at the read itself, since a picture not answered yet is no answer for a pass to resolve from. +func (r runtimeStore) Away() error { + if r.own == nil { + return nil + } + return r.own.Unread() +} + +// asking is a tool whose handler answers `away` at once while what it reads is not read yet (design 47 H2 H-A-708 (2)). +func asking(c *Config, t stdio.Tool) stdio.Tool { + run := t.Run + t.Run = func(a map[string]any) (any, error) { + if s, ok := c.Store.(interface{ Away() error }); ok { + if err := s.Away(); err != nil { + return nil, err + } + } + return run(a) + } + return t +} + func (r runtimeStore) Put(state, key string, value any) error { if r.own != nil && ownStates[state] { return r.own.write(state, key, value) @@ -418,7 +442,11 @@ func Tools(c *Config) []stdio.Tool { rows, err := c.Renames(strings.TrimSpace(m), true) return map[string]any{"renames": seatRenames(rows)}, err }} - return append(append(switchTools(c), viewTools(c, func() *ownerViews { return theViews })...), renames, stdio.Tool{ + var own []stdio.Tool + for _, t := range switchTools(c) { + own = append(own, asking(c, t)) + } + return append(append(own, viewTools(c, func() *ownerViews { return theViews })...), asking(c, renames), asking(c, stdio.Tool{ Name: Seat + "." + Verb, Description: "Set, clear, list or read the history of config values (novox/hq ADR 0348). A value is set at " + "one level: mesh config (no module, no node) or node config (a node) for a predefined key, or a " + @@ -452,7 +480,7 @@ func Tools(c *Config) []stdio.Tool { call.Caller = stdio.CallerOf(args) return c.Do(call) }, - }) + })) } // callOf reads a call's arguments strictly: an argument it does not know is refused, not ignored. diff --git a/modules/mesh-config/cmd/mesh-config/ownstates.go b/modules/mesh-config/cmd/mesh-config/ownstates.go index e7036caec..e1c7e3a1a 100644 --- a/modules/mesh-config/cmd/mesh-config/ownstates.go +++ b/modules/mesh-config/cmd/mesh-config/ownstates.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "sort" stdio "git.novox.be/novox/mesh-sdk/go" ) @@ -36,10 +37,8 @@ func newOwnCopy() *ownCopy { } func (o *ownCopy) get(state, key string) (*Entry, error) { - // A state whose copy is not read yet is the fault `away` at once, never a wait (design 47 H2 H-A-708 (2)). - if err := o.copy.Unread(state); err != nil { - return nil, err - } + // A read waits for a state whose copy is not read yet: the module's own start (the first decision, the deadline, the + // start judgement) is one. A verb or tool handler asks Unread first (design 47 H2 H-A-708 (2)). raw, ok, err := o.copy.Get(state, key) if err != nil || !ok { return nil, err @@ -48,14 +47,28 @@ func (o *ownCopy) get(state, key string) (*Entry, error) { } func (o *ownCopy) keys(state string) ([]string, error) { - if err := o.copy.Unread(state); err != nil { - return nil, err - } return o.copy.Keys(state) } -// follow starts the watch of every state the copy holds, each on its goroutine, so a read asked before one is in is -// answered `away` and the copy is read by the time it is asked again (Unread; design 47 H2 H-A-708 (2)). +// Unread is the fault `away` naming the first state, in name order, whose copy is not read yet, nil when every one is: a +// verb or tool handler asks it before it reads, so a call made while the module starts is answered at once (design 47 H2 +// H-A-708 (2)); the module's own reads wait for the copy. +func (o *ownCopy) Unread() error { + states := make([]string, 0, len(ownStates)) + for state := range ownStates { + states = append(states, state) + } + sort.Strings(states) + for _, state := range states { + if err := o.copy.Unread(state); err != nil { + return err + } + } + return nil +} + +// follow starts the watch of every state the copy holds, each on its goroutine, so a handler's ask is answered `away` until +// the copy is read (Unread; design 47 H2 H-A-708 (2)). func (o *ownCopy) follow() { for state := range ownStates { go o.copy.Follow(state, nil) diff --git a/modules/mesh-config/cmd/mesh-config/quiet_test.go b/modules/mesh-config/cmd/mesh-config/quiet_test.go index 4bfdaa057..0036270b3 100644 --- a/modules/mesh-config/cmd/mesh-config/quiet_test.go +++ b/modules/mesh-config/cmd/mesh-config/quiet_test.go @@ -204,15 +204,24 @@ func TestAnOwnStateIsReadFromItsWatchedCopyNotKeyByKey(t *testing.T) { } n := len(b.held[ValuesState]) own := b.ownCopy() - // H-A-708 (2): before the state's copy is read a read is the fault `away` at once, naming the state; the start's watch reads it. + // H-A-708 (2): a handler asks Unread and is answered `away` at once, naming the state; the module's own read waits for the + // copy, which the start's watch reads, so its first decision and its deadline are never lost to `away`. var away *busretry.Away - if _, err := own.keys(ValuesState); !errors.As(err, &away) || away.Part != "the state "+ValuesState || !strings.HasPrefix(away.Words, "not read yet since ") { + if err := own.Unread(); !errors.As(err, &away) || !strings.HasPrefix(away.Part, "the state ") || !strings.HasPrefix(away.Words, "not read yet since ") { t.Fatalf("before the copy is read: %v", err) } - if _, err := own.get(ValuesState, "mesh.key-0s"); !errors.As(err, &away) { - t.Fatalf("a get before the copy is read: %v", err) + c := &Config{Store: runtimeStore{own: own}} + ran := false + tool := asking(c, stdio.Tool{Name: "t", Run: func(map[string]any) (any, error) { ran = true; return nil, nil }}) + if _, err := tool.Run(nil); !errors.As(err, &away) || ran { + t.Fatalf("a tool's handler before the copy is read: ran %v, %v", ran, err) } + waited := make(chan error, 1) + go func() { _, err := own.keys(ValuesState); waited <- err }() own.copy.Follow(ValuesState, nil) + if err := <-waited; err != nil { + t.Fatalf("the module's own read before the copy is read must wait for it, not answer away: %v", err) + } for pass := 0; pass < 3; pass++ { keys, err := own.keys(ValuesState) if err != nil || len(keys) != n { diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go index 963ad9157..460739f58 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holder.go @@ -1738,22 +1738,38 @@ func (w watchingStore) copied(state string) bool { return slices.Contains(WatchedReads, state) || slices.Contains(OwnStates, state) } -// unread is the fault `away` while the copy of a state the holder follows from its start is not read yet (design 47 H2 -// H-A-708 (2), H-A-717 DQ-55): a call made then is answered at once, never waits for the copy. -func (w watchingStore) unread(state string) error { +// Unread is the fault `away` while the copy of a state the holder follows from its start is not read yet (design 47 H2 +// H-A-708 (2), H-A-717 DQ-55). A verb or tool handler asks it (Holder.Away) so a call made then is answered at once; the +// store's own reads, the passes' and the start's, wait for the copy. +func (w watchingStore) Unread(state string) error { if !slices.Contains(WatchedReads, state) { return nil } return w.ws.Unread(state) } +// Away is the fault `away` when the copy of any of these states, or of every followed state when none is named, is not +// read yet: a verb or tool handler asks it before it reads, never the passes (design 47 H2 H-A-708 (2)). +func (h *Holder) Away(states ...string) error { + u, ok := h.Store.(interface{ Unread(string) error }) + if !ok { + return nil + } + if len(states) == 0 { + states = WatchedReads + } + for _, state := range states { + if err := u.Unread(state); err != nil { + return err + } + } + return nil +} + func (w watchingStore) Get(state, key string) (*Entry, error) { if !w.copied(state) { return w.Store.Get(state, key) } - if err := w.unread(state); err != nil { - return nil, err - } v, found, err := w.ws.Get(state, key) if err != nil || !found { return nil, err @@ -1765,9 +1781,6 @@ func (w watchingStore) Keys(state string) ([]string, error) { if !w.copied(state) { return w.Store.Keys(state) } - if err := w.unread(state); err != nil { - return nil, err - } return w.ws.Keys(state) } diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go index e851efd0b..d18157f19 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holder_test.go @@ -489,8 +489,16 @@ func TestAModuleHeldWithoutAWantIsComposedAtTheBuildItRuns(t *testing.T) { wk := &work{pending: map[string]bool{}, wake: make(chan struct{}, 1)} // H-A-708 (2): a state the holder follows from its start, asked before its copy is read, is the fault `away` at once. var away *busretry.Away - if _, err := m.h.Store.Keys(WantsRead); !errors.As(err, &away) || !strings.HasPrefix(away.Words, "not read yet since ") || len(watches) != 0 { - t.Fatalf("a read before the copy: %v, watches %v", err, watches) + // A handler asks Away and is answered at once; the holder's own reads (the passes, the start) wait, so the first read + // starts the watch and is answered from it, never `away`. + if err := m.h.Away(); !errors.As(err, &away) || !strings.HasPrefix(away.Words, "not read yet since ") || len(watches) != 0 { + t.Fatalf("a handler's ask before the copy: %v, watches %v", err, watches) + } + if _, err := m.h.Store.Keys(WantsRead); err != nil || watches[WantsRead] != 1 { + t.Fatalf("the holder's own read before the copy is read: %v, watches %v", err, watches) + } + if _, err := m.h.read(WantsRead, "", "", ""); err != nil { + t.Fatalf("a handler's read of a state whose copy is read: %v", err) } for _, r := range []string{AssignmentsRead, WantsRead} { ws.Follow(r, nil) diff --git a/modules/mesh-provisioner/cmd/mesh-provisioner/holdertools.go b/modules/mesh-provisioner/cmd/mesh-provisioner/holdertools.go index 227695642..e535607ea 100644 --- a/modules/mesh-provisioner/cmd/mesh-provisioner/holdertools.go +++ b/modules/mesh-provisioner/cmd/mesh-provisioner/holdertools.go @@ -79,6 +79,9 @@ func holderTools(h *Holder) []stdio.Tool { if arg(a, "node") == "" { return nil, fmt.Errorf("compose names the node") } + if err := h.Away(); err != nil { + return nil, err + } many, _ := a["retire-many"].(bool) return h.ComposeNodeWith(context.Background(), arg(a, "node"), many) }}, @@ -118,6 +121,9 @@ func (h *Holder) health() health.Answer { // read is a state's keys narrowed, or one whole, with the state's fill. func (h *Holder) read(state, key, node, want string) (any, error) { + if err := h.Away(state); err != nil { + return nil, err + } if key != "" { e, err := h.Store.Get(state, key) if err != nil { From a37cde8bcc38571dc92adb1f35d31dc145173d68 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 18:57:21 +0100 Subject: [PATCH 4/4] mesh-config: the start waits for an owner view's Ready, the handlers ask the views' Unread beside the own copies' (review r1 finding 3) Builds: design 47 H2 H-A-708 (2), row S8 --- modules/mesh-config/cmd/mesh-config/main.go | 16 ++++++++------ .../mesh-config/cmd/mesh-config/ownerviews.go | 21 ++++++++++++------- .../cmd/mesh-config/ownerviews_test.go | 11 ++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/mesh-config/cmd/mesh-config/main.go b/modules/mesh-config/cmd/mesh-config/main.go index 3d1a2d9d5..9bfeb5307 100644 --- a/modules/mesh-config/cmd/mesh-config/main.go +++ b/modules/mesh-config/cmd/mesh-config/main.go @@ -58,14 +58,18 @@ func (r runtimeStore) Get(state, key string) (*Entry, error) { return &Entry{Key: e.Key, Value: e.Value, Revision: e.Revision}, nil } -// Away is the fault `away` while a copy of this module's own states is not read yet: a verb or tool handler asks it -// (asking), the module's own start never does (design 47 H2 H-A-708 (2)). The first views of the owners stay the fault -// `away` at the read itself, since a picture not answered yet is no answer for a pass to resolve from. +// Away is the fault `away` while a copy of this module's own states or a first view of an owner is not read yet: a verb or +// tool handler asks it (asking); the module's own start waits for them instead (design 47 H2 H-A-708 (2)). func (r runtimeStore) Away() error { - if r.own == nil { - return nil + if r.own != nil { + if err := r.own.Unread(); err != nil { + return err + } } - return r.own.Unread() + if theViews != nil { + return theViews.Unread() + } + return nil } // asking is a tool whose handler answers `away` at once while what it reads is not read yet (design 47 H2 H-A-708 (2)). diff --git a/modules/mesh-config/cmd/mesh-config/ownerviews.go b/modules/mesh-config/cmd/mesh-config/ownerviews.go index a0d0037d3..a25f3ab42 100644 --- a/modules/mesh-config/cmd/mesh-config/ownerviews.go +++ b/modules/mesh-config/cmd/mesh-config/ownerviews.go @@ -95,16 +95,25 @@ func (o *ownerViews) read(state string) (*views.Follower, bool) { return f, ok } +// Unread is the fault `away` naming the owner verb of the first view not answered yet, nil when every one is: a verb or tool +// handler asks it before it reads (design 47 H2 H-A-708 (2)). +func (o *ownerViews) Unread() error { + for _, f := range followed { + if err := o.by[f.Read].Unread(); err != nil { + return err + } + } + return nil +} + // get is one key of a followed state. func (o *ownerViews) get(state, key string) (*Entry, bool, error) { f, ok := o.read(state) if !ok { return nil, false, nil } - // A first view not answered yet is the fault `away`, naming the view's owner verb (design 47 H2 H-A-708 (2)). - if err := f.Unread(); err != nil { - return nil, true, err - } + // The module's own read waits for the first view, never reads an empty picture (design 47 H2 H-A-708 (2), row S8). + <-f.Ready() v, held := f.Get(key) if !held { return nil, true, nil @@ -118,9 +127,7 @@ func (o *ownerViews) keys(state string) ([]string, bool, error) { if !ok { return nil, false, nil } - if err := f.Unread(); err != nil { - return nil, true, err - } + <-f.Ready() var out []string for k := range f.Values() { out = append(out, k) diff --git a/modules/mesh-config/cmd/mesh-config/ownerviews_test.go b/modules/mesh-config/cmd/mesh-config/ownerviews_test.go index d961539fa..65e48f06d 100644 --- a/modules/mesh-config/cmd/mesh-config/ownerviews_test.go +++ b/modules/mesh-config/cmd/mesh-config/ownerviews_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/busretry" "git.novox.be/novox/mesh-sdk/go/views" ) @@ -36,9 +37,15 @@ func TestAFollowedStateIsReadFromItsOwnersFirstViewAndEvents(t *testing.T) { o := newOwnerViews(ask, func() { changed.Add(1) }, nopFindings{}) // H-A-708 (2): a read before the first view is answered `away`, naming the view's owner verb, at once. var away *busretry.Away - if _, followed, err := o.get(WantsRead, "want.g14.dunst"); !followed || !errors.As(err, &away) || away.Part != "mesh-delivery-assigner.assigner_read_wants" || + if err := o.Unread(); !errors.As(err, &away) || !strings.HasPrefix(away.Part, "mesh-delivery-") || !strings.HasPrefix(away.Words, "not read yet since ") { - t.Fatalf("before the first view: followed %v, %v", followed, err) + t.Fatalf("before the first view, a handler's ask: %v", err) + } + c := &Config{Store: runtimeStore{}} + theViews = o + defer func() { theViews = nil }() + if _, err := asking(c, stdio.Tool{Run: func(map[string]any) (any, error) { return nil, nil }}).Run(nil); !errors.As(err, &away) { + t.Fatalf("a tool's handler before an owner view is ready: %v", err) } if !o.reader.Follows("mesh-delivery-assigner.wants") { t.Error("the wants view is not one of the reader's (A-28)")