Files
mesh-catalog/modules/mesh-config/cmd/mesh-config/takeover.go
T
jschoubben a30852939c mesh-config: remove the pull request path (issue 1982; ADR 0681 §1, §3, §5, §6)
The mesh knows no pull request (design 47 G, G-1 §38-39). Removed:
- the states `pulls` and `kept` and all code that reads or writes them (pulls.go, the held values a proposal holds, the
  listing of held values), SweepPulls, settlePull, HeardPull and the forge call;
- the consumes of git.pull-merged and git.pull-closed, the invoke of seat:git.pull;
- the config verb's `pull`, `head`, `declares` and `pulls` arguments and its actions `pull-declares` and `held`;
- the indexer's config candidates, which only that path used: the consume of mesh-delivery-indexer.views.config-candidates
  and the invoke of indexer_read_config_candidates (the indexer's state goes in the same group).
A stored proposal that names a pull request is judged not one this module makes, so nothing is set on it.

Builds: ADR 0681 §1 (no pulls or kept, no git events, no seat:git.pull, no `pull` argument, no pull-declares or held), §3, §5, §6;
lead answer A-490l (a stored proposal naming a pull request is refused on its approval).

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 02:38:45 +01:00

171 lines
5.9 KiB
Go

package main
// Config's records out of the controller (novox/hq ADR 0565 §3, §15, and the progressive insight of 2026-10-29):
// mesh-config keeps each placed module's declarations in its own state `declared`, reads the list of predefined keys
// from the indexer's `predefined`. A pull request's config is not read: the mesh knows no pull request (design 47 G).
//
// **Its own sources hold always** (ADR 0590, issue 1126): the controller ended by its unassignment, so its pull-declares,
// the take-over that switched away from them, compare and hand-back are gone, and the switch is the indexer's whatever
// a key once said.
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"time"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
)
// The states and reads.
const (
// DeclaredState is each placed module's declarations at the trunk, one key per module (ADR 0565 §3).
DeclaredState = "declared"
// IndexerPredefinedRead is the indexer's state of the predefined list (ADR 0565 §2).
IndexerPredefinedRead = indexerModule + "." + catalog.StatePredefined
)
// SourceIndexer is the one source of the predefined list: the indexer's.
const SourceIndexer = "indexer"
// Switch is which source holds: the indexer's, always, since the controller ended (ADR 0590).
type Switch struct {
Source string `json:"source"`
Why string `json:"why"`
}
// source is the source that holds: the indexer's.
func (c *Config) source() (Switch, error) {
return Switch{Source: SourceIndexer, Why: "config reads its own sources since the controller ended by its unassignment (novox/hq ADR 0590)"}, nil
}
// ---- declared --------------------------------------------------------------------------------------------
// DeclaredKept is one key of `declared`: a module's declarations as the manifest its catalog graph entry
// carries holds them, with that manifest's digest and commit (ADR 0565 §3).
type DeclaredKept struct {
Module string `json:"module"`
Manifest string `json:"manifest"`
Commit string `json:"commit,omitempty"`
Config map[string]Declaration `json:"settings"`
}
// trunkKept is a module's declarations at the trunk with the manifest they come from.
func (c *Config) trunkKept(module string) (DeclaredKept, error) {
e, err := c.trunkEntry(module)
if err != nil {
return DeclaredKept{}, err
}
d, err := c.entryDeclarations(e)
if err != nil {
return DeclaredKept{}, err
}
return DeclaredKept{Module: module, Manifest: e.ManifestDigest, Commit: e.Commit, Config: d.Config}, nil
}
// writeDeclared makes `declared` hold each placed module's trunk declarations, writing a key only when it differs
// (ADR 0289 §1) and removing one of a module placed nowhere. It answers the modules written.
func (c *Config) writeDeclared(s Sources) ([]string, error) {
held := map[string][]byte{}
if err := c.each(DeclaredState, func(key string, raw []byte) error {
held[key] = raw
return nil
}); err != nil {
return nil, err
}
var written []string
var problems []error
placed := map[string]bool{}
for _, module := range modulesOf(s.Assignments) {
placed[module] = true
k, err := c.trunkKept(module)
if err != nil {
continue // unresolved, said by the resolution; its key stays as it was
}
raw, _ := json.Marshal(k)
if bytes.Equal(raw, held[module]) {
continue
}
if err := c.Store.Put(DeclaredState, module, k); err != nil {
problems = append(problems, fmt.Errorf("%s: %w", module, err))
continue
}
written = append(written, module)
}
for module := range held {
if !placed[module] {
if err := c.Store.Delete(DeclaredState, module); err != nil {
problems = append(problems, fmt.Errorf("%s: %w", module, err))
}
}
}
return written, errors.Join(problems...)
}
// ---- the predefined list from the indexer -----------------------------------------------------------------------------------------
// indexerList is the indexer's predefined list as the mirror's list holds one: the keys, and the commit.
func (c *Config) indexerList() (PredefinedList, bool, error) {
e, err := c.Store.Get(IndexerPredefinedRead, catalog.PredefinedByListKey())
if err != nil || e == nil {
return PredefinedList{}, false, err
}
var kept catalog.PredefinedByListValue
if err := json.Unmarshal(e.Value, &kept); err != nil {
return PredefinedList{}, false, fmt.Errorf("the indexer's predefined list is not one: %w", err)
}
list := PredefinedList{Keys: map[string]PredefinedKey{}, Commit: kept.Commit}
listed, err := json.Marshal(kept.List)
if err == nil {
err = json.Unmarshal(listed, &list.Keys)
}
if err != nil {
return PredefinedList{}, false, fmt.Errorf("the indexer's predefined list is not predefined.json: %w", err)
}
return list, true, nil
}
// Declared is the read of `declared`: every module's key, or one whole.
func (c *Config) Declared(module string) (any, error) {
if module != "" {
e, err := c.Store.Get(DeclaredState, module)
if err != nil {
return nil, err
}
if e == nil {
return nil, fmt.Errorf("declared holds no %s: it is placed nowhere, or its manifest cannot be read", module)
}
return json.RawMessage(e.Value), nil
}
rows := map[string]any{}
err := c.each(DeclaredState, func(key string, raw []byte) error {
var k DeclaredKept
if json.Unmarshal(raw, &k) == nil {
rows[key] = map[string]any{"manifest": k.Manifest, "commit": k.Commit, "keys": len(k.Config)}
}
return nil
})
sw, _ := c.source()
return map[string]any{"declared": rows, "count": len(rows), "source": sw}, err
}
// Resync reads every source again and writes what differs: the published list, the resolved values and `declared`
// (ADR 0565 §15).
func (c *Config) Resync() (any, error) {
r, err := c.Reconcile()
if err != nil {
return r, err
}
return map[string]any{"resolution": r}, nil
}
// timeOf is an optional time of a seat's value as a time, the zero time when it is absent.
func timeOf(t *time.Time) time.Time {
if t == nil {
return time.Time{}
}
return *t
}