diff --git a/.github/scripts/embedded-cmd-test-shards.txt b/.github/scripts/embedded-cmd-test-shards.txt index 46da38bc5..41e1d8180 100644 --- a/.github/scripts/embedded-cmd-test-shards.txt +++ b/.github/scripts/embedded-cmd-test-shards.txt @@ -152,6 +152,7 @@ 100 63 TestEmbeddedDepAndLinkBatchAutoCommitDoesNotAdvanceHead 100 63 TestEmbeddedGateCheckLimitCountsOnlyLiveGates 100 63 TestEmbeddedIfRevisionDeletePreflightGoneParentIsPreconditionFailed +100 63 TestEmbeddedListPageEdges 100 64 TestEmbeddedGateWaiterCheckLifecycle 100 64 TestEmbeddedPromoteMovesAWispParent diff --git a/CHANGELOG.md b/CHANGELOG.md index f12d72c83..cd35d71e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -551,6 +551,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `mc-gate-check-timer`, `mc-gate-check-gh`, `gate-check-all` and a served test over await-typed and template gates. +- **`bd list`'s text renderings read only the listed issues' dependency + edges.** The tree (the default), `--deps`, `--parent`, `--format` and + `--watch` loaded every dependency record in the workspace + (`GetAllDependencyRecords`) to draw one page. Over a connected HTTP + workspace that is a walk of the whole workspace: every issue id, 200 per + request, then every id's edges, 100 per request. `bd list --limit 20` + against a ~3,800-issue workspace made 62 sequential requests (~5.7 s at + ~50 ms a round trip). Every rendering reads only edges a listed issue owns, + so the listing now reads exactly those through the `EdgeReader` role: one + request per 100 listed ids over HTTP. The same listing makes 6 requests + (~0.5 s), one more than `bd list --json`, and prints the same bytes. On a + local store a default page is as fast or faster. A listing that covers most + of a large store now pays batched reads (four queries per 200 listed ids) + instead of one scan of both edge tables, which costs more past roughly + 1,000 listed rows: +0.07 s at 1,000 rows and +0.46 s at 4,000 on embedded + Dolt. A store with many wisps, whose edges the old read also scanned, is + faster at every page size. - **`bd gate list` works over a connected HTTP workspace** (S20). The workspace-wide listing built a raw `SearchIssues` filter, which the HTTP backend refuses, so gc's `renudge-stale-human-gates` order failed on every diff --git a/backend/http/BUILD.bazel b/backend/http/BUILD.bazel index dc6a908f1..81d915655 100644 --- a/backend/http/BUILD.bazel +++ b/backend/http/BUILD.bazel @@ -34,6 +34,7 @@ go_test( "e2e_cli_test.go", "e2e_export_test.go", "e2e_list_filters_test.go", + "e2e_list_page_edges_test.go", "e2e_mol_test.go", "e2e_promote_test.go", "e2e_read_your_own_write_test.go", diff --git a/backend/http/e2e_list_page_edges_test.go b/backend/http/e2e_list_page_edges_test.go new file mode 100644 index 000000000..641b9c63b --- /dev/null +++ b/backend/http/e2e_list_page_edges_test.go @@ -0,0 +1,221 @@ +//go:build cgo + +package bdhttp_test + +import ( + "encoding/json" + "net" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "slices" + "strings" + "sync" + "testing" +) + +// recordedRequest is one request the query-recording proxy forwarded. +type recordedRequest struct { + method, path string + query url.Values +} + +func (r recordedRequest) String() string { + if len(r.query) == 0 { + return r.method + " " + r.path + } + return r.method + " " + r.path + "?" + r.query.Encode() +} + +// queryRecorder keeps each request's decoded query beside its method and path, +// so a case can assert WHICH ids a read named rather than only how many reads a +// command made. requestCounter records paths alone, which cannot tell a read of +// the listed ids from a read of every id in the workspace. +type queryRecorder struct { + mu sync.Mutex + reqs []recordedRequest +} + +func (q *queryRecorder) reset() { + q.mu.Lock() + defer q.mu.Unlock() + q.reqs = nil +} + +func (q *queryRecorder) snapshot() []recordedRequest { + q.mu.Lock() + defer q.mu.Unlock() + return append([]recordedRequest(nil), q.reqs...) +} + +// startQueryRecordingProxy is startCountingProxy that also records each +// request's query. +func startQueryRecordingProxy(t *testing.T, upstream string) (string, *queryRecorder) { + t.Helper() + target, err := url.Parse("http://" + upstream) + if err != nil { + t.Fatal(err) + } + rec := &queryRecorder{} + proxy := httputil.NewSingleHostReverseProxy(target) + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + srv := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rec.mu.Lock() + rec.reqs = append(rec.reqs, recordedRequest{method: r.Method, path: r.URL.Path, query: r.URL.Query()}) + rec.mu.Unlock() + proxy.ServeHTTP(w, r) + })} + go func() { _ = srv.Serve(ln) }() + t.Cleanup(func() { _ = srv.Close() }) + return ln.Addr().String(), rec +} + +// TestE2E_ListTextRenderingsReadOnlyTheListedIssuesEdges pins the dependency +// read behind `bd list`'s text renderings over http — the default tree, --deps, +// a page cut by --limit, the --parent tree and --format — to ONE anchored +// listDependencies request naming exactly the listed issues. +// +// It used to be GetAllDependencyRecords, which over http enumerates every issue +// id in the workspace (all=true, 200 per page) and then reads every id's edges +// in chunks of 100: O(workspace/100) sequential requests for a 20-row page, +// 62 requests and ~6 s against a ~3.8k-issue workspace at ~50 ms a round trip. +// Every rendering reads only edges OWNED by a listed issue, so the listed ids +// are the whole question. The fixture makes the difference visible on a small +// workspace: a closed issue the default listing hides owns a parent-child edge +// onto the listed parent and a blocks edge onto a listed issue, and a read of +// the whole workspace would name it as an anchor. +// +// The ids are not dotted, so the nesting the tree prints can only have come +// from the parent-child edges this read returned: if the read failed, the tree +// would fall back to dotted-id nesting and print every issue as a root. +func TestE2E_ListTextRenderingsReadOnlyTheListedIssuesEdges(t *testing.T) { + skipUnlessEmbeddedDolt(t) + bin := buildBD(t) + proxyAddr, rec := startQueryRecordingProxy(t, startE2EServer(t)) + f := newHTTPFixture(t, bin, proxyAddr) + + // One graph apply seeds the whole fixture, so setup costs two subprocesses + // rather than one per issue and edge. An edge reads "from depends on to". + plan := filepath.Join(t.TempDir(), "plan.json") + if err := os.WriteFile(plan, []byte(`{ + "nodes": [ + {"key": "parent", "title": "tree parent", "type": "epic", "priority": 0}, + {"key": "a", "title": "tree child a", "type": "task", "priority": 1}, + {"key": "b", "title": "tree child b", "type": "task", "priority": 2}, + {"key": "loner", "title": "tree loner", "type": "task", "priority": 3}, + {"key": "hidden", "title": "tree hidden", "type": "task", "priority": 1} + ], + "edges": [ + {"from_key": "a", "to_key": "parent", "type": "parent-child"}, + {"from_key": "b", "to_key": "parent", "type": "parent-child"}, + {"from_key": "b", "to_key": "a", "type": "blocks"}, + {"from_key": "loner", "to_key": "a", "type": "related"}, + {"from_key": "hidden", "to_key": "parent", "type": "parent-child"}, + {"from_key": "hidden", "to_key": "loner", "type": "blocks"} + ] + }`), 0o600); err != nil { + t.Fatal(err) + } + var applied struct { + IDs map[string]string `json:"ids"` + } + if out := f.mustRun(nil, "create", "--graph", plan, "--json").stdout; json.Unmarshal([]byte(out), &applied) != nil || len(applied.IDs) != 5 { + t.Fatalf("bd create --graph --json did not report the five ids: %s", out) + } + parent, childA, childB := applied.IDs["parent"], applied.IDs["a"], applied.IDs["b"] + loner, hidden := applied.IDs["loner"], applied.IDs["hidden"] + // Closed separately: the batch create cannot carry a closed row's + // closed_at over the wire. --force because hidden is blocked by loner. + f.mustRun(nil, "close", hidden, "--reason", "done", "--force") + + // Through the subtest's own t: f.mustRun fails the PARENT test, which a + // subtest may not do. + run := func(t *testing.T, args ...string) string { + t.Helper() + r := runBD(t, f.bin, f.dir, nil, args...) + if r.code != 0 { + t.Fatalf("bd %s failed (exit %d): stdout=%s stderr=%s", strings.Join(args, " "), r.code, r.stdout, r.stderr) + } + return r.stdout + } + // The --json listing is the budget's base: a text rendering of a page may + // cost that page plus its ONE edge read. Its count does not depend on the + // page size below the 200-row page, so one measurement serves every page. + rec.reset() + run(t, "list", "--json") + base := len(rec.snapshot()) + + listed := []string{parent, childA, childB, loner} + for _, tc := range []struct { + name string + args []string + anchors []string + // page marks a rendering of the listing's page, held to the --json + // budget; the --parent tree is a walk, not a page. + page bool + want []string + }{ + { + name: "tree", args: []string{"list"}, anchors: listed, page: true, + want: []string{"├── ○ " + childA, "└── ○ " + childB}, + }, + { + name: "deps all", args: []string{"list", "--deps=all"}, anchors: listed, page: true, + want: []string{"[depends-on]", "[related]"}, + }, + { + name: "truncated page", args: []string{"list", "--limit", "2"}, anchors: []string{parent, childA}, page: true, + want: []string{"└── ○ " + childA}, + }, + { + name: "parent tree", args: []string{"list", "--parent", parent}, anchors: []string{parent, childA, childB}, + want: []string{"├── ○ " + childA, "└── ○ " + childB}, + }, + { + name: "format digraph", args: []string{"list", "--format", "digraph"}, anchors: listed, page: true, + want: []string{childA + " " + parent, childB + " " + parent, childB + " " + childA, loner + " " + childA}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + rec.reset() + out := run(t, tc.args...) + reqs := rec.snapshot() + t.Logf("bd %s: %d requests: %v", strings.Join(tc.args, " "), len(reqs), reqs) + + var edgeReads []recordedRequest + for _, r := range reqs { + if r.path == "/v0/beads/dependencies" { + edgeReads = append(edgeReads, r) + } + } + if len(edgeReads) != 1 { + t.Fatalf("bd %s made %d listDependencies requests, want exactly 1 (the listed issues' edges): %v", + strings.Join(tc.args, " "), len(edgeReads), edgeReads) + } + got := slices.Sorted(slices.Values(edgeReads[0].query["issue_id"])) + want := slices.Sorted(slices.Values(tc.anchors)) + if !slices.Equal(got, want) { + t.Errorf("bd %s read the edges of %v, want exactly the listed issues %v", + strings.Join(tc.args, " "), got, want) + } + if tc.page && len(reqs) > base+1 { + t.Errorf("bd %s made %d requests; bd list --json makes %d, and the text rendering may add only its one edge read", + strings.Join(tc.args, " "), len(reqs), base) + } + for _, w := range tc.want { + if !strings.Contains(out, w) { + t.Errorf("bd %s output lacks %q:\n%s", strings.Join(tc.args, " "), w, out) + } + } + if strings.Contains(out, hidden) { + t.Errorf("bd %s printed the closed issue %s, which the default listing hides:\n%s", + strings.Join(tc.args, " "), hidden, out) + } + }) + } +} diff --git a/cmd/bd/BUILD.bazel b/cmd/bd/BUILD.bazel index 1d1ff86d2..0cfa31cb3 100644 --- a/cmd/bd/BUILD.bazel +++ b/cmd/bd/BUILD.bazel @@ -217,6 +217,7 @@ go_library( "list_format.go", "list_input.go", "list_output.go", + "list_page_edges.go", "list_proxied_server.go", "list_roles.go", "list_show_filter_modes.go", @@ -945,6 +946,9 @@ go_test( "list_helpers_test.go", "list_limit_policy_test.go", "list_output_test.go", + "list_page_edges_embedded_test.go", + "list_page_edges_store_test.go", + "list_page_edges_test.go", "list_proxied_integration_test.go", "list_proxied_watch_max_rows_test.go", "list_ready_brief_test.go", diff --git a/cmd/bd/list.go b/cmd/bd/list.go index 9d3f9c6e5..7d307fb91 100644 --- a/cmd/bd/list.go +++ b/cmd/bd/list.go @@ -321,7 +321,7 @@ func runListCore(cmd *cobra.Command, _ []string) error { return nil } - allDeps, depErr := activeStore.GetAllDependencyRecords(ctx) + allDeps, depErr := listDependencyRecords(ctx, activeStore, treeIssues) if depErr != nil && in.depsMode != "" { return HandleError("loading dependencies for --deps: %v", depErr) } @@ -332,13 +332,14 @@ func runListCore(cmd *cobra.Command, _ []string) error { return nil } - allDeps, depErr := activeStore.GetAllDependencyRecords(ctx) + allDeps, depErr := listDependencyRecords(ctx, activeStore, issues) if depErr != nil && in.depsMode != "" { return HandleError("loading dependencies for --deps: %v", depErr) } - // allDeps is already the whole rig's edge map, so the gate decoration - // adds ONE call here — the hydration of the gate candidates it names, - // itself an id-set read of a few round trips. Per page, never per row. + // allDeps already holds every edge the page's rows own, so the gate + // decoration adds ONE call here — the hydration of the gate candidates + // it names, itself an id-set read of a few round trips. Per page, never + // per row. displayPrettyListWithDepsMode(issues, false, allDeps, in.depsMode, truncated, in.ReadyFlag, in.Status, in.SortBy, in.Reverse, gatedIssueIDs(ctx, activeStore, issues, allDeps)) printTruncationHint(truncated, in.effectiveLimit) @@ -347,7 +348,7 @@ func runListCore(cmd *cobra.Command, _ []string) error { } if in.formatStr != "" { - depsByIssueID, _ := activeStore.GetAllDependencyRecords(ctx) + depsByIssueID, _ := listDependencyRecords(ctx, activeStore, issues) if err := outputFormattedList(out, issues, depsByIssueID, in.formatStr); err != nil { return HandleError("%v", err) } diff --git a/cmd/bd/list_helpers_test.go b/cmd/bd/list_helpers_test.go index 2f81c72fc..763934a80 100644 --- a/cmd/bd/list_helpers_test.go +++ b/cmd/bd/list_helpers_test.go @@ -14,15 +14,6 @@ import ( "github.com/steveyegge/beads/internal/workapi" ) -type watchListDependencyStoreStub struct { - allDeps map[string][]*types.Dependency - err error -} - -func (s watchListDependencyStoreStub) GetAllDependencyRecords(_ context.Context) (map[string][]*types.Dependency, error) { - return s.allDeps, s.err -} - func TestListParseTimeFlag(t *testing.T) { cases := []string{ "2025-12-26", @@ -390,8 +381,8 @@ func TestListDisplayPrettyList_TruncatedSummary(t *testing.T) { func TestDisplayWatchedIssueList_UsesDependencyHierarchy(t *testing.T) { parent := &types.Issue{ID: "bd-zparent", Title: "Parent", Status: types.StatusOpen, Priority: 1, IssueType: types.TypeEpic} child := &types.Issue{ID: "bd-achild", Title: "Child", Status: types.StatusOpen, Priority: 1, IssueType: types.TypeTask} - store := watchListDependencyStoreStub{ - allDeps: map[string][]*types.Dependency{ + store := &edgeSourceStub{ + edges: map[string][]*types.Dependency{ child.ID: { {IssueID: child.ID, DependsOnID: parent.ID, Type: types.DepParentChild}, }, diff --git a/cmd/bd/list_page_edges.go b/cmd/bd/list_page_edges.go new file mode 100644 index 000000000..0a7492f64 --- /dev/null +++ b/cmd/bd/list_page_edges.go @@ -0,0 +1,64 @@ +package main + +import ( + "context" + + "github.com/steveyegge/beads/internal/types" + "github.com/steveyegge/beads/issueops" +) + +// listEdgeSource is the one accessor listDependencyRecords needs. Every +// storage.DoltStorage satisfies it, and the --watch display takes it rather +// than the whole store so a test can hand it a stub. +type listEdgeSource interface { + EdgeReader() (issueops.EdgeReader, error) +} + +// listDependencyRecords returns the stored outgoing dependency edges of the +// listed issues, keyed by issue id, in the shape GetAllDependencyRecords +// returns: no key for an issue with no edges, and a non-nil map on success. +// +// These are the only edges any `bd list` text rendering reads. Every reader +// keys the map by a LISTED issue's id: buildIssueTreeWithDepsOrdered nests a +// child under a parent only when both are listed, and it looks the edge up +// under the child; orderSiblingsByDeps and depRender.annotationsFor read the +// edges of the sibling or node they are drawing; gatesByIssueID reads the +// edges of the listed ids it decorates; and outputFormattedList prints the +// edges of listed issues whose target is listed too. An edge that an unlisted +// issue owns is never read, even when it points at a listed one, and a parent +// that is not listed nests nothing. So the listed ids are the whole question, +// and a full-store read would only fetch edges that are then ignored. +// +// It reads through the EdgeReader role rather than GetDependencyRecordsForIssues +// because every backend serves the role. The http store refuses the raw batch +// method (internal/httpclient/unsupported_gen.go) and answers the role with one +// anchored listDependencies request per 100 ids. GetAllDependencyRecords has no +// wire operation of its own, so over http it pages through every issue id in +// the workspace and then reads every id's edges in chunks of 100: about 60 +// sequential requests for a 20-row page of a ~3,800-issue workspace. +func listDependencyRecords(ctx context.Context, src listEdgeSource, issues []*types.Issue) (map[string][]*types.Dependency, error) { + deps := make(map[string][]*types.Dependency) + ids := make([]string, 0, len(issues)) + for _, issue := range issues { + if issue != nil { + ids = append(ids, issue.ID) + } + } + if len(ids) == 0 { + return deps, nil + } + reader, err := src.EdgeReader() + if err != nil { + return nil, err + } + result, err := reader.ReadEdges(ctx, issueops.EdgeReadRequest{IDs: ids}) + if err != nil { + return nil, err + } + for _, anchor := range result.Anchors { + if len(anchor.Edges) > 0 { + deps[anchor.ID] = anchor.Edges + } + } + return deps, nil +} diff --git a/cmd/bd/list_page_edges_embedded_test.go b/cmd/bd/list_page_edges_embedded_test.go new file mode 100644 index 000000000..05150ba6e --- /dev/null +++ b/cmd/bd/list_page_edges_embedded_test.go @@ -0,0 +1,26 @@ +//go:build cgo + +package main + +import ( + "os" + "testing" +) + +// TestEmbeddedListPageEdges runs the page-edge parity proof and the direct +// route's edge-read pin (list_page_edges_store_test.go) against embedded Dolt. +// The two share one seeded store; the Dolt-server lane runs them through +// TestListDependencyRecordsMatchesTheStoreWideRead and +// TestListTextRenderingsReadTheListedIssuesEdgesOnly. +func TestEmbeddedListPageEdges(t *testing.T) { + if os.Getenv("BEADS_TEST_EMBEDDED_DOLT") != "1" { + t.Skip("set BEADS_TEST_EMBEDDED_DOLT=1 to run embedded dolt integration tests") + } + f := seedListEdgeStore(t, openEmbeddedListEdgeStore(t)) + t.Run("records match the store-wide read", func(t *testing.T) { + checkListDependencyRecordsParity(t, f) + }) + t.Run("text renderings read the listed issues' edges", func(t *testing.T) { + checkListTextRenderingsReadListedEdges(t, f) + }) +} diff --git a/cmd/bd/list_page_edges_store_test.go b/cmd/bd/list_page_edges_store_test.go new file mode 100644 index 000000000..6b8837308 --- /dev/null +++ b/cmd/bd/list_page_edges_store_test.go @@ -0,0 +1,309 @@ +//go:build cgo + +package main + +import ( + "context" + "path/filepath" + "reflect" + "slices" + "strings" + "testing" + + "github.com/steveyegge/beads/internal/storage" + "github.com/steveyegge/beads/internal/storage/embeddeddolt" + "github.com/steveyegge/beads/internal/types" + "github.com/steveyegge/beads/internal/ui" + "github.com/steveyegge/beads/issueops" +) + +// openEmbeddedListEdgeStore opens a fresh embedded-Dolt store for +// TestEmbeddedListPageEdges, configured the way newTestStoreWithPrefix +// configures a server store. +func openEmbeddedListEdgeStore(t *testing.T) storage.DoltStorage { + t.Helper() + ctx := t.Context() + s, err := embeddeddolt.Open(ctx, t.TempDir(), "beads", "main") + if err != nil { + t.Fatalf("open embedded store: %v", err) + } + t.Cleanup(func() { _ = s.Close() }) + if err := s.SetConfig(ctx, "issue_prefix", "le"); err != nil { + t.Fatalf("set issue_prefix: %v", err) + } + if err := s.SetConfig(ctx, "types.custom", "molecule,gate,convoy,merge-request,slot,agent,role,rig,event,message"); err != nil { + t.Fatalf("set types.custom: %v", err) + } + return s +} + +// listEdgeStoreFixture is a seeded store and the ids it minted, by name. +type listEdgeStoreFixture struct { + store storage.DoltStorage + ids map[string]string +} + +func (f listEdgeStoreFixture) issues(t *testing.T, names ...string) []*types.Issue { + t.Helper() + ids := make([]string, len(names)) + for i, name := range names { + ids[i] = f.ids[name] + } + got, err := f.store.GetIssuesByIDs(t.Context(), ids) + if err != nil { + t.Fatalf("GetIssuesByIDs(%v): %v", names, err) + } + byID := make(map[string]*types.Issue, len(got)) + for _, is := range got { + byID[is.ID] = is + } + out := make([]*types.Issue, 0, len(ids)) + for i, id := range ids { + if byID[id] == nil { + t.Fatalf("issue %s (%s) not found", names[i], id) + } + out = append(out, byID[id]) + } + return out +} + +func (f listEdgeStoreFixture) idSet(names ...string) []string { + out := make([]string, len(names)) + for i, name := range names { + out[i] = f.ids[name] + } + slices.Sort(out) + return out +} + +// seedListEdgeStore builds, in both planes, the graph the page-scoped read has +// to answer exactly as the store-wide one does: parent-child children (one of +// them closed, so a default listing hides it), every edge type, an external +// reference, open and closed gates, a closed dependent pointing at listed +// issues, and wisps whose edges live in wisp_dependencies, one of them a child +// of a durable epic. +func seedListEdgeStore(t *testing.T, s storage.DoltStorage) listEdgeStoreFixture { + t.Helper() + ctx := t.Context() + f := listEdgeStoreFixture{store: s, ids: map[string]string{}} + create := func(name string, issue *types.Issue) { + t.Helper() + issue.Title = name + issue.Status = types.StatusOpen + if err := s.CreateIssue(ctx, issue, "tester"); err != nil { + t.Fatalf("create %s: %v", name, err) + } + f.ids[name] = issue.ID + } + edge := func(from, to string, typ types.DependencyType) { + t.Helper() + target := f.ids[to] + if target == "" { + target = to // external or foreign references are stored verbatim + } + if err := s.AddDependency(ctx, &types.Dependency{IssueID: f.ids[from], DependsOnID: target, Type: typ}, "tester"); err != nil { + t.Fatalf("add %s -[%s]-> %s: %v", from, typ, to, err) + } + } + + create("epic", &types.Issue{IssueType: types.TypeEpic, Priority: 0}) + create("alpha", &types.Issue{IssueType: types.TypeTask, Priority: 1}) + create("bravo", &types.Issue{IssueType: types.TypeTask, Priority: 2}) + create("delta", &types.Issue{IssueType: types.TypeBug, Priority: 3}) + create("other", &types.Issue{IssueType: types.TypeTask, Priority: 4}) + create("gate", &types.Issue{IssueType: types.TypeGate, Priority: 2}) + create("hidden", &types.Issue{IssueType: types.TypeTask, Priority: 1}) + create("gate done", &types.Issue{IssueType: types.TypeGate, Priority: 2}) + create("wisp", &types.Issue{IssueType: types.TypeTask, Priority: 2, Ephemeral: true}) + create("wisp child", &types.Issue{IssueType: types.TypeTask, Priority: 2, Ephemeral: true}) + + edge("alpha", "epic", types.DepParentChild) + edge("bravo", "epic", types.DepParentChild) + edge("bravo", "alpha", types.DepBlocks) + edge("bravo", "gate", types.DepBlocks) + edge("bravo", "gate done", types.DepBlocks) + edge("delta", "alpha", types.DepRelated) + edge("delta", "bravo", types.DepWaitsFor) + edge("delta", "other", types.DepDiscoveredFrom) + edge("delta", "epic", types.DepConditionalBlocks) + edge("delta", "external:other:cap", types.DepBlocks) + edge("other", "delta", types.DepDuplicates) + edge("hidden", "epic", types.DepParentChild) + edge("hidden", "delta", types.DepBlocks) + edge("hidden", "alpha", types.DepRelated) + edge("wisp", "epic", types.DepParentChild) + edge("wisp child", "wisp", types.DepParentChild) + edge("wisp child", "alpha", types.DepBlocks) + + for _, name := range []string{"hidden", "gate done"} { + if err := s.CloseIssue(ctx, f.ids[name], "done", "tester", ""); err != nil { + t.Fatalf("close %s: %v", name, err) + } + } + return f +} + +// newListEdgeServerStore is a fresh store on the shared Dolt test server +// (newTestStoreWithPrefix skips when there is none). +func newListEdgeServerStore(t *testing.T) storage.DoltStorage { + t.Helper() + return newTestStoreWithPrefix(t, filepath.Join(t.TempDir(), ".beads", "beads.db"), "le") +} + +// TestListDependencyRecordsMatchesTheStoreWideRead runs +// checkListDependencyRecordsParity on the Dolt server; TestEmbeddedListPageEdges +// runs it on embedded Dolt. +func TestListDependencyRecordsMatchesTheStoreWideRead(t *testing.T) { + checkListDependencyRecordsParity(t, seedListEdgeStore(t, newListEdgeServerStore(t))) +} + +// checkListDependencyRecordsParity is the parity proof on a real store: for +// every listed issue, listDependencyRecords answers exactly the records +// GetAllDependencyRecords holds for it (same rows, same fields, same order, +// both planes), it answers nothing for an issue it was not asked about, and +// every `bd list` text rendering prints the same bytes from either map. +func checkListDependencyRecordsParity(t *testing.T, f listEdgeStoreFixture) { + t.Helper() + ctx := t.Context() + all, err := f.store.GetAllDependencyRecords(ctx) + if err != nil { + t.Fatalf("GetAllDependencyRecords: %v", err) + } + + pages := map[string][]string{ + "default listing": {"epic", "alpha", "bravo", "delta", "other"}, + "truncated page": {"epic", "alpha"}, + "parent tree": {"epic", "alpha", "bravo"}, + "with closed": {"epic", "alpha", "bravo", "delta", "other", "hidden", "gate", "gate done"}, + "with wisps": {"epic", "alpha", "wisp", "wisp child"}, + "wisps only": {"wisp", "wisp child"}, + } + for name, names := range pages { + t.Run(name, func(t *testing.T) { + page := f.issues(t, names...) + got, err := listDependencyRecords(ctx, f.store, page) + if err != nil { + t.Fatalf("listDependencyRecords: %v", err) + } + listed := make(map[string]bool, len(page)) + for _, is := range page { + listed[is.ID] = true + if !reflect.DeepEqual(got[is.ID], all[is.ID]) { + t.Errorf("edges of %s: page read %v, store-wide read %v", is.ID, describeDeps(got[is.ID]), describeDeps(all[is.ID])) + } + } + for id := range got { + if !listed[id] { + t.Errorf("page read returned edges of %s, which is not listed", id) + } + } + hydrate := func(ctx context.Context, ids []string) ([]*types.Issue, error) { + return f.store.GetIssuesByIDs(ctx, ids) + } + assertSameListTextOutputs(t, + renderListTextOutputs(t, hydrate, page, all), + renderListTextOutputs(t, hydrate, page, got)) + }) + } +} + +func describeDeps(deps []*types.Dependency) string { + parts := make([]string, len(deps)) + for i, d := range deps { + parts[i] = d.IssueID + " -[" + string(d.Type) + "]-> " + d.DependsOnID + } + return "[" + strings.Join(parts, "; ") + "]" +} + +// listEdgeSpyStore is a real store that records how a command read its edges. +type listEdgeSpyStore struct { + storage.DoltStorage + wholeStoreReads int + anchors [][]string +} + +func (s *listEdgeSpyStore) GetAllDependencyRecords(ctx context.Context) (map[string][]*types.Dependency, error) { + s.wholeStoreReads++ + return s.DoltStorage.GetAllDependencyRecords(ctx) +} + +func (s *listEdgeSpyStore) EdgeReader() (issueops.EdgeReader, error) { + inner, err := s.DoltStorage.EdgeReader() + if err != nil { + return nil, err + } + return spyEdgeReader{inner: inner, spy: s}, nil +} + +type spyEdgeReader struct { + inner issueops.EdgeReader + spy *listEdgeSpyStore +} + +func (r spyEdgeReader) ReadEdges(ctx context.Context, req issueops.EdgeReadRequest) (issueops.EdgeReadResult, error) { + r.spy.anchors = append(r.spy.anchors, slices.Clone(req.IDs)) + return r.inner.ReadEdges(ctx, req) +} + +// TestListTextRenderingsReadTheListedIssuesEdgesOnly runs +// checkListTextRenderingsReadListedEdges on the Dolt server; +// TestEmbeddedListPageEdges runs it on embedded Dolt. +func TestListTextRenderingsReadTheListedIssuesEdgesOnly(t *testing.T) { + checkListTextRenderingsReadListedEdges(t, seedListEdgeStore(t, newListEdgeServerStore(t))) +} + +// checkListTextRenderingsReadListedEdges drives runListCore on the direct route +// over a real store and pins each text rendering that consumes edges to one +// edge read naming exactly the listed issues, never the store-wide +// GetAllDependencyRecords. backend/http's +// TestE2E_ListTextRenderingsReadOnlyTheListedIssuesEdges pins the same reads on +// the wire. +func checkListTextRenderingsReadListedEdges(t *testing.T, f listEdgeStoreFixture) { + t.Helper() + spy := &listEdgeSpyStore{DoltStorage: f.store} + oldStore, oldCtx, oldJSON := store, rootCtx, jsonOutput + store, rootCtx, jsonOutput = spy, t.Context(), false + t.Cleanup(func() { store, rootCtx, jsonOutput = oldStore, oldCtx, oldJSON }) + + gatedRow := ui.StatusIconGated + " " + f.ids["bravo"] + for _, tc := range []struct { + name string + args []string + anchors []string + want []string + }{ + {"tree", nil, f.idSet("epic", "alpha", "bravo", "delta", "other"), + []string{"├── ○ " + f.ids["alpha"], gatedRow}}, + {"deps all", []string{"--deps=all"}, f.idSet("epic", "alpha", "bravo", "delta", "other"), + []string{"[depends-on]", "[related]", "[waits-for]", "[duplicates]", "↗ 1 outside this view: external:other:cap"}}, + {"truncated page", []string{"--limit", "2"}, f.idSet("epic", "alpha"), + []string{"└── ○ " + f.ids["alpha"]}}, + {"parent tree", []string{"--parent", f.ids["epic"]}, f.idSet("epic", "alpha", "bravo"), + []string{"├── ○ " + f.ids["alpha"], gatedRow}}, + {"format digraph", []string{"--format", "digraph"}, f.idSet("epic", "alpha", "bravo", "delta", "other"), + []string{f.ids["bravo"] + " " + f.ids["alpha"], f.ids["delta"] + " " + f.ids["bravo"]}}, + } { + t.Run(tc.name, func(t *testing.T) { + spy.wholeStoreReads, spy.anchors = 0, nil + cmd := newListFlagsCommand(t, tc.args...) + out := captureStdout(t, func() error { return runListCore(cmd, nil) }) + if spy.wholeStoreReads != 0 { + t.Errorf("bd list %v read every edge in the store %d times", tc.args, spy.wholeStoreReads) + } + if len(spy.anchors) != 1 { + t.Fatalf("bd list %v made %d edge reads, want 1: %v", tc.args, len(spy.anchors), spy.anchors) + } + if got := slices.Sorted(slices.Values(spy.anchors[0])); !slices.Equal(got, tc.anchors) { + t.Errorf("bd list %v read the edges of %v, want exactly the listed issues %v", tc.args, got, tc.anchors) + } + for _, w := range tc.want { + if !strings.Contains(out, w) { + t.Errorf("bd list %v output lacks %q:\n%s", tc.args, w, out) + } + } + if strings.Contains(out, f.ids["hidden"]) { + t.Errorf("bd list %v printed the closed issue %s:\n%s", tc.args, f.ids["hidden"], out) + } + }) + } +} diff --git a/cmd/bd/list_page_edges_test.go b/cmd/bd/list_page_edges_test.go new file mode 100644 index 000000000..1c2a2ab36 --- /dev/null +++ b/cmd/bd/list_page_edges_test.go @@ -0,0 +1,353 @@ +package main + +import ( + "bytes" + "context" + "errors" + "reflect" + "slices" + "strings" + "testing" + "time" + + "github.com/steveyegge/beads/internal/types" + "github.com/steveyegge/beads/issueops" +) + +// edgeSourceStub answers EdgeReader from a fixed edge map keyed by source id, +// the shape GetAllDependencyRecords returns, and records each request's +// anchors so a test can assert which ids a rendering asked about. +type edgeSourceStub struct { + edges map[string][]*types.Dependency + accessErr error + readErr error + accessed int + requests [][]string +} + +func (s *edgeSourceStub) EdgeReader() (issueops.EdgeReader, error) { + s.accessed++ + if s.accessErr != nil { + return nil, s.accessErr + } + return edgeReaderStub{src: s}, nil +} + +type edgeReaderStub struct{ src *edgeSourceStub } + +func (r edgeReaderStub) ReadEdges(_ context.Context, req issueops.EdgeReadRequest) (issueops.EdgeReadResult, error) { + r.src.requests = append(r.src.requests, slices.Clone(req.IDs)) + if r.src.readErr != nil { + return issueops.EdgeReadResult{}, r.src.readErr + } + result := issueops.EdgeReadResult{Anchors: []issueops.AnchorEdges{}} + for _, id := range req.IDs { + edges := r.src.edges[id] + if edges == nil { + edges = []*types.Dependency{} + } + result.Anchors = append(result.Anchors, issueops.AnchorEdges{ID: id, Edges: edges}) + } + return result, nil +} + +func TestListDependencyRecordsReadsTheListedIssuesInOneRequest(t *testing.T) { + a := &types.Issue{ID: "pe-a"} + b := &types.Issue{ID: "pe-b"} + c := &types.Issue{ID: "pe-c"} + aToB := &types.Dependency{IssueID: "pe-a", DependsOnID: "pe-b", Type: types.DepBlocks} + cToX := &types.Dependency{IssueID: "pe-c", DependsOnID: "pe-x", Type: types.DepParentChild} + xToA := &types.Dependency{IssueID: "pe-x", DependsOnID: "pe-a", Type: types.DepBlocks} + src := &edgeSourceStub{edges: map[string][]*types.Dependency{ + "pe-a": {aToB}, + "pe-c": {cToX}, + "pe-x": {xToA}, + }} + + got, err := listDependencyRecords(context.Background(), src, []*types.Issue{a, nil, b, c}) + if err != nil { + t.Fatalf("listDependencyRecords: %v", err) + } + if want := [][]string{{"pe-a", "pe-b", "pe-c"}}; !reflect.DeepEqual(src.requests, want) { + t.Errorf("ReadEdges requests = %v, want one naming the listed ids %v", src.requests, want) + } + // pe-b has no edges, so it has no key, as in GetAllDependencyRecords; the + // unlisted pe-x's edge onto a listed issue is not read at all. + want := map[string][]*types.Dependency{"pe-a": {aToB}, "pe-c": {cToX}} + if !reflect.DeepEqual(got, want) { + t.Errorf("listDependencyRecords = %v, want %v", got, want) + } +} + +func TestListDependencyRecordsOfNoIssuesReadsNothing(t *testing.T) { + src := &edgeSourceStub{accessErr: errors.New("must not be reached")} + for _, issues := range [][]*types.Issue{nil, {}, {nil}} { + got, err := listDependencyRecords(context.Background(), src, issues) + if err != nil { + t.Fatalf("listDependencyRecords(%v): %v", issues, err) + } + // Non-nil: the gate decoration takes a nil map to mean "nothing was + // preloaded" and would read the edges a second time. + if got == nil || len(got) != 0 { + t.Errorf("listDependencyRecords(%v) = %#v, want an empty non-nil map", issues, got) + } + } + if src.accessed != 0 { + t.Errorf("an empty listing reached the edge reader %d times, want 0", src.accessed) + } +} + +func TestListDependencyRecordsReturnsTheReadError(t *testing.T) { + issues := []*types.Issue{{ID: "pe-a"}} + for name, src := range map[string]*edgeSourceStub{ + "accessor": {accessErr: errors.New("no edge reader")}, + "read": {readErr: errors.New("read failed")}, + } { + t.Run(name, func(t *testing.T) { + got, err := listDependencyRecords(context.Background(), src, issues) + if err == nil { + t.Fatalf("listDependencyRecords = %v, nil; want the %s error", got, name) + } + // nil, like a failed GetAllDependencyRecords: the tree then falls + // back to dotted-id nesting and the gate decoration reads its own. + if got != nil { + t.Errorf("listDependencyRecords returned %v beside its error, want nil", got) + } + }) + } +} + +// listEdgeFixture is a page of issues and the whole store's edge map around +// it. Besides an edge of every type the page itself owns, the store holds the +// edges a page-scoped read must be able to ignore: an unlisted child of a +// listed parent, unlisted issues that block or relate to listed ones, and a +// gate edge an unlisted issue owns. The page also leans on the renderers' +// other inputs: a parent that is not listed, a dotted child with no +// parent-child edge, a rooted parent-child cycle, open and closed gates, and a +// closed subject a gate does not decorate. +type listEdgeFixture struct { + listed []*types.Issue + all map[string][]*types.Dependency + stored map[string]*types.Issue // every issue in the store, for gate hydration +} + +func newListEdgeFixture() listEdgeFixture { + issue := func(id, title string, typ types.IssueType, status types.Status, priority int) *types.Issue { + return &types.Issue{ID: id, Title: title, IssueType: typ, Status: status, Priority: priority} + } + at := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC) + edge := func(from, to string, typ types.DependencyType) *types.Dependency { + return &types.Dependency{IssueID: from, DependsOnID: to, Type: typ, CreatedAt: at, CreatedBy: "tester"} + } + + listed := []*types.Issue{ + issue("pe-epic", "Epic", types.TypeEpic, types.StatusOpen, 0), + issue("pe-a", "Alpha", types.TypeTask, types.StatusOpen, 1), + issue("pe-b", "Bravo", types.TypeTask, types.StatusOpen, 1), + issue("pe-c", "Charlie", types.TypeTask, types.StatusInProgress, 0), + issue("pe-epic.1", "Dotted child", types.TypeTask, types.StatusOpen, 2), + issue("pe-d", "Delta", types.TypeBug, types.StatusOpen, 2), + issue("pe-gated", "Gated", types.TypeTask, types.StatusOpen, 1), + issue("pe-shut", "Closed subject", types.TypeTask, types.StatusClosed, 1), + issue("pe-r", "Cycle root", types.TypeEpic, types.StatusOpen, 3), + issue("pe-cyc1", "Cycle one", types.TypeEpic, types.StatusOpen, 3), + issue("pe-cyc2", "Cycle two", types.TypeEpic, types.StatusOpen, 3), + } + unlisted := []*types.Issue{ + issue("pe-x", "Unlisted blocker", types.TypeTask, types.StatusOpen, 2), + issue("pe-far-parent", "Unlisted parent", types.TypeEpic, types.StatusOpen, 1), + issue("pe-hidden-child", "Unlisted child", types.TypeTask, types.StatusClosed, 1), + issue("pe-hidden", "Unlisted dependent", types.TypeTask, types.StatusClosed, 1), + issue("pe-gate", "Open gate", types.TypeGate, types.StatusOpen, 1), + issue("pe-gate-done", "Closed gate", types.TypeGate, types.StatusClosed, 1), + } + + all := map[string][]*types.Dependency{ + // Owned by listed issues. + "pe-a": {edge("pe-a", "pe-epic", types.DepParentChild)}, + "pe-b": {edge("pe-b", "pe-a", types.DepBlocks), edge("pe-b", "pe-epic", types.DepParentChild)}, + "pe-c": {edge("pe-c", "pe-b", types.DepWaitsFor), edge("pe-c", "pe-epic", types.DepParentChild), edge("pe-c", "pe-x", types.DepConditionalBlocks)}, + "pe-d": { + edge("pe-d", "external:other:cap", types.DepBlocks), + edge("pe-d", "pe-a", types.DepRelated), + edge("pe-d", "pe-b", types.DepDuplicates), + edge("pe-d", "pe-c", types.DepRepliesTo), + edge("pe-d", "pe-far-parent", types.DepParentChild), + edge("pe-d", "pe-gated", types.DependencyType("tracks")), + edge("pe-d", "pe-old", types.DepSupersedes), + edge("pe-d", "pe-x", types.DepDiscoveredFrom), + }, + "pe-gated": {edge("pe-gated", "pe-gate", types.DepBlocks), edge("pe-gated", "pe-gate-done", types.DepBlocks)}, + "pe-shut": {edge("pe-shut", "pe-gate", types.DepBlocks)}, + "pe-cyc1": {edge("pe-cyc1", "pe-cyc2", types.DepParentChild), edge("pe-cyc1", "pe-r", types.DepParentChild)}, + "pe-cyc2": {edge("pe-cyc2", "pe-cyc1", types.DepParentChild)}, + // Owned by unlisted issues, each pointing at a listed one. + "pe-hidden-child": {edge("pe-hidden-child", "pe-epic", types.DepParentChild)}, + "pe-hidden": {edge("pe-hidden", "pe-a", types.DepBlocks), edge("pe-hidden", "pe-d", types.DepRelated)}, + "pe-x": {edge("pe-x", "pe-gate", types.DepBlocks), edge("pe-x", "pe-b", types.DepWaitsFor)}, + "pe-far-parent": {edge("pe-far-parent", "pe-c", types.DepParentChild)}, + } + + stored := make(map[string]*types.Issue) + for _, is := range append(slices.Clone(listed), unlisted...) { + stored[is.ID] = is + } + return listEdgeFixture{listed: listed, all: all, stored: stored} +} + +// hydrate is the gate decoration's candidate read against the fixture store. +func (f listEdgeFixture) hydrate(_ context.Context, ids []string) ([]*types.Issue, error) { + var out []*types.Issue + for _, id := range ids { + if is := f.stored[id]; is != nil { + out = append(out, is) + } + } + return out, nil +} + +// pick returns the listed issues with these ids, in this order. +func (f listEdgeFixture) pick(ids ...string) []*types.Issue { + out := make([]*types.Issue, 0, len(ids)) + for _, id := range ids { + for _, is := range f.listed { + if is.ID == id { + out = append(out, is) + } + } + } + return out +} + +// renderListTextOutputs renders every `bd list` text output that consumes an +// edge map, the way the direct route calls each one, and returns them by name. +// The gate decoration is computed from the same map, as the tree's caller does. +func renderListTextOutputs(t *testing.T, hydrate gateHydrator, issues []*types.Issue, deps map[string][]*types.Dependency) map[string]string { + t.Helper() + ctx := context.Background() + noLoad := func(context.Context, []string) (map[string][]*types.Dependency, error) { + t.Fatal("the gate decoration re-read edges although the caller preloaded them") + return nil, nil + } + gated := gatesByIssueID(ctx, issues, deps, noLoad, hydrate) + + out := map[string]string{} + for _, mode := range []string{"", "scheduling", "all"} { + for _, sort := range []struct { + by string + reverse bool + }{{"", false}, {"", true}, {"title", false}, {"id", true}, {"created", false}} { + for _, truncated := range []bool{false, true} { + name := "tree deps=" + mode + " sort=" + sort.by + " truncated=" + map[bool]string{false: "no", true: "yes"}[truncated] + if sort.reverse { + name += " reverse" + } + out[name] = captureStdout(t, func() error { + displayPrettyListWithDepsMode(issues, false, deps, mode, truncated, false, "", sort.by, sort.reverse, gated) + return nil + }) + } + } + } + out["tree ready"] = captureStdout(t, func() error { + displayPrettyListWithDepsMode(issues, false, deps, "scheduling", false, true, "open", "", false, gated) + return nil + }) + for _, format := range []string{"dot", "digraph", "{{.IssueID}} {{.Type}} {{.DependsOnID}} {{.Dependency.CreatedBy}} {{.Issue.Title}}"} { + var buf bytes.Buffer + if err := outputFormattedList(&buf, issues, deps, format); err != nil { + t.Fatalf("outputFormattedList(%q): %v", format, err) + } + out["format "+format] = buf.String() + } + gatedIDs := make([]string, 0, len(gated)) + for id, gates := range gated { + gatedIDs = append(gatedIDs, id+"<-"+strings.Join(gates, ",")) + } + slices.Sort(gatedIDs) + out["gated"] = strings.Join(gatedIDs, ";") + return out +} + +// assertSameListTextOutputs fails on each output the two edge maps rendered +// differently. +func assertSameListTextOutputs(t *testing.T, wholeStore, pageOnly map[string]string) { + t.Helper() + for output, want := range wholeStore { + if got := pageOnly[output]; got != want { + t.Errorf("%s differs between the page's edges and the whole store's.\nwhole store:\n%s\npage only:\n%s", output, want, got) + } + } +} + +// TestListRenderingsReadOnlyTheListedIssuesEdges is the parity proof for +// listDependencyRecords: every `bd list` text rendering prints the same bytes +// from the listed issues' own edges as from the whole store's edge map, so +// reading only the former loses nothing. It covers the tree in each --deps +// mode and sort, a page cut by --limit, the --parent tree's shape (the parent +// listed with its descendants), --ready's footer, the gate decoration and +// every --format. +// +// It also guards the renderers: one that started reading an edge an UNLISTED +// issue owns (an incoming edge, say) would print something here it does not +// print from the page's edges, and this test would say which output changed. +func TestListRenderingsReadOnlyTheListedIssuesEdges(t *testing.T) { + f := newListEdgeFixture() + pages := map[string][]*types.Issue{ + "full page": f.listed, + // A --limit cut: the parent stays, two of its children and the + // dotted child go, the gate subject goes and the cycle loses its root. + "truncated page": f.pick("pe-epic", "pe-c", "pe-d", "pe-shut", "pe-cyc1", "pe-cyc2"), + "parent tree": f.pick("pe-epic", "pe-a", "pe-b", "pe-c", "pe-epic.1"), + "single row": f.pick("pe-gated"), + "no edges": f.pick("pe-epic.1"), + } + for name, page := range pages { + t.Run(name, func(t *testing.T) { + src := &edgeSourceStub{edges: f.all} + pageDeps, err := listDependencyRecords(context.Background(), src, page) + if err != nil { + t.Fatalf("listDependencyRecords: %v", err) + } + assertSameListTextOutputs(t, + renderListTextOutputs(t, f.hydrate, page, f.all), + renderListTextOutputs(t, f.hydrate, page, pageDeps)) + }) + } +} + +// TestDisplayWatchedIssueListReadsTheShownIssuesEdges pins the --watch redraw +// to the shown issues' edges (it used to reload GetAllDependencyRecords on +// every change), with the tree it prints unchanged. +func TestDisplayWatchedIssueListReadsTheShownIssuesEdges(t *testing.T) { + f := newListEdgeFixture() + page := f.pick("pe-epic", "pe-a", "pe-b", "pe-c", "pe-d", "pe-epic.1") + src := &edgeSourceStub{edges: f.all} + + // The header line carries the wall-clock time, so it is dropped before the + // two renders are compared. + stripClock := func(s string) string { + var lines []string + for _, line := range strings.Split(s, "\n") { + if !strings.HasPrefix(line, "Beads - Open & In Progress (") { + lines = append(lines, line) + } + } + return strings.Join(lines, "\n") + } + got := stripClock(captureStdout(t, func() error { + displayWatchedIssueList(context.Background(), src, page, false, false, "", "", false) + return nil + })) + want := stripClock(captureStdout(t, func() error { + displayPrettyListWithDepsMode(page, true, f.all, "", false, false, "", "", false, nil) + return nil + })) + if got != want { + t.Errorf("--watch redraw differs from the whole-store render.\nwhole store:\n%s\nwatch:\n%s", want, got) + } + wantIDs := [][]string{{"pe-epic", "pe-a", "pe-b", "pe-c", "pe-d", "pe-epic.1"}} + if !reflect.DeepEqual(src.requests, wantIDs) { + t.Errorf("--watch read the edges of %v, want only the shown issues %v", src.requests, wantIDs) + } +} diff --git a/cmd/bd/list_show_filter_modes.go b/cmd/bd/list_show_filter_modes.go index 08c40f1ac..3876cb06f 100644 --- a/cmd/bd/list_show_filter_modes.go +++ b/cmd/bd/list_show_filter_modes.go @@ -128,13 +128,6 @@ func findAllDescendants(ctx context.Context, store storage.DoltStorage, dbPath s return nil } -// watchIssues polls for changes and re-displays (GH#654) -// Uses polling instead of fsnotify because Dolt stores data in a server-side -// database, not files — file watchers never fire. -type watchListDependencyStore interface { - GetAllDependencyRecords(ctx context.Context) (map[string][]*types.Dependency, error) -} - func loadWatchedIssues(ctx context.Context, store storage.DoltStorage, filter types.IssueFilter, ready bool, parentID string, sortBy string, reverse bool) ([]*types.Issue, error) { if ready { issues, err := store.GetReadyWork(ctx, workapi.ReadyFilterFromIssueFilter(workapi.WithFetchOneExtra(filter))) @@ -168,10 +161,14 @@ func loadWatchedIssues(ctx context.Context, store storage.DoltStorage, filter ty // names its scope instead of asserting an in-progress count the ready filter // forced to zero. A watch loop is where a stale "0 in progress" is most likely // to be read as a live fact, so this is the path that most needs it. -func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore, issues []*types.Issue, truncated, readyFiltered bool, statusSelector, sortBy string, reverse bool) { +// +// The tree reads only the displayed issues' edges (listDependencyRecords), the +// read the proxied watch makes too, so a redraw does not reload every edge in +// the store. +func displayWatchedIssueList(ctx context.Context, store listEdgeSource, issues []*types.Issue, truncated, readyFiltered bool, statusSelector, sortBy string, reverse bool) { var allDeps map[string][]*types.Dependency if store != nil { - deps, err := store.GetAllDependencyRecords(ctx) + deps, err := listDependencyRecords(ctx, store, issues) if err == nil { allDeps = deps } @@ -181,6 +178,10 @@ func displayWatchedIssueList(ctx context.Context, store watchListDependencyStore displayPrettyListWithDepsMode(issues, true, allDeps, "", truncated, readyFiltered, statusSelector, sortBy, reverse, nil) } +// watchIssues polls for changes and re-displays (GH#654) +// Uses polling instead of fsnotify because Dolt stores data in a server-side +// database, not files — file watchers never fire. +// // watchIssues returns an error only for the initial query — a failure there // means bd list --watch never displayed anything, so (unlike a mid-poll // refresh failure, which just logs and keeps the last good snapshot on diff --git a/cmd/bd/list_test.go b/cmd/bd/list_test.go index 4404f688c..501e515aa 100644 --- a/cmd/bd/list_test.go +++ b/cmd/bd/list_test.go @@ -881,9 +881,11 @@ func TestTreeViewUsesWispDependencyRecords(t *testing.T) { t.Fatalf("AddDependency: %v", err) } - allDeps, err := store.GetAllDependencyRecords(ctx) + // The tree's own edge read: the listed issues' records, which for a wisp + // live in wisp_dependencies. + allDeps, err := listDependencyRecords(ctx, store, []*types.Issue{parent, child}) if err != nil { - t.Fatalf("GetAllDependencyRecords: %v", err) + t.Fatalf("listDependencyRecords: %v", err) } if ds := allDeps[child.ID]; len(ds) != 1 || ds[0].DependsOnID != parent.ID { t.Fatalf("wisp dependency records = %+v, want child -> parent", ds)