Artifact 8dc3d7aceddef3c4dd730cbcf37e046a35ba237a20eacf02f781b8af5e54fca0:
- File
internal/index/strata_test.go
— part of check-in
[3e3ad17751]
at
2026-08-27 00:03:48
on branch strata-ui
— RFC 0006: the strata is derived, and the queue counts decisions
AttachStrata reads the chain from target -> branch across landings: base, position, depth, and why a chain cannot be walked — a cycle, or a rejected base. Derived at read time, never stored, so a segment retargeted by zit#144 after its base lands simply stops being one.
landing.list carries the reading and counts DECISIONS: a stack of five is one, the base's, because nothing above it can be acted on. landing.get carries the chain for the record's map and reports a rung above the bottom as stacked, which the merge probe must not overwrite: its answer is true and useless there. (user: dmestas, size: 3714) [annotate] [blame] [check-ins using] [more...]
package index import "testing" func ls(rows ...LandingSummary) []LandingSummary { return rows } func open(id, branch, target string) LandingSummary { return LandingSummary{ID: id, Branch: branch, Target: target, State: "open", Title: "t-" + id} } // RFC 0006: follow target → branch across open landings. The one whose // target is a plain branch is the base; position counts from it. func TestStrataIsReadFromTargets(t *testing.T) { rows := ls(open("c", "feat-c", "feat-b"), open("a", "feat-a", "trunk"), open("b", "feat-b", "feat-a"), open("x", "lone", "trunk")) AttachStrata(rows) got := map[string]LandingSummary{} for _, r := range rows { got[r.ID] = r } for id, want := range map[string][2]int{"a": {1, 3}, "b": {2, 3}, "c": {3, 3}} { if got[id].Stack != "a" || got[id].Position != want[0] || got[id].Depth != want[1] { t.Errorf("%s: stack=%q pos=%d depth=%d, want a/%d/%d", id, got[id].Stack, got[id].Position, got[id].Depth, want[0], want[1]) } } if got["x"].Stack != "" { t.Errorf("a standalone landing was put in a stack: %+v", got["x"]) } // Five open landings, two decisions: the stack's base and the loner. if n := Decisions(rows); n != 2 { t.Errorf("decisions=%d, want 2", n) } st := StrataOf(rows, "c") if st.Base != "a" || len(st.Segments) != 3 || st.Segments[0].ID != "a" || st.Segments[2].ID != "c" { t.Fatalf("StrataOf(c) = %+v", st) } if !st.Segments[0].Landable || st.Segments[1].Landable || st.Segments[2].Landable { t.Errorf("landable marks wrong: %+v", st.Segments) } } // A base that was rejected: everything above it is stacked on work // nobody will land, and the chain says so rather than reading the next // rung as a fresh base. func TestStrataFlagsARejectedBase(t *testing.T) { rows := ls( LandingSummary{ID: "a", Branch: "feat-a", Target: "trunk", State: "rejected"}, open("b", "feat-b", "feat-a"), open("c", "feat-c", "feat-b")) AttachStrata(rows) for _, r := range rows[1:] { if r.Broken != "base rejected" { t.Errorf("%s: broken=%q, want base rejected", r.ID, r.Broken) } } if st := StrataOf(rows, "c"); st.Broken != "base rejected" || st.Segments[0].Landable { t.Errorf("a stack on a rejected base offers a landable rung: %+v", st) } } // An accepted base not yet retargeted: the rung above is next, and is // the base of what remains. func TestStrataMovesUpWhenTheBaseLands(t *testing.T) { rows := ls( LandingSummary{ID: "a", Branch: "feat-a", Target: "trunk", State: "accepted"}, open("b", "feat-b", "feat-a"), open("c", "feat-c", "feat-b")) AttachStrata(rows) var b LandingSummary for _, r := range rows { if r.ID == "b" { b = r } } if b.Stack != "b" || b.Position != 1 || b.Broken != "" { t.Fatalf("after the base landed, b = %+v, want the new base", b) } if n := Decisions(rows); n != 1 { t.Errorf("decisions=%d, want 1", n) } } // A cycle is expressible and must be a rendering fault, not a hang. func TestStrataReportsACycle(t *testing.T) { rows := ls(open("a", "feat-a", "feat-b"), open("b", "feat-b", "feat-a")) AttachStrata(rows) for _, r := range rows { if r.Broken != "cycle" { t.Errorf("%s: broken=%q, want cycle", r.ID, r.Broken) } } } // A superseded landing is not a rung: the current landing on the branch is. func TestStrataSkipsSupersededLandings(t *testing.T) { old := open("a0", "feat-a", "trunk") old.SupersededBy = "a" rows := ls(old, open("a", "feat-a", "trunk"), open("b", "feat-b", "feat-a")) AttachStrata(rows) for _, r := range rows { if r.ID == "b" && r.Stack != "a" { t.Errorf("b stacked on %q, want the current landing a", r.Stack) } if r.ID == "a0" && r.Stack != "" { t.Error("the superseded landing was given a stack") } } }