/ test / e2e / e2e_test.go
e2e_test.go
 1  // Package e2e contains end-to-end tests for ShanClaw.
 2  //
 3  // Offline tests (no LLM API needed) run by default.
 4  // Live tests require SHANNON_E2E_LIVE=1 and a configured endpoint+API key.
 5  //
 6  // TestMain builds a fresh shan binary from the current checkout into a temp
 7  // directory. All tests that need the binary use testBinary() to get its path.
 8  package e2e
 9  
10  import (
11  	"os"
12  	"os/exec"
13  	"path/filepath"
14  	"testing"
15  )
16  
17  var builtBinary string
18  
19  func TestMain(m *testing.M) {
20  	// Build shan from current source into a temp dir.
21  	tmp, err := os.MkdirTemp("", "shan-e2e-*")
22  	if err != nil {
23  		panic("e2e: failed to create temp dir: " + err.Error())
24  	}
25  
26  	bin := filepath.Join(tmp, "shan")
27  	cmd := exec.Command("go", "build", "-o", bin, ".")
28  	cmd.Dir = filepath.Join(repoRoot())
29  	cmd.Stderr = os.Stderr
30  	if err := cmd.Run(); err != nil {
31  		panic("e2e: failed to build shan: " + err.Error())
32  	}
33  	builtBinary = bin
34  
35  	code := m.Run()
36  	os.RemoveAll(tmp)
37  	os.Exit(code)
38  }
39  
40  func testBinary(t *testing.T) string {
41  	t.Helper()
42  	if builtBinary == "" {
43  		t.Fatal("shan binary not built — TestMain should have built it")
44  	}
45  	return builtBinary
46  }
47  
48  func skipUnlessLive(t *testing.T) {
49  	t.Helper()
50  	if os.Getenv("SHANNON_E2E_LIVE") != "1" {
51  		t.Skip("skipping live E2E test (set SHANNON_E2E_LIVE=1 to run)")
52  	}
53  }
54  
55  func repoRoot() string {
56  	// test/e2e/ is two levels deep from repo root
57  	dir, _ := os.Getwd()
58  	return filepath.Join(dir, "..", "..")
59  }