Merge branch 'feat/47-H2-corrections-a' into feat/47-H2-corrections

This commit is contained in:
2026-11-25 18:59:37 +01:00
5 changed files with 153 additions and 9 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
Novox Mesh — delivery: the parts that build, check and deliver a change by watching and writing keys on the bus (ADR 0429).
Made by the mesh from the gitea module's config value `repositories` (novox/hq ADR 0428). Main takes no push: a change reaches it by a pull request whose `mesh/check`, the checker's verdict, passed (ADR 0447 §1); this repository holds no `merge-check.sh`.
Made by the mesh from the gitea module's config value `repositories` (novox/hq ADR 0428). Main takes no push: a change reaches it by a pull request, which the checker judges. The forge's branch protection of main requires no status today (read from the forge on 2026-11-25: no required check, no status on the pull request read); this repository holds no `merge-check.sh`.
@@ -183,4 +183,20 @@ func TestFixtures(t *testing.T) {
t.Errorf("%s: subject %q is not the contract's %s", c.name, c.subject, c.subjectIs)
}
}
// readers refuse a body naming none or two of the exclusive fields (H-A-645, H-A-644)
for _, r := range []struct {
name, given string
decode func([]byte) error
}{
{"a mover added naming none of from, caller and take-in", `{"fingerprint":"fp","module":"m","pipeline":"main.1","revision":1}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }},
{"a mover added naming from and take-in", `{"fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1,"take-in":2}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }},
{"a mover added naming caller and from", `{"caller":"x","fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1}`, func(b []byte) error { _, _, err := DecodeMoverAddedEvent(b); return err }},
{"a mover added naming all three", `{"caller":"x","fingerprint":"fp","from":"main.0","module":"m","pipeline":"main.1","revision":1,"take-in":2}`, func(b []byte) error { var v MoverAdded; return json.Unmarshal(b, &v) }},
{"place-unfinished naming key and all", `{"all":true,"key":"main.m","why":"x"}`, func(b []byte) error { var v PlaceUnfinishedInput; return json.Unmarshal(b, &v) }},
} {
if err := r.decode([]byte(r.given)); err == nil {
t.Errorf("%s: read, want refused", r.name)
}
}
}
@@ -0,0 +1,42 @@
package meshpipelinerunner
import (
"encoding/json"
"errors"
)
// UnmarshalJSON reads a mover-added body and refuses one naming none or two of from, caller and take-in
// (design 47 H2 H-A-594 (4), H-A-609 (3), H-A-645).
func (m *MoverAdded) UnmarshalJSON(raw []byte) error {
type plain MoverAdded
var v plain
if err := json.Unmarshal(raw, &v); err != nil {
return err
}
named := 0
for _, set := range []bool{v.From != "", v.Caller != "", v.TakeIn != 0} {
if set {
named++
}
}
if named != 1 {
return errors.New("mover-added names exactly one of from, caller and take-in")
}
*m = MoverAdded(v)
return nil
}
// UnmarshalJSON reads a place-unfinished input and refuses one naming both key and all
// (design 47 H2 H-A-644).
func (p *PlaceUnfinishedInput) UnmarshalJSON(raw []byte) error {
type plain PlaceUnfinishedInput
var v plain
if err := json.Unmarshal(raw, &v); err != nil {
return err
}
if v.All && v.Key != "" {
return errors.New("place-unfinished names exactly one of key and all")
}
*p = PlaceUnfinishedInput(v)
return nil
}
@@ -412,26 +412,31 @@ func absent(v []byte) bool { return v == nil }
func TestIndexerWhole(t *testing.T) {
const (
c10, c11, c12, c13 = "1010101010101010101010101010101010101010", "1111111111111111111111111111111111111111", "1212121212121212121212121212121212121212", "1313131313131313131313131313131313131313"
c15, c16 = "1515151515151515151515151515151515151515", "1616161616161616161616161616161616161616"
unread = "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"
)
var forge *forgeCommits
var heard *takeIns
var pins, held, takeinsKV, regs, runs, status jetstream.KeyValue
var pins, held, takeinsKV, regs, runs, status, heardKV jetstream.KeyValue
js, ctx, candidates, _, restart := startIndexerRun(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
heard = hearTakeIns(t, js.Conn())
forge = serveCommits(t, js.Conn())
for commit, tree := range map[string]string{c10: "t10", c11: "t11", c12: "t12", c13: "t13"} {
for commit, tree := range map[string]string{c10: "t10", c11: "t11", c12: "t12", c13: "t13", c15: "t15", c16: "t16"} {
forge.put(commit, catalogueAt(t, tree))
}
var err error
for _, b := range []struct {
state string
kv *jetstream.KeyValue
}{{index.HeldState, &held}, {index.TakeInsState, &takeinsKV}, {index.RunsState, &runs}, {views.StatusState, &status}} {
}{{index.HeldState, &held}, {index.TakeInsState, &takeinsKV}, {index.RunsState, &runs}, {views.StatusState, &status}, {index.HeardState, &heardKV}} {
if *b.kv, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, b.state), History: 64}); err != nil {
t.Fatal(err)
}
}
// The indexer's findings, which the grants part makes from its manifest's state findings (AC-I9 reads them).
if _, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: findingsBucket, History: 1}); err != nil {
t.Fatal(err)
}
regs = registerAvahi(t, ctx, js, "main", "beta")
tc, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.ToolchainsBucket("mesh-build-go"), History: 1})
if err != nil {
@@ -452,13 +457,17 @@ func TestIndexerWhole(t *testing.T) {
// Design 47 H2 H-A-578 (2), H-A-651 (AC-I9): an event of a subject the manifest no longer consumes, which the durable's
// filter still holds, is acknowledged with no work (the unit test of ackDropped holds that it says the subject once).
// Two rounds: the hub hands one message at a time and says an unhandled one's finding after its acknowledgement, so the
// second round's acknowledgements come after the first round's findings were written, if any.
var last uint64
for _, subject := range droppedSubjects {
ack, err := js.Publish(ctx, subject, []byte(`{}`))
if err != nil {
t.Fatal(err)
for range 2 {
for _, subject := range droppedSubjects {
ack, err := js.Publish(ctx, subject, []byte(`{}`))
if err != nil {
t.Fatal(err)
}
last = ack.Sequence
}
last = ack.Sequence
}
cons, err := testAccount.EventConsumer(ctx, js, views0Stream)
if err != nil {
@@ -476,6 +485,17 @@ func TestIndexerWhole(t *testing.T) {
t.Fatalf("the dropped subjects events are not acknowledged: ack floor %d, want %d", info.AckFloor.Stream, last)
}
}
// AC-I9: the hub says no finding event-unhandled of them, since the subjects have a handler (without it the hub
// acknowledges them just the same, so the acknowledgement above does not hold it).
findings, err := js.KeyValue(ctx, findingsBucket)
if err != nil {
t.Fatal(err)
}
if e, err := findings.Get(ctx, views.FindingKey(views.FindingScope, keys.EscapeName(testIndexer), views.EventUnhandledKind)); err == nil {
t.Errorf("the dropped subjects' events raised the finding %s: %s", e.Key(), e.Value())
} else if !errors.Is(err, jetstream.ErrKeyNotFound) {
t.Fatal(err)
}
// The first revision: no mover, no pin; its entries are the base.
sayMoved(t, ctx, js, "main", 10, c10, true)
// A revision's number is the indexer's own count, the branch's newest + 1 (design 47 H-A-213 (1)): the later take-ins of
@@ -695,6 +715,58 @@ func TestIndexerWhole(t *testing.T) {
t.Errorf("gamma.1 is not kept: %v", err)
}
// Design 47 H2 H-A-566, H-A-572, H-A-595, H-A-608 (AC-I7a, AC-I7b, AC-I7c, AC-I8): a pipeline that ended failed with a module
// unfinished pins the revision the module comes from and its base under the module's failed record; a cancelled end of a kept
// mover pins its kept revision and that revision's base; the record dropped by hand leaves the pins' other records; a module
// that leaves the registrations frees its record.
failedRecord := index.FailedRecord("main", "avahi")
lacks := func(record string) func([]byte) bool {
return func(v []byte) bool {
var p index.PinValue
return v == nil || (json.Unmarshal(v, &p) == nil && !slices.Contains(p.Records, record))
}
}
endedPipeline := func(pipeline string, revision int64, outcome string, movers []meshpipelinerunner.MoverEnded, unfinished ...string) {
t.Helper()
raw, _ := json.Marshal(meshpipelinerunner.PipelineEnded{V: 1, Pipeline: pipeline, Branch: "main", Source: revision, Revision: revision,
Outcome: outcome, Movers: movers, Unfinished: unfinished})
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineEnded("main", strconv.FormatInt(revision, 10)), raw); err != nil {
t.Fatal(err)
}
}
sayMoved(t, ctx, js, "main", 15, c15, false)
take15 := heard.next(t, "main", 15)
r15, p15 := take15.Revision, fmt.Sprintf("main.%d", take15.Revision)
r14 := r15 - 1
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p15))
untilKey(t, ctx, pins, index.PinKey("main", r14), pinned("pipeline."+p15))
endedPipeline(p15, r15, meshpipelinerunner.PipelineEndedOutcomeFailed, nil, "avahi") // AC-I7a: avahi unfinished
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned(failedRecord))
untilKey(t, ctx, pins, index.PinKey("main", r14), pinned(failedRecord)) // its base
sayMoved(t, ctx, js, "main", 16, c16, false)
take16 := heard.next(t, "main", 16)
r16, p16 := take16.Revision, fmt.Sprintf("main.%d", take16.Revision)
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned(failedRecord, "pipeline."+p16)) // main.16's base
// AC-I8: indexer_pin_drop with record drops that one record from every pin; the pin holding another record keeps it.
pinTools := index.PinsTools(kvStore{pins}, objects, askVia(t, ctx, takeinsKV), time.Now, func(string, string) error { return nil })
if _, err := toolNamed(t, pinTools, index.PinDropTool).Run(map[string]any{"record": failedRecord, "why": "the failed mover passed on its own"}); err != nil {
t.Fatal(err)
}
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p16))
untilKey(t, ctx, pins, index.PinKey("main", r14), lacks(failedRecord))
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16))
// AC-I7b: a pipeline of main.15 that keeps avahi at main.16 ended cancelled pins main.16 and its base main.15 under the
// record, the mover's own entry being where it is kept.
again := p15 + ".again"
startedAgain, _ := json.Marshal(meshpipelinerunner.PipelineStarted{V: 1, Pipeline: again, Branch: "main", Source: 15, Revision: r15, Kept: []int64{r16}})
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineStarted("main", strconv.FormatInt(r15, 10)), startedAgain); err != nil {
t.Fatal(err)
}
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16, "pipeline."+again))
endedPipeline(again, r15, meshpipelinerunner.PipelineEndedOutcomeCancelled, []meshpipelinerunner.MoverEnded{{Module: "avahi", Fingerprint: take16.Entries[0].Fingerprint,
Steps: []meshpipelinerunner.StepResult{{Step: meshpipelinerunner.StepResultStepUnit, Status: meshpipelinerunner.StepResultStatusRequired, Outcome: meshpipelinerunner.StepResultOutcomeCancelled}}}})
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16, failedRecord))
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p16, failedRecord))
// Design 47 H2 §815: a source-only registration, kept under source.<owner>.<name>, watches its branch as any registration
// does, and a move of that branch by its repository, which holds no manifest, is taken in with no movers.
const hqCommit = "4444444444444444444444444444444444444444"
@@ -719,6 +791,17 @@ func TestIndexerWhole(t *testing.T) {
t.Errorf("the move of novox/hq on delta said %+v, want revision 2 with no movers", hq)
}
// AC-I7c, H-A-756: avahi leaves main's registrations while a source-only registration is kept: the record is freed from every pin.
reg, _ = json.Marshal(meshcatalog.Registration{V: 1, Module: "avahi", Origin: "novox/mesh-catalog", Path: "modules/avahi", Branches: []string{"beta", "gamma"}})
if _, err := regs.Put(ctx, index.RegistrationKey("avahi"), reg); err != nil {
t.Fatal(err)
}
if _, err := js.Publish(ctx, meshcatalog.SubjectRegistrationChanged, []byte(`{"module":"avahi"}`)); err != nil {
t.Fatal(err)
}
untilKey(t, ctx, pins, index.PinKey("main", r16), lacks(failedRecord))
untilKey(t, ctx, pins, index.PinKey("main", r15), lacks(failedRecord))
// Design 47 H2 H-A-708 (1), H-A-717 DQ-54: the start's phases are kept at start-phase of the state first-views, and the
// start's last phase ended is null.
untilKey(t, ctx, status, views.StartPhaseKey, func(v []byte) bool { return string(v) == "null" })
@@ -340,6 +340,9 @@ func (r *Registry) RegisteredFailedRecords(ctx context.Context) (map[string]bool
if !found || json.Unmarshal(v, &reg) != nil {
continue
}
if strings.HasPrefix(k, "source.") {
continue // a source-only registration builds and delivers nothing, so it holds no failed record (H-A-756)
}
if reg.Module == "" {
return nil, fmt.Errorf("the registration %s names no module, so no failed record is freed by this read", k)
}