fix: canonicalise the repository path so one repository is one mirror [patch] - #26
Merged
Merged
Conversation
… [patch] The allow-list matches case insensitively on purpose, but every identity derived from the path afterwards compares ordinally: the mirror directory, the fetch coalescing key, the diff cache key, and the admission key. Two callers spelling one repository differently therefore got two bare mirrors on disk, two fetches per polling heartbeat, two computed diffs, and two ls-remote probes, which is exactly the duplication this service exists to remove. Reduce the path to lower case once, in BranchStateHandler.Resolve, right after the allow-list accepts it and before anything is derived from it. What is sent to the forge keeps the caller's spelling, because the forge is the authority on how it spells its own repository names. Fixes #24 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AADb2wQHKruFMAnTyzCfv
The seed was copied out of StateFlowTests, where the string interpolated a blob id constant. Here the ids are written out, so the $ prefix names no hole. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AADb2wQHKruFMAnTyzCfv
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #24
What was wrong
The allow-list matches case insensitively on purpose —
RepositoryPattern.Translatecompiles withRegexOptions.IgnoreCase, and its remarks say why. But every identity derived from the samerepositoryPathafterwards compares ordinally:MirrorStore.TryResolvePath.Combines the segments verbatim, so on the Linux container this ships as,Studio/Game.gitandstudio/game.gitare two differentmirror.gitdirectories.MirrorKey.ToFlightKey()backs both theSingleFlightclone/fetch coalescing inMirrorFetcherand theRepositorycomponent ofDiffKey, so the two spellings share neither fetch coalescing nor aDiffCacheentry.CredentialAdmission.Keyhashes the path ordinally, so each spelling is probed with its owngit ls-remote.Two callers addressing one repository with different casing therefore both pass the allow-list and then cost two bare mirrors on disk, two fetches per polling heartbeat, two computed diffs and two admission probes — the duplication this service exists to remove.
The change
BranchStateHandler.Resolvereduces the repository path to lower case once, immediately after the allow-list accepts it and before it becomes the mirror directory, the flight key, theDiffKeyor the admission key. The newCanonicalizehelper carries a remark explaining that the allow-list's case-insensitivity is what makes it necessary, so it does not get "simplified" away later, as the triage comment asked.What is sent to the forge keeps the caller's spelling: the canonical form exists for this service's own bookkeeping, and the forge is the authority on how it spells its own repository names. That also means a deployment against a case-sensitive forge keeps working.
The README gains a short paragraph on this, since the on-disk layout is operator-visible.
Tests
New
GitBranchStateCache.Tests/Integration/RepositoryIdentityTests.cs, driving the real handler through the existingServiceFixture(mock filesystem, scripted git):ls-remoteand onediff-treemirror.gitdirectory on the volumeThree of the four fail against
main(2 clones, 2 mirror directories, no canonical directory) and pass with the change; verified in both directions by temporarily revertingCanonicalizeto the identity function and re-running.Full suite: 197 passed, 0 failed, in both Debug and Release. Release build is clean, 0 warnings.
Noted, not changed
The upstream key has the same shape of problem —
UpstreamRegistryandRepositoryAllowListboth look it upOrdinalIgnoreCase, sogithubandGitHubwould split identity the same way. It is left alone here to keep this change to what the issue scopes; worth its own issue if it is judged worth fixing.🤖 Generated with Claude Code
https://claude.ai/code/session_019AADb2wQHKruFMAnTyzCfv
Generated by Claude Code