diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/deliveries_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/deliveries_test.go index f523fbda9..ba49f95cf 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/deliveries_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/deliveries_test.go @@ -243,33 +243,3 @@ func TestAMissedEventIsPutRightAtStart(t *testing.T) { t.Fatal("a forge that cannot be read is said") } } - -// A-281: the switch runs once; a start, then a pull-updated, then a second start opens no record. -func TestTheSwitchRunsOnceSoDeliveriesNeverBecomeRecordsAtAStart(t *testing.T) { - h, k := gateWithDeliveries(t) - h.Old = kvKeptOld{k} - if _, _, err := h.Switch(); err != nil { - t.Fatal(err) - } - if err := h.PullUpdated(updated("novox/app", 3, strings.Repeat("a", 40), "main", "feat")); err != nil { - t.Fatal(err) - } - opened, found, err := h.Switch() - if err != nil || opened != 0 || found != 0 { - t.Fatalf("the second start switched: %d %d %v", opened, found, err) - } - if kept, _ := h.Records.Kept(); len(kept) != 0 { - t.Fatalf("a delivery became a record: %+v", kept) - } - if done, err := h.Records.SwitchDone(); err != nil || !done { - t.Fatalf("switch.done %v %v", done, err) - } -} - -type kvKeptOld struct{ k *memKept } - -func (o kvKeptOld) Keys(state string) ([]string, error) { return o.k.Keys(state) } -func (o kvKeptOld) Get(state, key string) ([]byte, uint64, error) { - v, err := o.k.Get(state, key) - return v, 1, err -} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings.go index bae72c816..b5b1678f0 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings.go @@ -2,28 +2,22 @@ package main import ( "context" - "encoding/json" - "fmt" - "strconv" "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" stdio "git.novox.be/novox/mesh-sdk/go" - "git.novox.be/novox/mesh-sdk/go/keys" "git.novox.be/novox/mesh-sdk/go/views" ) // The gate's own findings (design 47 G A-39, A-29, A-37, A-30, §592): they go through one held writer over the gate's own state -// `findings`, whose three events the manifest declares. The first is `approval-carried-open`: for each `approval-carried` the -// gate says, a carried Approve nobody uses is seen, and cleared when the seat `git` says that pull request merged or closed. +// `findings`, whose three events the manifest declares. // Module is the gate's module name, the observer of its findings. const Module = "mesh-delivery-gate" // The scope and the kind of the finding a carried approval nobody uses is (design 47 §592, A-42: the scope the mesh already uses for the delivery's findings). const ( - FindingScope = "delivery" - ApprovalCarriedOpen = "approval-carried-open" + FindingScope = "delivery" ) // pullMergedEvent and pullClosedEvent are the seat git's events that end a pull request, as the gate's manifest consumes them. @@ -44,55 +38,5 @@ type FindingWriter interface { // generated contract of the seat that defines it (A-17). It is started once the runtime serves (A-40). func NewFindingWriter() (*views.HeldWriter[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent], error) { return views.NewStdioHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{ - Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State("findings"), Kinds: []string{ApprovalCarriedOpen, SourceUncompared}}) -} - -// approvalID is the id of a pull request's finding: its repository and number, each escaped as a key's name is. -func approvalID(repository string, number int64) string { - return keys.EscapeName(repository) + "." + keys.EscapeName(strconv.FormatInt(number, 10)) -} - -// approvalOpen writes the finding for an `approval-carried` the gate says, naming the head the Approve named, unless it holds it. -func (h *Holder) approvalOpen(repository string, number int, head string) error { - if h.Findings == nil { - return nil - } - id := approvalID(repository, int64(number)) - for _, f := range h.Findings.Held() { - if f.Scope == FindingScope && f.ID == id && f.Kind == ApprovalCarriedOpen { - return nil - } - } - at := h.Now().UTC() - pull := fmt.Sprintf("%s#%d", repository, number) - return h.Findings.Write(context.Background(), meshconditions.Finding{Scope: FindingScope, ID: id, Kind: ApprovalCarriedOpen, - Subject: meshconditions.Subject{Scope: FindingScope, ID: id}, - Severity: meshconditions.FindingSeverityWarning, Resolver: "operator", - Summary: fmt.Sprintf("the Approve of %s at %s, given before G, is carried and no merge or close of that pull request followed", pull, shortOf(head, 12)), - Headline: "An Approve carried over waits for its pull request", - Explanation: "The operator's Approve of this pull request, given before the delivery's switch, counts as its approval step. Nobody has merged or closed the pull request since.", - Needs: "merge the pull request through the seat git's merge-pull, or close it; the finding clears when the seat git says either.", - Source: "approval-carried", Observer: Module, At: at, Since: at}) -} - -// pullEnded clears the finding of a pull request the seat git said merged or closed; a pull request with none changes nothing. -func (h *Holder) pullEnded(body []byte, why string) error { - if h.Findings == nil { - return nil - } - var p struct { - Repository string `json:"repository"` - Number int64 `json:"number"` - } - if err := json.Unmarshal(body, &p); err != nil || p.Repository == "" || p.Number <= 0 { - h.Refuse(fmt.Errorf("a %s of the seat git is not readable: %v", why, err)) - return nil - } - id := approvalID(p.Repository, p.Number) - for _, f := range h.Findings.Held() { - if f.Scope == FindingScope && f.ID == id && f.Kind == ApprovalCarriedOpen { - return h.Findings.Clear(context.Background(), FindingScope, id, ApprovalCarriedOpen, "the pull request was "+why) - } - } - return nil + Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: stdio.State("findings"), Kinds: []string{SourceUncompared}}) } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings_test.go deleted file mode 100644 index 20a6418a0..000000000 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/findings_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "strings" - "sync" - "testing" - "time" - - "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" - mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - stdio "git.novox.be/novox/mesh-sdk/go" - "git.novox.be/novox/mesh-sdk/go/views" -) - -// memState is the gate's state `findings` in memory. -type memState struct { - mu sync.Mutex - m map[string][]byte -} - -func (s *memState) Get(key string) (*stdio.StateEntry, error) { - s.mu.Lock() - defer s.mu.Unlock() - if v, ok := s.m[key]; ok { - return &stdio.StateEntry{Key: key, Value: v}, nil - } - return nil, nil -} -func (s *memState) Put(key string, value any) (uint64, error) { - raw, _ := json.Marshal(value) - s.mu.Lock() - defer s.mu.Unlock() - s.m[key] = raw - return 1, nil -} -func (s *memState) Delete(key string) error { s.mu.Lock(); delete(s.m, key); s.mu.Unlock(); return nil } -func (s *memState) Keys() (k []string, _ error) { - s.mu.Lock() - defer s.mu.Unlock() - for key := range s.m { - k = append(k, key) - } - return -} - -type oldFake map[string][]byte - -func (o oldFake) Keys(string) (k []string, _ error) { - for key := range o { - k = append(k, key) - } - return -} -func (o oldFake) Get(_, key string) ([]byte, uint64, error) { return o[key], 1, nil } - -// The gate's own finding (A-39, A-29, A-37, §592): written through the held writer for each approval carried, once, and cleared -// when the seat git says that pull request merged or closed; the writer's events are the manifest's. -func TestTheGatesApprovalCarriedOpenIsWrittenThroughItsHeldWriterAndClearedByTheSeatGit(t *testing.T) { - at := time.Date(2026, 11, 11, 21, 0, 0, 0, time.UTC) - head := strings.Repeat("1", 40) - state := &memState{m: map[string][]byte{}} - var mu sync.Mutex - var said []string - w, err := views.NewHeldWriter(views.WriterConfig[meshconditions.Finding, meshconditions.FindingCleared, meshconditions.FindingsStated, meshconditions.FindingsAskedEvent]{ - Asked: meshconditions.SubjectFindingsAsked, Module: Module, State: state, Kinds: []string{ApprovalCarriedOpen}, Node: "ace", - Now: func() time.Time { return at }, - Publish: func(_ context.Context, subject string, _ []byte, _ string) error { - mu.Lock() - said = append(said, subject) - mu.Unlock() - return nil - }, - Listen: func(context.Context, string, func([]byte)) (func(), error) { return func() {}, nil }}) - if err != nil { - t.Fatal(err) - } - if err := w.Start(context.Background()); err != nil { - t.Fatal(err) - } - merge, merr := mdc.EncodeMerge(Merge{V: 1, Group: "feat/x", Ask: "merge.feat_x.0123456789ab", Approved: map[string]string{"novox/app@7": head, "novox/web@8": head, "novox/db@9": head}, - Pulls: []MergePull{{Head: mdc.Head{Repository: "novox/db", Number: 9, Head: head}, State: mdc.MergeMerged, Commit: "c0ffee"}}}.stored()) - h := &Holder{Logf: t.Logf, Now: func() time.Time { return at }, Old: oldFake{"feat_x": merge}, Findings: w, SaySeat: func(string, any, string) error { return nil }} - if merr != nil { - t.Fatal(merr) - } - if err := h.carryApprovals(); err != nil { - t.Fatal(err) - } - held := w.Held() - if len(held) != 2 { - t.Fatalf("held %+v", held) - } - for _, f := range held { - if f.Kind != ApprovalCarriedOpen || f.Scope != "delivery" || f.Observer != Module || !strings.Contains(f.Summary, head[:12]) { - t.Fatalf("finding %+v", f) - } - } - if id := approvalID("novox/app", 7); held[0].ID != id && held[1].ID != id { - t.Fatalf("no finding with id %s: %+v", id, held) - } - n := len(said) - if err := h.carryApprovals(); err != nil || len(said) != n { - t.Fatalf("said again: %v, %d events (was %d)", err, len(said), n) - } - // the seat git says one merged and the other closed; one it does not know changes nothing - if err := h.pullEnded([]byte(`{"repository":"novox/app","number":7}`), "merged"); err != nil { - t.Fatal(err) - } - if err := h.pullEnded([]byte(`{"repository":"novox/other","number":1}`), "merged"); err != nil || len(w.Held()) != 1 { - t.Fatalf("held %+v: %v", w.Held(), err) - } - if err := h.pullEnded([]byte(`{"repository":"novox/web","number":8}`), "closed"); err != nil || len(w.Held()) != 0 { - t.Fatalf("held %+v: %v", w.Held(), err) - } - got := strings.Join(said, " ") - for _, ev := range []string{"finding-written", "finding-cleared"} { - if !strings.Contains(got, ev) { - t.Fatalf("no %s said: %v", ev, said) - } - } -} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/gate.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/gate.go index 05222b46c..7522e6dc9 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/gate.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/gate.go @@ -20,8 +20,6 @@ type Holder struct { Settings func() Settings Now func() time.Time Logf func(format string, a ...any) - // Merges and Old are the old sections the switch reads (switch.go); Source is the gate's source (merges.go). - Merges MergeStore // Kept is the gate's states deliveries and groups, and Forge the seat git's reads (deliveries.go, §716). Kept DeliveryStore Forge ForgeReads @@ -29,7 +27,6 @@ type Holder struct { Catalog Registered startMu sync.Mutex dmu sync.Mutex - Old OldState Source SourceStore // Owed says what the gate owes the forge as the seat's event owed (owed.go). Owed OwedSayer diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps.go index 2ee1d5c80..7991c8974 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps.go @@ -6,7 +6,7 @@ import "git.novox.be/novox/mesh-sdk/go/announce" // issue 1790): the module says it itself, from its code, before it serves, and a reader is granted what it said // (clause 3). A state is readable when another module's manifest reads it (keeps_test.go names the readers). keeps_test.go holds the list to the // manifest's `state`, and keeps_integration_test.go that the module announces it on a bus. -var Kept = []announce.State{{Name: "conditions"}, {Name: "deliveries"}, {Name: "findings"}, {Name: "groups"}, {Name: "merges", Readable: true}, {Name: "owed", Readable: true}, {Name: "source", Readable: true}} +var Kept = []announce.State{{Name: "conditions"}, {Name: "deliveries"}, {Name: "findings"}, {Name: "groups"}, {Name: "source", Readable: true}} // announceKept says Kept through keeps, which is stdio.Keeps. func announceKept(keeps func(...announce.State) error) error { return keeps(Kept...) } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go index 4694f8f7c..79bddbc3f 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go @@ -13,14 +13,7 @@ import ( // announced the state readable), kept here and not read from other repositories' manifests (clause 1). Each line names // the modules of mesh-delivery whose manifest reads the state, as of R4e. var readers = map[string][]string{ - "asks": {"mesh-delivery-teller", "mesh-delivery-view"}, - "merges": {"mesh-delivery-forge-bridge"}, - "pulls": {"build-agent"}, // in mesh-controller - "owed": {"mesh-delivery-forge-bridge"}, "source": {"mesh-delivery-indexer", "mesh-delivery-checker"}, - // ADR 0548 §3, §4: the checker reads the merge turns and claims no check of a repository one names; the gate alone writes - // them (a state is written by its owner's account alone, ADR 0495 §3: announcing it readable grants a read, never a write). - "turns": {"mesh-delivery-checker"}, } // 1790/S: the states the module announces are the states its manifest declares, no more, no fewer, and the readable @@ -75,8 +68,9 @@ func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T } } -// Design 47 G §613 (A-20): deliveries, groups, owed and conditions are `requires` entries of the template `state` under -// their local names, taking the buckets they already had; merges and source stay in the old `state` section. +// Design 47 G §613 (A-20): deliveries, groups and conditions are `requires` entries of the template `state` under +// their local names, taking the buckets they already had; source stays in the old `state` section, and merges and the old +// owed go (design 47 H §764). func TestTheFourStatesMoveToTheTemplateAndTwoStayOld(t *testing.T) { raw, err := os.ReadFile(filepath.Join("..", "..", "module.json")) if err != nil { @@ -97,12 +91,12 @@ func TestTheFourStatesMoveToTheTemplateAndTwoStayOld(t *testing.T) { } old := string(raw[strings.Index(string(raw), `"state": [`):]) old = old[:strings.Index(old, "]")] - for _, n := range []string{"deliveries", "groups", "owed", "conditions"} { + for _, n := range []string{"deliveries", "groups", "conditions"} { if !moved[n] || strings.Contains(old, `"`+n+`"`) { t.Errorf("%s: template state %v, old section lists it %v", n, moved[n], strings.Contains(old, `"`+n+`"`)) } } - for _, n := range []string{"merges", "source"} { + for _, n := range []string{"source"} { if moved[n] || !strings.Contains(old, `"`+n+`"`) { t.Errorf("%s stays in the old section", n) } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go index ec423fb96..66ea8c028 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go @@ -54,7 +54,6 @@ func main() { h := &Holder{ Settings: settings, Logf: logf, - Merges: kvMerges{}, Source: kvSource{}, Owed: seatOwed{say: stdio.SeatPublish}, // The gate says what stalled to the operator itself (issue 1275, ADR 0437 §9). @@ -65,7 +64,6 @@ func main() { h.SaySeat = stdio.SeatPublish h.Records = &Records{Ledger: sdkLedger{}, Now: h.Now, Retention: h.recordRetention, Say: stdio.SeatPublish, Logf: logf} h.Records.Changed = h.recordChanged - h.Old = kvOld{} h.Kept = kvKept{} h.Forge = seatGit{ask: stdio.Ask} h.Catalog = seatCatalog{ask: stdio.Ask} @@ -100,7 +98,6 @@ func main() { // tick, no forge poll, no reconcile loop. Each step is retried, each failure said, never given up on quietly. func run(h *Holder, l *listening) { <-stdio.Served() // Serve first: the state is reached through it, and an event is heard from as soon as it serves - switchToRecords(h, l) statePins(h, l) go h.Work() for _, pattern := range followed { @@ -131,21 +128,6 @@ func run(h *Holder, l *listening) { } } -// switchToRecords carries the groups in flight into their delivery records (switch.go), retrying until it can: no event is -// taken before, so no outcome reaches a record the switch has not opened yet. -func switchToRecords(h *Holder, l *listening) { - for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) { - opened, found, err := h.Switch() - if err == nil { - logf("[mesh-delivery] the switch to the delivery records: %d opened, %d already there", opened, found) - return - } - l.set("not yet: " + err.Error()) - logf("[mesh-delivery] the switch to the delivery records cannot be made yet (%v); asking again in %s", err, wait) - time.Sleep(wait) - } -} - // statePins says every pin the records hold once at each start (design 47 G §579), retrying until it can. func statePins(h *Holder, l *listening) { for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) { @@ -179,7 +161,7 @@ func take(h *Holder, e stdio.Envelope) error { return h.PullUpdated(e.Body) } if e.Key == pullMergedEvent { - return errors.Join(h.DeliveryMerged(e.Body), h.pullEnded(e.Body, "merged")) + return h.DeliveryMerged(e.Body) } if e.Key == registrationChangedEvent { _, err := h.StartSources() @@ -189,7 +171,7 @@ func take(h *Holder, e stdio.Envelope) error { return h.ForgeMerged(e.Body) } if e.Key == pullClosedEvent { - return errors.Join(h.DeliveryClosed(e.Body), h.pullEnded(e.Body, "closed")) + return h.DeliveryClosed(e.Body) } return nil } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/manifest_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/manifest_test.go index de4dac66d..beaa20794 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/manifest_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/manifest_test.go @@ -161,7 +161,7 @@ func TestItClaimsTheDeliverySeatAndFollowsWhatItHandles(t *testing.T) { // Two buckets still in the old `state` (merges, source), `pulls` and `asks` gone (§613), the four of the template `state` moved to `requires` (design 47 G §613), and no `asked` (the teller asks, ADR 0437 §6): ADR 0450 §3 and the conditions it raised (issue 1275). No // `turns`, no turn tool and no `check-gates-merge`: no check gates a merge (novox/hq ADR 0661 §1, §2, §6). buckets := m.buckets() - if !reflect.DeepEqual(buckets, []string{"merges", "source"}) { + if !reflect.DeepEqual(buckets, []string{"source"}) { // merges goes (design 47 H §764) t.Fatalf("state %v", buckets) } for _, tool := range m.Tools { @@ -307,3 +307,39 @@ func TestTheGateHoldsTheSeatAsTheSDKsTableOfRelease6HasIt(t *testing.T) { } } } + +// GATE-1/AC1 (design 47 H §764): the earlier model's states leave the gate, as its manifest, its announced states and its +// code say: no `merges`, `owed` (the old bucket), `asks`, `pulls` or `turns`, and no `approval-carried` said. +func TestTheEarlierModelsStatesAndApprovalAreGone(t *testing.T) { + m, _ := readManifest(t) + kept := []string{} + for _, s := range Kept { + kept = append(kept, s.Name) + } + gone := []string{"merges", "owed", "asks", "pulls", "turns"} + for _, row := range []struct { + where string + names []string + }{{"the manifest's state and requires", m.withTemplateStates()}, {"the announced states", kept}} { + for _, n := range gone { + if slices.Contains(row.names, n) { + t.Errorf("%s still name %s", row.where, n) + } + } + } + sources, _ := filepath.Glob("*.go") + for _, f := range sources { + if strings.HasSuffix(f, "_test.go") { + continue + } + raw, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + for _, name := range []string{"approval-carried", "ApprovalCarried", "SwitchedOwed"} { + if strings.Contains(string(raw), name) { + t.Errorf("%s still names %s", f, name) + } + } + } +} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/merges.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/merges.go index 12d88bc9e..a90ab75e8 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/merges.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/merges.go @@ -12,38 +12,19 @@ import ( "git.novox.be/novox/mesh-sdk/go/keys" ) -// The gate merges nothing and hands nothing to the forge (design 47 G §592): `merges` stays an old section the switch reads -// (switch.go, §613), never written; `source` is the gate's source revision per watched branch (§15, §291), served by the verb +// The gate merges nothing and hands nothing to the forge (design 47 G §592; H §764: `merges` goes): `source` is the gate's source revision per watched branch (§15, §291), served by the verb // `source` below. +// Source is the state source's value, the seat mesh-delivery's type used as it is (novox/hq ADR 0634 §2). +type ( + Source = seat.SourceByBranchValue + // Owed is what the forge bridge performs, as the seat's event owed says it. + Owed = seat.OwedByRepositoryNumberHeadActValue +) + // changeAttempts is how often a lost compare-and-set is read and applied again before it is said. const changeAttempts = 10 -// MergeStore is the gate's bucket merges. -type MergeStore interface { - Get(group string) (*Merge, error) -} - -// OldState reads the gate's old state owed, which the switch says again as switched acts (switch.go): each key, and one -// key's value with its revision. -type OldState interface { - Keys(state string) ([]string, error) - Get(state, key string) (value []byte, revision uint64, err error) -} - -// kvOld is the old state over the runtime. -type kvOld struct{} - -func (kvOld) Keys(state string) ([]string, error) { return stdio.State(state).Keys() } - -func (kvOld) Get(state, key string) ([]byte, uint64, error) { - e, err := stdio.State(state).Get(key) - if err != nil || e == nil { - return nil, 0, err - } - return e.Value, e.Revision, nil -} - // SourceStore is the gate's bucket source, one key per watched branch (design 47 G §15), moved by compare-and-set. type SourceStore interface { // Set reads a branch's source key and writes what update makes of it, unless update says nothing is to be written, and answers @@ -55,25 +36,6 @@ type SourceStore interface { Branches() ([]string, error) } -// kvMerges is merges over the runtime. -type kvMerges struct{} - -func (kvMerges) Get(group string) (*Merge, error) { - key, err := mdc.MergesKey(group) - if err != nil { - return nil, err - } - e, err := stdio.State("merges").Get(key) - if err != nil || e == nil { - return nil, err - } - m, err := DecodeMerge(e.Value) - if err != nil { - return nil, fmt.Errorf("the merge of %s is not readable: %w", group, err) - } - return &m, nil -} - // kvSource is source over the runtime. type kvSource struct{} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go index 831f3f682..99edd8393 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go @@ -39,8 +39,6 @@ const RecordForm = 1 const ( TypeRecord = "record" TypeHeld = "held" - // TypeSwitch holds the one key `switch.done` (A-281): the gate's fingerprint and the time of the switch to the records. - TypeSwitch = "switch" ) // The operations of a record, each one effect (ADR 0597 §2), and of the month's list. The manifest's `requires` declares @@ -59,7 +57,6 @@ const ( OpAct = "act" // set-entry into acts, by id: an act owed the forge with its outcome OpHold = "hold" // a month's list: set-entry into records, by instance OpDrop = "drop" // a month's list: remove from records, by instance - OpDone = "done" // the switch: set-fields, the gate's fingerprint and the time ) // RecordOperations are a record's operations, in the order the manifest's type allows them. @@ -68,27 +65,6 @@ var RecordOperations = []string{OpOpen, OpGroup, OpTrace, OpEntry, OpOutcome, Op // HeldOperations are the month's list's operations. var HeldOperations = []string{OpHold, OpDrop} -// SwitchOperations are the switch key's operations. -var SwitchOperations = []string{OpDone} - -// switchInstance is the instance of the key `switch.done`, written once the switch has carried today's state in (A-281). -const switchInstance = TypeSwitch + "/done" - -// SwitchDone says whether the key `switch.done` is there: the switch has run, and no later start runs it again (A-281). -func (rs *Records) SwitchDone() (bool, error) { - raw, _, err := rs.Ledger.Get(switchInstance) - if err != nil { - return false, fmt.Errorf("the key switch.done cannot be read: %w", err) - } - return len(raw) > 0 && string(raw) != "null", nil -} - -// MarkSwitched writes the key `switch.done`: the gate's fingerprint and the time (A-281). -func (rs *Records) MarkSwitched(fingerprint string) error { - _, err := rs.Ledger.Apply(switchInstance, OpDone, map[string]any{"fingerprint": fingerprint, "at": rs.now().UTC().Format(time.RFC3339)}) - return err -} - // DefaultRecordRetention is how long a record is kept when the setting record-retention gives none (design 47: 90 days // covers every trace the operator has asked of a past delivery so far). const DefaultRecordRetention = 90 * 24 * time.Hour diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go index 0cb23b623..86e0a44a9 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go @@ -386,7 +386,7 @@ func TestTheDeliveryRecordIsALedgerInstanceKeyedByMilestoneAndHeads(t *testing.T // W11.1: the manifest's ledger types allow exactly the operations the gate applies, and the ledger is capped at 768 MiB. func TestTheManifestsLedgerTypesAreTheRecordsOperations(t *testing.T) { l := newLedgerFake(t) - for name, want := range map[string][]string{TypeRecord: RecordOperations, TypeHeld: HeldOperations, TypeSwitch: SwitchOperations} { + for name, want := range map[string][]string{TypeRecord: RecordOperations, TypeHeld: HeldOperations} { var got []string for _, op := range l.types[name].Operations { got = append(got, op.Name) diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go index aa0b7063c..d181be618 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go @@ -4,13 +4,14 @@ import ( "encoding/json" "errors" "fmt" - meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" - stdio "git.novox.be/novox/mesh-sdk/go" "reflect" "strings" "testing" "time" + + meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" + stdio "git.novox.be/novox/mesh-sdk/go" ) type branchSource struct{ memSource } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/switch.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/switch.go deleted file mode 100644 index 730eaea4e..000000000 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/switch.go +++ /dev/null @@ -1,296 +0,0 @@ -package main - -// The switch to the delivery record (design 47 *The delivery record*: "The switch carries today's state in, once"): at -// the new gate's start, every group in flight and its merge as the old sections hold them become records, keyed by the -// milestone and the heads. It is safe to run twice: a group in flight whose record is there already leaves it as it is -// (Records.Open), and a group state the record holds already is not written again (Records.SetGroup), so delivering milestone -// G again after a revert makes no second record and asks nothing again. The old sections are read, never written (§613). - -import ( - "encoding/json" - "errors" - "fmt" - "os" - "sort" - "strings" - - mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" - "git.novox.be/novox/mesh-sdk/go/keys" - "git.novox.be/novox/mesh-sdk/go/process" -) - -// oldDelivery is a delivery as the old section `deliveries` kept it, as far as the switch reads it. -type oldDelivery struct { - ID string `json:"id"` - Repository string `json:"repository"` - Commit string `json:"commit"` - Number int `json:"number"` - Branch string `json:"branch"` - Group string `json:"group"` - State string `json:"state"` - InSource bool `json:"in_source"` - NewerHead string `json:"newer_head"` - ClosedUnmerged bool `json:"closed_unmerged"` -} - -// milestone is the name a delivery's record is kept under: its group's, a lone pull request's branch, its id. -func (d oldDelivery) milestone() string { - switch { - case d.Group != "": - return d.Group - case d.Branch != "": - return d.Branch - } - return d.ID -} - -// recordGroupOf is a merge, as the old section merges holds it, as the record's group state. -func recordGroupOf(m Merge, members []string) RecordGroup { - g := RecordGroup{Group: m.Group, Members: members, Ask: m.Ask, Approved: m.Approved} - for _, p := range m.Pulls { - g.Pulls = append(g.Pulls, RecordPull{Repository: p.Repository, Number: p.Number, Head: p.Head.Head, State: string(p.State), - Commit: p.Commit, Words: p.Words}) - } - return g -} - -// switchGroup is one group in flight as the switch finds it: its milestone, its heads and its members. -type switchGroup struct { - milestone string - heads map[string]string - members []string -} - -// inFlight are the groups in flight in the old section deliveries: every milestone with a delivery not final, its live -// members' heads as `@` to the full commit. -func (h *Holder) inFlight() ([]switchGroup, error) { - if h.Old == nil { - return nil, nil - } - keys, err := h.Old.Keys("deliveries") - if err != nil { - return nil, fmt.Errorf("the old section deliveries cannot be read for the switch: %w", err) - } - by := map[string]*switchGroup{} - for _, key := range keys { - raw, _, err := h.Old.Get("deliveries", key) - if err != nil { - return nil, fmt.Errorf("the old delivery %s cannot be read for the switch: %w", key, err) - } - var d oldDelivery - if raw == nil || json.Unmarshal(raw, &d) != nil || d.ID == "" { - continue // a mark an earlier owner kept, or no delivery - } - final := d.State == "merged" || d.State == "held" || d.State == "closed" - if final && !(d.State == "merged" && !d.InSource) || d.Number == 0 || d.NewerHead != "" || d.ClosedUnmerged { - continue - } - name := d.milestone() - g := by[name] - if g == nil { - g = &switchGroup{milestone: name, heads: map[string]string{}} - by[name] = g - } - g.heads[mdc.ApprovedKey(d.Repository, d.Number)] = d.Commit - g.members = append(g.members, d.ID) - } - out := make([]switchGroup, 0, len(by)) - for _, g := range by { - sort.Strings(g.members) - out = append(out, *g) - } - sort.Slice(out, func(i, j int) bool { return out[i].milestone < out[j].milestone }) - return out, nil -} - -// Switch carries today's state into the records, once and safe to run again: each group in flight becomes a record at -// its heads, or at the heads its merge was approved at when `merges` holds one, with that merge as its group state. -// It answers how many records it opened and how many it found there. It runs once (A-281): when it has carried today's state in -// it writes the key `switch.done`, and a start that finds the key runs no switch, so the deliveries the gate writes from the -// seat git's events (§716) never become records at a start. A revert's restore brings back the state without the key, so -// delivering G again switches again. -func (h *Holder) Switch() (opened, found int, err error) { - if h.Records == nil { - return 0, 0, nil - } - if done, err := h.Records.SwitchDone(); err != nil || done { - return 0, 0, err - } - defer func() { - if err == nil { - err = h.Records.MarkSwitched(process.ReadOwnBuild(os.Getenv).String()) - } - }() - groups, err := h.inFlight() - if err != nil { - return 0, 0, err - } - for _, g := range groups { - var merge *Merge - if h.Merges != nil { - if merge, err = h.Merges.Get(g.milestone); err != nil { - return opened, found, fmt.Errorf("the merge of %s cannot be read for the switch: %w", g.milestone, err) - } - } - heads := g.heads - if merge != nil && len(merge.Approved) > 0 { - heads = merge.Approved - } - r, made, err := h.Records.Open(g.milestone, heads, false) - if err != nil { - return opened, found, fmt.Errorf("the switch cannot open the record of %s: %w", g.milestone, err) - } - if made { - opened++ - } else { - found++ - } - if merge != nil { - if err := h.Records.SetGroup(r, recordGroupOf(*merge, g.members)); err != nil { - return opened, found, fmt.Errorf("the switch cannot carry the merge of %s: %w", g.milestone, err) - } - } - } - if err := h.carryOwed(); err != nil { - return opened, found, err - } - err = h.carryApprovals() - return opened, found, err -} - -// oldMerge is a group's merge as the old state merges holds it, with its key and revision; nil when it holds none. -func (h *Holder) oldMerge(group string) (*Merge, uint64, error) { - if h.Old == nil { - return nil, 0, nil - } - key, err := mdc.MergesKey(group) - if err != nil { - return nil, 0, err - } - raw, rev, err := h.Old.Get(mdc.SwitchedMerges, key) - if err != nil || raw == nil { - return nil, 0, err - } - m, err := DecodeMerge(raw) - if err != nil { - return nil, 0, err - } - return &m, rev, nil -} - -// carryOwed says every act the old state owed holds as owed, under its switched id (the state, the key and its revision: -// meshdeliveryclient.SwitchedActID), so the forge bridge performs what the old bridge did not and counts as performed what -// it did (design 47 G §169). No merge act is made from the old state merges (G §167, §542). Said at every switch, it is the same act each time. A key that cannot be read as an act is said -// as refused and skipped. -func (h *Holder) carryOwed() error { - if h.Old == nil || h.Owed == nil { - return nil - } - now := h.Now().UTC() - keys, err := h.Old.Keys(mdc.SwitchedOwed) - if err != nil { - return fmt.Errorf("the state owed cannot be read for the switch: %w", err) - } - for _, key := range keys { - raw, rev, err := h.Old.Get(mdc.SwitchedOwed, key) - if err != nil { - return fmt.Errorf("the owed act %s cannot be read for the switch: %w", key, err) - } - if raw == nil { - continue - } - repository, number, head, _, kerr := mdc.ParseOwedKey(key) - var o Owed - id, ierr := mdc.SwitchedActID(mdc.SwitchedOwed, key, rev) - if derr := json.Unmarshal(raw, &o); kerr != nil || derr != nil || ierr != nil { - h.Refuse(fmt.Errorf("the owed act %s is not carried by the switch: %v", key, errors.Join(kerr, derr, ierr))) - continue - } - said := seatOwedOf(o, id, repository, number, head, &now) - if r := h.recordHolding(repository, head); r != nil { - err = h.owe(r, said) - } else { - err = h.Owed.Say(said) - } - if err != nil { - return fmt.Errorf("the owed act %s cannot be said for the switch: %w", key, err) - } - } - return nil -} - -// recordHolding is the open record that holds a pull request of the repository at the head, nil when none does. -func (h *Holder) recordHolding(repository, head string) *Record { - if h.Records == nil { - return nil - } - current, err := h.Records.Current() - if err != nil { - return nil - } - for _, r := range current { - for _, m := range membersOf(r) { - if strings.EqualFold(m.Repository, repository) && sameCommit(m.Head, head) { - return r - } - } - } - return nil -} - -// approver is who an Approve carried across the switch was given by (design 47 §542). -const approver = "the operator" - -// carryApprovals says, for each key of the old section merges the old bridge had not performed, `approval-carried` of each -// pull request it had not merged, once (design 47 §542, §592): the runner takes it as that pull request's `approval` step. -// The keys stay, read no more. Said at every switch, it is the same event under the same id each time, which the bus keeps once. -func (h *Holder) carryApprovals() error { - if h.Old == nil || h.SaySeat == nil { - return nil - } - names, err := h.Old.Keys(mdc.SwitchedMerges) - if err != nil { - return fmt.Errorf("the old section merges cannot be read for the switch: %w", err) - } - now := h.Now().UTC() - for _, key := range names { - raw, _, err := h.Old.Get(mdc.SwitchedMerges, key) - if err != nil { - return fmt.Errorf("the old merge %s cannot be read for the switch: %w", key, err) - } - if raw == nil { - continue - } - m, err := DecodeMerge(raw) - if err != nil { - h.Refuse(fmt.Errorf("the old merge %s is not carried by the switch: %v", key, err)) - continue - } - for approved, head := range m.Approved { - repository, number, ok := parseApprovedKey(approved) - if !ok || mergedIn(m, repository, number) { - continue - } - body := seat.ApprovalCarriedEvent{Approver: approver, At: now, Commit: head, Pull: int64(number), Repository: repository} - subject := seat.SubjectApprovalCarried(keys.EscapeName(repository), fmt.Sprint(number)) - if err := h.SaySeat(subject, body, fmt.Sprintf("approval-carried.%s.%d", repository, number)); err != nil { - return fmt.Errorf("the approval of %s#%d cannot be said carried: %w", repository, number, err) - } - if err := h.approvalOpen(repository, number, head); err != nil { - return fmt.Errorf("the finding of the approval of %s#%d cannot be written: %w", repository, number, err) - } - } - } - return nil -} - -// mergedIn is whether a merge's pull request of that repository and number was merged. -func mergedIn(m Merge, repository string, number int) bool { - for _, p := range m.Pulls { - if strings.EqualFold(p.Repository, repository) && p.Number == number && p.State == mdc.MergeMerged { - return true - } - } - return false -} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values.go deleted file mode 100644 index b1de5f8ce..000000000 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values.go +++ /dev/null @@ -1,130 +0,0 @@ -package main - -import ( - "encoding/json" - "reflect" - - mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" - seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" -) - -// The values the gate keeps in the seat mesh-delivery's states. The seat's types are the layout and meshdeliveryclient -// holds their rules and codecs; Source, Owed and Answer are used as they are, and the three whose seat form differs from the -// form the gate works in (a pull request that holds its head, the router's ask as bytes, a turn's times as plain times) -// are converted at the edge, so a stored value decodes unchanged (novox/hq ADR 0634 §2). -type ( - // Source is the state source's value. - Source = seat.SourceByBranchValue - // Owed is the state owed's value: what the forge bridge performs. - Owed = seat.OwedByRepositoryNumberHeadActValue - // Answer is the operator's answer as the gate acts on it. - Answer = mdc.Answer -) - -// Merge is the state merges' value: a group's merge. -type Merge struct { - V int - Group string - Ask string - Approved map[string]string - Pulls []MergePull -} - -// MergePull is one pull request of a merge: its expected head, its state, the merge commit once merged, the forge's words -// when refused. -type MergePull struct { - mdc.Head - State mdc.MergeState - Commit string - Words string -} - -func (m Merge) stored() seat.MergesByGroupValue { - out := seat.MergesByGroupValue{Approved: m.Approved, Ask: m.Ask, Group: m.Group, V: int64(m.V)} - if m.Pulls != nil { - out.Pulls = make([]seat.MergesByGroupValuePullsItem, len(m.Pulls)) - } - for i, p := range m.Pulls { - out.Pulls[i] = seat.MergesByGroupValuePullsItem{Commit: p.Commit, Head: p.Head.Head, Number: int64(p.Number), - Repository: p.Repository, State: string(p.State), Words: p.Words} - } - return out -} - -func mergeFromSeat(s seat.MergesByGroupValue) Merge { - out := Merge{V: int(s.V), Group: s.Group, Ask: s.Ask, Approved: s.Approved} - for _, p := range s.Pulls { - out.Pulls = append(out.Pulls, MergePull{Head: mdc.Head{Repository: p.Repository, Number: int(p.Number), Head: p.Head}, - State: mdc.MergeState(p.State), Commit: p.Commit, Words: p.Words}) - } - return out -} - -// EncodeMerge is m as the value of a merges key. -func EncodeMerge(m Merge) ([]byte, error) { return mdc.EncodeMerge(m.stored()) } - -// DecodeMerge reads the value of a merges key. -func DecodeMerge(data []byte) (Merge, error) { - s, err := mdc.DecodeMerge(data) - if err != nil { - return Merge{}, err - } - return mergeFromSeat(s), nil -} - -// SameMerge says whether two merges are the same value. -func SameMerge(a, b Merge) bool { return mdc.SameMerge(a.stored(), b.stored()) } - -// Ask is the state asks' value: the router's ask for a group's merge at its heads. -type Ask struct { - V int - Group string - Heads []mdc.Head - Ask json.RawMessage - // Asking counts the times the gate wrote this group's ask at these heads (0 or 1 for the first). - Asking int -} - -func (a Ask) stored() seat.AsksByMergeGroupHeadsValue { - out := seat.AsksByMergeGroupHeadsValue{Asking: int64(a.Asking), Group: a.Group, V: int64(a.V)} - if len(a.Ask) > 0 { - out.Ask = a.Ask - } - if a.Heads != nil { - out.Heads = make([]seat.AsksByMergeGroupHeadsValueHeadsItem, len(a.Heads)) - } - for i, h := range a.Heads { - out.Heads[i] = seat.AsksByMergeGroupHeadsValueHeadsItem{Head: h.Head, Number: int64(h.Number), Repository: h.Repository} - } - return out -} - -func askFromSeat(s seat.AsksByMergeGroupHeadsValue) (Ask, error) { - raw, err := json.Marshal(s.Ask) - if err != nil { - return Ask{}, err - } - return Ask{V: int(s.V), Group: s.Group, Heads: mdc.HeadsOf(s.Heads), Ask: raw, Asking: int(s.Asking)}, nil -} - -// EncodeAsk is a as the value of an asks key. -func EncodeAsk(a Ask) ([]byte, error) { return mdc.EncodeAsk(a.stored()) } - -// DecodeAsk reads the value of an asks key. -func DecodeAsk(data []byte) (Ask, error) { - s, err := mdc.DecodeAsk(data) - if err != nil { - return Ask{}, err - } - return askFromSeat(s) -} - -// SameAsk says whether two asks are the same value, the router's ask by its content. -func SameAsk(a, b Ask) bool { - var x, y any - if json.Unmarshal(a.Ask, &x) != nil || json.Unmarshal(b.Ask, &y) != nil { - return false - } - a.Ask, b.Ask = nil, nil - return reflect.DeepEqual(a, b) && reflect.DeepEqual(x, y) -} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values_test.go deleted file mode 100644 index d1b22ce26..000000000 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/values_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "encoding/json" - "reflect" - "testing" - - mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient" -) - -// What go/delivery wrote into the seat's states, key order and all, must decode as it did and encode to the same -// content (ADR 0634 §2): the gate's working values are converted to the seat's types at the edge. -func TestStoredValuesOfTheEarlierLayoutDecodeUnchanged(t *testing.T) { - head := mdc.Head{Repository: "novox/app", Number: 7, Head: "0123456789abcdef0123456789abcdef01234567"} - rows := []struct { - name string - stored string - decode func(string) (any, error) - encode func(any) ([]byte, error) - want any - }{ - {"merge with a merged and a refused pull", `{"v":1,"group":"feat/x","ask":"merge.feat_x.0123456789ab","approved":{"novox/app@7":"` + head.Head + `","novox/web@8":"abc"},` + - `"pulls":[{"repository":"novox/app","number":7,"head":"` + head.Head + `","state":"merged","commit":"c0ffee"},` + - `{"repository":"novox/web","number":8,"head":"abc","state":"refused","words":"mesh/check (missing)"}]}`, - func(s string) (any, error) { return DecodeMerge([]byte(s)) }, func(v any) ([]byte, error) { return EncodeMerge(v.(Merge)) }, - Merge{V: 1, Group: "feat/x", Ask: "merge.feat_x.0123456789ab", Approved: map[string]string{"novox/app@7": head.Head, "novox/web@8": "abc"}, Pulls: []MergePull{ - {Head: head, State: mdc.MergeMerged, Commit: "c0ffee"}, - {Head: mdc.Head{Repository: "novox/web", Number: 8, Head: "abc"}, State: mdc.MergeRefused, Words: "mesh/check (missing)"}}}}, - {"ask keeps the router's ask as bytes", `{"v":1,"group":"feat/x","heads":[{"repository":"novox/app","number":7,"head":"` + head.Head + `"}],"ask":{"id":"a","options":["Approve"]},"asking":2}`, - func(s string) (any, error) { return DecodeAsk([]byte(s)) }, func(v any) ([]byte, error) { return EncodeAsk(v.(Ask)) }, - Ask{V: 1, Group: "feat/x", Heads: []mdc.Head{head}, Ask: json.RawMessage(`{"id":"a","options":["Approve"]}`), Asking: 2}}, - {"source", `{"v":1,"group":"feat/x","heads":{"novox/app":"c0ffee"}}`, - func(s string) (any, error) { return mdc.DecodeSource([]byte(s)) }, func(v any) ([]byte, error) { return mdc.EncodeSource(v.(Source)) }, - Source{V: 1, Group: "feat/x", Heads: map[string]string{"novox/app": "c0ffee"}}}, - {"owed status", `{"v":1,"act":"status","context":"mesh/delivery","target":"https://x/y","state":"pending"}`, - func(s string) (any, error) { return mdc.DecodeOwed([]byte(s)) }, func(v any) ([]byte, error) { return mdc.EncodeOwed(v.(Owed)) }, - Owed{V: 1, Act: "status", Context: "mesh/delivery", Target: "https://x/y", State: "pending"}}, - {"answer", `{"v":1,"option":"Approve","warrant":"w@2026-11-05T10:00:00Z","words":"chose Approve"}`, - func(s string) (any, error) { return mdc.DecodeAnswer([]byte(s)) }, func(v any) ([]byte, error) { return mdc.EncodeAnswer(v.(Answer)) }, - Answer{V: 1, Option: "Approve", Warrant: "w@2026-11-05T10:00:00Z", Words: "chose Approve"}}, - } - for _, r := range rows { - t.Run(r.name, func(t *testing.T) { - got, err := r.decode(r.stored) - if err != nil { - t.Fatalf("the earlier layout does not decode: %v", err) - } - if !sameValue(got, r.want) { - t.Fatalf("decoded %+v, want %+v", got, r.want) - } - raw, err := r.encode(got) - if err != nil { - t.Fatalf("encode: %v", err) - } - var a, b any - if json.Unmarshal(raw, &a) != nil || json.Unmarshal([]byte(r.stored), &b) != nil || !reflect.DeepEqual(a, b) { - t.Fatalf("encoded %s, the earlier layout was %s", raw, r.stored) - } - }) - } -} - -func sameValue(a, b any) bool { - if x, ok := a.(Ask); ok { - return SameAsk(x, b.(Ask)) - } - return reflect.DeepEqual(a, b) -} diff --git a/modules/mesh-delivery-gate/go.mod b/modules/mesh-delivery-gate/go.mod index 3bf41633a..213a047f8 100644 --- a/modules/mesh-delivery-gate/go.mod +++ b/modules/mesh-delivery-gate/go.mod @@ -7,7 +7,6 @@ require ( git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel v0.0.0-00010101000000-000000000000 - git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliverycheckerclient v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery v0.0.0-00010101000000-000000000000 diff --git a/modules/mesh-delivery-gate/module.json b/modules/mesh-delivery-gate/module.json index ebddcb329..75af30f9a 100644 --- a/modules/mesh-delivery-gate/module.json +++ b/modules/mesh-delivery-gate/module.json @@ -282,27 +282,6 @@ "key": "instance" } ] - }, - { - "name": "switch", - "schema": { - "fingerprint": { - "type": "string" - }, - "at": { - "type": "string" - } - }, - "operations": [ - { - "name": "done", - "effect": "set-fields", - "fields": [ - "fingerprint", - "at" - ] - } - ] } ] }, @@ -316,14 +295,6 @@ "storage": "key-value", "template": "state" }, - { - "name": "owed", - "storage": "key-value", - "template": "state", - "options": { - "history": 5 - } - }, { "name": "conditions", "storage": "key-value", @@ -362,10 +333,6 @@ "seat:node-engine.composition" ], "state": [ - { - "name": "merges", - "history": 10 - }, { "name": "source", "history": 64