The assigner and the node-engine on one node waited for each other for ever: the assigner's want in step compose for the new node-engine, the node-engine's in step place for the new assigner, and the cycle check counted one step at a time, so nothing said it. The node-engine's own want (the holder of the seat node-engine on the node, read from the acting edges' seat) is now held by no acting edge, so it is written first and the node's other wants, the assigner's own included, wait for it. Cycles finds a cycle across steps as well as within one, and a want held on a cycle no rule breaks is the finding acting-cycle (scope module, id <node>.<module>), naming each edge's step, cleared by the next pass that finds it on none. Builds: design 47 G §49, §268, §272, A-323, A-330 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
61 lines
3.6 KiB
Go
61 lines
3.6 KiB
Go
package assigngraph
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
|
)
|
|
|
|
// Design 47 G §272 (AS10), A-323: a cycle among the waits is found within one step and across steps, each edge's step named across
|
|
// steps; a chain and provisioning edges are none.
|
|
func TestACycleAmongTheWaitsWithinOrAcrossStepsIsFound(t *testing.T) {
|
|
act := func(node, module, step string) meshwants.Edge {
|
|
return meshwants.Edge{Kind: EdgeActing, Node: node, Module: module, Step: step}
|
|
}
|
|
entry := func(module string, edges ...meshwants.Edge) meshwants.AssignmentEntry {
|
|
return meshwants.AssignmentEntry{Node: "ace", Module: module, Edges: edges}
|
|
}
|
|
for _, c := range []struct {
|
|
name string
|
|
entries []meshwants.AssignmentEntry
|
|
want []string
|
|
}{
|
|
{"two parts on each other in one step", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "a", "compose"))},
|
|
[]string{"compose: ace/a -> ace/b -> ace/a"}},
|
|
{"three in a ring, said once", []meshwants.AssignmentEntry{entry("c", act("ace", "a", "build")), entry("a", act("ace", "b", "build")), entry("b", act("ace", "c", "build"))},
|
|
[]string{"build: ace/a -> ace/b -> ace/c -> ace/a"}},
|
|
{"the indexer taking in the checker, the checker checking the indexer", []meshwants.AssignmentEntry{entry("checker", act("ace", "indexer", "take-in")), entry("indexer", act("ace", "checker", "check"))},
|
|
[]string{"ace/checker -[take-in]-> ace/indexer -[check]-> ace/checker"}},
|
|
{"the assigner and the node-engine, across compose and place", []meshwants.AssignmentEntry{entry("assigner", act("ace", "engine", "compose")),
|
|
entry("engine", act("ace", "assigner", "place")), entry("app", act("ace", "engine", "compose"), act("ace", "assigner", "place"))},
|
|
[]string{"ace/assigner -[compose]-> ace/engine -[place]-> ace/assigner"}},
|
|
{"a chain", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "c", "compose")), entry("c")}, nil},
|
|
{"provisioning edges are no wait of a step", []meshwants.AssignmentEntry{entry("a", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "b"}), entry("b", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "a"})}, nil},
|
|
} {
|
|
if got := Cycles(c.entries); !slices.Equal(got, c.want) {
|
|
t.Errorf("%s: cycles %v, want %v", c.name, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A-323, A-330: the node-engine on a node is read from the acting edges' seat, and the cycles that hold a want are those of the
|
|
// edges said to hold it, each from the entry, naming each edge's step.
|
|
func TestTheHeldCyclesAreThoseOfTheHoldingEdges(t *testing.T) {
|
|
entries := []meshwants.AssignmentEntry{
|
|
{Node: "ace", Module: "assigner", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "engine", Step: "compose", Seat: "node-engine"}}},
|
|
{Node: "ace", Module: "engine", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "assigner", Step: "place", Seat: "mesh-wants"}}},
|
|
}
|
|
if got := Engines(entries); len(got) != 1 || got["ace"] != "engine" {
|
|
t.Errorf("the node-engines %v, want engine on ace", got)
|
|
}
|
|
all := func(meshwants.AssignmentEntry, meshwants.Edge) bool { return true }
|
|
if got := HeldCycles(entries, all); len(got) != 2 || got["ace/engine"] != "ace/engine -[place]-> ace/assigner -[compose]-> ace/engine" {
|
|
t.Errorf("held cycles %v", got)
|
|
}
|
|
// the node-engine's want held by no acting edge: no cycle holds anything
|
|
if got := HeldCycles(entries, func(e meshwants.AssignmentEntry, _ meshwants.Edge) bool { return e.Module != "engine" }); len(got) != 0 {
|
|
t.Errorf("held cycles with the node-engine's edges holding nothing: %v", got)
|
|
}
|
|
}
|