From 4923d22ac6019f2714ae1d8a1a7602c1ec07cace Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:41:36 +0100 Subject: [PATCH] A12: assigner_want_drop drops one want by hand, recorded first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tool takes node, module and why: the act is recorded through the seat mesh-hand-acts, then the key want.. is deleted from the state wants; the next pass writes the want of the new form. Refused with no want under the key, no why, no proven caller, or when the act is not recorded. Builds: design 47 H §765; H-A-58 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- .../mesh-delivery-assigner/compositionstep.go | 2 +- .../compositionstep_test.go | 5 +- .../cmd/mesh-delivery-assigner/tools.go | 1 + .../mesh-delivery-assigner/wantdrop_tool.go | 62 +++++++++++++++++++ .../wantdrop_tool_test.go | 45 ++++++++++++++ .../mesh-delivery-assigner/manifest_test.go | 2 +- modules/mesh-delivery-assigner/module.json | 3 +- 7 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool.go create mode 100644 modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool_test.go diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep.go index fb8a4aa7..ab2c8fd9 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep.go @@ -124,7 +124,7 @@ func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.St stopWait() }() phase := &stepPhase{phase: meshwants.StepProgressEventPhaseFetch} - stop := c.sayProgress(id, "", phase) // no asker known: the callers lists go (design 47 H §752, H-A-66) + stop := c.sayProgress(id, run.Asker, phase) o := how(context.WithValue(ctx, phaseKey{}, phase), id, run) stop() if ctx.Err() != nil { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_test.go index 48dcfbfb..ee2541c1 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_test.go @@ -96,7 +96,8 @@ func TestARunningCompositionStepSaysItsProgress(t *testing.T) { <-release return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed} }} - body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main"}) + // A11/AC1 (design 47 H §752, H-A-88): with no callers in mesh-wants, the progress names the asker the step run carries. + body, _ := json.Marshal(meshwants.StepRun{Pipeline: "main.4", Step: meshwants.StepRunStepComposition, Module: "m", Branch: "main", Asker: "mesh-pipeline-runner"}) if !c.take(context.Background(), "ask-1", body) { t.Fatal("the composition step is not taken") } @@ -110,7 +111,7 @@ func TestARunningCompositionStepSaysItsProgress(t *testing.T) { said.mu.Lock() p, ok := said.said[progress].(meshwants.StepProgressEvent) said.mu.Unlock() - if !ok || p.Ask != "ask-1" || p.Asker != "" || p.Phase != meshwants.StepProgressEventPhaseRun || !p.At.Equal(at) || + if !ok || p.Ask != "ask-1" || p.Asker != "mesh-pipeline-runner" || p.Phase != meshwants.StepProgressEventPhaseRun || !p.At.Equal(at) || len(p.Shared) != 1 || p.Shared[0].Ask != "run-1" { // the runs the step waits on (§723) t.Fatalf("step-progress %+v", p) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go index c7123cb6..4d7e7697 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/tools.go @@ -420,6 +420,7 @@ func serveTools() error { tools = append(tools, writtenTools(runtimeStore{})...) tools = append(tools, whyTools(runtimeStore{})...) tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...) + tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...) return stdio.Serve("", tools) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool.go new file mode 100644 index 00000000..ae447344 --- /dev/null +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool.go @@ -0,0 +1,62 @@ +package main + +import ( + "encoding/json" + "errors" + "fmt" + + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" + stdio "git.novox.be/novox/mesh-sdk/go" +) + +// wantDropTool drops one want of a node for a module by hand (design 47 H §765, H-A-58): a held or failed want of the earlier +// model goes at the clean state, its key deleted and the act written in the hand-act log; the next pass writes the want of the +// new form. +const wantDropTool = "assigner_want_drop" + +// wantsState is the state the wants are kept in. +const wantsState = "wants" + +// dropWant deletes the want of module on node, the act first recorded through the seat mesh-hand-acts. +func dropWant(st seatStore, ask func(string, any) (json.RawMessage, error), node, module, why, by string) (any, error) { + switch { + case node == "" || module == "": + return nil, errors.New("name the node and the module whose want is dropped") + case why == "": + return nil, errors.New("a want dropped by hand says why") + case by == "" || by == stdio.Unproven: + return nil, errors.New("a want dropped by hand names who drops it, and the runtime proved no caller") + } + key, err := mwc.WantKey(node, module) + if err != nil { + return nil, err + } + raw, _, found, err := st.get(wantsState, key) + if err != nil { + return nil, err + } + if !found { + return nil, fmt.Errorf("the assigner holds no want under %s", key) + } + taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: wantDropTool + " " + key, Why: why + " (" + by + ")", Cause: "want-drop"}) + if err != nil { + return nil, fmt.Errorf("the drop of %s is not recorded, so the want stays: %w", key, err) + } + if err := st.del(wantsState, key); err != nil { + return nil, fmt.Errorf("the want %s is not dropped: %w", key, err) + } + return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil +} + +// wantDropTools is the tool over the runtime's states. +func wantDropTools(st seatStore, ask func(string, any) (json.RawMessage, error)) []stdio.Tool { + return []stdio.Tool{{Name: wantDropTool, Description: "Drop one want by hand (design 47 H §765): the want of module on node is " + + "deleted from the state wants, as the clean state drops a held or failed want of the earlier model; the next pass writes the " + + "want of the new form. Recorded as a hand act first; refused with no want under the key.", + Input: schema(map[string]string{"node": "the node's name", "module": "the module's name", "why": "why the want is dropped"}, + []string{"node", "module", "why"}), + Run: func(a map[string]any) (any, error) { + return dropWant(st, ask, arg(a, "node"), arg(a, "module"), arg(a, "why"), stdio.CallerOf(a)) + }}} +} diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool_test.go new file mode 100644 index 00000000..bd3fd0c0 --- /dev/null +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/wantdrop_tool_test.go @@ -0,0 +1,45 @@ +package main + +import ( + "encoding/json" + "errors" + "strings" + "testing" + + mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient" +) + +// A12/AC1 (design 47 H §765, H-A-58): assigner_want_drop with node, module and why records the act in the hand-act log first +// and then deletes that want; with no want under the key, no why or no proven caller, and when the act is not recorded, nothing is +// dropped. +func TestAWantIsDroppedByHandAndRecorded(t *testing.T) { + key, _ := mwc.WantKey("ace", "web") + held, _ := mwc.EncodeWant(mwc.Want{Fp: fpTest, Put: true, Hold: true, Words: "put: x"}) + for _, c := range []struct { + name, node, module, why, by string + refuse error + dropped bool + }{ + {"dropped", "ace", "web", "the clean state", "person.jochen", nil, true}, + {"no want there", "ace", "db", "the clean state", "person.jochen", nil, false}, + {"no why", "ace", "web", "", "person.jochen", nil, false}, + {"no caller", "ace", "web", "the clean state", "", nil, false}, + {"not recorded", "ace", "web", "the clean state", "person.jochen", errors.New("no responders"), false}, + } { + st := memStore{wantsState: &memKV{values: map[string][]byte{key: held}}} + var asked []string + ask := func(verb string, body any) (json.RawMessage, error) { + raw, _ := json.Marshal(body) + asked = append(asked, verb+" "+string(raw)) + return json.RawMessage(`{}`), c.refuse + } + out, err := dropWant(st, ask, c.node, c.module, c.why, c.by) + _, there := st[wantsState].values[key] + switch { + case c.dropped && (err != nil || there || len(asked) != 1 || !strings.Contains(asked[0], "seat:mesh-hand-acts.hand-act ") || !strings.Contains(asked[0], wantDropTool+" "+key)): + t.Errorf("%s: %v, %v; the want left %v, asked %v", c.name, out, err, there, asked) + case !c.dropped && (err == nil || !there): + t.Errorf("%s: %v, %v; the want left %v, want it refused and kept", c.name, out, err, there) + } + } +} diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index e0967a0c..a98c65bd 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -105,7 +105,7 @@ func TestManifest(t *testing.T) { // which lists and asks again what each node's engine reads. if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks", "assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies", - "assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why"}) { + "assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop"}) { t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5) and assigner_why (design 47 G A-439)", m.Tools) } if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs { diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index 57cc0156..9bcb6689 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -129,7 +129,8 @@ "assigner_seat_list_again", "assigner_ask_again", "assigner_written", - "assigner_why" + "assigner_why", + "assigner_want_drop" ], "state": [ { "name": "assignments", "history": 64 },