Skip to content

Commit ada8770

Browse files
committed
fix: harden bdstore ready filtering and conformance setup
1 parent 1e62309 commit ada8770

3 files changed

Lines changed: 65 additions & 13 deletions

File tree

internal/beads/bdstore.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,13 @@ func (s *BdStore) Ready() ([]Bead, error) {
738738
return nil, fmt.Errorf("bd ready: %w", err)
739739
}
740740
issues := parseIssuesTolerant(extractJSON(out))
741-
result := make([]Bead, len(issues))
741+
result := make([]Bead, 0, len(issues))
742742
for i := range issues {
743-
result[i] = issues[i].toBead()
743+
bead := issues[i].toBead()
744+
if IsReadyExcludedType(bead.Type) {
745+
continue
746+
}
747+
result = append(result, bead)
744748
}
745749
return result, nil
746750
}

internal/beads/bdstore_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,31 @@ func TestBdStoreReady(t *testing.T) {
518518
}
519519
}
520520

521+
func TestBdStoreReadyFiltersInfraTypes(t *testing.T) {
522+
runner := fakeRunner(map[string]struct {
523+
out []byte
524+
err error
525+
}{
526+
`bd ready --json --limit 0`: {
527+
out: []byte(`[
528+
{"id":"bd-task","title":"ready one","status":"open","issue_type":"task","created_at":"2025-01-15T10:30:00Z"},
529+
{"id":"bd-session","title":"infra session","status":"open","issue_type":"session","created_at":"2025-01-15T10:31:00Z"}
530+
]`),
531+
},
532+
})
533+
s := beads.NewBdStore("/city", runner)
534+
got, err := s.Ready()
535+
if err != nil {
536+
t.Fatal(err)
537+
}
538+
if len(got) != 1 {
539+
t.Fatalf("Ready() returned %d beads, want 1", len(got))
540+
}
541+
if got[0].ID != "bd-task" {
542+
t.Fatalf("Ready()[0].ID = %q, want %q", got[0].ID, "bd-task")
543+
}
544+
}
545+
521546
func TestBdStoreReadyEmpty(t *testing.T) {
522547
runner := fakeRunner(map[string]struct {
523548
out []byte

test/integration/bdstore_test.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/gastownhall/gascity/internal/beads"
1919
"github.com/gastownhall/gascity/internal/beads/beadstest"
2020
"github.com/gastownhall/gascity/internal/doctor"
21+
"gopkg.in/yaml.v3"
2122
)
2223

2324
const (
@@ -74,17 +75,7 @@ func TestBdStoreConformance(t *testing.T) {
7475

7576
runBDInit(t, wsDir, prefix, serverPort)
7677

77-
// Explicitly set issue_prefix (required for bd create).
78-
bdConfig := exec.Command("bd", "config", "set", "issue_prefix", prefix)
79-
bdConfig.Dir = wsDir
80-
if out, err := bdConfig.CombinedOutput(); err != nil {
81-
t.Fatalf("bd config set: %v: %s", err, out)
82-
}
83-
customTypes := exec.Command("bd", "config", "set", "types.custom", strings.Join(doctor.RequiredCustomTypes, ","))
84-
customTypes.Dir = wsDir
85-
if out, err := customTypes.CombinedOutput(); err != nil {
86-
t.Fatalf("bd config set types.custom: %v: %s", err, out)
87-
}
78+
writeCustomTypesConfig(t, wsDir, doctor.RequiredCustomTypes)
8879

8980
return beads.NewBdStore(wsDir, beads.ExecCommandRunner())
9081
}
@@ -176,6 +167,38 @@ func runBDInit(t *testing.T, dir, prefix, port string) {
176167
}
177168
}
178169

170+
func writeCustomTypesConfig(t *testing.T, wsDir string, customTypes []string) {
171+
t.Helper()
172+
173+
configPath := filepath.Join(wsDir, ".beads", "config.yaml")
174+
data, err := os.ReadFile(configPath)
175+
if err != nil {
176+
t.Fatalf("reading config.yaml: %v", err)
177+
}
178+
179+
cfg := map[string]any{}
180+
if len(data) > 0 {
181+
if err := yaml.Unmarshal(data, &cfg); err != nil {
182+
t.Fatalf("parsing config.yaml: %v", err)
183+
}
184+
}
185+
186+
typesCfg, ok := cfg["types"].(map[string]any)
187+
if !ok || typesCfg == nil {
188+
typesCfg = map[string]any{}
189+
}
190+
typesCfg["custom"] = strings.Join(customTypes, ",")
191+
cfg["types"] = typesCfg
192+
193+
out, err := yaml.Marshal(cfg)
194+
if err != nil {
195+
t.Fatalf("marshaling config.yaml: %v", err)
196+
}
197+
if err := os.WriteFile(configPath, out, 0o644); err != nil {
198+
t.Fatalf("writing config.yaml: %v", err)
199+
}
200+
}
201+
179202
// ensureDoltIdentity ensures dolt has user.name and user.email set.
180203
// Copies from git config if available, otherwise sets defaults.
181204
func ensureDoltIdentity(t *testing.T) {

0 commit comments

Comments
 (0)