test(list): pin --deps scheduling ordering under --sort closed in the tree (#7703)

* test(list): pin orderSiblingsByDeps ready-set ordering under a sort-derived comparator

Drive orderSiblingsByDeps with compareIssuesForTree("closed", false) over
shuffled input so the caller-supplied compare at the initial ready-set sort
and the post-pop re-sort is exercised with an ordering that disagrees with
priority. Exact-order assertion: dropping or re-hardcoding the post-pop sort
only swaps pa-b and pa-v.

AC: AC-1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5c973b4ba9)

Ported-From: opus/5c973b4ba9d93def077dfabe8186622052abffd5
AC: AC-1

* test(list): pin orderSiblingsByDeps cycle fallback under a sort-derived comparator

A two-node scheduling cycle where priority and ID favor pa-x but --sort
closed favors pa-y: the cycle fallback must follow the caller's compare.

AC: AC-2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d29c4611e6)

Ported-From: opus/d29c4611e63422cee2ff9aee9cf2a9719b5dff71
AC: AC-2

* test(list): pin --deps scheduling ordering under --sort closed in the tree

Render the tree with depsMode=scheduling and sortBy=closed at both the root
level and under one parent: the blocks edge must still put dep before late,
while the requested sort (not priority) puts the unlinked free first. Covers
both orderSiblingsByDeps call sites in list_tree.go.

AC: AC-3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f434dcd5e4)

Ported-From: opus/f434dcd5e47643121c1b4f882f57c7bc68fc69a9
AC: AC-3

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
This commit is contained in:
gascity-eddie[bot] 2026-10-20 02:19:13 +00:00 • committed by GitHub
commit d0d9aa2145
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 88 additions and 0 deletions

View file

@ -327,6 +327,50 @@ func TestListDisplayPrettyListHonorsSort(t *testing.T) {
t.Fatalf("tree siblings ignore --sort closed:\n%s", out)
}
})
t.Run("deps scheduling", func(t *testing.T) {
// At both levels the --deps tree orders (roots, and one parent's
// children): late depends on dep, so dep prints first although --sort
// closed alone would lead with the newer late; free has no edge, so
// --sort closed puts it ahead of dep, where priority would put it last.
oldest := time.Now().Add(-3 * time.Hour)
parentAt := time.Now().Add(-4 * time.Hour)
parent := &types.Issue{ID: "bd-parent", Title: "Parent", Status: types.StatusClosed, Priority: 2, IssueType: types.TypeEpic, ClosedAt: &parentAt}
rootDep := &types.Issue{ID: "bd-root-dep", Title: "Root dependency", Status: types.StatusClosed, Priority: 0, IssueType: types.TypeTask, ClosedAt: &oldest}
rootLate := &types.Issue{ID: "bd-root-late", Title: "Root dependent", Status: types.StatusClosed, Priority: 1, IssueType: types.TypeTask, ClosedAt: &newer}
rootFree := &types.Issue{ID: "bd-root-free", Title: "Root unlinked", Status: types.StatusClosed, Priority: 2, IssueType: types.TypeTask, ClosedAt: &older}
childDep := &types.Issue{ID: "bd-child-dep", Title: "Child dependency", Status: types.StatusClosed, Priority: 0, IssueType: types.TypeTask, ClosedAt: &oldest}
childLate := &types.Issue{ID: "bd-child-late", Title: "Child dependent", Status: types.StatusClosed, Priority: 1, IssueType: types.TypeTask, ClosedAt: &newer}
childFree := &types.Issue{ID: "bd-child-free", Title: "Child unlinked", Status: types.StatusClosed, Priority: 2, IssueType: types.TypeTask, ClosedAt: &older}
deps := map[string][]*types.Dependency{
rootLate.ID: {{IssueID: rootLate.ID, DependsOnID: rootDep.ID, Type: types.DepBlocks}},
childDep.ID: {{IssueID: childDep.ID, DependsOnID: parent.ID, Type: types.DepParentChild}},
childFree.ID: {{IssueID: childFree.ID, DependsOnID: parent.ID, Type: types.DepParentChild}},
childLate.ID: {
{IssueID: childLate.ID, DependsOnID: parent.ID, Type: types.DepParentChild},
{IssueID: childLate.ID, DependsOnID: childDep.ID, Type: types.DepBlocks},
},
}
issues := []*types.Issue{parent, rootDep, rootLate, rootFree, childDep, childLate, childFree}
out := captureStdout(t, func() error {
displayPrettyListWithDepsMode(issues, false, deps, "scheduling", false, false, "closed", "closed", false, nil)
return nil
})
// A dependency's id also appears on its dependent's annotation row; the
// first occurrence is still the dependency's own row whenever it prints first.
for _, want := range [][]string{
{rootFree.ID, rootDep.ID, rootLate.ID},
{childFree.ID, childDep.ID, childLate.ID},
} {
for i := 1; i < len(want); i++ {
before, after := strings.Index(out, want[i-1]), strings.Index(out, want[i])
if before < 0 || after < 0 || before > after {
t.Fatalf("--deps scheduling --sort closed: want %s before %s:\n%s", want[i-1], want[i], out)
}
}
}
})
}
func TestListDisplayPrettyList(t *testing.T) {

View file

@ -1,8 +1,10 @@
package main
import (
"slices"
"strings"
"testing"
"time"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/types"
@ -83,6 +85,48 @@ func TestOrderSiblingsByDeps_OutOfGroupEdgeIgnored(t *testing.T) {
}
}
// closedSibling builds a sibling closed hoursAgo hours before a fixed instant,
// so --sort closed (newest first) orders it independently of priority and ID.
func closedSibling(id string, priority, hoursAgo int) *types.Issue {
at := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC).Add(-time.Duration(hoursAgo) * time.Hour)
return &types.Issue{ID: id, Priority: priority, ClosedAt: &at}
}
func TestOrderSiblingsByDeps_ReadySetFollowsCallerCompare(t *testing.T) {
// b depends on a. Newest-closed first is b, u, a, v; priority order is
// v, a, u, b. The initial ready set {a, u, v} must follow the caller's
// compare (u, a, v), and once a frees b the re-sorted ready set must put
// the newer b ahead of v.
a := closedSibling("pa-a", 1, 3)
b := closedSibling("pa-b", 3, 1)
u := closedSibling("pa-u", 2, 2)
v := closedSibling("pa-v", 0, 4)
deps := map[string][]*types.Dependency{"pa-b": {schedDep("pa-b", "pa-a")}}
got := idsOf(orderSiblingsByDeps([]*types.Issue{b, a, v, u}, deps, compareIssuesForTree("closed", false)))
want := []string{"pa-u", "pa-a", "pa-b", "pa-v"}
if !slices.Equal(got, want) {
t.Fatalf("--sort closed ready set: got %v, want %v", got, want)
}
}
func TestOrderSiblingsByDeps_CycleFallbackFollowsCallerCompare(t *testing.T) {
// x <-> y cycle: x wins on priority and ID, but y closed more recently, so
// the cycle fallback under --sort closed must emit y first.
x := closedSibling("pa-x", 0, 2)
y := closedSibling("pa-y", 1, 1)
deps := map[string][]*types.Dependency{
"pa-x": {schedDep("pa-x", "pa-y")},
"pa-y": {schedDep("pa-y", "pa-x")},
}
got := idsOf(orderSiblingsByDeps([]*types.Issue{x, y}, deps, compareIssuesForTree("closed", false)))
want := []string{"pa-y", "pa-x"}
if !slices.Equal(got, want) {
t.Fatalf("--sort closed cycle fallback: got %v, want %v", got, want)
}
}
func TestDepEdgeDisplay(t *testing.T) {
cases := []struct {
name string