Indexer: the first registrations are written from the module graph it holds, with no ask (the operator, 2026-11-14: a module in the module graph is a registration)
This commit is contained in:
@@ -236,7 +236,7 @@ func TestProposalsSurviveARestartAndAreDropped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedIsOneAskAndWaitsForEveryBuildSeat(t *testing.T) {
|
||||
func TestSeedWritesTheModuleGraphWithNoAskAndWaitsForEveryBuildSeat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
g := newRegRig()
|
||||
g.unprotect["main"] = false
|
||||
@@ -245,38 +245,20 @@ func TestSeedIsOneAskAndWaitsForEveryBuildSeat(t *testing.T) {
|
||||
t.Fatalf("an unanswered build seat did not hold the seed: %v", err)
|
||||
}
|
||||
mods[0].Artifacts[0].Answered, mods[0].Artifacts[0].Steps = true, []string{"unit"}
|
||||
waits := ""
|
||||
g.r.SeedWaits = func(ask string, waiting bool) {
|
||||
if waiting {
|
||||
waits = ask
|
||||
} else {
|
||||
waits = ""
|
||||
}
|
||||
said, err := g.r.ProposeSeed(ctx, mods, false, "indexer")
|
||||
if err != nil || !strings.Contains(said, "1 registrations written") {
|
||||
t.Fatalf("seed: %q, %v", said, err)
|
||||
}
|
||||
ask, err := g.r.ProposeSeed(ctx, mods, false, "indexer")
|
||||
if err != nil || ask == "" {
|
||||
t.Fatalf("seed: %q, %v", ask, err)
|
||||
if len(g.asks) != 0 {
|
||||
t.Fatalf("the seed asked the operator: %v", g.asks)
|
||||
}
|
||||
// A step the seat answers none for is bypass; the statuses the check judged are the rest.
|
||||
g.decide(t, ask, "decline")
|
||||
if waits != ask {
|
||||
t.Fatalf("a declined seed does not keep seed-waits: %q", waits)
|
||||
}
|
||||
if _, err := g.r.ProposeSeed(ctx, mods, false, "indexer"); err == nil {
|
||||
t.Fatal("the seed was asked again with no indexer_seed_again")
|
||||
}
|
||||
g.now = g.now.Add(time.Hour)
|
||||
ask, err = g.r.ProposeSeed(ctx, mods, true, "s@n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g.decide(t, ask, "approve")
|
||||
got, _, _ := g.r.Registration(ctx, "a")
|
||||
if got.Version != 1 || got.Policy.Steps.Review != "optional" || got.Policy.Steps.Approval != "bypass" || got.Policy.Artifacts["program"].Lint != "bypass" || got.Policy.Artifacts["program"].Integration != "bypass" || got.Policy.Artifacts["program"].Unit != "" {
|
||||
t.Fatalf("the seeded registration: %+v", got)
|
||||
}
|
||||
if waits != "" {
|
||||
t.Fatalf("seed-waits is not cleared by the warrant: %q", waits)
|
||||
if _, err := g.r.ProposeSeed(ctx, mods, true, "s@n"); err == nil {
|
||||
t.Fatal("the seed wrote over registrations the indexer holds")
|
||||
}
|
||||
// An unprotected default branch is left out and named.
|
||||
g2 := newRegRig()
|
||||
|
||||
@@ -101,8 +101,8 @@ func RegistrationTools(registrations, proposals Store, ask func(key string, valu
|
||||
}
|
||||
return res, nil
|
||||
}},
|
||||
{Name: SeedAgainTool, Description: "Raise the ask of the first registrations again from the seed's key (design 47 G §8), after a Decline, an expiry or a drop " +
|
||||
"ended it and while the indexer holds no registration. A hand act: who and why are said in the hand-act log.",
|
||||
{Name: SeedAgainTool, Description: "Write the first registrations from the module graph the indexer holds (design 47 G §8; a module in the module graph is a " +
|
||||
"registration), while the indexer holds no registration: no ask. A hand act: who and why are said in the hand-act log.",
|
||||
Input: map[string]any{"type": "object", "required": []string{"why"}, "properties": map[string]any{
|
||||
"why": map[string]any{"type": "string", "description": "why it is asked again, in plain words"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
@@ -105,9 +104,11 @@ func (r *Registry) ComposeSeed(modules []SeedModule) (SeedProposal, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ProposeSeed raises the first registrations as one ask (§8), when the indexer holds no registration and the seed's key is not
|
||||
// open or applied; again (indexer_seed_again) it raises the ask once more from a key a Decline, an expiry or a drop ended.
|
||||
// It answers the ask's id, or why none was raised.
|
||||
// ProposeSeed writes the first registrations from the module graph the indexer holds, when it holds no registration (§8): a
|
||||
// module in the module graph is a registration, so they are written at once, each as version 1, with no ask (the operator,
|
||||
// 2026-11-14: "a module in the module graph IS a registration"). The registrations a seed key already composed are written as
|
||||
// composed; otherwise they are composed from modules. A seed key still open is ended applied. again is kept for the tool's
|
||||
// form and changes nothing. It answers what it wrote.
|
||||
func (r *Registry) ProposeSeed(ctx context.Context, modules []SeedModule, again bool, by string) (string, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
@@ -118,45 +119,47 @@ func (r *Registry) ProposeSeed(ctx context.Context, modules []SeedModule, again
|
||||
if len(held) > 0 {
|
||||
return "", errors.New("the indexer holds registrations already: the seed is for the first start only")
|
||||
}
|
||||
if old, _, found, err := r.load(ctx, SeedKey); err != nil {
|
||||
return "", err
|
||||
} else if found && old.State == ProposalOpen {
|
||||
return old.Ask, nil
|
||||
} else if found && !again {
|
||||
return "", fmt.Errorf("the seed ended %s: indexer_seed_again asks it again", old.State)
|
||||
}
|
||||
seed, err := r.ComposeSeed(modules)
|
||||
old, _, found, err := r.load(ctx, SeedKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(seed.Unanswered) > 0 {
|
||||
return "", fmt.Errorf("the build seats %v have not answered steps: the seed waits for them (call-unanswered after five minutes)", seed.Unanswered)
|
||||
regs := old.Seed
|
||||
var left []string
|
||||
if !found || len(regs) == 0 {
|
||||
seed, err := r.ComposeSeed(modules)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(seed.Unanswered) > 0 {
|
||||
return "", fmt.Errorf("the build seats %v have not answered steps: the seed waits for them (call-unanswered after five minutes)", seed.Unanswered)
|
||||
}
|
||||
regs, left = seed.Registrations, seed.Left
|
||||
}
|
||||
if len(seed.Registrations) == 0 {
|
||||
return "", errors.New("no module of the trunk revision can be registered: " + strings.Join(seed.Left, "; "))
|
||||
if len(regs) == 0 {
|
||||
return "", errors.New("no module of the trunk revision can be registered: " + strings.Join(left, "; "))
|
||||
}
|
||||
change, err := json.Marshal(seed.Registrations)
|
||||
if err != nil {
|
||||
return "", err
|
||||
w := oc.Warrant{Ask: "module-graph"}
|
||||
for _, reg := range regs {
|
||||
p := Proposal{V: 1, Verb: verbRegister, Module: reg.Module, Caller: by, At: r.now(), State: ProposalOpen,
|
||||
Lines: []string{fmt.Sprintf("%s: registered from the module graph (%s)", reg.Module, reg.Origin)}}
|
||||
if err := r.write(ctx, "", p, reg, w); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
p := Proposal{V: 1, Verb: verbSeed, Change: change, Seed: seed.Registrations, Caller: by, At: r.now(), State: ProposalOpen}
|
||||
for _, g := range seed.Registrations {
|
||||
p.Lines = append(p.Lines, fmt.Sprintf("%s: registered from %s, watching %s", g.Module, g.Origin, strings.Join(g.Branches, ", ")))
|
||||
said := fmt.Sprintf("%d registrations written from the module graph", len(regs))
|
||||
if found && old.State == ProposalOpen {
|
||||
if err := r.end(ctx, SeedKey, old.Ask, ProposalApplied, said); err != nil {
|
||||
r.logf("the seed key is not ended: %v", err)
|
||||
}
|
||||
}
|
||||
for _, l := range seed.Left {
|
||||
p.Lines = append(p.Lines, "left out: "+l)
|
||||
if r.SeedWaits != nil && old.Ask != "" {
|
||||
r.SeedWaits(old.Ask, false)
|
||||
}
|
||||
if p.Digest, err = DigestOf(map[string]any{"verb": verbSeed, "change": json.RawMessage(change)}); err != nil {
|
||||
return "", err
|
||||
for _, l := range left {
|
||||
r.logf("the seed left out: %s", l)
|
||||
}
|
||||
if err := r.keepAndAsk(ctx, SeedKey, &p); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if r.SeedWaits != nil {
|
||||
// The seed waits on the operator while its ask is open; only the warrant clears the finding (design 47 G §704).
|
||||
r.SeedWaits(p.Ask, true)
|
||||
}
|
||||
return p.Ask, nil
|
||||
r.logf("the seed: %s", said)
|
||||
return said, nil
|
||||
}
|
||||
|
||||
// applySeed writes every registration the seed proposes, each as version 1 on the warrant, and ends the key applied.
|
||||
|
||||
Reference in New Issue
Block a user