From 9ffd288557b4dddb38ac24f728ebdbad9a676904 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Mon, 13 Jul 2026 10:08:34 -0700 Subject: [PATCH] test(protocol): realign show --json contract tests with count-only payload (wy-017ry) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seven tests in cmd/bd/protocol were red on main. Both failure families are stale test expectations, not a bd regression: 1. comments/dependents "missing" from show --json. cfcc95799 (be-ijck6q) made `bd show --json` count-only by default — comment_count / dependent_count instead of materializing every row — and moved the full lists behind --include-comments / --include-dependents. The preservation and round-trip tests kept reading the inline lists and saw empty. The data was never lost: the same tests pass unchanged once they ask for the payload, and they now also assert the counts agree with the streamed bodies. 2. show --json "missing" schema_version. show has always emitted a top-level ARRAY (one element per requested ID), and wrapWithSchemaVersion injects schema_version only into object output. These assertions were red from the day they were written (0d4b97935) — the golden corpus has always pinned show as "array-of-one". Replaced with TestJSONContract_ShowOutputIsArray, which pins the real contract; schema_version coverage moves to create + ping. These never failed CI because the required job runs only -run 'TestCorpusGolden|TestCanonicalize|TestCorpusDoubleRunByteIdentical|TestCheckCaptureExit' against this package — the rest of it has been unguarded. Filed separately. Verification: go test -tags gms_pure_go ./cmd/bd/protocol/ -count=1 — whole package green (was 7 failures on b63453f27). Co-Authored-By: Claude Opus 4.8 --- cmd/bd/protocol/CATALOG.md | 4 ++ cmd/bd/protocol/helpers_test.go | 24 ++++++++++++ cmd/bd/protocol/json_contract_test.go | 55 ++++++++++++++++++++++++--- cmd/bd/protocol/preservation_test.go | 13 +++++-- cmd/bd/protocol/roundtrip_test.go | 13 +++++-- 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/cmd/bd/protocol/CATALOG.md b/cmd/bd/protocol/CATALOG.md index 1982604a9..5733fd4fd 100644 --- a/cmd/bd/protocol/CATALOG.md +++ b/cmd/bd/protocol/CATALOG.md @@ -50,6 +50,10 @@ pinned-decoder migration off. - `bd sql` is **not supported in embedded mode** (this harness's mode), so it is not in the corpus. A downstream consumer's ready-projection enrichment depends on `bd sql` against a managed Dolt server; covering it needs a server-mode generation path. +- The `show` blob pins the **count-only** default payload (`comment_count`, + `dependent_count`); the opt-in `--include-comments` / `--include-dependents` + shapes are not in the corpus. They are covered at the CLI level by the + preservation and round-trip tests, not byte-pinned for a consumer. - The `error` blob pins the not-found envelope; other error classifiers (claim-conflict, silent-fallback auto-import, `bd sql` unsupported) are plain-text on stderr and belong in a separate error-string fixture set. diff --git a/cmd/bd/protocol/helpers_test.go b/cmd/bd/protocol/helpers_test.go index c3ea7659d..2add21a77 100644 --- a/cmd/bd/protocol/helpers_test.go +++ b/cmd/bd/protocol/helpers_test.go @@ -304,6 +304,11 @@ func (w *workspace) create(args ...string) string { } // showJSON runs bd show --json and returns the first issue object. +// +// The payload is count-only: labels and dependencies are inline, but comments +// and dependents are reported as comment_count / dependent_count and their +// bodies are omitted. Use showJSONFull to assert on comment or dependent +// content. func (w *workspace) showJSON(id string) map[string]any { w.t.Helper() out := w.run("show", id, "--json") @@ -314,6 +319,25 @@ func (w *workspace) showJSON(id string) map[string]any { return items[0] } +// showJSONFull runs bd show --json with the opt-in relational payloads and +// returns the first issue object — the shape to assert against when a test +// cares about comment or dependent CONTENT rather than counts. +// +// bd show --json has been count-only by default since cfcc95799 ("count-only +// JSON details with opt-in streamed payloads", be-ijck6q): materializing every +// comment and dependent made show pathologically slow on hub beads, so the full +// lists moved behind --include-comments / --include-dependents. The data is +// still there — these flags are how you ask for it. +func (w *workspace) showJSONFull(id string) map[string]any { + w.t.Helper() + out := w.run("show", id, "--json", "--include-comments", "--include-dependents") + items := parseJSONOutput(w.t, out) + if len(items) == 0 { + w.t.Fatalf("bd show %s --json --include-comments --include-dependents returned no items", id) + } + return items[0] +} + // --------------------------------------------------------------------------- // Assertion and comparison helpers // --------------------------------------------------------------------------- diff --git a/cmd/bd/protocol/json_contract_test.go b/cmd/bd/protocol/json_contract_test.go index 471791e7d..11c0c8c96 100644 --- a/cmd/bd/protocol/json_contract_test.go +++ b/cmd/bd/protocol/json_contract_test.go @@ -26,7 +26,12 @@ func TestJSONContract_ListOutputIsValidJSON(t *testing.T) { } // TestJSONContract_ShowOutputHasRequiredFields verifies bd show --json -// includes all required issue fields. +// includes all required issue fields, including the relational counts that +// stand in for the opt-in comment and dependent payloads. +// +// schema_version is deliberately NOT required here: show is an array-returning +// command (see TestJSONContract_ShowOutputIsArray), and wrapWithSchemaVersion +// only injects the field into object-shaped output. func TestJSONContract_ShowOutputHasRequiredFields(t *testing.T) { t.Parallel() w := newWorkspace(t) @@ -39,7 +44,10 @@ func TestJSONContract_ShowOutputHasRequiredFields(t *testing.T) { } issue := items[0] - requiredFields := []string{"id", "title", "status", "priority", "issue_type", "created_at", "schema_version"} + requiredFields := []string{ + "id", "title", "status", "priority", "issue_type", "created_at", + "dependency_count", "dependent_count", "comment_count", + } for _, field := range requiredFields { if _, ok := issue[field]; !ok { t.Errorf("bd show --json missing required field %q", field) @@ -47,6 +55,41 @@ func TestJSONContract_ShowOutputHasRequiredFields(t *testing.T) { } } +// TestJSONContract_ShowOutputIsArray pins the shape of bd show --json: a +// top-level JSON array with one element per requested ID, NOT a schema_version +// envelope. This is what the golden corpus commits (CATALOG.md: show = +// "array-of-one") and what wrapWithSchemaVersion does with a slice — it returns +// it bare, injecting schema_version only into object output. +// +// The shape is load-bearing for every consumer that parses show --json, so a +// change here is a breaking wire change, not a cleanup. +func TestJSONContract_ShowOutputIsArray(t *testing.T) { + t.Parallel() + w := newWorkspace(t) + id1 := w.create("Array shape one") + id2 := w.create("Array shape two") + + out := w.run("show", id1, id2, "--json") + + var arr []map[string]any + if err := json.Unmarshal([]byte(out), &arr); err != nil { + t.Fatalf("bd show --json is not a top-level JSON array: %v\nOutput:\n%s", err, out) + } + if len(arr) != 2 { + t.Fatalf("bd show --json returned %d items, want 2\nOutput:\n%s", len(arr), out) + } + + gotIDs := make([]string, 0, len(arr)) + for _, item := range arr { + id, _ := item["id"].(string) + gotIDs = append(gotIDs, id) + if _, ok := item["schema_version"]; ok { + t.Errorf("bd show --json item %s carries schema_version; array-returning commands do not", id) + } + } + requireStringSetEqual(t, gotIDs, []string{id1, id2}, "bd show --json ids") +} + // TestJSONContract_ReadyOutputIsValidJSON verifies bd ready --json produces // valid JSON even when no issues are ready. func TestJSONContract_ReadyOutputIsValidJSON(t *testing.T) { @@ -209,18 +252,18 @@ func TestJSONContract_PingOutputIsValidJSON(t *testing.T) { } // TestJSONContract_SchemaVersionPresent verifies that schema_version is -// present in object-returning --json commands (show, create, ping). -// Array-returning commands (list, ready) do not include schema_version. +// present in object-returning --json commands (create, ping). +// Array-returning commands (list, ready, show) do not include schema_version — +// see TestJSONContract_ShowOutputIsArray. func TestJSONContract_SchemaVersionPresent(t *testing.T) { t.Parallel() w := newWorkspace(t) - id := w.create("Schema version test") tests := []struct { name string args []string }{ - {"show", []string{"show", id, "--json"}}, + {"create", []string{"create", "Schema version test", "--json"}}, {"ping", []string{"ping", "--json"}}, } diff --git a/cmd/bd/protocol/preservation_test.go b/cmd/bd/protocol/preservation_test.go index 5e6325424..842a525d9 100644 --- a/cmd/bd/protocol/preservation_test.go +++ b/cmd/bd/protocol/preservation_test.go @@ -50,11 +50,14 @@ func TestProtocol_CommentsPreservedAcrossUpdate(t *testing.T) { // Update an unrelated field w.run("update", id, "--title", "Commented issue (renamed)") - issue := w.showJSON(id) + issue := w.showJSONFull(id) requireCommentTextsEqual(t, getObjectSlice(issue, "comments"), []string{"Important design note", "Follow-up from review"}, "comments after title update") + + // The count-only default payload must agree with the streamed bodies. + assertFieldFloat(t, w.showJSON(id), "comment_count", 2) } // TestProtocol_ScalarUpdatePreservesRelationalData asserts that updating @@ -87,8 +90,9 @@ func TestProtocol_ScalarUpdatePreservesRelationalData(t *testing.T) { w.run("update", id1, "--assignee", "alice") w.run("update", id1, "--notes", "Updated notes") - // Verify via show --json - issue := w.showJSON(id1) + // Verify via show --json. Comment bodies are opt-in (--include-comments), + // so ask for the full payload; labels and deps are inline either way. + issue := w.showJSONFull(id1) t.Run("labels_preserved", func(t *testing.T) { requireStringSetEqual(t, getStringSlice(issue, "labels"), @@ -106,6 +110,7 @@ func TestProtocol_ScalarUpdatePreservesRelationalData(t *testing.T) { requireCommentTextsEqual(t, getObjectSlice(issue, "comments"), []string{"Design review notes", "Implementation started"}, "comments after 5 scalar updates") + assertFieldFloat(t, w.showJSON(id1), "comment_count", 2) }) } @@ -126,7 +131,7 @@ func TestProtocol_StatusTransitionsPreserveLabels(t *testing.T) { w.run("close", a) w.run("reopen", a) - shown := w.showJSON(a) + shown := w.showJSONFull(a) // Labels preserved labels := getStringSlice(shown, "labels") diff --git a/cmd/bd/protocol/roundtrip_test.go b/cmd/bd/protocol/roundtrip_test.go index 399787e73..30e27fe6e 100644 --- a/cmd/bd/protocol/roundtrip_test.go +++ b/cmd/bd/protocol/roundtrip_test.go @@ -28,8 +28,10 @@ func TestProtocol_ImportPreservesRelationalData(t *testing.T) { w.run("comments", "add", id1, "Design notes for the feature") w.run("comments", "add", id1, "Review feedback from team") - // Verify via bd show --json - featShow := w.showJSON(id1) + // Verify via bd show --json. The feature's comment bodies are opt-in + // (--include-comments), so it needs the full payload; the dep target is + // only checked for labels, which are inline in the default one. + featShow := w.showJSONFull(id1) depTargetShow := w.showJSON(id2) t.Run("labels", func(t *testing.T) { @@ -177,7 +179,9 @@ func TestProtocol_ParentChildDepShowRoundTrip(t *testing.T) { child := w.create("--title", "Child task", "--type", "task", "--priority", "2", "--parent", parent) childIssue := w.showJSON(child) - parentIssue := w.showJSON(parent) + // The parent's dependents list is opt-in (--include-dependents); its + // dependent_count is what the default payload carries. + parentIssue := w.showJSONFull(parent) // Child must have a dependency pointing to parent t.Run("child_references_parent", func(t *testing.T) { @@ -221,6 +225,9 @@ func TestProtocol_ParentChildDepShowRoundTrip(t *testing.T) { t.Errorf("parent %s does not list child %s in dependents (got %d dependents)", parent, child, len(parentDependents)) } + + // The count-only default payload must agree with the streamed list. + assertFieldFloat(t, w.showJSON(parent), "dependent_count", 1) }) }