I4: predefined is read from the take-in of the catalog's commit

The take-in of a source revision moving the catalogue repository reads predefined.json from
that commit's trees through the seat git (wholeAt) and rewrites the state predefined when a
key changes. The read was already the take-in's (I8's wholeAt); this test holds it at the
take-in, and fails when the take-in writes no predefined.

Builds: design 47 H §769

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
2026-11-20 04:56:27 +01:00
parent b4f0c3ec88
commit d40e922be4
@@ -116,3 +116,37 @@ func TestAFirstSourceRevisionIsTakenInWithNoMover(t *testing.T) {
t.Errorf("a later take-in of the same head said %+v (%v), want no mover against the first revision", again, err)
}
}
// Design 47 H §769: the take-in of a source revision moving the catalogue repository reads `predefined` from that commit's
// trees, and one changing a predefined key rewrites it.
func TestATakeInOfTheCatalogsCommitRewritesPredefined(t *testing.T) {
ctx := context.Background()
ix, _, _, f := takeInIndexer(t)
ix.Predefined = newMem()
ix.Contains = func(context.Context, string, string, string) (bool, error) { return false, nil }
ix.Read = func(_ context.Context, _, _, _ string) (RepoRead, error) {
return RepoRead{Root: f.Root, Trees: f.Trees, Manifests: f.Manifests, Locks: f.Locks, Packages: f.Packages}, nil
}
lists := map[string]string{"c1": `{"keys":["a"]}`, "c2": `{"keys":["a","b"]}`}
ix.ReadFile = func(_ context.Context, _, sha, path string) ([]byte, error) {
if path != predefinedFile {
return nil, nil
}
return []byte(lists[sha]), nil
}
for i, commit := range []string{"c1", "c2"} {
moved := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: int64(i + 1), Call: "0123456789abcde" + commit[1:],
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: catalogueRepo, Commit: commit}}}
if _, err := ix.TakeInSource(ctx, moved); err != nil {
t.Fatal(err)
}
raw, _, found, _ := ix.Predefined.Get(ctx, PredefinedListKey)
var kept struct {
Commit string `json:"commit"`
List json.RawMessage `json:"list"`
}
if !found || json.Unmarshal(raw, &kept) != nil || kept.Commit != commit || string(kept.List) != lists[commit] {
t.Errorf("after the take-in of %s predefined holds %s, want its list at %s", commit, raw, commit)
}
}
}