beads/cmd/bd/import_prefix_test.go
matt wilkie 66af62221e
fix(ci): drop ICU linkage from test jobs, use -tags gms_pure_go everywhere (#3240)
* fix(ci): drop ICU linkage from Linux/macOS test jobs (bd-sz5, GH#3506)

Align the CI test matrix with how we ship: all Go build/test invocations
now use -tags gms_pure_go, matching the Windows job, goreleaser, and the
install scripts. Remove libicu-dev / icu4c installs and CGO_* env setup
from ubuntu-latest and macos-latest jobs in ci.yml, plus nightly,
migration-test, and cross-version-smoke workflows.

Upstream dolthub/go-mysql-server#3506 confirmed -tags=gms_pure_go is the
sanctioned escape hatch; testing an ICU-linked config nobody installs was
wasting CI minutes and producing spurious duplicate-rpath / malformed
LC_DYSYMTAB linker warnings on macOS.

Update docs/ICU-POLICY.md to reflect that the CI matrix no longer
intentionally omits the tag; scripts/test-cgo.sh remains as the local
developer tool for exercising the ICU code path on demand.

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

* fix(ci): add -tags gms_pure_go to test-helper go build shell-outs (bd-sz5)

Addresses review feedback on 7b36ab653. Several integration tests shell
out to `go build ./cmd/bd` (or `go build .`) from TestMain / t.Helper
setup functions. The outer `go test -tags 'integration gms_pure_go'`
tag does not propagate into these subprocesses, so the inner builds were
still trying to link ICU and failing with
`unicode/uregex.h: No such file or directory` in the nightly workflow.

Repo-wide audit of `exec.Command("go", "build", ...)` test helpers:
- internal/beads/beads_hash_multiclone_test.go (reviewer's cite)
- tests/regression/regression_test.go
- cmd/bd/protocol/helpers_test.go
- cmd/bd/doctor/dolt_e2e_test.go
- cmd/bd/{scripttest,import_prefix,explicit_db_nodb,init_embedded,
  main,init,cli_fast,shared_server_integration,doctor_repair,
  dolt_autostart_lifecycle_integration}_test.go

All 15 call sites now pass `-tags gms_pure_go`. `cmd/bd/preflight.go`
is production code (`bd preflight` user command), not a test helper,
and is intentionally left as-is.

Also narrow docs/ICU-POLICY.md "Common Mistakes" #3 -- libicu-dev is
needed only for local on-demand testing via scripts/test-cgo.sh, not
for CI test workflows (which no longer exercise the ICU path).

Verified: `go test -tags 'integration gms_pure_go' -run '^$' ./...`
passes cleanly from the worktree root (previously failed in
internal/beads).

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

* fix(preflight): add -tags gms_pure_go to test/lint shell-outs (bd-sz5)

preflight is a beads-maintainer pre-PR tool. On dev machines without
ICU dev libraries installed, `bd preflight --check` was failing at the
`go test -short ./...` step with the same `unicode/uregex.h` error we
fixed in nightly CI (bd13871bd).

Apply the gms_pure_go tag consistently:
- runTestCheck: `go test -tags gms_pure_go -short ./...`
- runLintCheck: `golangci-lint run --build-tags=gms_pure_go ./...`
- Update the user-visible Command labels to match
- Update the static checklist printed by `bd preflight` (no --check)
  so copy-pasted commands work on no-ICU machines

Matches the tag golangci-lint is now passed in CI, keeping local and
CI runs consistent.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:01:46 -07:00

82 lines
2.4 KiB
Go

//go:build cgo && integration
package main
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestCLI_Import_PrefixValidation_E2E(t *testing.T) {
if testing.Short() {
t.Skip("skipping slow CLI test in short mode")
}
if testDoltServerPort == 0 {
t.Skip("skipping: Dolt test container not available")
}
// Step 0: Build the bd binary
tmpDir := t.TempDir()
bdName := "bd"
if runtime.GOOS == "windows" {
bdName = "bd.exe"
}
bdBinary := filepath.Join(tmpDir, bdName)
buildCmd := exec.Command("go", "build", "-tags", "gms_pure_go", "-o", bdBinary, ".")
if out, err := buildCmd.CombinedOutput(); err != nil {
t.Fatalf("Failed to build bd: %v\nOutput: %s", err, out)
}
// Step 1: Setup a database with a specific prefix
projDir := filepath.Join(tmpDir, "proj")
if err := os.MkdirAll(projDir, 0755); err != nil {
t.Fatalf("Failed to create proj dir: %v", err)
}
runCmd := func(args ...string) (string, error) {
cmd := exec.Command(bdBinary, args...)
cmd.Dir = projDir
out, err := cmd.CombinedOutput()
return string(out), err
}
if out, err := runCmd("init", "--prefix", "current", "--quiet"); err != nil {
t.Fatalf("bd init failed: %v\nOutput: %s", err, out)
}
// Step 2: Create a JSONL file with a mismatched prefix
legacyIssue := `{"id":"legacy-123","title":"Legacy issue","status":"open","priority":2,"issue_type":"task","created_at":"2026-01-01T00:00:00Z"}`
jsonlPath := filepath.Join(projDir, "legacy.jsonl")
if err := os.WriteFile(jsonlPath, []byte(legacyIssue+"\n"), 0644); err != nil {
t.Fatalf("Failed to write legacy JSONL: %v", err)
}
// Step 3: Attempt import without flag - should fail
out, err := runCmd("import", "-i", "legacy.jsonl")
if err == nil {
t.Error("Expected import to fail without --skip-prefix-validation")
}
if !strings.Contains(out, "prefix validation failed") {
t.Errorf("Expected prefix validation error, got: %s", out)
}
// Step 4: Attempt import with --skip-prefix-validation - should succeed
out, err = runCmd("import", "-i", "legacy.jsonl", "--skip-prefix-validation")
if err != nil {
t.Errorf("Import failed with --skip-prefix-validation: %v\nOutput: %s", err, out)
}
// Step 5: Verify issue was imported
out, err = runCmd("list", "--id", "legacy-123", "--json")
if err != nil {
t.Errorf("bd list failed: %v\nOutput: %s", err, out)
}
if !strings.Contains(out, "legacy-123") {
t.Errorf("Expected legacy-123 to be imported, but list output was: %s", out)
}
}