Skip to content

Commit d9c8c4b

Browse files
committed
test: normalize paths in TestDiscoverIntegration for cross-OS matrix
The diagnose-test-failure job uploaded test artifacts and showed the exact failure on both macOS and Windows is the same: macOS: Root() = "/private/var/folders/.../001" want "/var/folders/.../001" Windows: Root() = "C:/Users/runneradmin/AppData/Local/Temp/.../001" want "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\...\\001" `git rev-parse --show-toplevel` (which Discover() returns verbatim): - Resolves symlinks on macOS — /var → /private/var - Returns forward slashes on Windows where Go's filepath uses backslash - Returns the Windows long-path form (runneradmin) where t.TempDir() may return the 8.3 short form (RUNNER~1) These are real OS differences exposed by the new cross-OS test matrix, not bugs in Discover() itself. Fix the comparison in the test by piping both sides through filepath.FromSlash + filepath.EvalSymlinks before the equality check. Also drop the temporary diagnose-test-failure job — its purpose was to surface this failure once, and it's no longer needed. https://claude.ai/code/session_01Sy9fRJ7oL6ghGxJAVvEPLW
1 parent 9b41ec7 commit d9c8c4b

2 files changed

Lines changed: 17 additions & 48 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,52 +95,6 @@ jobs:
9595
path: coverage.out
9696
if-no-files-found: error
9797

98-
# Temporary diagnostic job: when the test matrix fails, download every test
99-
# output artifact and post the tail of each as a PR comment. Actions logs
100-
# are gated behind authentication so this is currently the most reliable way
101-
# to surface OS-specific failures. Remove once the matrix is consistently
102-
# green.
103-
diagnose-test-failure:
104-
if: failure() && github.event_name == 'pull_request'
105-
needs: test
106-
runs-on: ubuntu-latest
107-
timeout-minutes: 5
108-
109-
permissions:
110-
contents: read
111-
pull-requests: write
112-
113-
steps:
114-
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
115-
with:
116-
path: ./diag
117-
pattern: test-output-*
118-
119-
- name: Post test output as PR comment
120-
env:
121-
GH_TOKEN: ${{ github.token }}
122-
GH_REPO: ${{ github.repository }}
123-
PR_NUMBER: ${{ github.event.pull_request.number }}
124-
shell: bash
125-
run: |
126-
set -euo pipefail
127-
{
128-
echo "## Test failure diagnostics ($(date -u +%Y-%m-%dT%H:%M:%SZ))"
129-
echo
130-
echo "Auto-generated from ci run \`${GITHUB_RUN_ID}\` on commit \`${GITHUB_SHA::7}\`."
131-
for d in diag/test-output-*; do
132-
os="${d#diag/test-output-}"
133-
echo
134-
echo "<details><summary>$os (last 200 lines)</summary>"
135-
echo
136-
echo '```'
137-
tail -200 "$d/test-output.txt"
138-
echo '```'
139-
echo "</details>"
140-
done
141-
} > comment.md
142-
gh pr comment "$PR_NUMBER" --body-file comment.md
143-
14498
vuln:
14599
runs-on: ubuntu-latest
146100
timeout-minutes: 5

internal/git/git_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"os"
66
"os/exec"
7+
"path/filepath"
78
"strings"
89
"testing"
910
"time"
@@ -603,8 +604,22 @@ func TestDiscoverIntegration(t *testing.T) {
603604
if err != nil {
604605
t.Fatalf("Discover() error = %v", err)
605606
}
606-
if repo.Root() != tempDir {
607-
t.Fatalf("Root() = %q, want %q", repo.Root(), tempDir)
607+
// `git rev-parse --show-toplevel` returns a path that has been resolved
608+
// for symlinks (macOS: /var → /private/var) and that uses forward slashes
609+
// regardless of OS (Windows: C:/Users/... vs Go's native C:\Users\...).
610+
// Normalize both sides through filepath.FromSlash + EvalSymlinks so the
611+
// comparison is OS-agnostic — also resolves Windows 8.3 short names like
612+
// RUNNER~1 to their long form.
613+
got, err := filepath.EvalSymlinks(filepath.FromSlash(repo.Root()))
614+
if err != nil {
615+
t.Fatalf("EvalSymlinks(Root()=%q) error = %v", repo.Root(), err)
616+
}
617+
want, err := filepath.EvalSymlinks(filepath.FromSlash(tempDir))
618+
if err != nil {
619+
t.Fatalf("EvalSymlinks(tempDir=%q) error = %v", tempDir, err)
620+
}
621+
if got != want {
622+
t.Fatalf("Root() = %q (normalized %q), want %q (normalized %q)", repo.Root(), got, tempDir, want)
608623
}
609624

610625
if err := repo.SetConfigBool("gitreal.enabled", true); err != nil {

0 commit comments

Comments
 (0)