Repository navigation
shape-doctor.py: cp is Copy-Item on Windows and its -Path reads [old] as a wildcard, so the drifted-file repair says Copy-Item -LiteralPath there (#105) - #107
Conversation
… `[old]` as a wildcard, so the drifted-file repair says `Copy-Item -LiteralPath` there (#105) Lane: openreposhape-2 (openRepoShape-2) Claim: #105 (comment) Closes #105. ## What was wrong Copilot's final review on PR #102, read after that merge. The `leg shape files` row offers a repair for a leg file that is simply absent, and it offered it as one string on every platform: ```python fix = (f"cp {quote_arg(source)} {quote_arg(ctx.root / rel / name)}") ``` **On Windows `cp` is not a program, it is an alias of `Copy-Item`** — the cmdlet reference says exactly that ("PowerShell includes the following aliases for `Copy-Item`: ... Windows: `cp`") — and **`Copy-Item -Path` does not take a path, it takes a pattern**: "Wildcard characters are permitted". So `[`, `]`, `*` and `?` in the value are that cmdlet's syntax, and a perfectly ordinary root at `C:\work[old]\Atlas` gives the reader one of two outcomes from a line this tool told them to run: * `Cannot find path` for a directory that is plainly there, or * where `[old]` is a character class with a sibling that matches it — a `C:\workd\Atlas` next door — **a copy out of the wrong directory, silently.** **`quote_arg` (#102) cannot reach this and is not wrong.** Quoting decides where an argument ENDS; the cmdlet decides how to read what arrived. A PowerShell verbatim `'...'` does not spare `[` from `-Path`. That is tokenization; this is parameter semantics, one layer past it. ## What landed One `copy_command(source, target, platform=None)` in `shape-doctor.py`, beside its only caller, in the shape `scaffold_command` already has: * `nt` → `Copy-Item -LiteralPath <source> -Destination <target>`. `-LiteralPath` is the parameter that means this path: "used exactly as it's typed. No characters are interpreted as wildcards." * POSIX → `cp <source> <target>`, unchanged and correct: there `cp` is `/bin/cp`, the glob belongs to the shell, and `quote_arg`'s single quotes already hand the brackets through intact. * Both values still go through `quote_arg`, because the two answer different questions — a destination with a space in it needs the quoting exactly as much as a bracket needs the literal parameter. **The destination needs no twin and has none.** `Copy-Item` has no `-LiteralDestination`, and wants none: `-Destination` is documented "Supports wildcards: False" — it names where the copy LANDS rather than searching for what to copy, so a `[` in it is already a character. Quoting is all it needs, and quoting is what it gets. **`platform` is passed ON, not merely branched on.** `quote_arg(value)` with no platform reads the REAL host's `os.name`, so a Windows line built on a POSIX runner would be quoted by `sh` rules — the function claiming a spelling it did not produce. That is the defect #103 names next door in `scaffold_command`; this function is written not to have it, which is also what lets the `nt` expectations below use genuine `PureWindowsPath` fixtures and hold on Linux, macOS and Windows alike. **`--json` is fixed by the same line**: the `next` field carries the row's command string, so it carries this one. ## Every other verb, checked rather than assumed `shape-doctor.py` emitted exactly ONE shell verb, this `cp`. Every other remediation is `python3 ...`, `git -C ... fetch --all` or `git -C ... checkout -- <path>` — the same programs with the same parsing on both platforms, no cmdlet aliases and no PowerShell parameter semantics. (`git checkout -- 'file[old].txt'` over a file literally so named was run here and restores that file; git pathspec wildcards would be a platform-independent question of git's own, not this one.) A new test makes that a rule rather than an observation. ## The proof **7 tests added (4 functions), 1 existing test changed, 950 → 957.** * `copy_command` asserted BYTE FOR BYTE on both platforms, over a bracket in the TARGET (`/srv/work[old]/Atlas/...`, `C:\work[old]\Atlas\...`) and a bracket in the SOURCE (`/srv/shape[2]/...`, `C:\shape[2]\...`) — the half a fix that only guarded the destination would miss. `PurePosixPath` and `PureWindowsPath`, never `Path`, so the rendering does not depend on which runner ran it (the lesson of #102's `tests-windows` job, run 34594408797). * `platform=None` is this host's, and the two spellings are proved to be two. * **End to end, with the failure standing next door**: a project at `<tmp>/work[old]/Atlas` with a sibling `<tmp>/workd/Atlas` — what the character class `[old]` matches — its `spec/CLAUDE.md` deleted, and the row's own line pasted into `bash -c` exactly as printed. Quoted, the file is restored from the template and the sibling is untouched. Unquoted, the same line resolves to the SIBLING, overwrites a file in a repository the reader never named and leaves the one they were fixing still missing — which is the Windows failure written where a runner can actually execute it, since on PowerShell that expansion is `Copy-Item`'s own and only `-LiteralPath` stops it. * A guard on the CLASS: `shape-doctor.py` may spell a bare `cp`, `mv`, `rm`, `ln`, `cat`, `touch`, `mkdir` or `chmod` in exactly one place, inside `copy_command` (found by `ast`, so the function's real line range). A future row that reaches for a shell verb fails in CI with that comment to read, rather than on somebody's Windows machine. * The existing `test_a_missing_rendered_leg_file_is_not_offered_a_cp` hard-coded `startswith("cp ")` and ran on all three runners: on Windows it would now be asserting the very defect this fixes. It reads the host's verb and parses either spelling (`shlex` on POSIX; `Copy-Item -LiteralPath ... -Destination ...` on Windows, apostrophes un-doubled). ## Housekeeping * `python3 scripts/render-cli-reference.py --check` — `[ok] docs/cli.md is what the generator produces`; no `--help` text moved. * `git diff --stat origin/main -- templates/` — empty. No README/AGENTS.md change and therefore no cap moved. * Locally 955 pass, 1 skipped, and one PRE-EXISTING environmental failure unrelated to this change: `test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` expects the offline `declared-unverified` warning, and this workstation has a real `openXdox` checkout sitting beside the repository — precisely what the validator's "a checkout beside the project" rule verifies the link against. The same command prints the same unwarned line from the untouched main checkout at `origin/main` (32450eb), and CI has no such sibling. ## Neighbouring, not taken * `scaffold_command`'s inner `quote_arg` calls (#103) and the `naming` row (#104) are being fixed in their own lanes; nothing here touches either, and the new tests sit NEXT TO the drifted-file tests rather than at the end of the file, so the three rebase clean. * `update-shape.py check` prints its own `NEXT ...` lines with the same interpolation and is still outside this file's quoter, as #102 already noted. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@codex review |
There was a problem hiding this comment.
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 3 days and 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Reviewer's GuideThe PR fixes missing-leg-file repair commands that incorrectly emitted Sequence diagram for platform-aware missing-file repairsequenceDiagram
participant Doctor as shape-doctor.py
participant Reader as Reader shell
participant Filesystem
Doctor->>Doctor: check_leg_shape_files(ctx)
Doctor->>Doctor: copy_command(source, target, platform)
alt Windows
Doctor-->>Reader: Copy-Item -LiteralPath source -Destination target
Reader->>Filesystem: Copy literal source to target
else POSIX
Doctor-->>Reader: cp source target
Reader->>Filesystem: Copy quoted source to target
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
… failure names which half broke (Sonar S9073) Lane: openreposhape-2 (openRepoShape-2) SonarCloud's two new issues on PR #107, both `python:S9073` ("Split this composite assertion into separate assertions"), both in the tests this PR adds. The gate passed either way; the finding is right anyway, and in a suite whose assertion messages are written to be read it is more than style: `words[1] == "-LiteralPath" and words[3] == "-Destination"` failing told a reader only that the line was not the expected shape, not which parameter was missing, and `str(source) in line and str(target) in line` could not say which of the two paths had been eaten by a quoter. * `copied_paths`: the `-LiteralPath` and `-Destination` checks are now two assertions. * `test_the_copy_line_is_literal_where_cp_is_a_cmdlet`: the source and the target are asserted separately. No production code and no expectation changed; the same 957 tests collect and the same 9 in this area pass. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
SonarCloud's two |
There was a problem hiding this comment.
🟡 Changes recommended
The Windows test parser splits quoted paths containing spaces, causing valid command assertions to fail.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates missing leg-file repair commands to handle literal paths safely across POSIX and Windows.
Changes:
- Uses
Copy-Item -LiteralPathon Windows andcpon POSIX. - Adds cross-platform and bracketed-path coverage.
- Updates repair-command assertions.
File summaries
| File | Summary |
|---|---|
tests/test_shape_doctor.py |
Adds command-rendering and end-to-end path tests. |
shape-doctor.py |
Adds platform-aware copy command generation. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
The Windows test parser is not quote-aware for valid paths containing # and spaces.
Review details
Suppressed comments (1)
tests/test_shape_doctor.py:831
- This Windows-only parser is not quote-aware:
line.split("#")truncates a valid quoted path containing#, andcommand.split()below breaks the quoted arguments thatcopy_commandemits for paths containing spaces. Thus this test can fail on a valid Windows temp/root path even though the generated repair command is correct. Tokenize PowerShell single-quoted arguments (including doubled apostrophes) and ignore only the trailing unquoted comment.
command = line.split("#")[0]
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
…rShell's quoting, so a checkout at `C:\Users\Jane Doe\...` is one token and not two (Copilot, PR #107) Lane: openreposhape-2 (openRepoShape-2) Copilot's review of 89dfd78, and it is right. `copied_paths` is the suite's own reader of the row's copy line and it was `line.split("#")[0].split()`: * a path with a SPACE in it -- exactly the value `quote_arg` exists for, and exactly the `C:\Users\Jane Doe\...` this repository's own examples are written with -- is quoted by `copy_command`, and `str.split()` then tore that one token in half and failed an assertion about a command that was perfectly correct; * a path with a `#` in it was truncated by the pre-split before any assertion was made at all. Nothing shipped is affected -- `copy_command` and the row are unchanged -- but a test that fails on a valid Windows path is a test that would have blocked the next person for no reason. ## What landed * `powershell_tokens(line)`: verbatim `'...'` with doubled apostrophes, bare words, and `#` as a comment only where a TOKEN starts, which is PowerShell's own rule and is what lets a `#` inside a quoted path survive while the row's trailing `# and the rest are RENDERED...` note is dropped. * `copied_paths(line, platform=None)`: `shlex.split(line, comments=True)` on POSIX -- the reader's own parser there, dropping the trailing note the way the shell would rather than by cutting the string at the first `#` -- and the tokenizer above on Windows. `platform` for the same reason `copy_command` has one: either branch is now asserted from either host. * One round-trip test over both platforms' spelling of a path that breaks a naive parser three ways at once -- a space, an apostrophe and a `#`, with the row's real trailing comment appended: what `copy_command` wrote, `copied_paths` reads back identically, and the line is asserted to be quoted at all so the round trip cannot pass over two bare words. 958 tests collect, 110 in `tests/test_shape_doctor.py` pass. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|



Lane: openreposhape-2 (openRepoShape-2)
Claim: #105 (comment)
Closes #105.
What was wrong
Copilot's final review on PR #102, read after that merge. The
leg shape filesrow offers a repair for a leg file that is simply absent, and itoffered it as one string on every platform:
On Windows
cpis not a program, it is an alias ofCopy-Item— thecmdlet reference says exactly that ("PowerShell includes the following
aliases for
Copy-Item: ... Windows:cp") — andCopy-Item -Pathdoesnot take a path, it takes a pattern: "Wildcard characters are permitted".
So
[,],*and?in the value are that cmdlet's syntax, and aperfectly ordinary root at
C:\work[old]\Atlasgives the reader one of twooutcomes from a line this tool told them to run:
Cannot find pathfor a directory that is plainly there, or[old]is a character class with a sibling that matches it — aC:\workd\Atlasnext door — a copy out of the wrong directory, silently.quote_arg(#102) cannot reach this and is not wrong. Quoting decideswhere an argument ENDS; the cmdlet decides how to read what arrived. A
PowerShell verbatim
'...'does not spare[from-Path. That istokenization; this is parameter semantics, one layer past it.
What landed
One
copy_command(source, target, platform=None)inshape-doctor.py,beside its only caller, in the shape
scaffold_commandalready has:nt→Copy-Item -LiteralPath <source> -Destination <target>.-LiteralPathis the parameter that means this path: "used exactly asit's typed. No characters are interpreted as wildcards."
cp <source> <target>, unchanged and correct: therecpis/bin/cp, the glob belongs to the shell, andquote_arg's single quotesalready hand the brackets through intact.
quote_arg, because the two answer differentquestions — a destination with a space in it needs the quoting exactly as
much as a bracket needs the literal parameter.
The destination needs no twin and has none.
Copy-Itemhas no-LiteralDestination, and wants none:-Destinationis documented"Supports wildcards: False" — it names where the copy LANDS rather than
searching for what to copy, so a
[in it is already a character. Quotingis all it needs, and quoting is what it gets.
platformis passed ON, not merely branched on.quote_arg(value)withno platform reads the REAL host's
os.name, so a Windows line built on aPOSIX runner would be quoted by
shrules — the function claiming aspelling it did not produce. That is the defect #103 names next door in
scaffold_command; this function is written not to have it, which is alsowhat lets the
ntexpectations below use genuinePureWindowsPathfixtures and hold on Linux, macOS and Windows alike.
--jsonis fixed by the same line: thenextfield carries the row'scommand string, so it carries this one.
Every other verb, checked rather than assumed
shape-doctor.pyemitted exactly ONE shell verb, thiscp. Every otherremediation is
python3 ...,git -C ... fetch --allorgit -C ... checkout -- <path>— the same programs with the same parsing onboth platforms, no cmdlet aliases and no PowerShell parameter semantics.
(
git checkout -- 'file[old].txt'over a file literally so named was runhere and restores that file; git pathspec wildcards would be a
platform-independent question of git's own, not this one.) A new test makes
that a rule rather than an observation.
The proof
9 tests added (5 functions), 1 existing test changed, 950 → 959 (the fifth function and its two cases came in from Copilot's review; see the bottom of this body).
copy_commandasserted BYTE FOR BYTE on both platforms, over a bracket inthe TARGET (
/srv/work[old]/Atlas/...,C:\work[old]\Atlas\...) and abracket in the SOURCE (
/srv/shape[2]/...,C:\shape[2]\...) — the half afix that only guarded the destination would miss.
PurePosixPathandPureWindowsPath, neverPath, so the rendering does not depend on whichrunner ran it (the lesson of shape-doctor.py: one platform-aware quoter, on every next command, so a root or a name with a space in it is a line that runs (#101) #102's
tests-windowsjob, run 34594408797).platform=Noneis this host's, and the two spellings are proved to be two.<tmp>/work[old]/Atlaswith a sibling<tmp>/workd/Atlas— what thecharacter class
[old]matches — itsspec/CLAUDE.mddeleted, and therow's own line pasted into
bash -cexactly as printed. Quoted, the fileis restored from the template and the sibling is untouched. Unquoted, the
same line resolves to the SIBLING, overwrites a file in a repository the
reader never named and leaves the one they were fixing still missing —
which is the Windows failure written where a runner can actually execute
it, since on PowerShell that expansion is
Copy-Item's own and only-LiteralPathstops it.shape-doctor.pymay spell a barecp,mv,rm,ln,cat,touch,mkdirorchmodin exactly one place, insidecopy_command(found byast, so the function's real line range). Afuture row that reaches for a shell verb fails in CI with that comment to
read, rather than on somebody's Windows machine.
test_a_missing_rendered_leg_file_is_not_offered_a_cphard-coded
startswith("cp ")and ran on all three runners: on Windows itwould now be asserting the very defect this fixes. It reads the host's verb
and parses either spelling (
shlexon POSIX;Copy-Item -LiteralPath ... -Destination ...on Windows, apostrophes un-doubled).Housekeeping
python3 scripts/render-cli-reference.py --check—[ok] docs/cli.md is what the generator produces; no--helptext moved.git diff --stat origin/main -- templates/— empty. No README/AGENTS.mdchange and therefore no cap moved.
unrelated to this change:
test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifiesexpects the offline
declared-unverifiedwarning, and this workstation hasa real
openXdoxcheckout sitting beside the repository — precisely whatthe validator's "a checkout beside the project" rule verifies the link
against. The same command prints the same unwarned line from the untouched
main checkout at
origin/main(32450eb), and CI has no such sibling.Review, taken
python:S9073(composite assertion) findings, both inthe new tests — taken in 186a514: each is two assertions now, so a failure
names which half broke. The gate had passed either way.
copied_paths— taken in 24cc7d9, and the suppressed halfof the same finding with it. That helper is the SUITE's reader of the
row's line, and
line.split("#")[0].split()tore the one token'C:\Users\Jane Doe\...'in half at the space and truncated a path witha
#in it, failing assertions about commands that were correct. It nowuses
shlex.split(line, comments=True)on POSIX and apowershell_tokensthat knows verbatim
'...', doubled apostrophes and#-only-at-a-token-start on Windows, with a
platformargument so either branch is assertedfrom either host — plus a round-trip test over a path with a space, an
apostrophe and a
#in it, with the row's real trailing comment appended.Nothing shipped changed.
usage limits respectively); Sourcery's guide is on the PR, neither carries
a finding.
Neighbouring, not taken
scaffold_command's innerquote_argcalls (shape-doctor.py:scaffold_command(…, platform)quotes for the HOST while it spells the interpreter and entry point for the REQUESTED platform — threadplatformthrough itsquote_argcalls #103) and thenamingrow(shape-doctor.py: the naming row hands repository names to argparse as bare positionals — a directory named
--helpis read as an option in both the validator call and the emitted--explainline; put--before the names #104) are being fixed in their own lanes; nothing here touches either, andthe new tests sit NEXT TO the drifted-file tests rather than at the end of
the file, so the three rebase clean.
update-shape.py checkprints its ownNEXT ...lines with the sameinterpolation and is still outside this file's quoter, as shape-doctor.py: one platform-aware quoter, on every next command, so a root or a name with a space in it is a line that runs (#101) #102 already
noted.
🤖 Generated with Claude Code
Summary by Sourcery
Make drifted-file repair commands safe and platform-appropriate across POSIX shells and PowerShell.
Bug Fixes:
Copy-Item -LiteralPathso bracketed and other wildcard-like paths are copied literally instead of being misinterpreted by PowerShell.Enhancements:
cprepair commands while selecting shell-specific quoting and command syntax through a shared copy-command helper.Tests: