Commit 79b65cf
committed
build: review pass 5 — close MCP guard bypass + add ctx cancel
HIGH: MCP build_prune footgun guard was bypassed by older_than=
"0s" / "0h" / "-1h". The string-based check (args.OlderThan == "")
treated those values as "filter set"; ParseDuration accepted them;
selectForPrune then silently ignored the zero/negative result
(gates on OlderThan > 0). Net: keep_last=N + confirm=true +
older_than="0s" passed both guards and reached the near-wipe path
the guard exists to prevent.
Fix: parse older_than FIRST in buildPruneTool, derive a hasOlderThan
boolean from the parsed value (> 0), then run all guards against
that boolean. Wording also clarified: "older_than (>0)" in the
suggestion messages so an LLM doesn't try "0s" thinking it's valid.
MED: Prune's per-entry loop didn't honor ctx cancellation between
iterations. Each iteration may run a `docker image rm` (image
artifacts) that can take seconds; without an explicit ctx.Err()
check, Ctrl+C only takes effect at the next docker round-trip,
making the CLI feel unresponsive on long prunes. Added a single
ctx.Err() check at the top of each iteration; on cancel, returns
(result, context.Canceled) with Plan still populated so the caller
sees what would have been done.
Tests added:
- TestBuildPrune_ZeroDurationDoesNotBypassFootgun (3 sub-cases:
"0s", "0h", "-1h" all correctly rejected with the footgun
message — the exact LLM mistake the guard exists to prevent)
- TestPrune_HonorsContextCancellation (cancel before iteration
one; assert context.Canceled propagates and Removed is empty)1 parent cd13e0c commit 79b65cf
4 files changed
Lines changed: 116 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
299 | 308 | | |
300 | 309 | | |
301 | 310 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
321 | 355 | | |
322 | 356 | | |
323 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
117 | 141 | | |
118 | 142 | | |
119 | | - | |
| 143 | + | |
120 | 144 | | |
121 | | - | |
| 145 | + | |
122 | 146 | | |
123 | 147 | | |
124 | 148 | | |
| |||
131 | 155 | | |
132 | 156 | | |
133 | 157 | | |
134 | | - | |
| 158 | + | |
135 | 159 | | |
136 | 160 | | |
137 | 161 | | |
138 | | - | |
| 162 | + | |
139 | 163 | | |
140 | 164 | | |
141 | 165 | | |
142 | 166 | | |
143 | 167 | | |
144 | 168 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
244 | 289 | | |
245 | 290 | | |
246 | 291 | | |
| |||
0 commit comments