Skip to content

Migrate crates/pycc_codegen test wrapper onto ScratchDir (Batch A of #782) - #792

Merged
rotnov merged 2 commits into
feat/issue-781-scratch-dirfrom
feat/issue-782-batch-a-codegen-scratch
Aug 26, 2026
Merged

Migrate crates/pycc_codegen test wrapper onto ScratchDir (Batch A of #782)#792
rotnov merged 2 commits into
feat/issue-781-scratch-dirfrom
feat/issue-782-batch-a-codegen-scratch

Conversation

@rotnov

@rotnov rotnov commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

Batch A of the sequential migration plan published on #782: retires crates/pycc_codegen/src/tests_support.rs's tempfile_dir/TempTestDir wrapper entirely, replacing every call site with pycc_scratch::ScratchDir.

  • Adds pycc_scratch as a [dev-dependencies] entry to root Cargo.toml and to crates/pycc_codegen/Cargo.toml (the latter had no [dev-dependencies] section before).
  • Migrates all 273 tempfile_dir("label") call sites in crates/pycc_codegen/src/tests.rs (269 literal-argument calls plus 5 &format!(...)-argument calls migrated one at a time in the str_truthy/float_truthy/str_cmp_runtime/nested_finally/try_pep758_multi tests — one more site than initially matched by the bulk-substitution regex, brought the total to 273 as the plan estimated) to pycc_scratch::ScratchDir::new("label").expect("failed to create scratch dir").
  • Migrates the file's one raw std::env::temp_dir().join(...) occurrence (write_to_file_failure_is_reported_as_an_error) to derive its path from a new ScratchDir binding instead — the test deliberately builds a nonexistent nested path to exercise a real failure mode, so no create_dir/create_dir_all was added; only the root of the path changed.
  • Migrates crates/pycc_codegen/src/bigint_rc.rs's 2 call sites and drops its use crate::tests::tempfile_dir; import.
  • Deletes crates/pycc_codegen/src/tests_support.rs and the #[path = "tests_support.rs"] mod support; pub(crate) use support::tempfile_dir; wiring in tests.rs.
  • Shrinks scripts/check_scratch_dir_usage.py's ALLOWLIST: removes the now-zero crates/pycc_codegen/src/tests.rs entry and the entry for the now-deleted tests_support.rs. No other files' entries were touched — bigint_rc.rs was never in ALLOWLIST (0 raw occurrences to begin with, only wrapper calls, confirmed before editing).

Every ScratchDir::new(...) call in this diff uses .expect(...) only, never ? or match/if let Err, per the plan's D-014 coverage-gate guidance (§6.1) — this is a near-pure constructor swap with no new fallible branch requiring a dedicated failure-path test.

Part of #782 (Batch A). The remaining batches — src/main.rs's test module + src/project_config.rs (Batch B), and the remaining tests/*.rs integration files (Batches C/D) — are separate follow-up pull requests; #782 stays open until all batches land.

Baseline note

Branched from feat/issue-781-scratch-dir (PR #786's head), re-confirmed still open and unmerged both before starting and immediately before opening this PR, per the plan's own re-resolution instruction (§1).

Overlap note

Cross-referenced open PRs against crates/pycc_codegen/src/tests.rs and bigint_rc.rs before starting: PR #780 (feat/issue-769-optional-narrowing) appends new tests to the end of tests.rs using tempfile_dir(...) calls of its own. This is a same-file textual collision (not a logical one — different, non-overlapping regions of the file) consistent with the plan's own risk table (§7); whichever of this PR / #780 merges second will need to migrate #780's newly-added call sites onto ScratchDir as part of its own rebase, or as quick follow-up. No other open PR touches either target file.

Test plan

  • cargo build --workspace --tests after the setup step (Cargo dev-dependency additions) alone, before any call-site edits
  • cargo build --workspace --tests after the full batch
  • cargo test --workspace — 0 failures across the full suite
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • python3 -B scripts/check_scratch_dir_usage.py — no violations
  • python3 -B -m unittest discover -s scripts -p 'test_*.py' — 951 tests, OK (6 skipped)
  • cargo llvm-cov --workspace --fail-under-lines 100 --fail-under-regions 100 — 100.00% lines, 100.00% regions
  • D-068 pinned local reviewer (ievo:deep-reviewer) — 0 findings, independently re-verified the 273/273 ScratchDir::new/.expect pairing, the ALLOWLIST counts against the live tree, and the write_to_file_failure_is_reported_as_an_error nonexistent-path invariant

rotnov and others added 2 commits August 25, 2026 15:54
…782)

Retire the crate-local tempfile_dir()/TempTestDir wrapper in favor of
pycc_scratch::ScratchDir across crates/pycc_codegen/src/tests.rs (273
call sites) and bigint_rc.rs (2 call sites), including the file's one
raw std::env::temp_dir().join(...) occurrence. Deletes
tests_support.rs and its #[path]/pub(crate) re-export wiring, adds
pycc_scratch as a dev-dependency to root Cargo.toml and
crates/pycc_codegen/Cargo.toml, and shrinks
check_scratch_dir_usage.py's ALLOWLIST to match.

Part of #782 (Batch A per the published implementation plan); the
remaining batches (src/main.rs + project_config.rs, and the
tests/*.rs integration files) are separate follow-up PRs, so #782
stays open.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
crates/pycc_codegen/Cargo.toml already declares pycc_scratch as its
own dev-dependency (path = "../pycc_scratch"), which is sufficient
for the crate's tests. The duplicate entry in root Cargo.toml's
[dev-dependencies] was unused, and it tripped the D-091 bench-manifest
fingerprint check in frontend-perf-measure: that check hard-aborts on
any change to root Cargo.toml's [dev-dependencies]-onward tail by
design, since anything there could affect the pinned benchmark's
measurement rather than the compiled artifact it measures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rotnov
rotnov merged commit d9d3582 into feat/issue-781-scratch-dir Aug 26, 2026
16 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.

1 participant