Skip to content

Commit a23e03f

Browse files
adhikjoshiclaude
andcommitted
Fix integration tests to auto-build binary and use portable paths
- Add TestMain that builds the binary before running tests - Use filepath.Join for cross-platform path handling - Replace hardcoded project root with dynamic go.mod detection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 40a87b9 commit a23e03f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/integration_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"os/exec"
9+
"path/filepath"
910
"strings"
1011
"testing"
1112

@@ -17,10 +18,19 @@ import (
1718
// Set MODELSLAB_TEST_URL to override.
1819
var baseURL = "http://127.0.0.1:8888"
1920

20-
func init() {
21+
func TestMain(m *testing.M) {
2122
if url := os.Getenv("MODELSLAB_TEST_URL"); url != "" {
2223
baseURL = url
2324
}
25+
// Build the binary before running tests
26+
root := getProjectRoot()
27+
build := exec.Command("go", "build", "-o", filepath.Join(root, "modelslab"), "./cmd/modelslab/")
28+
build.Dir = root
29+
if out, err := build.CombinedOutput(); err != nil {
30+
fmt.Fprintf(os.Stderr, "Failed to build binary: %s\n%s\n", err, out)
31+
os.Exit(1)
32+
}
33+
os.Exit(m.Run())
2434
}
2535

2636
func runCLI(args ...string) (string, string, int) {
@@ -51,7 +61,19 @@ func runCLIJSON(args ...string) (map[string]interface{}, string, int) {
5161
}
5262

5363
func getProjectRoot() string {
54-
return "/Users/admin/Documents/GitHub/modelslab-cli"
64+
// Walk up from the test directory to find go.mod
65+
dir, _ := os.Getwd()
66+
for {
67+
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
68+
return dir
69+
}
70+
parent := filepath.Dir(dir)
71+
if parent == dir {
72+
break
73+
}
74+
dir = parent
75+
}
76+
return "."
5577
}
5678

5779
// --- Tests ---

0 commit comments

Comments
 (0)