beads/cmd/bd/list_embedded_test.go
Julian Knutsen 1137aeb70d
ci(bazel): embedded-Dolt tier 20/5 → 50/15 duration-balanced Bazel shards (F1) (#7156)
* ci(bazel): embedded-Dolt tier 20/5 -> 40/14 duration-balanced shards (F1)

Give the Bazel-only bazel-embedded job its own duration-balanced manifest
blocks for //cmd/bd:bd_embedded_test (20 -> 40 shards) and
//internal/storage/embeddeddolt:embeddeddolt_embedded_test (5 -> 14
shards), decoupled from PR Risk's/main.yml's legacy frozen 20/5-shard
fork/push jobs, mirroring F2's bd_proxied_test precedent.

- Measured every TestEmbedded* / embeddeddolt test's wall time in
  isolation; split 21 cmd-tier and 1 storage-tier single top-level test
  over 180s into disjoint sub-tests (3 irreducible exceptions left:
  TestEmbeddedUpdateConcurrent 475s, TestEmbeddedCloseConcurrent 308s,
  TestLargeBatchApplyStatementCounts712_Embedded 261s).
- New scripts/ci/gen_embedded_{cmd,storage}_shard_manifest.py +
  _embedded_shard_manifest_lib.py generate/check duration-balanced
  manifest blocks (LPT packing, incremental --write/--repack, exact-once
  --check), chosen at N=40/M=14 where the heaviest shard reaches the
  irreducible-test floor.
- Fixed 18 stale legacy 20-shard cmd manifest entries (and 1 storage
  entry) left over from earlier test splits, which would have hard-failed
  every shard of PR Risk's real test-embedded-cmd jobs on their next run.
- New scripts/embedded_shard_count_test.go policy tests tie the
  Bazel-only block's shard count to bazel.yml's check_shard_coverage.py
  argument and catch generator staleness; generalized
  TestBazelRetiredLanesCheckListedTestsRan's live-shard-count dispatch
  from bd_proxied_test-only to a map covering both embedded targets;
  removed TestBazelEmbeddedJobMirrorsEmbeddedTier's now-invalid
  BUILD.bazel-shard-count-equals-PR-Risk-matrix assertion.
- Verified: go test ./scripts/..., bazel test //scripts:scripts_test,
  actionlint, make ci-pr-policy, make bazel-sync-check all pass; full
  local bazel test of both targets at 40/14 shards passes 2/2; mutation
  testing confirms each new/changed policy test fails exactly when it
  should.

See ~/beads-bazel-plan/f1/impl-report.md for full detail.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(embedded-dolt): skip 712-item statement-count assertion under -race (F1)

TestLargeBatchApplyStatementCounts712_Embedded genuinely costs ~260-300s
under -race (confirmed by solo re-measurement: 298.60s) -- 14014 real SQL
statement round-trips through the race-instrumented in-process Dolt engine,
not an artifact and not splittable (one indivisible ApplyBatchInTx
transaction). It was the storage tier's single-test floor for CI shard
packing.

Apply the exact precedent TestLargeBatchApplyWallClock_Embedded already set
for its 1000-item shape: skip this assertion under raceEnabled (the cost is
race-instrumentation overhead on the Dolt engine's own internal
goroutine/lock machinery, not this test's own logic) and extend nightly.yml's
"Embedded Dolt batch-apply suite (non-race)" step's -run regex so the full
pinned 14014-statement baseline still runs, non-race, every night. Verified
directly: under -race the assertion now skips in 0.00s; without -race it
still runs and asserts Total=14015 (within the existing +/-2 tolerance) in
36.76s.

Updates scripts/ci_workflow_test.go's
TestNightlyFullTestRunsEmbeddedDoltBatchApplySuite to match the extended
regex.

Storage tier's new single-test ceiling under the per-PR -race lane drops
from ~260.7s to 152.38s (TestBatchApplyContract).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* ci(bazel): correct cmd-tier long-pole durations, re-pack embedded manifolds (F1)

Investigated coordinator item 2 (single-test long poles): TestEmbeddedUpdateConcurrent
(recorded 475.39s) and TestEmbeddedCloseConcurrent (recorded 308.06s), plus
the two other >180s cmd-tier entries from the same capture
(TestEmbeddedInitA 196.94s, TestEmbeddedEpicCloseEligibleReason 192.47s).

Root cause: NOT host contention, NOT backoff/retry sleeps (bdRunWithFlockRetry
contributes negligibly), NOT race-instrumented-subprocess overhead alone.
These numbers were captured via `bazel --nohome_rc test --config=embedded`
with the then-current 20-shard legacy manifest (~10-11 tests/shard) and
`-test.parallel=4`. Go's t.Parallel() starts each parallel test's elapsed
clock when its function is invoked, before the Parallel() call blocks it
waiting for a free one-of-4 slot -- so a test queued behind several other
heavy shard-mates has that queueing wait baked into its own recorded
`--- PASS: TestX (Ys)` time. This is shard-composition-dependent scheduling
delay, not a cost intrinsic to the test.

Confirmed two ways in an isolated clone (not this worktree, per the
no-plain-go-test-from-a-beads-checkout rule):
- Solo (no rivals at all): 151.83s / 106.48s / 63.58s / 66.08s.
- All four together with the real -race -test.parallel=4 flags and exactly
  4 tests requested (so nobody queues -- parallel slots == test count):
  141.34s / 113.80s / 69.79s / 74.63s.
Both agree closely and both are far below the capture-time numbers.

F1's LPT packer already isolates the heaviest tests into shards with few or
no other heavy rivals (TestEmbeddedUpdateConcurrent lands alone in its own
40-shard-block shard), so under the new manifest these tests see little to
no queueing delay in real CI. None of the four needed splitting, parallel
subtests, or raceEnabled-scaled N: once correctly measured, none exceeds the
180s single-test guideline (new corrected weights: 155.0 / 115.0 / 72.0 /
77.0s). Corrected scripts/ci/embedded_cmd_test_durations.json accordingly
(with a doc-comment explaining the methodology and both confirmations) and
re-packed the 40-shard Bazel-only block (--repack --write); --check passes
(exact-once coverage of all 241 discovered tests). The frozen legacy 20-shard
block is untouched and independently re-verified exact-once by simulating
embedded-test-shard.sh across all 20 shards (241/241 tests, no
duplicates/misses/errors).

New cmd-tier single-test ceiling: 179.47s (TestEmbeddedCloseAlreadyClosed,
likely itself somewhat inflated by the same mechanism but already under the
180s line as recorded, so no action needed).

Also updates scripts/ci/embedded_storage_test_durations.json: the prior
commit's raceEnabled-skip for TestLargeBatchApplyStatementCounts712_Embedded
means it now costs ~0s in the per-PR -race lane bazel-embedded actually
packs for (not its real ~260-300s non-race cost, which nightly.yml still
exercises) -- weight set to 1.0 with a doc comment tying it to the skip in
large_batch_apply_measure_test.go. Re-packed the 14-shard Bazel-only block
accordingly; --check passes (exact-once coverage of all 387 discovered
tests, excluding TestMain/TestConformance per that file's existing
convention). The frozen legacy 5-shard block is untouched and independently
re-verified exact-once via embedded-storage-test-shard.sh simulation
(388/388 tests, no duplicates/misses/errors).

Verification: go test ./scripts/... (includes the nightly.yml policy test),
make ci-pr-policy, make bazel-sync-check, actionlint all pass. Real local
`bazel --nohome_rc test --config=embedded //cmd/bd:bd_embedded_test
//internal/storage/embeddeddolt:embeddeddolt_embedded_test`
(--local_test_jobs=8, both targets together, on a shared/noisy sandbox host)
passes both targets; per-shard wall time from each shard's test.xml: cmd/bd
max 218.9s (shard 23/40, min 20.6s), storage max 251.1s (shard 5/14, min
0.98s) -- down from the prior oversubscribed sweep's 783.41s / 351.94s and
well under the single-test-floor-based ~475s projection this slice started
from. Projected tier lane time (max of the two targets, real dedicated CI
runners should do at least this well): ~251s, under the 5-minute target.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test(embedded): un-vacuous TestEmbeddedDepB edges, split epic-close test, trim concurrency stress N (F1 review)

Coordinator review follow-ups on the F1 embedded-Dolt resharding slice:

- TestEmbeddedDepB (one of TestEmbeddedDep's two CI-speed split halves) was
  asserting its tree_* subtests against an edgeless graph, passing
  vacuously; restores the same parent-child/blocks edges TestEmbeddedDepA
  builds so those subtests exercise real multi-node traversal (review S2).
- TestEmbeddedEpicCloseEligibleReason split into
  TestEmbeddedEpicCloseEligibleReasonFlag/...Output for CI shard balance,
  matching the project's established single-concern split pattern.
- TestEmbeddedUpdateConcurrent/TestEmbeddedCloseConcurrent's
  issuesPerWorker reduced 5->2: under real concurrent-shard-load
  measurement these were genuine (not queueing-artifact) serialized-write
  costs; 2 preserves every invariant the test checks (duplicate-ID
  detection across all workers, one non-decreasing-list-count check per
  worker) at a fraction of the serialized work.
- large712ShapeName: the 712-shape's race skip and its zero-match guard now
  share one named constant instead of two independent literal shape-name
  strings, so a future rename of the shape can't silently skip the pinned
  statement-count assertion under race (review N2).
- Comment-only fixes (review N5) in files referencing test names since
  renamed/split by this slice's earlier work: close_proxied_integration_test.go,
  graph_apply_test.go, storage_class_proxied_integration_test.go,
  tests/regression/discovery_test.go, plus doc-comment path cleanups (N1:
  drop unverified ~/beads-bazel-plan paths/bead ids in favor of the
  committed duration JSON files and engdocs/TESTING.md).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* ci(bazel): re-derive embedded-Dolt durations under concurrent load; cap cmd shards at Bazel's 50-shard limit (F1 round 2)

Coordinator review required re-deriving every per-test duration weight from
a single, consistent, CI-realistic measurement (all shards running
concurrently, -test.parallel=4, race-enabled) instead of the prior pass's
mix of crowded-shard captures and solo/4-together spot-corrections, and
required measuring per-shard wall time via BEP testAttemptDuration rather
than a shard's outer test.xml <testsuites time> (which can include a
different, already-finished shard-mate's setup/teardown).

- scripts/ci/embedded_cmd_test_durations.json (242 tests) and
  scripts/ci/embedded_storage_test_durations.json (387 tests) rewritten in
  full from one consistent sweep. Every entry is now a fresh measurement;
  none is a carried-over capture-time value or an unverified estimate. Both
  files' _comment blocks retract the earlier "queueing delay baked into a
  test's own reported elapsed time" theory (testing.go's (*T).Parallel does
  not add wait time to a blocked test's own clock) and document the real
  methodology.
- Only one cmd-tier test remains over 200s (TestEmbeddedListFiltering,
  239.70s), already under the ~240s ceiling; no further top-level splits
  were needed this round.
- New finding: Bazel hard-caps shard_count at 50 per sh_test-like rule
  ("Having more than 50 shards is indicative of poor test organization";
  a native analysis-time limit, not configurable). The previous 88-shard
  plan for //cmd/bd:bd_embedded_test (chosen as the LPT-packed floor before
  this limit was discovered) is reverted to 50, Bazel's real ceiling.
  Repacking the fresh weights at 50 shards gives a heaviest shard of
  409.6s -- above the single-test floor of 239.7s, because 50 bins is not
  enough headroom over the suite's ~20145 measured test-seconds to flatten
  every bin to that floor. This makes the <=5 min lane target unreachable
  for the cmd tier via resharding alone within Bazel's native per-rule
  limit; see ~/beads-bazel-plan/f1/impl-report.md section 3c for the full
  writeup and the two remaining levers (suite-wide speedups or a
  multi-Bazel-rule split), neither attempted in this slice.
- internal/storage/embeddeddolt gets 15 Bazel-only shards (unaffected by
  the 50-shard cap): LPT-packed heaviest shard 225.3s, within target.
- cmd/bd/BUILD.bazel, internal/storage/embeddeddolt/BUILD.bazel,
  .github/workflows/bazel.yml, engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md,
  scripts/embedded_shard_count_test.go, scripts/pr_risk_bazel_coverage_test.go,
  scripts/ci/gen_embedded_cmd_shard_manifest.py updated to the corrected
  50/15 shard counts (and, for the generator, N3: --write without an
  explicit total_shards now errors instead of silently regenerating the
  frozen legacy 20-shard block).
- .github/scripts/embedded-{cmd,storage}-test-shards.txt: re-packed
  Bazel-only blocks at 50/15; frozen legacy 20/5 blocks untouched except for
  N5 fixes to stale entries left by this slice's earlier test splits
  (TestShardScriptsListOnlyRealTests catches this class of bug; both
  legacy blocks reconfirmed exact-once).
- .github/workflows/nightly.yml / scripts/ci_workflow_test.go (N4): the
  embedded-dolt batch-apply nightly step now runs with `if: ${{
  !cancelled() }}` and its own explicit `-timeout 20m`, independent of the
  job-level timeout, with both halves now asserted by
  TestNightlyFullTestRunsEmbeddedDoltBatchApplySuite.

Verified: gofmt -l clean, go vet ./scripts/... clean, go test ./scripts/...
green, both generators' --check pass at 50/15 (and legacy 20/5 remain
exact-once via the frozen-block invariant).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test(ci): rename embedded manifest staleness tests out of the ^TestEmbedded skip

The allowlisted go-test leg runs with -skip ^TestEmbedded, so tests named
TestEmbedded*ShardManifestGeneratorNotStale never ran there and the leg
failed with "matched no test that ran".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-03 21:30:03 -07:00

1044 lines
37 KiB
Go

//go:build cgo
package main
import (
"bytes"
"encoding/json"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
)
// bdList runs "bd list" with the given flags and returns stdout.
func bdList(t *testing.T, bd, dir string, args ...string) string {
t.Helper()
fullArgs := append([]string{"list"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
t.Fatalf("bd list %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
}
return stdout.String()
}
// bdListJSON runs "bd list --json" and parses the result as an array of IssueWithCounts.
func bdListJSON(t *testing.T, bd, dir string, args ...string) []*types.IssueWithCounts {
t.Helper()
fullArgs := append([]string{"list", "--json"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
t.Fatalf("bd list --json %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
}
// Parse stdout only; hints/warnings (e.g. truncation) go to stderr (GH#3212).
s := stdout.String()
start := strings.Index(s, "[")
if start < 0 {
// Empty list returns "[]" or possibly "null"
if strings.Contains(s, "null") || strings.TrimSpace(s) == "" {
return nil
}
t.Fatalf("no JSON array found in output:\n%s", s)
}
var issues []*types.IssueWithCounts
if err := json.Unmarshal([]byte(s[start:]), &issues); err != nil {
t.Fatalf("failed to parse JSON list output: %v\nraw: %s", err, s[start:])
}
return issues
}
type bdListSkipLabelsJSON struct {
SchemaVersion int `json:"schema_version"`
Issues []struct {
ID string `json:"id"`
Labels []string `json:"labels"`
} `json:"issues"`
Meta struct {
SkipLabels bool `json:"skip_labels"`
Count int `json:"count"`
} `json:"meta"`
}
func bdListSkipLabelsJSONOutput(t *testing.T, bd, dir string, args ...string) bdListSkipLabelsJSON {
t.Helper()
fullArgs := append([]string{"list", "--json", "--skip-labels"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
t.Fatalf("bd list --json --skip-labels %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
}
var out bdListSkipLabelsJSON
if err := json.Unmarshal(stdout.Bytes(), &out); err != nil {
t.Fatalf("failed to parse skip-labels JSON output: %v\nraw: %s", err, stdout.String())
}
return out
}
// bdListCapture runs "bd list" and returns (stdout, stderr) separately.
func bdListCapture(t *testing.T, bd, dir string, args ...string) (string, string) {
t.Helper()
fullArgs := append([]string{"list"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
t.Fatalf("bd list %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
}
return stdout.String(), stderr.String()
}
// bdListJSONWithEnv runs "bd list --json" with extra environment variables.
func bdListJSONWithEnv(t *testing.T, bd, dir string, extraEnv []string, args ...string) []*types.IssueWithCounts {
t.Helper()
fullArgs := append([]string{"list", "--json"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = append(bdEnv(dir), extraEnv...)
stdout, stderr, err := runCommandBuffers(t, cmd)
if err != nil {
t.Fatalf("bd list --json %s failed: %v\nstdout:\n%s\nstderr:\n%s", strings.Join(args, " "), err, stdout.String(), stderr.String())
}
s := stdout.String()
start := strings.Index(s, "[")
if start < 0 {
if strings.Contains(s, "null") || strings.TrimSpace(s) == "" {
return nil
}
t.Fatalf("no JSON array found in output:\n%s", s)
}
var issues []*types.IssueWithCounts
if err := json.Unmarshal([]byte(s[start:]), &issues); err != nil {
t.Fatalf("failed to parse JSON list output: %v\nraw: %s", err, s[start:])
}
return issues
}
// bdListFail runs "bd list" expecting failure.
func bdListFail(t *testing.T, bd, dir string, args ...string) string {
t.Helper()
fullArgs := append([]string{"list"}, args...)
cmd := exec.Command(bd, fullArgs...)
cmd.Dir = dir
cmd.Env = bdEnv(dir)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("expected bd list %s to fail, but it succeeded:\n%s", strings.Join(args, " "), out)
}
return string(out)
}
// issueIDs extracts issue IDs from a list result.
func listIssueIDs(issues []*types.IssueWithCounts) []string {
ids := make([]string, len(issues))
for i, issue := range issues {
ids[i] = issue.ID
}
return ids
}
// containsID checks if an ID is in the list.
func containsID(issues []*types.IssueWithCounts, id string) bool {
for _, issue := range issues {
if issue.ID == id {
return true
}
}
return false
}
// testSeedData holds IDs created during test setup.
// All issues are created via `bd create` only — no `bd update` or `bd close`
// since those are not yet implemented on EmbeddedDoltStore.
type testSeedData struct {
openBug string // P0, alice, labels: backend,urgent, has description
feature string // P1, bob, labels: frontend
task string // P2, alice, labels: backend
chore string // P3, no assignee, defer_until set
epic string // P1, labels: planning (has blocking dep on openBug)
decision string // P4, labels: pinned-ref
childTaskA string // P2, bob, labels: backend, parent=epic
childTaskB string // P3, labels: frontend, parent=epic
noDescBug string // P1, empty description
overdueTask string // P1, alice, due_at in past, labels: urgent
metadataIssue string // P1, metadata: env=prod
readyTask string // P0, labels: backend, no blockers
}
// TestEmbeddedListFiltering and TestEmbeddedListSearchAndOutput were split
// from TestEmbeddedList (originally ~298s, measured under --config=embedded)
// into 2 top-level tests over disjoint subtest groups, for CI shard balance
// (see scripts/ci/embedded_cmd_test_durations.json and engdocs/TESTING.md). Every original
// subtest is preserved exactly once.
func TestEmbeddedListFiltering(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")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "tl")
// Seed test data
seed := seedTestData(t, bd, dir)
// --- A. Basic filtering ---
t.Run("status_open", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--status", "open")
for _, issue := range issues {
if issue.Status != types.StatusOpen {
t.Errorf("expected status open, got %s for %s", issue.Status, issue.ID)
}
}
})
t.Run("all", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--all")
if !containsID(issues, seed.openBug) {
t.Error("--all should include open bug")
}
if !containsID(issues, seed.decision) {
t.Error("--all should include decision")
}
})
t.Run("assignee", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--assignee", "alice", "--all")
for _, issue := range issues {
if issue.Assignee != "alice" {
t.Errorf("expected assignee alice, got %q for %s", issue.Assignee, issue.ID)
}
}
if !containsID(issues, seed.openBug) {
t.Error("alice's open bug should appear")
}
})
t.Run("type_bug", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--type", "bug")
for _, issue := range issues {
if issue.IssueType != types.TypeBug {
t.Errorf("expected type bug, got %s for %s", issue.IssueType, issue.ID)
}
}
})
t.Run("priority", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--priority", "0")
for _, issue := range issues {
if issue.Priority != 0 {
t.Errorf("expected priority 0, got %d for %s", issue.Priority, issue.ID)
}
}
if !containsID(issues, seed.openBug) {
t.Error("P0 open bug should appear")
}
if !containsID(issues, seed.readyTask) {
t.Error("P0 ready task should appear")
}
})
t.Run("limit", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--limit", "2")
if len(issues) != 2 {
t.Errorf("expected 2 issues with --limit 2, got %d", len(issues))
}
})
t.Run("limit_truncation_hint", func(t *testing.T) {
// GH#4094: hint is suppressed when stderr is not a terminal (piped).
// bdListCapture always runs in piped mode, so no hint expected even when truncated.
stdout, stderr := bdListCapture(t, bd, dir, "--limit", "2")
if strings.Contains(stderr, "more results matched") {
t.Errorf("truncation hint must not appear on piped stderr (GH#4094):\nstderr: %q\nstdout: %q", stderr, stdout)
}
// Hint must never appear in stdout.
if strings.Contains(stdout, "more results matched") {
t.Errorf("truncation hint leaked into stdout:\n%s", stdout)
}
// Not truncated: --limit 0 (unlimited) must not emit the hint.
_, stderrAll := bdListCapture(t, bd, dir, "--limit", "0")
if strings.Contains(stderrAll, "more results matched") {
t.Errorf("unexpected truncation hint with --limit 0:\n%s", stderrAll)
}
// Not truncated: exact count match (we seed 12 issues, closed ones excluded by default).
// Use a generous --limit that exceeds any default view.
_, stderrHigh := bdListCapture(t, bd, dir, "--limit", "1000")
if strings.Contains(stderrHigh, "more results matched") {
t.Errorf("false-positive truncation hint when under limit:\n%s", stderrHigh)
}
})
t.Run("list_limit_config_env", func(t *testing.T) {
// BD_LIST_LIMIT env var sets the default limit when --limit not passed.
// With BD_LIST_LIMIT=1, default list should return at most 1 issue.
limitedIssues := bdListJSONWithEnv(t, bd, dir, []string{"BD_LIST_LIMIT=1"})
if len(limitedIssues) > 1 {
t.Errorf("BD_LIST_LIMIT=1 should limit to at most 1, got %d", len(limitedIssues))
}
// --limit flag still takes precedence over env var.
allIssues := bdListJSONWithEnv(t, bd, dir, []string{"BD_LIST_LIMIT=1"}, "--limit", "0")
if len(allIssues) <= 1 {
t.Errorf("--limit 0 should override BD_LIST_LIMIT=1, got %d", len(allIssues))
}
// --all is also an explicit list request and should override the configured default.
allFlagIssues := bdListJSONWithEnv(t, bd, dir, []string{"BD_LIST_LIMIT=1"}, "--all")
if len(allFlagIssues) <= 1 {
t.Errorf("--all should override BD_LIST_LIMIT=1, got %d", len(allFlagIssues))
}
})
t.Run("list_limit_config_file", func(t *testing.T) {
// Write project config.yaml with list.limit: 1.
configPath := filepath.Join(dir, ".beads", "config.yaml")
if err := os.WriteFile(configPath, []byte("list:\n limit: 1\n"), 0o644); err != nil {
t.Fatalf("write config.yaml: %v", err)
}
defer func() { _ = os.Remove(configPath) }()
// Config file should limit to at most 1 issue.
limitedIssues := bdListJSON(t, bd, dir)
if len(limitedIssues) > 1 {
t.Errorf("list.limit=1 in config should limit to at most 1, got %d", len(limitedIssues))
}
// --limit flag still takes precedence over config file.
allIssues := bdListJSON(t, bd, dir, "--limit", "0")
if len(allIssues) <= 1 {
t.Errorf("--limit 0 should override config list.limit=1, got %d", len(allIssues))
}
// --all is also an explicit list request and should override the configured default.
allFlagIssues := bdListJSON(t, bd, dir, "--all")
if len(allFlagIssues) <= 1 {
t.Errorf("--all should override config list.limit=1, got %d", len(allFlagIssues))
}
})
t.Run("id_filter", func(t *testing.T) {
idList := seed.openBug + "," + seed.readyTask
issues := bdListJSON(t, bd, dir, "--id", idList)
if len(issues) != 2 {
t.Errorf("expected 2 issues with --id filter, got %d", len(issues))
}
})
// --- B. Label filtering ---
t.Run("label_and", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--label", "backend", "--label", "urgent")
// Only openBug has both backend AND urgent
if len(issues) != 1 || issues[0].ID != seed.openBug {
t.Errorf("expected only open bug with backend+urgent labels, got %v", listIssueIDs(issues))
}
})
t.Run("label_any", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--label-any", "backend,frontend")
if len(issues) < 2 {
t.Errorf("expected multiple issues with --label-any backend,frontend, got %d", len(issues))
}
})
t.Run("no_labels", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--no-labels")
for _, issue := range issues {
if len(issue.Labels) > 0 {
t.Errorf("expected no labels for %s, got %v", issue.ID, issue.Labels)
}
}
})
t.Run("label_pattern", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--label-pattern", "back*")
if !containsID(issues, seed.openBug) {
t.Error("openBug with label 'backend' should match pattern 'back*'")
}
// be-ucslk4 regression guard: prior version returned the full set
// because LabelPattern was set on IssueFilter but never consumed by
// the SQL builder. Issues without a 'back*' label must be excluded.
if containsID(issues, seed.feature) {
t.Error("feature (no 'back*' label) should NOT match pattern 'back*'")
}
if containsID(issues, seed.chore) {
t.Error("chore (no 'back*' label) should NOT match pattern 'back*'")
}
})
t.Run("label_regex", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--label-regex", "back(end|log)")
if !containsID(issues, seed.openBug) {
t.Error("openBug with label 'backend' should match regex 'back(end|log)'")
}
if !containsID(issues, seed.readyTask) {
t.Error("readyTask with label 'backend' should match regex 'back(end|log)'")
}
// be-ucslk4 regression guard: prior version returned the full set
// because LabelRegex was set on IssueFilter but never consumed by
// the SQL builder. Issues without a 'back(end|log)' label must be excluded.
if containsID(issues, seed.feature) {
t.Error("feature (label 'frontend') should NOT match regex 'back(end|log)'")
}
if containsID(issues, seed.epic) {
t.Error("epic (label 'planning') should NOT match regex 'back(end|log)'")
}
// Alternation across unrelated labels: verifies REGEXP semantics
// (not just glob-style prefix matching) — 'urgent' and 'planning'
// share no substring, so only a true regex OR catches both.
altIssues := bdListJSON(t, bd, dir, "--label-regex", "urgent|planning")
if !containsID(altIssues, seed.openBug) {
t.Error("openBug with label 'urgent' should match regex 'urgent|planning'")
}
if !containsID(altIssues, seed.epic) {
t.Error("epic with label 'planning' should match regex 'urgent|planning'")
}
if containsID(altIssues, seed.task) {
t.Error("task (label 'backend' only) should NOT match regex 'urgent|planning'")
}
})
t.Run("exclude_label", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--exclude-label", "urgent")
// openBug has labels: backend,urgent — should be excluded
if containsID(issues, seed.openBug) {
t.Error("openBug with 'urgent' label should be excluded by --exclude-label urgent")
}
// overdueTask also has label: urgent — should be excluded
if containsID(issues, seed.overdueTask) {
t.Error("overdueTask with 'urgent' label should be excluded by --exclude-label urgent")
}
})
t.Run("exclude_label_with_include", func(t *testing.T) {
// Include backend but exclude urgent — should get issues with backend but not urgent
issues := bdListJSON(t, bd, dir, "--label", "backend", "--exclude-label", "urgent")
// openBug has both backend and urgent — should be excluded
if containsID(issues, seed.openBug) {
t.Error("openBug with backend+urgent should be excluded when --exclude-label urgent")
}
})
t.Run("skip_labels_json_suppresses_labeled_issue", func(t *testing.T) {
out := bdListSkipLabelsJSONOutput(t, bd, dir, "--id", seed.openBug)
if !out.Meta.SkipLabels {
t.Fatal("expected meta.skip_labels=true")
}
if out.Meta.Count != 1 || len(out.Issues) != 1 {
t.Fatalf("expected one issue and matching count, got count=%d issues=%d", out.Meta.Count, len(out.Issues))
}
if out.Issues[0].ID != seed.openBug {
t.Fatalf("expected issue %s, got %s", seed.openBug, out.Issues[0].ID)
}
if out.Issues[0].Labels == nil {
t.Fatal("expected labels field to be present as an empty array, got nil")
}
if len(out.Issues[0].Labels) != 0 {
t.Fatalf("--skip-labels JSON leaked labels: %v", out.Issues[0].Labels)
}
})
// --- C. Status/special filtering ---
// Note: --ready, --pinned, --status closed/deferred/in_progress tests are
// skipped because bd update and bd close are not yet implemented on
// EmbeddedDoltStore. All seeded issues have status=open.
t.Run("ready", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--ready")
for _, issue := range issues {
if issue.Status != types.StatusOpen {
t.Errorf("--ready should only return open issues, got status %s for %s", issue.Status, issue.ID)
}
}
// All seeded issues are open, so --ready should return most of them
if len(issues) == 0 {
t.Error("--ready should return open issues")
}
})
t.Run("ready_exclude_type", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--ready", "--exclude-type", "epic", "--limit", "0")
if containsID(issues, seed.epic) {
t.Errorf("--ready --exclude-type epic should exclude epic %s, got %v", seed.epic, listIssueIDs(issues))
}
if !containsID(issues, seed.readyTask) {
t.Errorf("--ready --exclude-type epic should still include ready task %s, got %v", seed.readyTask, listIssueIDs(issues))
}
})
t.Run("overdue", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--overdue")
if !containsID(issues, seed.overdueTask) {
t.Error("overdue task should appear with --overdue")
}
for _, issue := range issues {
if issue.Status == types.StatusClosed {
t.Errorf("closed issue %s should not appear in --overdue", issue.ID)
}
}
})
// --- D. Parent/hierarchy ---
t.Run("parent_filter", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--parent", seed.epic)
ids := listIssueIDs(issues)
if !containsID(issues, seed.childTaskA) {
t.Errorf("child A should appear with --parent, got %v", ids)
}
if !containsID(issues, seed.childTaskB) {
t.Errorf("child B should appear with --parent, got %v", ids)
}
})
t.Run("parent_filter_short_id", func(t *testing.T) {
// Regression for #5440: a --parent value without its project prefix
// (e.g. "c7v" instead of "tl-c7v") must resolve the same way
// `bd history <shortid>` already does (GH#4868), not error "not found".
// Uses the plain (non-JSON) render, matching the issue's own repro and
// tree_parent above -- --json --parent takes a different code path
// (reader.List's own filter, not getHierarchicalChildren) that this
// fix does not touch; see the relay notes for that separate finding.
idParts := strings.Split(seed.epic, "-")
shortID := idParts[len(idParts)-1]
if shortID == seed.epic {
t.Fatalf("test setup: seed.epic %q has no prefix to strip", seed.epic)
}
out := bdList(t, bd, dir, "--parent", shortID)
if !strings.Contains(out, seed.childTaskA) {
t.Errorf("child A %s should appear with --parent %s (short id):\n%s", seed.childTaskA, shortID, out)
}
if !strings.Contains(out, seed.childTaskB) {
t.Errorf("child B %s should appear with --parent %s (short id):\n%s", seed.childTaskB, shortID, out)
}
})
t.Run("no_parent", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--no-parent")
if containsID(issues, seed.childTaskA) {
t.Error("child A should not appear with --no-parent")
}
if containsID(issues, seed.childTaskB) {
t.Error("child B should not appear with --no-parent")
}
})
t.Run("tree_parent", func(t *testing.T) {
// --tree --parent shows hierarchical display
out := bdList(t, bd, dir, "--tree", "--parent", seed.epic)
if !strings.Contains(out, seed.epic) {
t.Errorf("tree output should contain parent ID %s", seed.epic)
}
})
t.Run("ready_parent_tree_excludes_blocked_descendants", func(t *testing.T) {
parent := bdCreate(t, bd, dir, "Ready parent tree", "--type", "epic")
readyChild := bdCreate(t, bd, dir, "Ready child in tree", "--type", "task", "--parent", parent.ID)
blockedChild := bdCreate(t, bd, dir, "Blocked child in tree", "--type", "task", "--parent", parent.ID)
blocker := bdCreate(t, bd, dir, "Tree child blocker", "--type", "task")
bdDepAdd(t, bd, dir, blockedChild.ID, blocker.ID)
out := bdList(t, bd, dir, "--ready", "--parent", parent.ID, "--no-pager")
if !strings.Contains(out, readyChild.ID) {
t.Errorf("ready child %s should appear in ready parent tree:\n%s", readyChild.ID, out)
}
if strings.Contains(out, blockedChild.ID) {
t.Errorf("blocked child %s should not appear in ready parent tree:\n%s", blockedChild.ID, out)
}
})
// Regression for gastownhall/beads#3936: relates-to between two epics
// must not nest them in `bd list` tree mode, and a bidirectional
// relates-to must not silently drop both epics from the output.
t.Run("tree_relates_to_does_not_nest_or_drop_epics", func(t *testing.T) {
epicA := bdCreate(t, bd, dir, "Relates Epic A", "--type", "epic", "--priority", "2")
epicB := bdCreate(t, bd, dir, "Relates Epic B", "--type", "epic", "--priority", "2")
bdDep(t, bd, dir, "add", epicA.ID, epicB.ID, "--type", "relates-to")
out := bdList(t, bd, dir, "--no-pager", "--type", "epic")
if !strings.Contains(out, epicA.ID) || !strings.Contains(out, epicB.ID) {
t.Fatalf("one-direction relates-to should keep both epics visible:\n%s", out)
}
if strings.Contains(out, "└── "+epicA.ID) || strings.Contains(out, "└── "+epicB.ID) ||
strings.Contains(out, "├── "+epicA.ID) || strings.Contains(out, "├── "+epicB.ID) {
t.Fatalf("relates-to must not nest epics under each other:\n%s", out)
}
bdDep(t, bd, dir, "add", epicB.ID, epicA.ID, "--type", "relates-to")
out = bdList(t, bd, dir, "--no-pager", "--type", "epic")
if !strings.Contains(out, epicA.ID) || !strings.Contains(out, epicB.ID) {
t.Fatalf("bidirectional relates-to must not drop epics from tree output:\n%s", out)
}
})
t.Run("ready_parent_filter_includes_grandchildren", func(t *testing.T) {
parent := bdCreate(t, bd, dir, "Ready parent recursive", "--type", "epic")
child := bdCreate(t, bd, dir, "Ready child recursive", "--type", "task", "--parent", parent.ID)
grandchild := bdCreate(t, bd, dir, "Ready grandchild recursive", "--type", "task", "--parent", child.ID)
issues := bdListJSON(t, bd, dir, "--ready", "--parent", parent.ID, "--limit", "0")
if !containsID(issues, child.ID) {
t.Errorf("ready parent filter should include direct child %s, got %v", child.ID, listIssueIDs(issues))
}
if !containsID(issues, grandchild.ID) {
t.Errorf("ready parent filter should include recursive grandchild %s, got %v", grandchild.ID, listIssueIDs(issues))
}
})
t.Run("flat", func(t *testing.T) {
// --flat disables tree format, uses legacy flat list
out := bdList(t, bd, dir, "--flat")
if strings.Contains(out, "└") || strings.Contains(out, "├") {
t.Error("--flat should not contain tree characters")
}
})
}
func TestEmbeddedListSearchAndOutput(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")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "tl")
// Seed test data
seed := seedTestData(t, bd, dir)
// --- E. Content search ---
t.Run("title_search", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--title", "Open bug")
if !containsID(issues, seed.openBug) {
t.Error("title search should find 'Open bug'")
}
})
t.Run("title_contains", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--title-contains", "task", "--all")
if len(issues) == 0 {
t.Error("title-contains 'task' should match some issues")
}
})
t.Run("empty_description", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--empty-description")
if !containsID(issues, seed.noDescBug) {
t.Error("no-desc bug should appear with --empty-description")
}
})
t.Run("no_assignee", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--no-assignee")
for _, issue := range issues {
if issue.Assignee != "" {
t.Errorf("expected no assignee for %s, got %q", issue.ID, issue.Assignee)
}
}
})
// --- F. Date range filtering ---
t.Run("created_after_yesterday", func(t *testing.T) {
yesterday := time.Now().Add(-24 * time.Hour).Format("2006-01-02")
issues := bdListJSON(t, bd, dir, "--created-after", yesterday)
if len(issues) == 0 {
t.Error("all issues created today should match --created-after yesterday")
}
})
t.Run("created_before_yesterday", func(t *testing.T) {
yesterday := time.Now().Add(-24 * time.Hour).Format("2006-01-02")
issues := bdListJSON(t, bd, dir, "--created-before", yesterday)
if len(issues) != 0 {
t.Errorf("no issues should match --created-before yesterday, got %d", len(issues))
}
})
// --- G. Priority range ---
t.Run("priority_range", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--priority-min", "0", "--priority-max", "1")
for _, issue := range issues {
if issue.Priority > 1 {
t.Errorf("expected priority 0-1, got %d for %s", issue.Priority, issue.ID)
}
}
})
t.Run("priority_min", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--priority-min", "3", "--all")
for _, issue := range issues {
if issue.Priority < 3 {
t.Errorf("expected priority >= 3, got %d for %s", issue.Priority, issue.ID)
}
}
})
// --- H. Sort and reverse ---
t.Run("sort_priority", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--sort", "priority")
if len(issues) >= 2 {
if issues[0].Priority > issues[1].Priority {
t.Errorf("--sort priority should put lower priority first, got P%d before P%d",
issues[0].Priority, issues[1].Priority)
}
}
})
t.Run("sort_title", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--sort", "title")
if len(issues) >= 2 {
if strings.ToLower(issues[0].Title) > strings.ToLower(issues[1].Title) {
t.Errorf("--sort title should be alphabetical, got %q before %q",
issues[0].Title, issues[1].Title)
}
}
})
t.Run("sort_reverse", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--sort", "priority", "--reverse")
if len(issues) >= 2 {
if issues[0].Priority < issues[1].Priority {
t.Errorf("--sort priority --reverse should put higher priority first, got P%d before P%d",
issues[0].Priority, issues[1].Priority)
}
}
})
// --- I. Output formats ---
t.Run("json_output", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--all")
if len(issues) == 0 {
t.Fatal("expected non-empty JSON output")
}
// Verify fields are populated
for _, issue := range issues {
if issue.ID == "" {
t.Error("issue ID should not be empty in JSON output")
}
if issue.Title == "" {
t.Error("issue title should not be empty in JSON output")
}
}
// Verify child has parent field
for _, issue := range issues {
if issue.ID == seed.childTaskA {
if issue.Parent == nil || *issue.Parent != seed.epic {
t.Errorf("child A should have parent=%s, got %v", seed.epic, issue.Parent)
}
}
}
})
t.Run("long_format", func(t *testing.T) {
out := bdList(t, bd, dir, "--long", "--flat")
if !strings.Contains(out, "Found") {
t.Error("--long format should contain 'Found N issues'")
}
if !strings.Contains(out, "Description:") || !strings.Contains(out, "This is a bug") {
t.Errorf("--long format should include issue descriptions, got: %s", out)
}
})
t.Run("pretty_format", func(t *testing.T) {
out := bdList(t, bd, dir, "--pretty")
// Pretty format uses status symbols
if len(out) == 0 {
t.Error("--pretty should produce output")
}
})
t.Run("format_digraph", func(t *testing.T) {
out := bdList(t, bd, dir, "--format", "digraph", "--all")
// Digraph format outputs dependency edges — may be empty if no blocking deps
// but should not panic
if out == "" {
t.Error("digraph output should not be empty")
}
})
t.Run("format_dot", func(t *testing.T) {
// DOT format calls GetDependencyRecords per issue — verify it doesn't panic.
// --flat disables tree mode which would otherwise override --format.
out := bdList(t, bd, dir, "--format", "dot", "--flat", "--all")
if !strings.Contains(out, "digraph") {
t.Errorf("dot output should contain 'digraph' header, got: %s", out)
}
})
t.Run("format_dot_output_error", func(t *testing.T) {
stderr, err := runWithReadOnlyStdout(t, bd, dir, bdEnv(dir), "list", "--format", "dot", "--flat", "--all")
if err == nil {
t.Fatalf("list --format dot succeeded with read-only stdout; stderr:\n%s", stderr)
}
if !strings.Contains(stderr, "writing DOT output") {
t.Fatalf("list --format dot stderr = %q, want writer diagnostic", stderr)
}
})
t.Run("compact_default", func(t *testing.T) {
out := bdList(t, bd, dir, "--flat")
if !strings.Contains(out, seed.openBug) {
t.Error("default compact output should contain issue IDs")
}
})
// --- J. Metadata filtering ---
t.Run("metadata_field", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--metadata-field", "env=prod")
if !containsID(issues, seed.metadataIssue) {
t.Error("metadata issue with env=prod should appear")
}
// Should not contain issues without that metadata
if containsID(issues, seed.openBug) {
t.Error("open bug should not match env=prod metadata filter")
}
})
t.Run("has_metadata_key", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--has-metadata-key", "env")
if !containsID(issues, seed.metadataIssue) {
t.Error("metadata issue should appear with --has-metadata-key env")
}
})
// --- K. Edge cases ---
t.Run("empty_database", func(t *testing.T) {
// Create a fresh empty database
emptyDir, _, _ := bdInit(t, bd, "--prefix", "empty")
issues := bdListJSON(t, bd, emptyDir)
if len(issues) != 0 {
t.Errorf("expected 0 issues in empty database, got %d", len(issues))
}
})
t.Run("limit_zero_unlimited", func(t *testing.T) {
issues := bdListJSON(t, bd, dir, "--limit", "0")
// limit 0 means unlimited — should return more than the default limit of 50
// (we have ~13 non-default issues, just verify we get them all)
if len(issues) == 0 {
t.Error("--limit 0 should return all issues")
}
})
t.Run("invalid_sort_field", func(t *testing.T) {
out := bdListFail(t, bd, dir, "--sort", "nonexistent")
if !strings.Contains(out, "invalid sort field") {
t.Errorf("expected 'invalid sort field' error, got: %s", out)
}
})
t.Run("invalid_status", func(t *testing.T) {
out := bdListFail(t, bd, dir, "--status", "nonexistent")
if !strings.Contains(out, "invalid status") {
t.Errorf("expected 'invalid status' error, got: %s", out)
}
})
t.Run("reject_offset_in_direct_mode", func(t *testing.T) {
// --offset is only honored under --proxied-server; the direct
// (embedded) path must fatal before touching the store.
out := bdListFail(t, bd, dir, "--offset", "1")
if !strings.Contains(out, "--offset is only supported under --proxied-server") {
t.Errorf("expected --offset direct-mode rejection, got: %s", out)
}
})
}
// seedTestData creates a rich set of test issues covering all filter dimensions.
// Uses only `bd create` and `bd dep add` — no `bd update` or `bd close` since
// those are not yet implemented on EmbeddedDoltStore.
func seedTestData(t *testing.T, bd, dir string) testSeedData {
t.Helper()
var s testSeedData
// 1. Open bug, P0, alice, labels: backend,urgent, with description
issue := bdCreate(t, bd, dir, "Open bug", "--type", "bug", "--priority", "0",
"--assignee", "alice", "--description", "This is a bug", "--label", "backend", "--label", "urgent")
s.openBug = issue.ID
// 2. Feature, P1, bob, labels: frontend
issue = bdCreate(t, bd, dir, "Feature request", "--type", "feature", "--priority", "1",
"--assignee", "bob", "--label", "frontend")
s.feature = issue.ID
// 3. Task, P2, alice, labels: backend
issue = bdCreate(t, bd, dir, "Backend task", "--type", "task", "--priority", "2",
"--assignee", "alice", "--label", "backend")
s.task = issue.ID
// 4. Chore, P3, no assignee, defer_until set
issue = bdCreate(t, bd, dir, "Deferred chore", "--type", "chore", "--priority", "3",
"--defer", "+7d")
s.chore = issue.ID
// 5. Epic, P1, labels: planning
// Note: no blocking deps via `bd dep add` — DetectCycles is not implemented
// on EmbeddedDoltStore. Parent-child deps are created via --parent on create.
issue = bdCreate(t, bd, dir, "Epic with deps", "--type", "epic", "--priority", "1",
"--label", "planning")
s.epic = issue.ID
// 6. Decision, P4, labels: pinned-ref
issue = bdCreate(t, bd, dir, "Architecture decision", "--type", "decision", "--priority", "4",
"--label", "pinned-ref")
s.decision = issue.ID
// 7. Child task A, P2, bob, labels: backend, parent=epic
issue = bdCreate(t, bd, dir, "Child task A", "--type", "task", "--priority", "2",
"--assignee", "bob", "--label", "backend", "--parent", s.epic)
s.childTaskA = issue.ID
// 8. Child task B, P3, labels: frontend, parent=epic
issue = bdCreate(t, bd, dir, "Child task B", "--type", "task", "--priority", "3",
"--label", "frontend", "--parent", s.epic)
s.childTaskB = issue.ID
// 9. No-desc bug, P1
issue = bdCreate(t, bd, dir, "No desc bug", "--type", "bug", "--priority", "1")
s.noDescBug = issue.ID
// 10. Overdue task, P1, alice, due in past, labels: urgent
pastDue := time.Now().Add(-48 * time.Hour).Format("2006-01-02")
issue = bdCreate(t, bd, dir, "Overdue task", "--type", "task", "--priority", "1",
"--assignee", "alice", "--label", "urgent", "--due", pastDue)
s.overdueTask = issue.ID
// 12. Metadata issue, P1, metadata: env=prod
issue = bdCreate(t, bd, dir, "Metadata issue", "--type", "feature", "--priority", "1",
"--metadata", `{"env":"prod"}`)
s.metadataIssue = issue.ID
// 13. Ready task, P0, labels: backend, no blockers
issue = bdCreate(t, bd, dir, "Ready task", "--type", "task", "--priority", "0",
"--label", "backend")
s.readyTask = issue.ID
t.Logf("Seeded %d test issues", 12)
t.Logf(" openBug=%s feature=%s task=%s chore=%s", s.openBug, s.feature, s.task, s.chore)
t.Logf(" epic=%s decision=%s childA=%s childB=%s", s.epic, s.decision, s.childTaskA, s.childTaskB)
t.Logf(" noDescBug=%s overdue=%s metadata=%s ready=%s",
s.noDescBug, s.overdueTask, s.metadataIssue, s.readyTask)
// Verify seeding worked
all := bdListJSON(t, bd, dir, "--all", "--limit", "0")
if len(all) < 12 {
t.Fatalf("expected at least 12 seeded issues, got %d", len(all))
}
return s
}
// TestEmbeddedListConcurrent verifies one simultaneous embedded-Dolt writer
// and reader complete without corrupting the list snapshot or durable state.
func TestEmbeddedListConcurrent(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")
}
t.Parallel()
bd := buildEmbeddedBD(t)
dir, _, _ := bdInit(t, bd, "--prefix", "cl")
seedID := bdCreateSilent(t, bd, dir, "seed")
createCmd := exec.Command(bd, "create", "--silent", "concurrent")
createCmd.Dir = dir
createCmd.Env = bdEnv(dir)
var createStdout, createStderr bytes.Buffer
createCmd.Stdout = &createStdout
createCmd.Stderr = &createStderr
listCmd := exec.Command(bd, "list", "--json", "--limit", "0")
listCmd.Dir = dir
listCmd.Env = bdEnv(dir)
var listStdout, listStderr bytes.Buffer
listCmd.Stdout = &listStdout
listCmd.Stderr = &listStderr
if err := createCmd.Start(); err != nil {
t.Fatalf("start concurrent create: %v", err)
}
if err := listCmd.Start(); err != nil {
_ = createCmd.Wait()
t.Fatalf("start concurrent list: %v", err)
}
createErr := createCmd.Wait()
listErr := listCmd.Wait()
if createErr != nil {
t.Fatalf("concurrent create failed: %v\nstdout:\n%s\nstderr:\n%s", createErr, createStdout.String(), createStderr.String())
}
if listErr != nil {
t.Fatalf("concurrent list failed: %v\nstdout:\n%s\nstderr:\n%s", listErr, listStdout.String(), listStderr.String())
}
createdID := strings.TrimSpace(createStdout.String())
if createdID == "" {
t.Fatalf("concurrent create returned an empty ID\nstderr:\n%s", createStderr.String())
}
listOutput := listStdout.String()
start := strings.Index(listOutput, "[")
if start < 0 {
t.Fatalf("concurrent list returned no JSON array:\n%s", listOutput)
}
var concurrentIssues []*types.IssueWithCounts
if err := json.Unmarshal([]byte(listOutput[start:]), &concurrentIssues); err != nil {
t.Fatalf("decode concurrent list JSON: %v\nstdout:\n%s\nstderr:\n%s", err, listOutput, listStderr.String())
}
concurrentIDs := make(map[string]struct{}, len(concurrentIssues))
for _, issue := range concurrentIssues {
if _, duplicate := concurrentIDs[issue.ID]; duplicate {
t.Fatalf("concurrent list returned duplicate ID %q", issue.ID)
}
concurrentIDs[issue.ID] = struct{}{}
}
if _, found := concurrentIDs[seedID]; !found {
t.Fatalf("concurrent list did not contain seed ID %q", seedID)
}
finalIssues := bdListJSON(t, bd, dir, "--limit", "0")
finalIDCounts := make(map[string]int, len(finalIssues))
for _, issue := range finalIssues {
finalIDCounts[issue.ID]++
}
for id, count := range finalIDCounts {
if count != 1 {
t.Fatalf("authoritative list returned ID %q %d times", id, count)
}
}
for _, id := range []string{seedID, createdID} {
if finalIDCounts[id] != 1 {
t.Fatalf("authoritative list returned ID %q %d times, want once", id, finalIDCounts[id])
}
}
for id := range concurrentIDs {
if finalIDCounts[id] == 0 {
t.Fatalf("authoritative list omitted concurrent snapshot ID %q", id)
}
}
}