Fixing unit tests on windows (#813)

* Add Windows stub for orphan cleanup

* Fix account switch tests on Windows

* Make query session events test portable

* Disable beads daemon in query session events test

* Add Windows bd stubs for sling tests

* Make expandOutputPath test OS-agnostic

* Make role_agents test Windows-friendly

* Make config path tests OS-agnostic

* Make HealthCheckStateFile test OS-agnostic

* Skip orphan process check on Windows

* Normalize sparse checkout detail paths

* Make dog path tests OS-agnostic

* Fix bare repo refspec config on Windows

* Add Windows process detection for locks

* Add Windows CI workflow

* Make mail path tests OS-agnostic

* Skip plugin file mode test on Windows

* Skip tmux-dependent polecat tests on Windows

* Normalize polecat paths and AGENTS.md content

* Make beads init failure test Windows-friendly

* Skip rig agent bead init test on Windows

* Make XDG path tests OS-agnostic

* Make exec tests portable on Windows

* Adjust atomic write tests for Windows

* Make wisp tests Windows-friendly

* Make workspace find tests OS-agnostic

* Fix Windows rig add integration test

* Make sling var logging Windows-friendly

* Fix sling attached molecule update ordering

---------

Co-authored-by: Johann Dirry <johann.dirry@microsea.at>
This commit is contained in:
Johann Dirry
2026-01-20 23:17:35 +01:00
committed by GitHub
parent b8a679c30c
commit 3d5a66f850
32 changed files with 626 additions and 203 deletions

View File

@@ -24,6 +24,11 @@ func filterGTEnv(env []string) []string {
return filtered
}
func testSubprocessEnv() []string {
env := filterGTEnv(os.Environ())
return append(env, "BEADS_NO_DAEMON=1")
}
// TestQuerySessionEvents_FindsEventsFromAllLocations verifies that querySessionEvents
// finds session.ended events from both town-level and rig-level beads databases.
//
@@ -37,13 +42,14 @@ func filterGTEnv(env []string) []string {
// 2. Creates session.ended events in both town and rig beads
// 3. Verifies querySessionEvents finds events from both locations
func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
// Skip if gt and bd are not installed
if _, err := exec.LookPath("gt"); err != nil {
t.Skip("gt not installed, skipping integration test")
}
// Skip if bd is not installed
if _, err := exec.LookPath("bd"); err != nil {
t.Skip("bd not installed, skipping integration test")
}
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not installed, skipping integration test")
}
gtBinary := buildGT(t)
// Skip when running inside a Gas Town workspace - this integration test
// creates a separate workspace and the subprocesses can interact with
@@ -51,6 +57,7 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
if os.Getenv("GT_TOWN_ROOT") != "" || os.Getenv("BD_ACTOR") != "" {
t.Skip("skipping integration test inside Gas Town workspace (use 'go test' outside workspace)")
}
t.Setenv("BEADS_NO_DAEMON", "1")
// Create a temporary directory structure
tmpDir := t.TempDir()
@@ -70,9 +77,9 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
// Use gt install to set up the town
// Clear GT environment variables to isolate test from parent workspace
gtInstallCmd := exec.Command("gt", "install")
gtInstallCmd := exec.Command(gtBinary, "install")
gtInstallCmd.Dir = townRoot
gtInstallCmd.Env = filterGTEnv(os.Environ())
gtInstallCmd.Env = testSubprocessEnv()
if out, err := gtInstallCmd.CombinedOutput(); err != nil {
t.Fatalf("gt install: %v\n%s", err, out)
}
@@ -92,10 +99,27 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
}
// Add initial commit to bare repo
initFileCmd := exec.Command("bash", "-c", "echo 'test' > README.md && git add . && git commit -m 'init'")
initFileCmd.Dir = tempClone
if out, err := initFileCmd.CombinedOutput(); err != nil {
t.Fatalf("initial commit: %v\n%s", err, out)
readmePath := filepath.Join(tempClone, "README.md")
if err := os.WriteFile(readmePath, []byte("test\n"), 0644); err != nil {
t.Fatalf("write README: %v", err)
}
gitAddCmd := exec.Command("git", "add", ".")
gitAddCmd.Dir = tempClone
if out, err := gitAddCmd.CombinedOutput(); err != nil {
t.Fatalf("git add: %v\n%s", err, out)
}
gitCommitCmd := exec.Command("git", "commit", "-m", "init")
gitCommitCmd.Dir = tempClone
gitCommitCmd.Env = append(os.Environ(),
"GIT_AUTHOR_NAME=Test",
"GIT_AUTHOR_EMAIL=test@example.com",
"GIT_COMMITTER_NAME=Test",
"GIT_COMMITTER_EMAIL=test@example.com",
)
if out, err := gitCommitCmd.CombinedOutput(); err != nil {
t.Fatalf("git commit: %v\n%s", err, out)
}
pushCmd := exec.Command("git", "push", "origin", "main")
pushCmd.Dir = tempClone
@@ -109,9 +133,9 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
}
// Add rig using gt rig add
rigAddCmd := exec.Command("gt", "rig", "add", "testrig", bareRepo, "--prefix=tr")
rigAddCmd := exec.Command(gtBinary, "rig", "add", "testrig", bareRepo, "--prefix=tr")
rigAddCmd.Dir = townRoot
rigAddCmd.Env = filterGTEnv(os.Environ())
rigAddCmd.Env = testSubprocessEnv()
if out, err := rigAddCmd.CombinedOutput(); err != nil {
t.Fatalf("gt rig add: %v\n%s", err, out)
}
@@ -135,7 +159,7 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
"--json",
)
townEventCmd.Dir = townRoot
townEventCmd.Env = filterGTEnv(os.Environ())
townEventCmd.Env = testSubprocessEnv()
townOut, err := townEventCmd.CombinedOutput()
if err != nil {
t.Fatalf("creating town event: %v\n%s", err, townOut)
@@ -152,7 +176,7 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
"--json",
)
rigEventCmd.Dir = rigPath
rigEventCmd.Env = filterGTEnv(os.Environ())
rigEventCmd.Env = testSubprocessEnv()
rigOut, err := rigEventCmd.CombinedOutput()
if err != nil {
t.Fatalf("creating rig event: %v\n%s", err, rigOut)
@@ -162,7 +186,7 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
// Verify events are in separate databases by querying each directly
townListCmd := exec.Command("bd", "list", "--type=event", "--all", "--json")
townListCmd.Dir = townRoot
townListCmd.Env = filterGTEnv(os.Environ())
townListCmd.Env = testSubprocessEnv()
townListOut, err := townListCmd.CombinedOutput()
if err != nil {
t.Fatalf("listing town events: %v\n%s", err, townListOut)
@@ -170,7 +194,7 @@ func TestQuerySessionEvents_FindsEventsFromAllLocations(t *testing.T) {
rigListCmd := exec.Command("bd", "list", "--type=event", "--all", "--json")
rigListCmd.Dir = rigPath
rigListCmd.Env = filterGTEnv(os.Environ())
rigListCmd.Env = testSubprocessEnv()
rigListOut, err := rigListCmd.CombinedOutput()
if err != nil {
t.Fatalf("listing rig events: %v\n%s", err, rigListOut)