Commit e6cf0b9
Add CLI parser improvements and comprehensive test coverage (#694)
This commit addresses the priority improvements from issue #694 for the CLI argument parser (yargs).
## Changes Made
### 1. Test Coverage for configExporter Module (Priority 1)
- Added comprehensive test suite for CLI parseArguments function
- 49 tests covering all CLI options, validation logic, type coercion, and edge cases
- Tests validate mutual exclusivity checks, option combinations, and error handling
- All tests passing with full coverage of validation scenarios
### 2. Path Validation for Security (Priority 1)
- Added validatePath() function to prevent path traversal attacks
- Validates that --output and --save-dir paths are within current working directory
- Prevents malicious paths like "../../etc/passwd" or absolute paths outside cwd
- **SECURITY FIX**: Validation now happens in run() AFTER defaults are applied, not during parsing
- This prevents bypassing validation via default path assignments
### 3. Improved Depth Coercion Error Handling (Priority 2)
- Added NaN validation for --depth option
- Rejects non-numeric types (arrays, objects) with clear error messages
- Handles invalid inputs like "abc", "invalid" gracefully
- Removed type: "number" to allow "null" string for unlimited depth
- Added type check for non-string/non-number inputs
### 4. Error Handling for Version Reading (Priority 2)
- Added try-catch block around package.json version reading
- Defaults to "unknown" if file cannot be read or is invalid
- Prevents module load failures in different build/deployment contexts
- Logs warning if version cannot be determined
## Technical Details
- Exported parseArguments() function for testing
- All existing functionality preserved
- No breaking changes to API or behavior
- Linting passes (yarn lint)
- All 49 tests pass
## Security Note
The path validation was moved from parseArguments() to run() after applyDefaults() to ensure all paths (including defaults) are validated. This prevents potential security bypasses where default paths could be set outside validation.
Closes #694 (Priority 1 and 2 items)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 3dfcfdb commit e6cf0b9
2 files changed
Lines changed: 463 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
34 | 55 | | |
35 | 56 | | |
36 | 57 | | |
| |||
103 | 124 | | |
104 | 125 | | |
105 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
106 | 135 | | |
107 | 136 | | |
108 | 137 | | |
| |||
144 | 173 | | |
145 | 174 | | |
146 | 175 | | |
147 | | - | |
| 176 | + | |
148 | 177 | | |
149 | 178 | | |
150 | 179 | | |
| |||
235 | 264 | | |
236 | 265 | | |
237 | 266 | | |
238 | | - | |
239 | 267 | | |
240 | 268 | | |
| 269 | + | |
241 | 270 | | |
242 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
243 | 285 | | |
244 | 286 | | |
245 | 287 | | |
| |||
0 commit comments