beads/cmd/bd/test_helpers_integration_test.go
beads/crew/jane 43df89b2ff fix: repair nightly integration test compilation failures
Six categories of orphaned test references accumulated from prior
refactorings (JSONL removal, SQLite removal, daemon deletion, sync
engine rewrite):

- delete_test.go: remove removeIssueFromJSONL call and JSONL helpers
  (deleted in JSONL refactoring)
- dolt_autocommit_integration_test.go: restore setupGitRepoForIntegration
  and isDoltBackendUnavailable helpers (lost in SQLite backend removal)
- gitlab_integration_test.go: remove tests calling doPullFromGitLab,
  doPushToGitLab, detectGitLabConflicts (replaced by tracker.Engine)
- init_cancel_e2e_test.go: restore runGitCmd helper (lost in sync
  engine gut)
- update_custom_type_test.go, update_edge_cases_test.go: delete
  orphaned dual-mode tests referencing removed RunDualModeTest infra
- dolt_autostart_lifecycle_integration_test.go: rename redeclared
  runBDExecAllowErrorWithEnv to avoid conflict with cli_fast_test.go
- Add test_helpers_integration_test.go with initExecTestDB and
  createExecTestIssue helpers for CLI integration tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 18:05:48 -07:00

45 lines
1.2 KiB
Go

//go:build cgo && integration
package main
import (
"encoding/json"
"os"
"os/exec"
"strings"
"testing"
)
// initExecTestDB initializes a test database using the bd binary and returns the temp dir.
func initExecTestDB(t *testing.T) string {
t.Helper()
tmpDir := createTempDirWithCleanup(t)
initCmd := exec.Command(testBD, "init", "--prefix", "test", "--quiet")
initCmd.Dir = tmpDir
initCmd.Env = os.Environ()
if out, err := initCmd.CombinedOutput(); err != nil {
t.Fatalf("init failed: %v\n%s", err, out)
}
return tmpDir
}
// createExecTestIssue creates a test issue using the bd binary and returns the ID.
func createExecTestIssue(t *testing.T, tmpDir, title string) string {
t.Helper()
createCmd := exec.Command(testBD, "create", title, "-p", "1", "--json")
createCmd.Dir = tmpDir
createCmd.Env = os.Environ()
out, err := createCmd.CombinedOutput()
if err != nil {
t.Fatalf("create failed: %v\n%s", err, out)
}
jsonStart := strings.Index(string(out), "{")
if jsonStart < 0 {
t.Fatalf("No JSON in create output: %s", out)
}
var issue map[string]interface{}
if err := json.Unmarshal(out[jsonStart:], &issue); err != nil {
t.Fatalf("parse create JSON: %v\n%s", err, out)
}
return issue["id"].(string)
}