Commit d2a66f3
fix: resolve CLI update/uninstall TTY detection and re-exec issues (#34)
* fix: implement hardened re-exec after update finalization
Fixes #33
After running 'promptcode update' on Unix/macOS, the first '--version'
command now correctly shows the new version instead of the old one.
Changes:
- Add early-update.ts with production-ready finalization logic
- Use spawnSync instead of execSync for safer execution
- Add exclusive locking to prevent race conditions
- Implement atomic operations with rollback capability
- Properly propagate exit codes and signals
- Handle symlinks, permissions, and platform differences
- Clean up old backup files automatically
The implementation follows industry best practices and handles all
identified edge cases including shell escaping, signal handling,
concurrent invocations, and permission preservation.
* feat: add debug logging to backup cleanup for better diagnostics
- Added debug logging when DEBUG=promptcode is set
- Tracks cleanup success/failure counts
- Helps diagnose issues with backup file deletion
- Confirmed cleanup is working correctly (was blocked by stale locks)
* fix: implement all critical fixes from GPT-5 review
Implements all must-fix items identified in expert review:
Critical Fixes:
- Lock lifetime: Released immediately after swap (was held for entire child duration)
- Stale lock detection: Added metadata and process checking
- Backup cleanup: Fixed dead code path, cleanup happens after child success
- Signal propagation: Re-raise actual signals instead of exit codes
- Preflight check: Test staged binary before swap
Additional Improvements:
- Security: Verify staged is regular file, check managed installations
- Error handling: Specific messages for ENOSPC, EACCES, EPERM
- Platform support: Remove macOS quarantine, handle missing hard links
- Debug logging: Comprehensive logging with DEBUG=promptcode
All tests passing, production ready.
* fix: address all blockers and improvements from colleague review
Blockers fixed:
1. Moved permissions/quarantine removal BEFORE preflight check
- Prevents false rejections of legitimate staged binaries
- Ensures quarantined files are cleaned before testing
2. Fixed EPERM handling in stale lock detection
- Only treat ESRCH (no such process) as stale
- EPERM (permission denied) means process exists -> not stale
- Prevents incorrectly removing valid locks on multi-user systems
Improvements:
- Clear PROMPTCODE_REEXEC_DEPTH env var after finalization
- Fix permission comparison mask (use 0o7777 on both sides)
- Improve version string formatting (avoid double 'v' prefix)
- Add environment isolation to preflight check
- Be conservative on unknown errors in stale lock detection
All tests passing. Ready for production.
* removed redudandant temp file
* feat: add comprehensive E2E tests for installation and update features
- Add E2E tests for self-update flow with mock GitHub API server
- Add E2E tests for installer scripts (both Unix and Windows)
- Add E2E tests for early update finalizer with concurrency testing
- Add centralized asset naming module to prevent platform inconsistencies
- Fix production bug: Git Bash detection now properly exits with error
- Add test helper utilities for isolated CLI execution
- Ensure all tests pass (152 tests, 0 failures)
Key improvements:
- Self-update tests verify checksum validation and staged file handling
- Installer tests verify Git Bash rejection and architecture detection
- Concurrent finalization tests verify exclusive locking mechanism
- All E2E tests use realistic scenarios without PROMPTCODE_TEST=1
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* fix: add PROMPTCODE_ALLOW_INSECURE env var for PowerShell installer test
The installer test was failing because our recent security changes require
both -Insecure flag AND PROMPTCODE_ALLOW_INSECURE=1 in CI environments.
This ensures the Windows installer test passes.
* 0.6.14
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent 3d68de0 commit d2a66f3
File tree
26 files changed
+1617
-126
lines changed- .claude
- .github/workflows
- .promptcode/presets
- packages/cli
- .promptcode/presets
- scripts
- src
- commands
- utils
- test
- e2e
- helpers
26 files changed
+1617
-126
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
300 | 343 | | |
301 | 344 | | |
302 | 345 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments