@@ -6,7 +6,7 @@ package cmd
66
77import (
88 "bytes"
9- "database/sql "
9+ "context "
1010 "encoding/json"
1111 "fmt"
1212 "os"
@@ -15,6 +15,7 @@ import (
1515 "strings"
1616 "testing"
1717
18+ beadsdk "github.com/steveyegge/beads"
1819 "github.com/steveyegge/gastown/internal/config"
1920 "github.com/steveyegge/gastown/internal/scheduler/capacity"
2021 "github.com/steveyegge/gastown/internal/testutil"
@@ -228,7 +229,7 @@ func addBeadDependency(t *testing.T, blocked, blocker, dir string) {
228229//
229230// bd v1.0.0 no longer resolves cross-rig IDs via routes for dep add. If the CLI
230231// fails with "no issue found", falls back to inserting the dependency directly
231- // via the Dolt server ( bypasses target-existence validation).
232+ // via the beads Go SDK (which bypasses target-existence validation).
232233func addBeadDependencyOfType (t * testing.T , from , to , depType , dir string ) {
233234 t .Helper ()
234235 cmd := exec .Command ("bd" , "dep" , "add" , from , to , "--type=" + depType )
@@ -237,56 +238,34 @@ func addBeadDependencyOfType(t *testing.T, from, to, depType, dir string) {
237238 if err == nil {
238239 return
239240 }
240- // bd v1.0.0 can't resolve cross-rig IDs — fall back to direct SQL
241- // on the Dolt server (same connection pattern as test cleanup code) .
241+ // bd v1.0.0 can't resolve cross-rig IDs — fall back to the beads Go SDK
242+ // which writes directly to the embedded store without validating the target .
242243 if strings .Contains (string (out ), "no issue found" ) {
243- port := os .Getenv ("GT_DOLT_PORT" )
244- if port == "" {
245- port = "3307"
246- }
247- // Extract the database prefix from the 'from' bead ID (e.g., "r8" from "r8-kha").
248- prefix := from [:strings .Index (from , "-" )]
249- dbName := "beads_" + prefix
250- dsn := fmt .Sprintf ("root@tcp(127.0.0.1:%s)/%s" , port , dbName )
251- db , dbErr := sql .Open ("mysql" , dsn )
252- if dbErr != nil {
253- t .Fatalf ("bd dep add %s %s --type=%s: CLI failed (%s), SQL fallback connect failed: %v" ,
254- from , to , depType , strings .TrimSpace (string (out )), dbErr )
255- }
256- defer db .Close ()
257- _ , execErr := db .Exec (
258- "INSERT INTO dependencies (issue_id, depends_on_id, type, created_by) VALUES (?, ?, ?, 'test')" ,
259- from , to , depType )
260- if execErr != nil {
261- t .Fatalf ("bd dep add %s %s --type=%s: CLI failed (%s), SQL insert failed: %v" ,
262- from , to , depType , strings .TrimSpace (string (out )), execErr )
263- }
244+ ensureCrossRigDep (t , from , to , depType , dir )
264245 return
265246 }
266247 t .Fatalf ("bd dep add %s %s --type=%s failed: %v\n %s" , from , to , depType , err , out )
267248}
268249
269- // ensureCrossRigDep creates a cross-rig dependency via direct SQL on the Dolt
270- // server. Used when bd v1.0.0 can't create cross-rig deps via CLI or store.
250+ // ensureCrossRigDep creates a cross-rig dependency via the beads Go SDK,
251+ // writing directly to the embedded store. Used when bd v1.0.0 can't create
252+ // cross-rig deps via the CLI (which validates target existence).
271253func ensureCrossRigDep (t * testing.T , from , to , depType , dir string ) {
272254 t .Helper ()
273- port := os .Getenv ("GT_DOLT_PORT" )
274- if port == "" {
275- port = "3307"
276- }
277- prefix := from [:strings .Index (from , "-" )]
278- dbName := "beads_" + prefix
279- dsn := fmt .Sprintf ("root@tcp(127.0.0.1:%s)/%s" , port , dbName )
280- db , err := sql .Open ("mysql" , dsn )
255+ ctx := context .Background ()
256+ beadsDir := filepath .Join (dir , ".beads" )
257+ store , err := beadsdk .OpenFromConfig (ctx , beadsDir )
281258 if err != nil {
282- t .Fatalf ("ensureCrossRigDep: connect to %s: %v" , dbName , err )
259+ t .Fatalf ("ensureCrossRigDep: open store at %s: %v" , beadsDir , err )
283260 }
284- defer db .Close ()
285- _ , err = db .Exec (
286- "INSERT IGNORE INTO dependencies (issue_id, depends_on_id, type, created_by) VALUES (?, ?, ?, 'test')" ,
287- from , to , depType )
288- if err != nil {
289- t .Fatalf ("ensureCrossRigDep: insert dep %s→%s: %v" , from , to , err )
261+ defer store .Close ()
262+ dep := & beadsdk.Dependency {
263+ IssueID : from ,
264+ DependsOnID : to ,
265+ Type : beadsdk .DependencyType (depType ),
266+ }
267+ if err := store .AddDependency (ctx , dep , "test" ); err != nil {
268+ t .Fatalf ("ensureCrossRigDep: add dep %s→%s: %v" , from , to , err )
290269 }
291270}
292271
0 commit comments