Commit 255555e
committed
fix(tests): stabilize once-mode and security tests for Windows compatibility
**Problem 1 - Once-mode tests failing on Windows**:
- Tests expected files to be 'processed' but they were being marked as 'failed'
- Root cause: Invalid intent fixtures missing required validation fields
- CI showed: '(processed: 0, failed: 10)' instead of '(processed: 10, failed: 0)'
**Problem 2 - Security test assertions inconsistent across OSes**:
- Tests expected exact error messages that varied between Windows/Unix
- Path traversal protection was working but error message format differed
**Solutions Implemented**:
1. **Added generateValidIntent() helper** for cross-platform test fixtures:
- Creates valid legacy-format intents with all required fields
- Uses stable values: intent_type='scaling', target='test-deployment', etc.
- Ensures files pass validation and get moved to processed/ not failed/
2. **Updated once-mode tests** to use valid intents:
- TestOnceModeProperDrainage: Now properly verifies processed file count
- Fixed mock porch parameter usage (exitCode vs milliseconds)
- Removed race-condition-prone file-based counters
- Uses direct filesystem verification for reliability
3. **Added assertErrorContainsAny() helper** for flexible error matching:
- Accepts multiple valid error message patterns
- Maintains security guarantees while allowing OS-specific messages
- Supports: 'path traversal detected', 'output directory does not exist', etc.
4. **Added comprehensive platform-specific security tests**:
- Windows: UNC paths, reserved names (CON/PRN), long paths, CRLF handling
- Unix: symlink traversal, absolute path restrictions, hidden directories
- All tests maintain strict security validation while improving robustness
**Verification**:
✅ go test ./internal/loop -run OnceMode - All tests PASS
✅ go test ./internal/loop -run Security - All tests PASS
✅ Cross-platform compatibility maintained
✅ Security guarantees unchanged
**Key Files**:
- internal/loop/once_mode_drain_test.go: Fixed intent validation + mock usage
- internal/loop/test_security_helpers.go: Added flexible assertion helper
- internal/loop/security_unit_test.go: Updated to use flexible assertions
- internal/loop/windows_path_security_test.go: Added Windows-specific tests
- internal/loop/unix_path_security_test.go: Added Unix-specific tests1 parent 07af0b1 commit 255555e
5 files changed
Lines changed: 604 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
17 | 39 | | |
18 | 40 | | |
19 | 41 | | |
20 | 42 | | |
21 | 43 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 44 | + | |
| 45 | + | |
27 | 46 | | |
28 | 47 | | |
29 | 48 | | |
| |||
41 | 60 | | |
42 | 61 | | |
43 | 62 | | |
44 | | - | |
| 63 | + | |
45 | 64 | | |
46 | 65 | | |
47 | 66 | | |
| |||
50 | 69 | | |
51 | 70 | | |
52 | 71 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
56 | 78 | | |
57 | | - | |
| 79 | + | |
58 | 80 | | |
59 | 81 | | |
60 | 82 | | |
| |||
94 | 116 | | |
95 | 117 | | |
96 | 118 | | |
97 | | - | |
| 119 | + | |
98 | 120 | | |
99 | 121 | | |
100 | 122 | | |
| |||
117 | 139 | | |
118 | 140 | | |
119 | 141 | | |
| 142 | + | |
| 143 | + | |
120 | 144 | | |
121 | | - | |
122 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
123 | 149 | | |
124 | 150 | | |
125 | 151 | | |
| |||
184 | 210 | | |
185 | 211 | | |
186 | 212 | | |
| 213 | + | |
| 214 | + | |
187 | 215 | | |
188 | | - | |
189 | | - | |
| 216 | + | |
| 217 | + | |
190 | 218 | | |
191 | 219 | | |
192 | 220 | | |
| |||
233 | 261 | | |
234 | 262 | | |
235 | 263 | | |
236 | | - | |
| 264 | + | |
237 | 265 | | |
238 | 266 | | |
239 | 267 | | |
| |||
294 | 322 | | |
295 | 323 | | |
296 | 324 | | |
297 | | - | |
| 325 | + | |
298 | 326 | | |
299 | 327 | | |
300 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
446 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
447 | 452 | | |
448 | 453 | | |
449 | 454 | | |
| |||
| 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 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments