Skip to content

fix(tests,paths): skip the POSIX-mode assertion on Windows, and stop leaking a temp file on failed atomic writes - #2623

Closed
rajarshidattapy wants to merge 1 commit into
Graphify-Labs:v8from
rajarshidattapy:fix/atomic-write-mode-test-windows
Closed

rajarshidattapy wants to merge 1 commit into
Graphify-Labs:v8from
rajarshidattapy:fix/atomic-write-mode-test-windows

Conversation

@rajarshidattapy

Copy link
Copy Markdown
Contributor

Fixes #2622.

Problem

test_write_text_atomic_preserves_existing_mode sets 0o644 and asserts the atomic write
preserves it. Windows does not implement POSIX permission bits, so the assertion can never
hold:

E       AssertionError: assert (33206 & 511) == 420

33206 is 0o100666. Confirmed on this platform — chmod only toggles the read-only
attribute, and any writable file reports 0o666:

chmod(0o644) -> st_mode & 0o777 = 0o666
chmod(0o600) -> st_mode & 0o777 = 0o666

So the os.chmod(p, 0o644) on line 4 is a no-op and the test fails on a completely healthy
write_text_atomic.

Fix

Skip it on Windows. The property under test — "an atomic replace must not tighten a 0644 file
to mkstemp's 0600 default" — is POSIX-only and has no Windows equivalent.

The issue's open question, answered

The issue asked whether the suggested Windows analogue (read-only attribute survives a
replace) is actually desired behaviour, flagging it as "possibly its own papercut". I
checked, and it is worse than a papercut:

before: writable=False mode=0o444
write_text_atomic: RAISED PermissionError: [Errno 13] Permission denied: ...\ro.json
  content preserved = 'original'

files in dir: ['.ro.json.uqew9or4.tmp', 'ro.json']     <-- leaked temp

Two findings:

  1. A read-only destination is refused, not silently overwritten. The existing
    PermissionError → shutil.copy2 fallback does not help, because copying onto a
    read-only file fails the same way. This diverges from POSIX, where os.replace needs only
    directory write permission and so happily replaces a read-only file. Left as-is and
    documented: refusing to overwrite a file the user marked read-only is the defensible
    behaviour, and changing it is out of scope for a test fix.

  2. The failed write leaks a temp file — a real bug, fixed here. _atomic_replace chmods
    the temp to match the destination, so against a read-only target the temp is read-only
    too. Windows then refuses to unlink it, and the cleanup's except OSError: pass swallowed
    the failure — dropping a .graph.json.*.tmp into graphify-out/ on every failed
    write, accumulating silently. The cleanup now clears the read-only bit and retries.

Changes

  • tests/test_atomic_writes.py — skipif(os.name == "nt") on the POSIX-mode test, with the
    reason spelling out why it can never hold rather than just "Windows".
  • tests/test_atomic_writes.py — new test_write_text_atomic_refuses_a_readonly_destination_without_leaking_a_temp,
    the Windows analogue: pins that the original survives, the write raises rather than
    clobbering, and no temp is left behind.
  • graphify/paths.py — the temp-file leak fix (9 lines).

Verification

  • The POSIX-mode test now skips on Windows instead of failing; its body is unchanged, so
    POSIX coverage is untouched.
  • The new Windows test fails without the paths.py fix, with the leak visible:
    E   AssertionError: failed write leaked a temp file:
        ['.graph.json.57kqk4yl.tmp', 'graph.json']
    
    and passes with it — so it is guarding the fix, not just describing it.
graphify/paths.py           | 10 +++++++++-
tests/test_atomic_writes.py | 44 ++++++++++++++++++++++++++++++++++++++++++++

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

This PR reverts the unreleased 0.9.39 changelog section back to 0.9.38 status and removes several features that were associated with it. Specifically, it deletes the fuzzy-dedup _content_token_swap/_same_word_variant logic (the #2576 content-word distinction) from dedup.py and their call sites in deduplicate_entities and _llm_tiebreak, and simplifies the JS dynamic-import rescue in extract.py so it keys/skips on the resolved target rather than checking whether the deferred edge originates from the file's node (#2584). The change touches dedup, JS/dynamic-import extraction, and related engine/resolution helpers, along with corresponding updates across the watch, dedup, extract, atomic-writes, and JS-dynamic-imports test suites and changelog entries. Reviewers should focus on the dedup and dynamic-import behavior being rolled back and whether the test suite changes match that reduced surface area.

Worth a look

  • Dynamic-import dedupe reverts to target-only keying, dropping file-level edge for in-function imports — graphify/extract.py:1271 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Reintroduced dedupe by target alone drops file-level dynamic_import edges for in-function imports — graphify/extract.py:1271 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2774 functions depend on the 1525 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • extract() — 400 callers, 39 callees (high)
  • _rebuild_code() — 93 callers, 51 callees (high)
  • deduplicate_entities() — 53 callers, 19 callees (high)
  • build_merge() — 41 callers, 14 callees (high)
  • _extract_generic() — 18 callers, 22 callees (high)
  • extract_xaml() — 19 callers, 17 callees (high)
  • save_manifest() — 29 callers, 11 callees (high)
  • to_json() — 42 callers, 6 callees (high)
  • …and 2 more

Verification — 2774 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: 2581 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify \_llm\_tiebreak.

The verifier did not have enough to check \_llm\_tiebreak, 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: not verifiable: all 105 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)

Could not verify: Could not verify deduplicate\_entities.

The verifier did not have enough to check deduplicate\_entities, 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: not verifiable: all 7 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)

Could not verify: Could not verify \_rescue\_js\_dynamic\_imports.

The verifier did not have enough to check \_rescue\_js\_dynamic\_imports, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_resolve\_objc\_member\_calls.

The verifier did not have enough to check \_resolve\_objc\_member\_calls, 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: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify extract\_objc.

The verifier did not have enough to check extract\_objc, 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: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_merge\_decl\_def\_classes.

The verifier did not have enough to check \_merge\_decl\_def\_classes, 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: not verifiable: the input domain has 49 values but only 7 distinct were tested — a small finite domain must be EXHAUSTED, not sampled (an untested input could invert the result)

Could not verify: Could not verify \_atomic\_replace.

The verifier did not have enough to check \_atomic\_replace, 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: parameter `path` is annotated `'str | Path'` — outside the synthesizable primitive/collection set

Could not verify: Could not verify watch.

The verifier did not have enough to check watch, 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: parameter `watch_path` is annotated `Path` — outside the synthesizable primitive/collection set

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.42 (graphifyy==0.9.42 on PyPI) (#2622). Read-only atomic-write temp cleanup on Windows. Credited in the release notes. Thanks @rajarshidattapy!

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.

test_write_text_atomic_preserves_existing_mode asserts POSIX mode bits that Windows cannot represent

2 participants