Skip to content

test: stop three assertions assuming POSIX separators on native paths - #644

Merged
zzet merged 1 commit into
zzet:mainfrom
tiendungdev:fix/windows-separator-test-assumptions
Aug 21, 2026
Merged

test: stop three assertions assuming POSIX separators on native paths#644
zzet merged 1 commit into
zzet:mainfrom
tiendungdev:fix/windows-separator-test-assumptions

Conversation

@tiendungdev

Copy link
Copy Markdown
Contributor

Problem

Three tests compare against a /-spelled path while the value under test is a native filesystem path. On POSIX the two spellings coincide, so the linux/macos matrix has never been able to see it. On windows/amd64, go1.26.6, all three fail at main:

--- FAIL: TestFeedbackDir
    "\home\user\.cache\gortex\5887dcec1741_latest"
      does not contain ".cache/gortex"

--- FAIL: TestParseDiffGitPaths
    parseDiffGitPaths("diff --git a/pkg/foo.go b/pkg/foo.go")
      = "pkg\foo.go", want "pkg/foo.go"

--- FAIL: TestParseDiffLinesNewSide
    diffmap_test.go:63: expected new-side lines for pkg/foo.go

The production values are correct — I checked before touching them

This looked at first like a separator bug in cleanDiffPath. It is not, and the tests are what needs to change:

  • FeedbackDir is filepath.Join(cacheDir, RepoCacheKey(repoPath)) and its result feeds os.Open through LoadFeedback. It must carry native separators.
  • cleanDiffPath is filepath.Clean, and JoinFileNodes looks a diff path up as repoPrefix + "/" + path. Per internal/graphpath's package doc, indexed paths are repoPrefix + '/' + the repo-relative path in native separators — on Windows repo/dir\file. So the cleaned native form is exactly the shape the join needs. Making diff paths slash-canonical would produce repo/pkg/foo.go and break the lookup on Windows.

So the fix is on the assertion side: build the expectation with filepath.Join / filepath.Clean instead of a literal. On POSIX both are the identity for these inputs, so the assertions keep exactly the strength they have today on the matrix that already runs them.

Guarding it

Folded into the existing Test native-separator store path comparisons step rather than adding a new one — internal/analysis, internal/mcp, internal/resolver and internal/graph/store_sqlite are already in that step's package list, and internal/persistence is already compiled by the sidecar step directly above it. The regex gains exactly the three tests and nothing else:

$ go test -list 'NativeSeparator|MixedSeparator|ImportAdjacency|ParseDiffGitPaths|ParseDiffLinesNewSide|FeedbackDir' <pkgs>
… existing 12 …
TestParseDiffLinesNewSide
TestParseDiffGitPaths
TestFeedbackDir

Verification

  • The exact extended CI command, on windows: ok for all five packages.
  • Sabotage-verified: with only the two test files reverted (ci.yml kept), that same command reports --- FAIL for all three. The step provably binds.
  • golangci-lint run ./internal/persistence/... — 0 issues.
  • Committed blobs add CR exactly in step with the added lines (+6/+12/+4 against numstat 8-2 / 16-4 / 5-1), so no line-ending noise rides along.

Declared

  • internal/analysis/grounding.go's cleanFile says it "normalizes a path the same way DiffHunk.FilePath / parseDiffLines do" but only does TrimPrefix(p, "./") — no Clean. That is a real inconsistency, and on Windows it would miss the parseDiffLines map key. I did not touch it: its only production caller (internal/review/anchor.go:277) builds the map and looks it up with the same variable, so the mismatch is not reachable today. Happy to send it separately if you want the comment and the code reconciled.
  • Two further Windows failures in internal/analysis (TestMapGitDiffRepoPrefixJoin, TestMapGitDiffFileChangeKinds, both TempDir RemoveAll cleanup: …\.git: The directory is not empty) are not included: I traced them to a non-stock git on my machine that writes .git/ai/logs on every git init. Reproduced with a bare git init outside this repo, so they are my environment, not gortex.

Branched from main at b8b13ca7. Windows 11, go1.26.6.

TestFeedbackDir, TestParseDiffGitPaths and TestParseDiffLinesNewSide all
compare against a '/'-spelled path while the value under test is a native
filesystem path. On POSIX the two coincide, so the linux/macos matrix has
never seen it; on windows/amd64 all three fail:

    "\home\user\.cache\gortex\5887dcec1741_latest"
      does not contain ".cache/gortex"
    parseDiffGitPaths("diff --git a/pkg/foo.go b/pkg/foo.go")
      = "pkg\foo.go", want "pkg/foo.go"
    diffmap_test.go:63: expected new-side lines for pkg/foo.go

The production values are correct in each case and are left alone:

  - FeedbackDir is filepath.Join(cacheDir, key) and feeds os.Open, so it
    must carry native separators.
  - cleanDiffPath is filepath.Clean, and JoinFileNodes looks a diff path
    up as repoPrefix + "/" + path. Indexed paths are repoPrefix + '/' +
    the rest in native separators (see internal/graphpath), so the
    cleaned native form is exactly what the join needs. Making diff paths
    slash-canonical would break that lookup on Windows.

So the fix is on the assertion side: build the expectation with
filepath.Join / filepath.Clean instead of a literal. On POSIX both are
identity for these inputs, so the assertions keep exactly the strength
they had on the matrix that already runs them.

Fold the three into the existing native-separator windows step rather
than adding one: internal/analysis, internal/mcp, internal/resolver and
internal/graph/store_sqlite are already in that step's package list, and
internal/persistence is already compiled by the sidecar step above it.
@zzet
zzet merged commit b09f89c into zzet:main Aug 21, 2026
10 checks passed
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