fix(terminal): run scripts, $PROFILE, execution policy and chmod modes (THI-353) - #387
Conversation
…s (THI-353)
Six lesson x environment cases validated while the terminal printed an
error. They now run for real:
- Scripts: `./script.sh`, `bash|sh|zsh script.sh`, and `.\script.sh` on
Windows execute the file line by line. `./x` needs the execute bit, as the
chmod lesson teaches ("Permission denied" otherwise). A script runs in a
child shell: the files it writes stay, its cd and exported variables do
not, and its lines stay out of the history. A depth limit stops a script
that calls itself.
- PowerShell: `$PROFILE` expands to the profile path, and the configuration
lesson now starts with a real profile file, so `cat $PROFILE` shows it
(the setup note is Windows-only, via the new `noteByEnv`).
`(Get-Content f).Count` counts lines. `Set-ExecutionPolicy` records the
policy that `Get-ExecutionPolicy` reports; both are PowerShell-only.
- chmod: `+x` wrote the bits one position too far (`-rw-r--r--` became
`-rw-xr-xr-x`, the owner still could not run the file), and only six
octal modes were known. It now handles any 3-digit octal mode and
symbolic modes (`u+x`, `go-w`, `a=r`, comma lists), and rejects invalid
ones. Found by the new script tests.
Code-review follow-ups in the same change: `clear` inside a script now
clears the screen (and keeps what the script prints after it); a shared
budget of 500 script lines per command bounds fan-out (N lines each calling
an N-line script is N^3 runs within the depth limit); `(Get-Content
$PROFILE).Count` expands $PROFILE; pipes run their left side in the session
environment instead of a hard-coded 'linux'.
Not in this change: `./script.sh > out.txt` still ignores the redirection,
like every command except echo today. That is the next THI-353 step
(generic redirection), together with the 3 `2>` cases left in the ratchet.
The THI-353 ratchet shrinks from 9 to 3 known cases.
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 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Guide du reviewerCette PR aligne le simulateur de terminal sur six cas de leçons/environnements auparavant désynchronisés en ajoutant l’exécution limitée des scripts, la prise en charge du profil Windows PowerShell et de la stratégie d’exécution, une analyse robuste de chmod, des pipes qui préservent l’environnement et la gestion de l’effacement des scripts, ainsi que des mises à jour de la configuration du programme et une couverture ciblée. Diagramme de séquence pour l’exécution limitée des scriptssequenceDiagram
participant User
participant TerminalEngine
participant ScriptFile
participant ChildShell
User->>TerminalEngine: processCommand ./script.sh
TerminalEngine->>ScriptFile: read and validate executable bit
alt executable and within limits
TerminalEngine->>ChildShell: runScript(script)
loop each script line
ChildShell->>TerminalEngine: processCommand(line, env)
TerminalEngine-->>ChildShell: output and state
end
ChildShell-->>TerminalEngine: preserve file changes only
TerminalEngine-->>User: script output
else permission, depth, or line limit failure
TerminalEngine-->>User: error
end
Diagramme de séquence pour les commandes de profil PowerShell et de stratégie d’exécutionsequenceDiagram
participant User
participant TerminalEngine
participant PowerShellState
participant ProfileFile
User->>TerminalEngine: $PROFILE
TerminalEngine-->>User: profile path
User->>TerminalEngine: cat $PROFILE
TerminalEngine->>ProfileFile: read profile
ProfileFile-->>TerminalEngine: profile contents
TerminalEngine-->>User: profile contents
User->>TerminalEngine: Set-ExecutionPolicy RemoteSigned
TerminalEngine->>PowerShellState: store executionPolicy
TerminalEngine-->>User: policy confirmation
User->>TerminalEngine: Get-ExecutionPolicy
TerminalEngine->>PowerShellState: read executionPolicy
PowerShellState-->>TerminalEngine: RemoteSigned
TerminalEngine-->>User: RemoteSigned
Diagramme de flux pour l’application du mode chmodflowchart TD
A["chmod mode path"] --> B{mode format}
B -->|3-digit octal| C["convert digits to rwx bits"]
B -->|symbolic or comma list| D["apply u/g/o changes"]
B -->|invalid| E["return invalid mode error"]
C --> F["update permission string"]
D --> F
F --> G["file can be executed when x is set"]
Modifications au niveau des fichiers
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 brings the terminal simulator in line with six previously desynchronized lesson/environment cases by adding bounded script execution, Windows PowerShell profile and execution-policy support, robust chmod parsing, environment-preserving pipes, and script clear handling, with curriculum setup updates and focused coverage. Sequence diagram for bounded script executionsequenceDiagram
participant User
participant TerminalEngine
participant ScriptFile
participant ChildShell
User->>TerminalEngine: processCommand ./script.sh
TerminalEngine->>ScriptFile: read and validate executable bit
alt executable and within limits
TerminalEngine->>ChildShell: runScript(script)
loop each script line
ChildShell->>TerminalEngine: processCommand(line, env)
TerminalEngine-->>ChildShell: output and state
end
ChildShell-->>TerminalEngine: preserve file changes only
TerminalEngine-->>User: script output
else permission, depth, or line limit failure
TerminalEngine-->>User: error
end
Sequence diagram for PowerShell profile and execution policy commandssequenceDiagram
participant User
participant TerminalEngine
participant PowerShellState
participant ProfileFile
User->>TerminalEngine: $PROFILE
TerminalEngine-->>User: profile path
User->>TerminalEngine: cat $PROFILE
TerminalEngine->>ProfileFile: read profile
ProfileFile-->>TerminalEngine: profile contents
TerminalEngine-->>User: profile contents
User->>TerminalEngine: Set-ExecutionPolicy RemoteSigned
TerminalEngine->>PowerShellState: store executionPolicy
TerminalEngine-->>User: policy confirmation
User->>TerminalEngine: Get-ExecutionPolicy
TerminalEngine->>PowerShellState: read executionPolicy
PowerShellState-->>TerminalEngine: RemoteSigned
TerminalEngine-->>User: RemoteSigned
Flow diagram for chmod mode applicationflowchart TD
A["chmod mode path"] --> B{mode format}
B -->|3-digit octal| C["convert digits to rwx bits"]
B -->|symbolic or comma list| D["apply u/g/o changes"]
B -->|invalid| E["return invalid mode error"]
C --> F["update permission string"]
D --> F
F --> G["file can be executed when x is set"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
- CHANGELOG: entries for 23 and 24 September (#383-#387) and for the 18-19 August fixes that had none (#377-#379) - STORY: "Le bug était dans la police" section (23-24 September) - plan.md / ROADMAP.md / docs/README.md banners moved off 6 June - README: test count 1000+ -> 2500+ - security-audit-log: gates of #383-#387, #380 gate debt status Co-authored-by: Claude Opus 5.5 <[email protected]>
Why
THI-353, step 2. Six lesson × environment cases still validated while the terminal printed an error: the 3 script cases (
./script.sh,.\script.sh),cat $PROFILE,(Get-Content f).CountandSet-ExecutionPolicyon Windows.What
./x,bash|sh|zsh x,.\x(Windows) run the file line by line../xneeds the execute bit (Permission deniedotherwise — what the chmod lesson teaches). Child-shell semantics: written files stay;cd, exported variables and the script's lines (history) do not. Depth limit 3 + a shared budget of 500 lines per command.$PROFILE(alone → path; as an argument → the profile file),(Get-Content f).Count,Set-ExecutionPolicy/Get-ExecutionPolicy(new optionalexecutionPolicystate; PowerShell-only). The configuration lesson gets a real profile file via a newpowershellProfilesetup, with a Windows-only note (noteByEnv).+xwrote the bits one position too far (-rw-r--r--→-rw-xr-xr-x: the owner still could not run the file) and only six octal modes existed. Now: any 3-digit octal, symbolicu+x/go-w/a=r/ comma lists, invalid modes rejected.'linux').clearin a script clears the screen and keeps what follows.Ratchet
KNOWN_DESYNCS: 9 → 3 (the2>cluster, next PR — together with./script.sh > out.txt, which still ignores the redirection like every non-echo command today).Gates
terminalEngine.test.ts$PROFILEin.Count, pipe env), each with a test; the 5th (redirecting a script's output) belongs to the redirection PR.\script.shruns and validates,cat $PROFILEshows the profile,Set-ExecutionPolicy RemoteSignedconfirms,(Get-Content documents/rapport.md).Count→ 10 — no red lineRefs THI-353
🤖 Generated with Claude Code
Résumé par Sourcery
Activez des workflows réalistes pour les scripts, PowerShell et les permissions dans les environnements de terminal pris en charge, tout en corrigeant les problèmes associés liés à l’exécution et à la validation du programme pédagogique.
Nouvelles fonctionnalités :
chmodpour accepter des modes octaux arbitraires et des expressions de mode symboliques courantes.Corrections de bugs :
chmodafin que les fichiers reçoivent les permissions prévues.clearexécutées dans des scripts conservent la sortie produite ensuite.Améliorations :
Tests :
chmod, les limites de sécurité des scripts, la gestion declearet les tubes tenant compte de l’environnement.Original summary in English
Summary by Sourcery
Enable realistic script, PowerShell, and permission workflows across supported terminal environments while fixing related execution and curriculum validation issues.
New Features:
Bug Fixes:
Enhancements:
Tests: