Repository navigation
Conversation
`to_wiki` writes each article through `write_text_atomic_if_changed`, then
sweeps the `*.md` files the run did not produce. On a case-preserving,
case-insensitive filesystem (APFS, NTFS) the write for `Groups.md` replaces the
contents of the existing `groups.md` entry without renaming it. The sweep then
compared names case-sensitively, saw `"groups.md" not in {"Groups.md"}` and
unlinked the file the same run had just written, so `index.md` linked to a
`Groups.md` that no longer existed.
Comparisons now fold case, and a case-only difference is renamed through a
temporary name so the new case reaches disk. The two-step rename is required
because a case-insensitive filesystem treats source and destination as one
file. `_unique_slug` already folds case when it dedups colliding labels; this
was the remaining case-sensitive comparison.
Tests: tests/test_wiki_case_only_relabel.py (4 tests) covers the article
surviving, the new case landing on disk, no dangling link in `index.md`, and a
genuinely stale article still being swept. The first three fail on unmodified
v8; the fourth passes both ways, which is the guard against over-correcting the
sweep.
Fixes Graphify-Labs#4508
Co-Authored-By: Claude <[email protected]>
|
Thanks for the pull request, @dupeisen. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: to\_wiki (vacuous: never exercised).
Graphify review — findings
Fixes the orphan sweep in to_wiki so a community relabelled only by letter case keeps its article, instead of having the freshly written file deleted and index.md left pointing at nothing (#4508). The sweep now compares filenames case-folded, and any on-disk entry whose folded name matches a produced article but differs in case is renamed to the new spelling through a temporary .{name}.case-tmp file, since a case-insensitive filesystem treats a direct rename as a no-op. That rename runs on every folded match with a different case, so it also fires where the old-case file is a separate entry from the one just written, and a failure between the two steps leaves the temp file behind. Names with no folded match are still unlinked as before, and the new tests cover the surviving article, the new case on disk, resolvable index.md links, and genuine stale-file removal.
Worth a look
- On case-sensitive filesystems, the case-only rename overwrites the fresh article with stale content —
graphify/wiki.py:461· Escalate · high- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 322 functions depend on the 28 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
to_wiki()— 53 callers, 8 callees
Verification — 322 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 88 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
6 of 466 test file(s) selected (1%) via static blast radius.
tests/test_export_idempotent_writes.py— impacttests/test_export_path_length.py— impacttests/test_wiki.py— impacttests/test_wiki_case_only_relabel.py— impact, changed-testtests/test_wiki_link_filename_parity.py— impacttests/test_wiki_truncation_indicator.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify to\_wiki.
The verifier did not have enough to check to\_wiki, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 225 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)
· 1 more finding(s) on lines outside this diff (see the check run).
… rename over the fresh file Follow-up to #4798. Its case-only-relabel sweep ran the two-step rename unconditionally whenever the on-disk name differed from the produced name by case. That is right on a case-INSENSITIVE filesystem (APFS, NTFS) where the two are the same inode, but on a case-SENSITIVE filesystem (ext4, most Linux CI and production hosts) the run already wrote the correct content to a distinct file, so renaming the stale lower-case twin over it silently restored the old body: no missing file, no dangling link, just wrong content. #4508 never existed on case-sensitive hosts, so the PR turned a non-bug into a silent corruption there. Guard the rename with target.exists() and not target.samefile(old): a distinct inode is a stale twin and is unlinked; the same inode takes the rename. Adds a content-level regression test (the PR's existence/link tests pass on both filesystems even with the bug, so they could not catch this); it fails on a case-sensitive host without the guard. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.97, now on PyPI (pip install graphifyy==0.9.97). A community relabelled only by case keeps its article, with a case-sensitive-filesystem guard. Thanks for the fix, @dupeisen. |
What this fixes
to_wikiwrites each article throughwrite_text_atomic_if_changed, then sweeps the*.mdfiles the run did not produce. On a case-preserving, case-insensitive filesystem (APFS, NTFS) the write forGroups.mdreplaces the contents of the existinggroups.mdentry without renaming it. The sweep then compared names case-sensitively:So a community relabelled from
groupstoGroupsloses its article entirely, andindex.mdkeeps a link to aGroups.mdthat no longer exists.Repro (on v8 @ dac0634, Windows NTFS)
index.mdstill links toGroups.md, which does not exist.After the change
Implementation
Comparisons fold case, and a case-only difference is renamed through a temporary name:
The two-step rename is not defensive noise: on a case-insensitive filesystem
groups.mdandGroups.mdare the same file, soPath.renamewith the direct target is a no-op that leaves the old case on disk. Going through a distinct temporary name is what actually changes the directory entry._unique_slugin the same function already folds case when it dedups colliding labels, with a comment naming APFS/NTFS explicitly — so the sweep was the one remaining case-sensitive comparison, which is what the issue suggested.Verification
New
tests/test_wiki_case_only_relabel.py(4 tests):index.mdhas no dangling link;The first three fail on unmodified v8 (
3 failed, 1 passed). The fourth passes both ways — that is deliberate, it is the guard against over-correcting the sweep into "never delete anything".Note on the
test_wiki.pynumbers: those 20 failures are pre-existing on this Windows checkout and are allUnicodeDecodeErrorfrom test code callingread_text()without an encoding (seetest_index_links_every_article_writtenreadingindex.md). I confirmed the same20 failed, 15 passedon unmodified v8, so this change neither adds nor hides any of them. I did not touch them — that is a separate concern and not what this issue reports.Limitations
_unique_slug's dedup, which is unchanged..Groups.md.case-tmp; if a run is killed between the two renames the temp file survives and the next sweep deletes it, since it is not inproduced. Leaving it rather than guessing at recovery seemed right for a file the next run regenerates anyway.Fixes #4508
Disclosure: I used an AI coding assistant for this change, as the contributing guide asks. I reproduced the bug before and after on a clean checkout, and confirmed the new assertions fail without the fix.