fix(bd): events golden reflects real runtime dep shape (no inline dependencies)

The golden fixture populated the shared `full` issue's Dependencies array
inline, so records seq 2 (create), 3 (dep_add), and 4 (dep_remove) carried an
inline "dependencies" array. The runtime never emits that: every journal
snapshot comes from issueops.GetIssueInTx, which loads the issue row and its
labels only — never Dependencies. Verified against prod (bd 37d3f6b98): real
journal records carry no inline "dependencies", only the top-level "dep"
{kind,target} on dep_add/dep_remove.

Drop the inline Dependencies from the fixture and regenerate the golden so it
pins what bd actually writes, and add assertNoInlineDependencies as a permanent
guard: no record's issue snapshot may carry a "dependencies" array, since the
snapshot excludes it. Downstream consumers pin against reality.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
CI Bot 2026-07-21 06:48:15 +00:00
commit 3666e50261
2 changed files with 49 additions and 12 deletions

View file

@ -21,12 +21,19 @@ const goldenPath = "testdata/events_journal_records.jsonl"
// events journal. It marshals REAL beads types.Issue and EventDep values
// through the same buildRecord path `bd events tail` uses, so the golden
// captures bd's actual field marshaling — issue_type, omitempty elision, and the
// real dependency fields — that external consumers parse. A change to the wire
// shape (a renamed/added/removed field, a lost omitempty) fails this test until
// the golden is regenerated deliberately.
// top-level dep edge (kind/target) — that external consumers parse. A change to
// the wire shape (a renamed/added/removed field, a lost omitempty) fails this
// test until the golden is regenerated deliberately.
func TestEventsJournalGolden(t *testing.T) {
got := renderGoldenLines(t)
// The runtime snapshot comes from issueops.GetIssueInTx, which loads the
// issue row and its labels only — never its Dependencies. So no journal
// record can carry an inline "dependencies" array; dependency edges surface
// solely through the top-level "dep" field on dep_add / dep_remove records.
// Enforce that here so the golden pins what bd actually writes.
assertNoInlineDependencies(t, got)
if os.Getenv("BD_UPDATE_GOLDEN") == "1" {
if err := os.MkdirAll(filepath.Dir(goldenPath), 0o755); err != nil {
t.Fatalf("mkdir testdata: %v", err)
@ -62,8 +69,12 @@ func renderGoldenLines(t *testing.T) []byte {
ID: "bd-100", Title: "wire the seam", Status: types.StatusOpen,
IssueType: types.TypeTask, Priority: 1, CreatedAt: created, UpdatedAt: updated,
}
// A richly populated feature with a real dependency edge, labels, metadata,
// and an external ref — exercises the full field surface consumers may read.
// A richly populated feature with labels, metadata, and an external ref —
// exercises the full field surface consumers may read. It deliberately omits
// Dependencies: the runtime snapshot (issueops.GetIssueInTx) loads the issue
// row and its labels only, so a real journal record never carries an inline
// "dependencies" array. Dependency edges are recorded solely through the
// top-level "dep" field on the dep_add / dep_remove records below.
full := &types.Issue{
ID: "bd-101", Title: "durable journal", Description: "append-only record",
AcceptanceCriteria: "replayable", Status: types.StatusInProgress,
@ -72,10 +83,6 @@ func renderGoldenLines(t *testing.T) []byte {
CreatedBy: "author", UpdatedAt: updated, ExternalRef: strptr("gh-9"),
SourceSystem: "github", Metadata: json.RawMessage(`{"k":"v"}`),
Labels: []string{"infra", "urgent"},
Dependencies: []*types.Dependency{{
IssueID: "bd-101", DependsOnID: "bd-100", Type: types.DepBlocks,
CreatedAt: created, CreatedBy: "author",
}},
}
// A closed issue — exercises close_reason / closed_at marshaling.
closedIssue := &types.Issue{
@ -112,6 +119,36 @@ func renderGoldenLines(t *testing.T) []byte {
return buf.Bytes()
}
// assertNoInlineDependencies fails if any record's issue snapshot carries a
// "dependencies" array. The runtime snapshot (GetIssueInTx: issue + labels
// only) never populates Dependencies, so a real record cannot contain one; a
// fixture that does would pin a shape bd never emits.
func assertNoInlineDependencies(t *testing.T, jsonl []byte) {
t.Helper()
for _, line := range bytes.Split(bytes.TrimSpace(jsonl), []byte("\n")) {
if len(line) == 0 {
continue
}
var rec struct {
Seq int64 `json:"seq"`
Issue json.RawMessage `json:"issue"`
}
if err := json.Unmarshal(line, &rec); err != nil {
t.Fatalf("unmarshal record: %v", err)
}
if len(rec.Issue) == 0 || string(rec.Issue) == "null" {
continue
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(rec.Issue, &fields); err != nil {
t.Fatalf("unmarshal issue for seq %d: %v", rec.Seq, err)
}
if _, ok := fields["dependencies"]; ok {
t.Errorf("record seq %d carries an inline \"dependencies\" array, but the runtime snapshot (GetIssueInTx loads issue + labels only) never emits one; dependency edges belong only in the top-level \"dep\" field", rec.Seq)
}
}
}
func mustJSON(t *testing.T, v any) string {
t.Helper()
b, err := json.Marshal(v)

View file

@ -1,7 +1,7 @@
{"seq":1,"ts":"2026-01-02 03:04:05","op":"create","issue_id":"bd-100","issue":{"id":"bd-100","title":"wire the seam","status":"open","priority":1,"issue_type":"task","created_at":"2026-01-02T03:00:00Z","updated_at":"2026-01-02T03:04:05Z"}}
{"seq":2,"ts":"2026-01-02 03:04:05","op":"create","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"],"dependencies":[{"issue_id":"bd-101","depends_on_id":"bd-100","type":"blocks","created_at":"2026-01-02T03:00:00Z","created_by":"author"}]}}
{"seq":3,"ts":"2026-01-02 03:04:05","op":"dep_add","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"],"dependencies":[{"issue_id":"bd-101","depends_on_id":"bd-100","type":"blocks","created_at":"2026-01-02T03:00:00Z","created_by":"author"}]},"dep":{"kind":"blocks","target":"bd-100"}}
{"seq":4,"ts":"2026-01-02 03:04:05","op":"dep_remove","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"],"dependencies":[{"issue_id":"bd-101","depends_on_id":"bd-100","type":"blocks","created_at":"2026-01-02T03:00:00Z","created_by":"author"}]},"dep":{"kind":"blocks","target":"bd-100"}}
{"seq":2,"ts":"2026-01-02 03:04:05","op":"create","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"]}}
{"seq":3,"ts":"2026-01-02 03:04:05","op":"dep_add","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"]},"dep":{"kind":"blocks","target":"bd-100"}}
{"seq":4,"ts":"2026-01-02 03:04:05","op":"dep_remove","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","description":"append-only record","acceptance_criteria":"replayable","status":"in_progress","priority":0,"issue_type":"feature","assignee":"worker-1","owner":"dev@example.com","estimated_minutes":90,"created_at":"2026-01-02T03:00:00Z","created_by":"author","updated_at":"2026-01-02T03:04:05Z","external_ref":"gh-9","source_system":"github","metadata":{"k":"v"},"labels":["infra","urgent"]},"dep":{"kind":"blocks","target":"bd-100"}}
{"seq":5,"ts":"2026-01-02 03:04:05","op":"close","issue_id":"bd-101","issue":{"id":"bd-101","title":"durable journal","status":"closed","priority":0,"issue_type":"feature","created_at":"2026-01-02T03:00:00Z","updated_at":"2026-01-02T03:30:00Z","closed_at":"2026-01-02T03:30:00Z","close_reason":"shipped"}}
{"seq":6,"ts":"2026-01-02 03:04:05","op":"create","issue_id":"bd-wisp-1","issue":{"id":"bd-wisp-1","title":"convoy member","status":"open","priority":2,"issue_type":"task","created_at":"2026-01-02T03:00:00Z","updated_at":"2026-01-02T03:04:05Z","ephemeral":true,"wisp_type":"convoy"}}
{"seq":7,"ts":"2026-01-02 03:04:05","op":"delete","issue_id":"bd-100","issue":null}