Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/cli/run_engram_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -502,6 +503,9 @@ func TestRunInstallBetaEngramUsesMainGoInstallAndInstalledBinary(t *testing.T) {
home := t.TempDir()
gobin := filepath.Join(home, "go-bin")
betaEngram := filepath.Join(gobin, "engram")
if runtime.GOOS == "windows" {
betaEngram += ".exe"
}

restoreCommand := runCommand
restoreLookPath := cmdLookPath
Expand Down
21 changes: 17 additions & 4 deletions internal/components/engram/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ func TestEngramGoInstallFromMain_UsesGoEnvForBinDir(t *testing.T) {
t.Fatalf("engramGoInstallFromMain: unexpected error: %v", err)
}

wantDir := fakeInstallDir
wantDir := filepath.FromSlash(fakeInstallDir)
gotDir := filepath.Dir(binaryPath)
if gotDir != wantDir {
t.Errorf("binary dir = %q, want %q (from go env GOBIN)", gotDir, wantDir)
Expand All @@ -1278,9 +1278,22 @@ func TestEngramGoInstallFromMain_BypassesPublicGoProxy(t *testing.T) {
binDir := t.TempDir()
goPath := filepath.Join(binDir, "go")
recordPath := filepath.Join(t.TempDir(), "go-env.txt")
fakeGo := filepath.Join(binDir, "go")
script := "#!/usr/bin/env bash\n" +
"printf 'GONOSUMDB=%s\\nGOPRIVATE=%s\\nGONOPROXY=%s\\n' \"${GONOSUMDB:-}\" \"${GOPRIVATE:-}\" \"${GONOPROXY:-}\" > \"$GO_ENV_RECORD\"\n"

var fakeGo string
var script string
if runtime.GOOS == "windows" {
fakeGo = filepath.Join(binDir, "go.bat")
script = "@echo off\n" +
"(\n" +
"echo GONOSUMDB=%GONOSUMDB%\n" +
"echo GOPRIVATE=%GOPRIVATE%\n" +
"echo GONOPROXY=%GONOPROXY%\n" +
") > \"%GO_ENV_RECORD%\"\n"
} else {
fakeGo = filepath.Join(binDir, "go")
script = "#!/usr/bin/env bash\n" +
"printf 'GONOSUMDB=%s\\nGOPRIVATE=%s\\nGONOPROXY=%s\\n' \"${GONOSUMDB:-}\" \"${GOPRIVATE:-}\" \"${GONOPROXY:-}\" > \"$GO_ENV_RECORD\"\n"
}
if err := os.WriteFile(fakeGo, []byte(script), 0o755); err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/components/gga/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gga
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -119,6 +120,10 @@ func TestBuildConfigDifferentProviders(t *testing.T) {
func TestInjectWritesConfigAndAgents(t *testing.T) {
home := t.TempDir()

if runtime.GOOS == "windows" {
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
}

result, err := Inject(home, []model.AgentID{model.AgentClaudeCode})
if err != nil {
t.Fatalf("Inject() error = %v", err)
Expand Down Expand Up @@ -163,6 +168,10 @@ func TestInjectWritesConfigAndAgents(t *testing.T) {
func TestInjectIsIdempotent(t *testing.T) {
home := t.TempDir()

if runtime.GOOS == "windows" {
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
}

first, err := Inject(home, []model.AgentID{model.AgentOpenCode})
if err != nil {
t.Fatalf("Inject() first error = %v", err)
Expand Down
4 changes: 3 additions & 1 deletion internal/components/permissions/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func TestInjectCodexWritesGentleDevPermissionsProfile(t *testing.T) {
`"~/.gitconfig" = "read"`,
`"~/.local/state/nix/profiles/home-manager/home-path" = "read"`,
`"~/.nix-profile" = "read"`,
`"/nix/store" = "read"`,
`":tmpdir" = "write"`,
`":slash_tmp" = "write"`,
`[permissions.gentle-dev.workspace_roots]`,
Expand All @@ -365,6 +364,9 @@ func TestInjectCodexWritesGentleDevPermissionsProfile(t *testing.T) {
`"**/*.key" = "deny"`,
`"**/secrets/**" = "deny"`,
}
if codexPermissionsGOOS != "windows" {
wantSubstrings = append(wantSubstrings, `"/nix/store" = "read"`)
}
for _, want := range wantSubstrings {
if !strings.Contains(text, want) {
t.Fatalf("config.toml missing %q; got:\n%s", want, text)
Expand Down
2 changes: 1 addition & 1 deletion internal/components/uninstall/cleaners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestReadManagedFile_RejectsSymlink(t *testing.T) {
}
link := filepath.Join(dir, "link.json")
if err := os.Symlink(target, link); err != nil {
t.Fatalf("Symlink() error = %v", err)
t.Skipf("skipping symlink test; symlink creation failed (likely due to missing privileges on Windows): %v", err)
}

_, err := readManagedFile(link)
Expand Down
12 changes: 9 additions & 3 deletions internal/tui/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,9 @@ func sddMultiCursor(t *testing.T) int {
// opencode.json and otherwise shows its explicit empty state instead of silently
// skipping model assignment.
func TestSDDModeMultiShowsModelPickerWhenCacheMissing(t *testing.T) {
t.Setenv("HOME", t.TempDir())
tmp := t.TempDir()
t.Setenv("HOME", tmp)
t.Setenv("USERPROFILE", tmp)

m := NewModel(system.DetectionResult{}, "dev")
m.Screen = ScreenSDDMode
Expand All @@ -917,7 +919,9 @@ func TestSDDModeMultiShowsModelPickerWhenCacheMissing(t *testing.T) {
}

func TestSDDModeMultiEmptyModelPickerCanContinueWithDefaults(t *testing.T) {
t.Setenv("HOME", t.TempDir())
tmp := t.TempDir()
t.Setenv("HOME", tmp)
t.Setenv("USERPROFILE", tmp)

m := NewModel(system.DetectionResult{}, "dev")
m.Screen = ScreenSDDMode
Expand Down Expand Up @@ -6008,7 +6012,9 @@ func TestPickerFlowSlice(t *testing.T) {
{
name: "non-custom all agents SDDMode Multi cache absent excludes ModelPicker",
setup: func(t *testing.T) Model {
t.Setenv("HOME", t.TempDir()) // guarantees cache path resolves to missing file
tmp := t.TempDir()
t.Setenv("HOME", tmp)
t.Setenv("USERPROFILE", tmp)
m := NewModel(system.DetectionResult{}, "dev")
m.Selection.Preset = model.PresetFullGentleman
m.Selection.Agents = allPickerAgents
Expand Down
4 changes: 2 additions & 2 deletions internal/update/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,9 @@ func TestCheckSingleTool_EngramUsesBinaryReleaseChannel(t *testing.T) {
}
execCommand = func(name string, args ...string) *exec.Cmd {
if name == "engram" {
return exec.Command("echo", "engram 1.15.13")
return mockCmd("echo", "engram 1.15.13")
}
return exec.Command("false")
return mockCmd("false")
}

result := checkSingleTool(context.Background(), Tools[1], "dev", system.PlatformProfile{OS: "darwin", PackageManager: "brew", Supported: true})
Expand Down
27 changes: 23 additions & 4 deletions internal/update/install_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestInstallScriptBetaGoInstallBypassesPublicGoProxy(t *testing.T) {
t.Fatalf("ReadFile(%q) error = %v", path, err)
}

script := string(content)
script := strings.ReplaceAll(string(content), "\r\n", "\n")
for _, want := range []string{
"prepend_go_env_pattern GONOSUMDB github.com/gentleman-programming/gentle-ai",
"prepend_go_env_pattern GOPRIVATE github.com/gentleman-programming/gentle-ai",
Expand Down Expand Up @@ -103,21 +103,40 @@ func TestInstallScriptBetaGoInstallBypassesPublicGoProxy(t *testing.T) {
}
function := script[start : start+end+3]

cmd := exec.Command("bash", "-c", function+`
cmdStr := function + `
GONOSUMDB=example.com/private
GOPRIVATE=github.com/acme/*
GONOPROXY=github.com/gentleman-programming/gentle-ai
prepend_go_env_pattern GONOSUMDB github.com/gentleman-programming/gentle-ai
prepend_go_env_pattern GOPRIVATE github.com/gentleman-programming/gentle-ai
prepend_go_env_pattern GONOPROXY github.com/gentleman-programming/gentle-ai
printf '%s\n%s\n%s\n' "$GONOSUMDB" "$GOPRIVATE" "$GONOPROXY"
`)
`
cmdStr = strings.ReplaceAll(cmdStr, "\r", "")
tmpFile := "script_test_" + t.Name() + ".sh"
if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile)
cmd := exec.Command("bash", tmpFile)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("run prepend_go_env_pattern fixture: %v\noutput: %s", err, out)
}

got := strings.TrimSpace(string(out))
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
var cleanLines []string
for _, l := range lines {
l = strings.TrimSpace(l)
if strings.HasPrefix(l, "wsl:") {
continue
}
if l == "" {
continue
}
cleanLines = append(cleanLines, l)
}
got := strings.Join(cleanLines, "\n")
want := strings.Join([]string{
"github.com/gentleman-programming/gentle-ai,example.com/private",
"github.com/gentleman-programming/gentle-ai,github.com/acme/*",
Expand Down
13 changes: 9 additions & 4 deletions internal/update/upgrade/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"github.com/gentleman-programming/gentle-ai/internal/backup"
"github.com/gentleman-programming/gentle-ai/internal/components/gga"
"github.com/gentleman-programming/gentle-ai/internal/model"
"github.com/gentleman-programming/gentle-ai/internal/state"
"github.com/gentleman-programming/gentle-ai/internal/system"
Expand Down Expand Up @@ -856,17 +857,21 @@ func TestConfigPathsForBackup_CoversRegistryAgentsNotInOldList(t *testing.T) {
func TestConfigPathsForBackup_GGAExtrasAreIncluded(t *testing.T) {
homeDir := t.TempDir()

// Create GGA config file at ~/.config/gga/config
ggaConfigFile := filepath.Join(homeDir, ".config", "gga", "config")
if runtime.GOOS == "windows" {
t.Setenv("APPDATA", filepath.Join(homeDir, "AppData", "Roaming"))
}

// Create GGA config file at the platform-appropriate path
ggaConfigFile := gga.ConfigPath(homeDir)
if err := os.MkdirAll(filepath.Dir(ggaConfigFile), 0o755); err != nil {
t.Fatalf("MkdirAll gga config: %v", err)
}
if err := os.WriteFile(ggaConfigFile, []byte("gga-config"), 0o644); err != nil {
t.Fatalf("WriteFile gga config: %v", err)
}

// Create GGA runtime lib file at ~/.local/share/gga/lib/pr_mode.sh
ggaLibFile := filepath.Join(homeDir, ".local", "share", "gga", "lib", "pr_mode.sh")
// Create GGA runtime lib file at the platform-appropriate path
ggaLibFile := gga.RuntimePRModePath(homeDir)
if err := os.MkdirAll(filepath.Dir(ggaLibFile), 0o755); err != nil {
t.Fatalf("MkdirAll gga lib: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ install_go() {
prepend_go_env_pattern() {
local name="$1"
local pattern="$2"
local current="${!name:-}"
eval "current=\${$name:-}"

if [ -z "$current" ]; then
printf -v "$name" '%s' "$pattern"
Expand Down
Loading