Skip to content

fix(test): resolve Windows test failures and isolate environments#962

Open
decode2 wants to merge 2 commits into
Gentleman-Programming:mainfrom
decode2:fix/issue-960-windows-backup-test
Open

fix(test): resolve Windows test failures and isolate environments#962
decode2 wants to merge 2 commits into
Gentleman-Programming:mainfrom
decode2:fix/issue-960-windows-backup-test

Conversation

@decode2

@decode2 decode2 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes various Windows test failures across the codebase to ensure complete Windows compatibility and full test isolation.

Problem

Several tests failed on Windows due to:

  1. Environment isolation issues: AppData/Roaming (APPDATA) and USERPROFILE not being isolated in tests.
  2. Unix-style path separators (/) hardcoded in expectations instead of using platform-specific pathing.
  3. Windows-specific executable suffixes (.exe) missing in tool setup binary assertions.
  4. Symlink permission requirements on Windows (elevated privileges required by default).
  5. Bash test execution on Windows encountering WSL warning output pollution (e.g. wsl: Failed to start...).
  6. POSIX-incompatible bash extensions in installation script execution.

Solution

  1. Isolated APPDATA via t.Setenv in config_test.go and executor_test.go to prevent pollution.
  2. Isolated both HOME and USERPROFILE in TUI model picker tests (model_test.go).
  3. Used filepath.FromSlash for TestEngramGoInstallFromMain_UsesGoEnvForBinDir.
  4. Appended .exe to expected binary names when running on Windows in CLI engram tests.
  5. Safely skipped symlink test assertions in cleaners_test.go if the user lacks elevated privileges on Windows.
  6. Replaced bash-specific indirect variable expansion (${!name:-}) with a standard eval syntax in scripts/install.sh.
  7. Staged bash test commands in install_script_test.go as a file run directly, and stripped wsl: warnings from command outputs.
  8. Replaced direct exec.Command calls in check tests with mockCmd to support Windows.

Closes #960

Summary by CodeRabbit

  • Bug Fixes
    • Improved cross-platform reliability for installation, update, and uninstall flows, with better Windows handling for executable naming and environment/config paths.
    • Made update/install scripting more resilient to platform differences, including line-ending normalization and more robust command output processing.
  • Tests
    • Expanded automated test coverage to be OS-aware and deterministic, updating expectations and harness behavior to match Windows and non-Windows execution.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 19b68778-56e1-4a84-a34d-ed7fa46ddb92

📥 Commits

Reviewing files that changed from the base of the PR and between e3aa9ff and 3b46ac3.

📒 Files selected for processing (2)
  • internal/update/install_script_test.go
  • scripts/install.sh

📝 Walkthrough

Walkthrough

Tests were updated for Windows-specific paths, binary names, environment variables, and symlink behavior across the CLI, component, TUI, and update flows. The install script helper now reads environment values with eval, and the install-script test normalizes line endings and shell output before asserting proxy-bypass behavior.

Changes

Windows compatibility updates

Layer / File(s) Summary
Windows config paths
internal/components/gga/config_test.go, internal/update/upgrade/executor_test.go
Windows AppData and GGA path helpers are used when creating config and runtime fixture files in tests.
Windows test expectations
internal/cli/run_engram_download_test.go, internal/components/engram/download_test.go, internal/components/permissions/inject_test.go, internal/components/uninstall/cleaners_test.go, internal/update/check_test.go
Tests now normalize Windows binary names and paths, generate platform-specific proxy-bypass wrappers, gate the /nix/store rule on non-Windows, skip symlink setup failures, and use mocked command execution.
TUI cache env
internal/tui/model_test.go
Cache-missing TUI tests set both HOME and USERPROFILE to the same temporary directory.
Install script env lookup
internal/update/install_script_test.go, scripts/install.sh
The install script now reads the named environment variable with eval, and the install-script test normalizes CRLF and filters shell output before comparison.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

type:bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing Windows test failures and isolating test environments.
Linked Issues check ✅ Passed The executor test now uses platform-aware GGA paths and Windows APPDATA handling, which addresses #960.
Out of Scope Changes check ✅ Passed The remaining test and script changes align with the PR's stated Windows-compatibility and isolation goals.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/update/install_script_test.go`:
- Around line 116-120: The test helper in install_script_test.go is writing to a
fixed relative filename, which can collide with leftover files and is not
isolated for parallel runs. Update the temp script creation used around
os.WriteFile and defer os.Remove to use a unique path from t.TempDir() instead
of the hardcoded script_test.sh name, keeping the rest of the test flow the
same.

In `@scripts/install.sh`:
- Line 314: The current env-var lookup in the install script uses eval in a way
that trips set -u when the referenced variable is unset. Update the current
value expansion in the relevant install logic to use an explicit default so
unset variables resolve to empty instead of aborting, while keeping the existing
empty-check behavior intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 86918576-ab1d-4d5c-acfd-3b150dca151e

📥 Commits

Reviewing files that changed from the base of the PR and between 49e5e4d and e3aa9ff.

📒 Files selected for processing (10)
  • internal/cli/run_engram_download_test.go
  • internal/components/engram/download_test.go
  • internal/components/gga/config_test.go
  • internal/components/permissions/inject_test.go
  • internal/components/uninstall/cleaners_test.go
  • internal/tui/model_test.go
  • internal/update/check_test.go
  • internal/update/install_script_test.go
  • internal/update/upgrade/executor_test.go
  • scripts/install.sh

Comment thread internal/update/install_script_test.go Outdated
Comment on lines +116 to +120
tmpFile := "script_test.sh"
if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a unique temp path instead of a fixed script_test.sh in the package dir.

Writing to a hardcoded relative filename in the current working directory risks colliding with a leftover file (e.g. if a prior run crashed before the defer os.Remove) and is not isolated if the package ever runs tests in parallel. Prefer t.TempDir() so cleanup and uniqueness are guaranteed.

♻️ Proposed fix
-	tmpFile := "script_test.sh"
-	if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
-		t.Fatal(err)
-	}
-	defer os.Remove(tmpFile)
+	tmpFile := filepath.Join(t.TempDir(), "script_test.sh")
+	if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
+		t.Fatal(err)
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tmpFile := "script_test.sh"
if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile)
tmpFile := filepath.Join(t.TempDir(), "script_test.sh")
if err := os.WriteFile(tmpFile, []byte(cmdStr), 0o755); err != nil {
t.Fatal(err)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/update/install_script_test.go` around lines 116 - 120, The test
helper in install_script_test.go is writing to a fixed relative filename, which
can collide with leftover files and is not isolated for parallel runs. Update
the temp script creation used around os.WriteFile and defer os.Remove to use a
unique path from t.TempDir() instead of the hardcoded script_test.sh name,
keeping the rest of the test flow the same.

Comment thread scripts/install.sh Outdated
@decode2

decode2 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@Alan-TheGentleman I've addressed the CodeRabbit review comments: isolated the temporary bash test script using a unique name containing the test's identity (avoiding absolute paths that fail in WSL bash), and updated the env-var eval fallback in scripts/install.sh to utilize default expansion to prevent set -u failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(upgrade): TestConfigPathsForBackup_GGAExtrasAreIncluded fails on Windows due to hardcoded Unix paths

1 participant