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>
This commit is contained in:
Julian Knutsen 2026-10-19 07:06:45 +00:00
commit 5c973b4ba9

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,31 @@ 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 TestDepEdgeDisplay(t *testing.T) {
cases := []struct {
name string