From 7a00780777ea842796d9ecca5c44f67affe04b3c Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Tue, 7 Jul 2026 00:19:15 -0700 Subject: [PATCH] fix: unbreak red main CI (errcheck, testing.Short policy, unclaim test regressions) (#4623) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Repairs three independent failures that turned main red: - fix(formula): check outputJSON error return in schema command (errcheck → Lint/PR Lint/Build Artifacts) - test(quiet): run quiet embedded test under embedded Dolt instead of testing.Short (policy → PR Policy/Build Artifacts); also fixes a latent ID-parse bug so the test actually runs - test(unclaim): fix stale --json and claim-error assertions from #4614 (Embedded Dolt Cmd shards 5 & 19) Validated locally and by the PR's embedded-Dolt CI tier (all 20 cmd shards green). --- cmd/bd/formula_schema.go | 10 +++++-- cmd/bd/unclaim_embedded_test.go | 22 +++++++++++--- cmd/bd/update_embedded_test.go | 4 +-- cmd/bd/verbosity_quiet_embedded_test.go | 40 +++++++++---------------- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/cmd/bd/formula_schema.go b/cmd/bd/formula_schema.go index eaa4261a3..ec9b81180 100644 --- a/cmd/bd/formula_schema.go +++ b/cmd/bd/formula_schema.go @@ -43,7 +43,10 @@ func runFormulaSchema(cmd *cobra.Command, args []string) { func runFormulaSchemaList() { if jsonOutput { - outputJSON(formula.Primitives) + if err := outputJSON(formula.Primitives); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } return } @@ -68,7 +71,10 @@ func runFormulaSchemaShow(name string) { } if jsonOutput { - outputJSON(p) + if err := outputJSON(p); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } return } diff --git a/cmd/bd/unclaim_embedded_test.go b/cmd/bd/unclaim_embedded_test.go index 9b3c614d1..3d1768899 100644 --- a/cmd/bd/unclaim_embedded_test.go +++ b/cmd/bd/unclaim_embedded_test.go @@ -3,6 +3,7 @@ package main import ( + "encoding/json" "os" "os/exec" "strings" @@ -99,11 +100,24 @@ func TestEmbeddedUnclaim(t *testing.T) { issue := bdCreate(t, bd, dir, "JSON test", "--type", "task") bdUpdate(t, bd, dir, issue.ID, "--claim") out := bdUnclaim(t, bd, dir, issue.ID, "--json") - if !strings.Contains(out, `"assignee":""`) && !strings.Contains(out, `"assignee": null`) { - t.Errorf("expected empty assignee in JSON output, got: %s", out) + // bd unclaim --json emits an array of the affected issues. A cleared + // assignee is empty and omitempty drops it from the payload, so parse + // and assert on the decoded fields rather than raw substrings. + var unclaimed []struct { + Assignee string `json:"assignee"` + Status string `json:"status"` } - if !strings.Contains(out, `"status":"open"`) { - t.Errorf("expected status open in JSON output, got: %s", out) + if err := json.Unmarshal([]byte(out), &unclaimed); err != nil { + t.Fatalf("failed to parse unclaim --json output: %v\n%s", err, out) + } + if len(unclaimed) != 1 { + t.Fatalf("expected 1 issue in unclaim --json output, got %d:\n%s", len(unclaimed), out) + } + if unclaimed[0].Assignee != "" { + t.Errorf("expected empty assignee after unclaim, got %q", unclaimed[0].Assignee) + } + if unclaimed[0].Status != "open" { + t.Errorf("expected status open after unclaim, got %q", unclaimed[0].Status) } }) diff --git a/cmd/bd/update_embedded_test.go b/cmd/bd/update_embedded_test.go index a8f23b4e7..fc00c83ad 100644 --- a/cmd/bd/update_embedded_test.go +++ b/cmd/bd/update_embedded_test.go @@ -665,8 +665,8 @@ func TestEmbeddedUpdate(t *testing.T) { issue := bdCreate(t, bd, dir, "Claim fail test", "--type", "task") bdUpdate(t, bd, dir, issue.ID, "--assignee", "alice") out := bdUpdateFail(t, bd, dir, issue.ID, "--claim") - if !strings.Contains(out, "already claimed") { - t.Errorf("expected 'already claimed' error, got: %s", out) + if !strings.Contains(out, "already assigned to") { + t.Errorf("expected 'already assigned to' error, got: %s", out) } }) diff --git a/cmd/bd/verbosity_quiet_embedded_test.go b/cmd/bd/verbosity_quiet_embedded_test.go index 6e1dacf29..7313d163a 100644 --- a/cmd/bd/verbosity_quiet_embedded_test.go +++ b/cmd/bd/verbosity_quiet_embedded_test.go @@ -3,20 +3,22 @@ package main import ( + "encoding/json" + "os" "os/exec" "strings" "testing" ) -// TestQuietFlagSuppressesSuccessOutput verifies that --quiet suppresses success -// output on create, close, and update while still exiting 0. +// TestEmbeddedQuietFlagSuppressesSuccessOutput verifies that --quiet suppresses +// success output on create, close, and update while still exiting 0. // // Each sub-test: run the command with --quiet, capture stdout+stderr separately, // assert stdout is empty and exit code is 0. Errors still flow to stderr (not // tested here — the contract is "success output suppressed", not "all output"). -func TestQuietFlagSuppressesSuccessOutput(t *testing.T) { - if testing.Short() { - t.Skip("skipping slow embedded-bd quiet-mode tests in short mode") +func TestEmbeddedQuietFlagSuppressesSuccessOutput(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") } bd := buildEmbeddedBD(t) @@ -53,30 +55,16 @@ func TestQuietFlagSuppressesSuccessOutput(t *testing.T) { if err != nil { t.Fatalf("bd list --json failed: %v", err) } - issueID := "" - for _, line := range strings.Split(listStdout.String(), "\n") { - line = strings.TrimSpace(line) - if strings.HasPrefix(line, `"id"`) { - parts := strings.SplitN(line, `"`, 4) - if len(parts) >= 4 { - issueID = parts[3] - } - break - } + var listed []struct { + ID string `json:"id"` } - if issueID == "" { - // Fallback: scan for first `"id": "..."` pattern - s := listStdout.String() - if idx := strings.Index(s, `"id": "`); idx >= 0 { - rest := s[idx+7:] - if end := strings.Index(rest, `"`); end >= 0 { - issueID = rest[:end] - } - } + if err := json.Unmarshal(listStdout.Bytes(), &listed); err != nil { + t.Fatalf("failed to parse bd list --json output: %v\n%s", err, listStdout.String()) } - if issueID == "" { - t.Skip("could not determine created issue ID; skipping close/update quiet tests") + if len(listed) == 0 || listed[0].ID == "" { + t.Fatalf("bd list --json returned no usable issue ID:\n%s", listStdout.String()) } + issueID := listed[0].ID t.Run("update", func(t *testing.T) { cmd := exec.Command(bd, "--quiet", "update", issueID, "--priority", "1")