Skip to content

Conversation

@vmaerten
Copy link
Member

@vmaerten vmaerten commented Jan 31, 2026

Summary

Fix Windows CI test failures that were previously undetected.

Context: Windows tests were somehow not running or being skipped, hiding multiple path-related issues.

Problems discovered:

  1. Backslashes in paths like D:\a\task\task were interpreted as escape sequences (\a → bell, \t → tab) when used in shell commands
  2. Path format mismatches between expected (forward slashes) and actual (backslashes) in test assertions
  3. CRLF line endings causing checksum differences

Solution:

  • Use filepath.ToSlash() for all special variables (ROOT_DIR, TASK_DIR, USER_WORKING_DIR, etc.) to ensure consistent forward slashes on all platforms
  • Normalize paths in error messages for consistent output
  • Add cross-platform test helpers (normalizeOutput, normalizePathSeparators)
  • Force LF line endings in testdata via .gitattributes for consistent checksums
  • Simplify CI workflow (remove redundant steps, fix cache order)

Test plan

  • All tests pass on Linux/macOS/Windows
  • Linter passes
  • Verified forward slashes work correctly on Windows (Go, bash, PowerShell all accept /)

@vmaerten vmaerten force-pushed the fix/ci-windows-tests branch 6 times, most recently from 44f9c32 to fd64eb2 Compare January 31, 2026 09:04
- Normalize paths to forward slashes in glob.go for consistent sorting
- Use filepath.ToSlash in error messages to avoid double-escaped backslashes
- Add goldie.WithEqualFn for cross-platform line ending normalization
- Simplify CI workflow (go run ./cmd/task test)
Use filepath.ToSlash() in test assertions to handle Windows backslashes:
- TestIncludesOptionalImplicitFalse
- TestIncludesOptionalExplicitFalse
- TestIncludesRelativePath
- Extend normalizeLineEndings to convert backslashes to forward slashes
- Normalize TEST_DIR with filepath.ToSlash() for template data
- Fix TestIncludedTaskfileVarMerging assertion to use filepath.ToSlash()

This fixes golden file tests on Windows where paths contain backslashes.
Add .gitattributes rule to ensure testdata files use LF line endings
on all platforms, preventing checksum mismatches on Windows.
goldie's AssertWithTemplate doesn't respect the EqualFn option, so we
manually handle template substitution and use NormalizedEqual directly
for cross-platform comparison.
Instead of manually handling template substitution, normalize the output
before passing it to AssertWithTemplate. This keeps goldie's features
(diff, -update flag) intact while ensuring cross-platform compatibility.
Replace escaped backslashes (\\) before single backslashes to avoid
creating double forward slashes (D://a//task//) in normalized output.
Use filepath.ToSlash() for ROOT_DIR, ROOT_TASKFILE, USER_WORKING_DIR,
TASK_DIR, TASKFILE, and TASKFILE_DIR to ensure consistent forward
slashes across platforms.

This fixes an issue on Windows where backslashes in paths were being
interpreted as escape sequences when used in shell commands like
`echo {{.ROOT_DIR}}`.
On Windows, paths returned by pwd or filepath operations use
backslashes which get interpreted as escape sequences when
printed. This caused tests to fail with corrupted path output.

Fix by normalizing path separators before comparison:
- TestWhenNoDirAttributeItRunsInSameDirAsTaskfile
- TestWhenDirAttributeAndDirExistsItRunsInThatDir
- TestWhenDirAttributeItCreatesMissingAndRunsInThatDir
- TestDynamicVariablesRunOnTheNewCreatedDir
- TestUserWorkingDirectory
- TestUserWorkingDirectoryWithIncluded
- TestUserWorkingDirectoryWithIncluded: normalize actual output instead
  of just expected, since task outputs backslashes on Windows
- TestDynamicVariablesRunOnTheNewCreatedDir: take first line only, as
  Windows may output additional corrupted path info
- Disable fail-fast in CI to see all test failures at once
- Rename normalizeLineEndings to normalizeOutput (clearer name)
- Add normalizePathSeparators helper for string path normalization
- Replace inline strings.ReplaceAll patterns with helper function
- Add unit tests for both normalization functions
The test proved that normalizing only in tests is not sufficient.
The production code must use forward slashes to:
1. Prevent escape sequence issues (\a, \t interpreted as bell, tab)
2. Ensure consistent behavior across platforms
3. Allow portable Taskfiles that work on all OSes
@vmaerten vmaerten force-pushed the fix/ci-windows-tests branch from 5953b76 to b8c5c89 Compare January 31, 2026 17:54
@vmaerten vmaerten changed the title fix(ci): simplify test workflow to fix Windows execution fix: Windows CI test failures and path normalization Jan 31, 2026
@vmaerten vmaerten marked this pull request as ready for review January 31, 2026 18:07
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.

2 participants