Skip to content

Drive bootstrap.ps1's Kept-Tree Functions from the Test Suite, and Move a Tree Whole - #2496

Merged
ptr727 merged 3 commits into
developfrom
test/1791-ps-kept-tree-tests
Oct 7, 2026
Merged

ptr727 merged 3 commits into
developfrom
test/1791-ps-kept-tree-tests

Conversation

@ptr727

@ptr727 ptr727 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

bootstrap.ps1's kept-tree handling had no automated test. Its ownership check, marker-last removal, swap and rollback, and cleanup's restore had only been checked by scratch probes on Linux. This change drives them from tests/test_bootstrap.py through the loader's own functions, extracted by AST, as tests/test_install_tools.py already does for install-tools.ps1.

Running those functions natively on Windows exposed #2492, which this change also fixes:

  • Move-Tree: every tree move now goes through one helper that renames with [IO.Directory]::Move, so a move happens whole or not at all. When a held file stops the directory rename, PowerShell 7's Move-Item instead moves the tree entry by entry. That moves the ownership marker and every free entry out of the live skills-tree and leaves only the held file behind. The loader's swap ordering assumes a rename either completes or does nothing, and Move-Item breaks that.
  • Resolve-Directory: it now requires a fully qualified -Dir. [IO.Directory]::Move resolves a path against the process directory rather than PowerShell's location, so a rooted but drive-relative -Dir such as C:hs would be read in two places. Every form the old check accepted, UNC and \?\ included, is still accepted.
  • TestPowerShellKeptTreeHandling: 19 cases, each against a scratch directory. An entry a case locks is held by a real FileShare.None handle on Windows and a read-only directory elsewhere. The download and the tar are stubbed for the fetch cases. Four cases depend on Windows behavior and skip elsewhere: a held file blocking a rename, a lone held file beside the marker, and a path that is rooted but not fully qualified.
  • TestKeptTreeHandling: two new cases cover swap_in's rollback succeeding and failing, the two bash paths Drive the PowerShell Loader's Kept-Tree Functions from the Test Suite #1791 names as uncovered.

Closes #1791 and #2492 once promoted.

Verification

  • Windows 11, pwsh 7.6: python3 -m unittest tests.test_bootstrap runs 58 tests, OK, 21 skipped (the Linux-only bash cases).
  • WSL Ubuntu: TestKeptTreeHandling, the two new cases included, runs 12 tests, OK.
  • The first review pass ran the PowerShell class's Linux path in an Ubuntu container under pwsh 7.6: 15 tests passed and the Windows-only ones skipped. Linux CI runs the same path.
  • Mutation checks on Windows show each test catches the defect it names. Against the pre-change loader, and against Move-Item restored, the two held-file swap and cleanup cases fail on a split tree. Removing the marker-last removal, the exception unwrap, or the fully-qualified check each fails its own case.
  • ruff, mypy and PSScriptAnalyzer are clean.
  • The comments label is on this PR for the Move-Tree header comment. CI is Linux-only, so that comment is what keeps a later edit from going back to Move-Item.
  • local-strict-review ran three rounds:
    • Round 1 raised four findings: the drive-relative -Dir, a marker test that passed vacuously, a cleanup test missing its assertion, and the untested unwrap. All four are fixed in 9d10170.
    • Round 2 raised one: the -Dir test was vacuous on Linux. It is fixed in 47ba386.
    • Round 3 found nothing.
  • Pre-existing -Dir validation gaps outside this diff are filed as Canonicalize -Dir in bootstrap.ps1 Before Refusing a Drive or Share Root #2495.

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 7, 2026 11:39
…ve a Tree Whole

Extract the PowerShell loader's tree functions by AST and run them against a scratch directory,
holding an entry with a real open handle on Windows, so the ownership check, marker-last removal,
the swap and its rollback, cleanup's restore, and a kept-tree fetch are each exercised. The bash
loader's two uncovered rollback paths get tests too.

Driving the swap natively showed Move-Item does not fail whole where a file in the tree is held:
it falls back to moving entry by entry, so the marker and every free entry left the live tree.
Every tree move now goes through Move-Tree, a [IO.Directory]::Move rename that happens whole or
not at all.

Closes #1791
Closes #2492

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… They Name

Move-Tree renames through [IO.Directory]::Move, which resolves a path against the process directory
rather than PowerShell's location, so a rooted but drive-relative -Dir such as C:hs would land the
staging tree in one place and look for it in another. Resolve-Directory now requires a fully
qualified path.

The marker-last removal test now holds a file sorting after the marker, so a plain recursive
removal fails it, the staging-removal cleanup test asserts the removal actually failed, and new
tests cover the exception unwrap and the -Dir refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Unix has no path that is rooted but not fully qualified, so IsPathRooted already refuses both
inputs there and the test could not tell the fix from the code it replaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 7, 2026
Copilot AI lite review requested due to automatic review settings October 7, 2026 19:08
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41538355-5c81-46fb-b025-36d25d85dfd1
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review issues remain.

0 open findings

What changed in this PR

Adds automated kept-tree coverage and makes bootstrap.ps1 tree moves atomic on Windows.

Changes:

  • Adds PowerShell and Bash rollback tests.
  • Replaces partial moves with whole-tree directory renames.
  • Requires fully qualified -Dir paths.
File Description
tests/​test_bootstrap.py Adds PowerShell and rollback test coverage.
host-setup/​bootstrap.ps1 Implements atomic moves and stricter path validation.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.50%. Comparing base (173eece) to head (47ba386).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2496   +/-   ##
========================================
  Coverage    58.50%   58.50%           
========================================
  Files           16       16           
  Lines         8066     8066           
========================================
  Hits          4719     4719           
  Misses        3347     3347           
Flag Coverage Δ
python-3.13 58.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727
ptr727 merged commit 3582087 into develop Oct 7, 2026
13 checks passed
@ptr727
ptr727 deleted the test/1791-ps-kept-tree-tests branch October 7, 2026 19:12
ptr727 added a commit that referenced this pull request Oct 7, 2026
…2497)

## Summary

Promotes one change to `main`, from the Windows-host lane, verified on a
native Windows 11 host.

- [#2496](#2496):
`tests/test_bootstrap.py` now drives `bootstrap.ps1`'s kept-tree
functions, extracted by AST, holding an entry with a real open handle on
Windows. Running them natively exposed a defect, and the loader is
fixed:
- **Tree moves:** they now go through `[IO.Directory]::Move`, so a move
happens whole or not at all. PowerShell 7's `Move-Item` moved a tree
holding an open file entry by entry, which emptied the live
`skills-tree` and moved its ownership marker away.
- **`-Dir`:** it must now be fully qualified, since that rename resolves
a drive-relative path against the process directory.
- **Bash rollback:** two tests cover the two `swap_in` rollback paths
that had none.

Closes #1791
Closes #2492

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants