Files
gastown/internal/dog/manager_test.go
Johann Dirry 3d5a66f850 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>
2026-01-20 14:17:35 -08:00

105 lines
2.3 KiB
Go

package dog
import (
"os"
"path/filepath"
"testing"
"time"
"github.com/steveyegge/gastown/internal/config"
)
// TestDogStateJSON verifies DogState JSON serialization.
func TestDogStateJSON(t *testing.T) {
now := time.Now()
state := &DogState{
Name: "alpha",
State: StateIdle,
LastActive: now,
Work: "",
Worktrees: map[string]string{
"gastown": "/path/to/gastown",
"beads": "/path/to/beads",
},
CreatedAt: now,
UpdatedAt: now,
}
// Create temp file
tmpDir := t.TempDir()
statePath := filepath.Join(tmpDir, ".dog.json")
// Write and read back
data, err := os.ReadFile(statePath)
if err == nil {
t.Logf("Data already exists: %s", data)
}
// Test state values
if state.Name != "alpha" {
t.Errorf("expected name 'alpha', got %q", state.Name)
}
if state.State != StateIdle {
t.Errorf("expected state 'idle', got %q", state.State)
}
if len(state.Worktrees) != 2 {
t.Errorf("expected 2 worktrees, got %d", len(state.Worktrees))
}
}
// TestManagerCreation verifies Manager initialization.
func TestManagerCreation(t *testing.T) {
rigsConfig := &config.RigsConfig{
Version: 1,
Rigs: map[string]config.RigEntry{
"gastown": {
GitURL: "git@github.com:test/gastown.git",
},
"beads": {
GitURL: "git@github.com:test/beads.git",
},
},
}
m := NewManager("/tmp/test-town", rigsConfig)
if filepath.ToSlash(m.townRoot) != "/tmp/test-town" {
t.Errorf("expected townRoot '/tmp/test-town', got %q", m.townRoot)
}
if filepath.ToSlash(m.kennelPath) != "/tmp/test-town/deacon/dogs" {
t.Errorf("expected kennelPath '/tmp/test-town/deacon/dogs', got %q", m.kennelPath)
}
}
// TestDogDir verifies dogDir path construction.
func TestDogDir(t *testing.T) {
rigsConfig := &config.RigsConfig{
Version: 1,
Rigs: map[string]config.RigEntry{},
}
m := NewManager("/home/user/gt", rigsConfig)
path := m.dogDir("alpha")
expected := "/home/user/gt/deacon/dogs/alpha"
if filepath.ToSlash(path) != expected {
t.Errorf("expected %q, got %q", expected, path)
}
}
// TestStateConstants verifies state constants.
func TestStateConstants(t *testing.T) {
tests := []struct {
state State
expected string
}{
{StateIdle, "idle"},
{StateWorking, "working"},
}
for _, tc := range tests {
if string(tc.state) != tc.expected {
t.Errorf("expected %q, got %q", tc.expected, string(tc.state))
}
}
}