fix(terminal): cp/mv into a directory, and Windows paths PowerShell accepts (THI-353) - #392
Conversation
…ccepts (THI-353) cp / mv (GNU coreutils semantics) - A destination that is an existing directory receives the source inside it. `mv documents/notes.txt .` used to replace the home directory with the file; `cp file dir` / `Move-Item file dir` overwrote the directory. - Several sources need a directory; no directory into itself; same-file check; -v, -n, -i (answers "n" in the simulator, and says so), -f; invalid options rejected like GNU; moving the directory you stand in takes you along; `cp -rn` keeps existing files at any depth. Windows - PowerShell paths: `\` separators, `.\`, `C:\Users\user\...` (= /home/user); `C:\` shows `Users`, `cd ..` from the home reaches `C:\Users`. Bash is unchanged (a backslash is not a separator there). - Remove-Item / Copy-Item -Recurse; -Path / -Destination in any order; mkdir creates missing parents like New-Item -ItemType Directory. - Exercises accept `\` on Windows (exerciseAccepts); Tab completes after `\`. Lessons - mv, rm and cat examples run as shown, with PowerShell variants and Windows versions of the rm warning and tip. Theory gaps 174 -> 162, lessons showing bash to Windows learners 39 -> 37. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Sorry @thierryvm, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 2 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Guide du reviewerCette PR centralise la sémantique des transferts Diagramme de séquence pour le transfert de fichiers multiplateformesequenceDiagram
participant User
participant TerminalEmulator
participant CommandEngine
participant Transfer
participant FileSystem
User->>TerminalEmulator: Enter cp or mv command
TerminalEmulator->>CommandEngine: processCommand(command, environment)
CommandEngine->>Transfer: cmdCp or cmdMv(args)
Transfer->>FileSystem: resolvePath(source, destination)
Transfer->>Transfer: transfer(cmd, state, args)
alt destination is an existing directory
Transfer->>FileSystem: Copy source inside destination or move source inside destination
else invalid or unsafe transfer
Transfer-->>CommandEngine: Return GNU-style error
end
CommandEngine-->>TerminalEmulator: Updated root, cwd, and output
Modifications fichier par fichier
Conseils et commandesInteragir avec Sourcery
Personnaliser votre expérienceAccédez à votre tableau de bord pour :
Obtenir de l’aide
Original review guide in EnglishReviewer's GuideThis PR centralizes Sequence diagram for cross-platform file transfersequenceDiagram
participant User
participant TerminalEmulator
participant CommandEngine
participant Transfer
participant FileSystem
User->>TerminalEmulator: Enter cp or mv command
TerminalEmulator->>CommandEngine: processCommand(command, environment)
CommandEngine->>Transfer: cmdCp or cmdMv(args)
Transfer->>FileSystem: resolvePath(source, destination)
Transfer->>Transfer: transfer(cmd, state, args)
alt destination is an existing directory
Transfer->>FileSystem: Copy source inside destination or move source inside destination
else invalid or unsafe transfer
Transfer-->>CommandEngine: Return GNU-style error
end
CommandEngine-->>TerminalEmulator: Updated root, cwd, and output
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Why
Found while replaying lesson theory (#391):
mv documents/notes.txt .— shown in themvlesson — replaced the learner's home directory with the file.cp file dirandMove-Item file diroverwrote the target directory. On the way: the Windows environment understood no Windows path (documents\notes.txt,C:\Users\user\…), andRemove-Item -Recurseignored-Recurse. THI-353.What
cp / mv — GNU coreutils semantics (
transfer()in terminalEngine.ts)mvonto a non-empty directory,mv .-v,-n,-i(simulator answers "n" and says so),-f, long options; unknown options rejected with GNU's messagecp -r dir existing/→existing/dir, merging;-nrespected at any depthWindows / PowerShell
\,.\,C:\…;C:\Users= simulated/home(ls C:\showsUsers,cd usersfromC:\works); bash unchangedRemove-Item -Recurse,Copy-Item -Recurse(any accepted prefix of-Recurse);-Path/-Destinationin any ordermkdir a\bcreates missing parents (New-Item -ItemType Directory)\(exerciseAcceptsin validators.ts, used by LessonPage); Tab completes after\Lessons — mv / rm / cat examples run as shown, PowerShell variants, Windows rm warning & tip. Ratchets: theory gaps 174 → 162, bash shown on Windows 39 → 37 (only removals in lessonTheoryGaps.ts).
Tests
cp / mv — destination directory (GNU semantics)(18) andWindows paths in PowerShell(8) in terminalEngine.test.ts — expected values from real coreutils / PowerShell behaviour; the core cases were reproduced failing on the old engine (lsempty aftermv … .).\→ no error + validates (10 cases; git commands excluded: branch names are not paths).Gates
cp -rndepth,-Path/-Destinationorder), pass 2 → 1 finding (C:\root showedhome) — all fixed with testsrmlesson commands,Move-Item documents\notes.txt ., Linuxmvlesson,Get-Content documents\notes.txtvia Tab validates thecatexercise (fresh isolated context)🤖 Generated with Claude Code
Résumé par Sourcery
Rendre les transferts de fichiers sûrs et fidèles à GNU coreutils et PowerShell, tout en ajoutant une prise en charge complète des chemins Windows dans le terminal et les leçons.
Nouvelles fonctionnalités :
cpetmvlors du transfert de fichiers et de répertoires vers des destinations existantes, y compris les options et vérifications de sécurité pertinentes.Corrections de bugs :
cp,mvet les commandes PowerShell de gestion des éléments de remplacer des répertoires existants par des fichiers ou de détruire le contenu des répertoires de toute autre manière.Améliorations :
Documentation :
Tests :
cp/mvde style GNU, les options de transfert, le comportement des répertoires récursifs, les erreurs de sécurité et les chemins PowerShell sous Windows.Tâches annexes :
Original summary in English
Summary by Sourcery
Make file transfers safe and faithful to GNU coreutils and PowerShell while adding comprehensive Windows path support across the terminal and lessons.
New Features:
cpandmvbehavior when transferring files and directories into existing destinations, including relevant options and safety checks.Bug Fixes:
cp,mv, and PowerShell item commands from replacing existing directories with files or otherwise destroying directory contents.Enhancements:
Documentation:
Tests:
Chores: