Skip to content
quarry Artifact [94eec82e17]
Login

Artifact [94eec82e17]

Artifact 94eec82e17422e1e984fc9d68cf72f34e8ad106343307b65ee8222a521f7a6b5:


package index

import "testing"

// RFC 0006: "An abandoned base is flagged: the record page says the base
// was rejected and names it."
//
// It did the opposite. Rejecting the base of a two-segment stack left
// the top segment reading as an ORDINARY landing: its stack fields went
// empty, mergeable flipped from "stacked" to clean, and the record page
// offered a live Accept on work whose base is gone. Taking it writes a
// merge check-in for a stack nobody will land (ticket b3aad27c).
//
// The cause was one condition. The walk stops at a rejected rung with
// position still 1, and nothing is stacked above a top segment, so the
// "standalone: no stack at all" shortcut fired and threw the membership
// away — while Broken had already been set and was about to be lost
// with it.
func TestARejectedBaseLeavesTheSegmentAboveFlagged(t *testing.T) {
	ls := []LandingSummary{
		{ID: "base01", Branch: "ci-pipeline", Target: "trunk", State: "rejected"},
		{ID: "top001", Branch: "puzzle-0923", Target: "ci-pipeline", State: "open"},
	}
	AttachStrata(ls)

	top := ls[1]
	if top.Broken != "base rejected" {
		t.Fatalf("FAIL: the top segment is not flagged: Broken=%q", top.Broken)
	}
	t.Log("ok: the top segment knows its base was rejected")
	if top.Stack == "" {
		t.Error("FAIL: the top segment lost its stack membership, so the page draws it as an ordinary landing")
	} else {
		t.Logf("ok: it keeps a stack (%s), so the page still has a chain to describe", top.Stack)
	}

	st := StrataOf(ls, "top001")
	if len(st.Segments) == 0 {
		t.Fatal("FAIL: StrataOf returned nothing; the record page has no chain to show")
	}
	t.Logf("ok: StrataOf answers with %d segment(s)", len(st.Segments))
	if st.Broken != "base rejected" {
		t.Errorf("FAIL: the strata does not carry the reason: %q", st.Broken)
	} else {
		t.Log("ok: the strata carries the reason the page must print")
	}
	// The one that matters: the accept control is not offered.
	for _, sgm := range st.Segments {
		if sgm.ID == "top001" && sgm.Landable {
			t.Error("FAIL: the orphaned segment is landable — a live Accept on work whose base is gone")
		} else if sgm.ID == "top001" {
			t.Log("ok: the orphaned segment is not landable")
		}
	}
}

// A genuinely standalone landing must NOT grow a stack out of this. The
// shortcut still fires for it; only a broken one is kept.
func TestAStandaloneLandingStaysStandalone(t *testing.T) {
	ls := []LandingSummary{{ID: "solo01", Branch: "fix", Target: "trunk", State: "open"}}
	AttachStrata(ls)
	if ls[0].Stack != "" {
		t.Errorf("FAIL: a lone landing was given a stack %q", ls[0].Stack)
	} else {
		t.Log("ok: a lone landing has no stack")
	}
	if st := StrataOf(ls, "solo01"); len(st.Segments) != 0 {
		t.Errorf("FAIL: StrataOf invented a chain for a standalone landing: %+v", st)
	} else {
		t.Log("ok: and no chain is drawn for it")
	}
}

// An intact stack is unchanged: the base lands, the top waits.
func TestAnIntactStackIsUnaffected(t *testing.T) {
	ls := []LandingSummary{
		{ID: "base01", Branch: "ci-pipeline", Target: "trunk", State: "open"},
		{ID: "top001", Branch: "puzzle-0923", Target: "ci-pipeline", State: "open"},
	}
	AttachStrata(ls)
	st := StrataOf(ls, "top001")
	if len(st.Segments) != 2 {
		t.Fatalf("FAIL: %d segments, want 2", len(st.Segments))
	}
	if st.Segments[0].ID != "base01" || !st.Segments[0].Landable {
		t.Error("FAIL: the base is not the landable bottom rung")
	} else {
		t.Log("ok: the base lands first")
	}
	if st.Segments[1].Landable {
		t.Error("FAIL: the top of an intact stack is landable")
	} else {
		t.Log("ok: the top waits its turn")
	}
}