Repository navigation
Disclose a store known by two spellings differing only in case (#298) - #300
Merged
Merged
Conversation
…n case (#298) The issue as filed claimed a store created under the pre-#263 drive-letter spelling is orphaned by the post-#263 resolver. @jqit-ricky measured it on the only Windows box we can point at and disproved it: both spellings resolve to the same directory object, 88 files through either name. NTFS is case-insensitive, so two stores differing only in case is not a state it can be in. Nothing is stranded; no migration is needed or wanted. What survives is git. Its index is case-sensitive where NTFS is not, so a store can be C--Users-you-proj on disk and c--Users-you-proj in the repository that backs it up. On a case-sensitive restore — confirmed on a real case-sensitive APFS volume, not predicted — a repository carrying both spellings clones to two directories with two remember.md files, and the resolver reads one of them. So: a session-start check that discloses, and only discloses. Two probes — the store root's directory names (no fork, and the only half that can fire on Windows) and HEAD's top-level tree (one `git ls-tree`, and HEAD rather than the history because a clone checks out HEAD). Four answers: they agree / a second spelling exists / could not check, with a reason / not applicable. An absence produced by the check is never rendered as agreement. Message on `systemMessage` only when the finding changes, and in /remember:doctor every time. Nothing is renamed, merged or migrated; an allowlist test fails if mv/git add/git checkout ever appear in the library. Measured, interleaved against origin/main, macOS, n=25: +2.3ms for the library and the disk probe with no fork, +35ms for the `git ls-tree`, +34ms median end to end on a store whose root is its own repository. Layouts without one sit in the hook's own noise. The per-tool-call path is byte-identical. tests/test_case_divergence_298.py, 20 tests, red 18/20 first. Full suite 1431 passed, 43 skipped, coverage 94.26%. Co-Authored-By: Max <noreply>
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.
Part of #298. Deliberately not
Closes: the measurement that decides the rest of that issue — whether any real store's history carries both spellings — is still outstanding, and the issue should outlive this.What this is not
The premise #298 was filed on does not survive @jqit-ricky's listing. It claimed a store created under the pre-#263 spelling (
C--Users-…) is orphaned by the post-#263 resolver (c--Users-…).Test-Pathon both spellings returnsTruefor the same directory object, with 88 files reachable through either name. NTFS is case-insensitive, so two stores differing only in case is not a state that filesystem can be in. Nothing is stranded, the plugin reads that store, and the orphaning cannot happen on the platform #263 came from.So there is no migration here, no merge, and no rename.
test_nothing_here_repairs_anythingis an allowlist — it fails ifmv,cp,rm,mkdir,git mv,git add,git commit,git checkout,git clone,git fetch,git pull,git merge,git rebase,git resetorgit pushever appear in the library — rather than a denylist, for the reason #253's restore hook gives: a denylist has to guess the name of the next dangerous verb.What is actually detected
Git's index is case-sensitive where NTFS is not. On the reporter's machine:
Free while the store stays on NTFS, and the git backup exists precisely so the store can be restored elsewhere. Confirmed on a real case-sensitive APFS volume rather than reasoned about: one repository carrying both spellings, one plain
git clone,out/C--proj/remember.mdbesideout/c--proj/remember.md.Two probes, and why the git one alone was not enough
The issue frames this as "the path git tracked vs the path we resolved". Built as stated it would not fire on the one machine we can point at: there git tracks
c--…and the post-#263 resolver computesc--…. Those agree. The divergence that is currently true on that box is between the directory's own name and the resolved one, which is what their listing shows. A git-only check would have been dead code on Windows — the reporter's exact objection to the sibling-scan shape, arriving a second time by a different route.So there are two:
disk — the directory names in the store root that case-fold to the one we resolved. Not "does a sibling exist": on a case-insensitive filesystem there is exactly one entry, and the question is whether it is spelled the way we resolved it. Pure
shopt -s nocasematchover a glob, no fork at all, and the only half that can fire on NTFS.git — the top-level names in
HEAD's tree of the store's own repository.HEAD's tree and not the history, which is a narrower claim than the issue makes and I think the correct one: a clone checks outHEAD, so a history carrying both spellings whileHEADcarries one is inert. The split needs both spellings in the tree a checkout materialises. This is why the check does not rungit log --all, and why it does not depend on the answer to the outstanding measurement.Four answers, not two
ok(compared, they agree) /diverged/unavailable/not-applicable.unavailablecarries a reason:not-a-repository,git-not-installed,nothing-committed,store-not-tracked,store-root-unreadable. The last two matter most — "this store has never been backed up" and "the store root could not be read" are both absences produced by the check, and neither may read as agreement.unavailablenever outranks adivergedanother probe found; there is a test for that.not-applicableis separate from all three: the legacy layout, and any store whose directory is not named by the slug. That is not "we looked and found nothing", it is "there is nothing here that could diverge" — and it is also the guard that stops this going anywhere near the user's own project repository, the same refusal50-git-backup.shmakes at its top for #138.The message
One hard requirement: a reader must not be able to conclude the opposite of the truth. On the reporter's machine the condition is TRUE and completely harmless. So the message says what is true now (nothing to fix, memory reading and writing normally), what would change that (a restore onto a case-sensitive filesystem), and that nothing will be done for them.
test_the_notice_says_it_is_a_heads_up_and_not_a_faultasserts the words broken, lost, corrupt, stranded and not being read do not appear in it.Delivered on
systemMessagethroughuser-prompt-hook.sh's notice loop — the one channel a human sees (#200, #253) — and only when the finding changes. The condition never clears itself and is harmless today, so a line every session start is wallpaper on the channel that can least afford it. Theunavailablelog line is gated the same way, because its commonest reason by far (not-a-repository, an external store nobody has pointed a backup at) is a standing condition rather than an event, and one identical daily line for five weeks is what #252 proved nobody reads./remember:doctorre-runs the check live and reports every time — that is the answer to the issue's last question. A user who suspects their memory went missing had no way to check.WARN, neverFAIL, and theVERDICTline is deliberately untouched: capture is entirely unaffected by this.Cost
Interleaved A/B against
origin/main, macOS, n=25.git ls-tree, isolated{slug}store whose root is its own repoThe one
gitinvocation is the whole cost and there is a test capping it at one. Everything else was pushed to zero forks:not-applicablereturns before either probe runs,.git's absence is a shell builtin away, the disk probe isshopt/glob, the previous record is read by the shell rather thangrep | tr, and the record is rewritten only when its content changes — so the steady state costs no fork in any layout that has no git answer to fetch.session_dir_slugand the per-tool-call path are untouched:scripts/post-tool-hook.sh,scripts/lib-slug.shandscripts/lib-memory-dir.share byte-identical toorigin/main, asserted here as well as by #299'stest_the_per_tool_call_path_is_not_touched.Tests
tests/test_case_divergence_298.py, 20 tests. Red 18/20 first — the two that passed against no code at all are the absence assertions (nothing is repaired, the hot path is untouched), which is what they are for.No test needs a case-sensitive volume. One can be built on macOS with
hdiutil create -fs "Case-sensitive APFS", and I did, to watch the clone actually produce two directories. A test that needed one could not run on a CI runner — so the divergence is instead built by writing a blob straight into git's index withupdate-index --cacheinfo, which is not a simulation: the condition being detected is a name in git's index, and that is exactly what the fixture writes. The disk half is exercised by pre-creating the store directory under the other spelling, and asserts on the finding rather than on the entry count, so it holds on a case-sensitive and a case-insensitive filesystem alike.One bug the tests caught, worth naming because it is this file's own recurring shape: a
[ -n … ] && printfas the last command of a redirected group makes a correct write look like a failed one, and the error branch then deleted a record that had been produced correctly.Full suite: 1431 passed, 43 skipped, coverage 94.26%.
Still open on #298
Whether any real store's history carries both spellings. Nothing here assumes an answer, and this check would be worth having either way — it is what tells us how common the condition is before anyone considers writing a migration nobody currently has grounds for.