Commit d1a2acd
authored
[test-improver] Improve tests for sys package (#7848)
# Test Improvements: `internal/sys/container_test.go` +
`container_detect_test.go`
## File Analyzed
- **Test Files**: `internal/sys/container_test.go`,
`internal/sys/container_detect_test.go`
- **Package**: `internal/sys`
## Improvements Made
### 1. Scanner-overflow coverage (new test case)
Added a test case `"single line exceeding scanner buffer limit returns
empty string"` to `TestExtractContainerIDFromContent`. This covers the
previously-untested `scanner.Err() != nil` branch in
`extractContainerIDFromContent` (triggered when a single line exceeds
`bufio.MaxScanTokenSize` = 65,536 bytes):
```go
{
name: "single line exceeding scanner buffer limit returns empty string",
input: strings.Repeat("x", bufio.MaxScanTokenSize+1),
want: "",
},
```
### 2. Parallel test execution
Added `t.Parallel()` to all pure-function tests (safe to run
concurrently — no environment mutation, no shared state):
- `TestExtractContainerIDFromContent` + all 16 subtests
- `TestContainsAny_Helper` + all subtests
- 6 × `TestExtractContainerIDFromCgroupFiles_*` tests in
`container_detect_test.go` (temp-file only, no `t.Setenv`)
### 3. Increased Coverage
- **Previous coverage**: `extractContainerIDFromContent` → 92.3%,
package total → 98.9%
- **New coverage**: `extractContainerIDFromContent` → **100.0%**,
package total → **100.0%**
- **Improvement**: +1.1% package, +7.7% on the targeted function
## Test Execution
```
ok github.com/github/gh-aw-mcpg/internal/sys coverage: 100.0% of statements
```
All tests pass with `-race` flag enabled. Tests run multiple times with
consistent results.
## Why These Changes?
`extractContainerIDFromContent` used `bufio.Scanner` to parse cgroup
content but the error path (`scanner.Err() != nil`) was never exercised
— it requires a line longer than 64 KiB, an unusual but valid edge case.
Adding the overflow test ensures the error path is verified. The
parallelism additions are low-risk improvements to pure-function tests,
reducing wall-clock test time with no behavior changes.
---
*Generated by Test Improver Workflow*
*Focuses on better patterns, increased coverage, and more stable tests*
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/27887903074)
· 1.8K AIC · ⊞ 29.5K ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, version:
1.0.60, model: claude-sonnet-4.6, id: 27887903074, workflow_id:
test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/27887903074 -->
<!-- gh-aw-workflow-id: test-improver -->
<!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/test-improver -->2 files changed
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
220 | 222 | | |
221 | 223 | | |
222 | 224 | | |
| |||
229 | 231 | | |
230 | 232 | | |
231 | 233 | | |
| 234 | + | |
| 235 | + | |
232 | 236 | | |
233 | 237 | | |
234 | 238 | | |
| |||
241 | 245 | | |
242 | 246 | | |
243 | 247 | | |
| 248 | + | |
| 249 | + | |
244 | 250 | | |
245 | 251 | | |
246 | 252 | | |
| |||
252 | 258 | | |
253 | 259 | | |
254 | 260 | | |
| 261 | + | |
255 | 262 | | |
256 | 263 | | |
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
260 | 267 | | |
| 268 | + | |
261 | 269 | | |
262 | 270 | | |
263 | 271 | | |
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
267 | 275 | | |
| 276 | + | |
268 | 277 | | |
269 | 278 | | |
270 | 279 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
| 277 | + | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| |||
348 | 351 | | |
349 | 352 | | |
350 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
351 | 361 | | |
352 | 362 | | |
353 | 363 | | |
354 | 364 | | |
| 365 | + | |
355 | 366 | | |
356 | 367 | | |
357 | 368 | | |
| |||
423 | 434 | | |
424 | 435 | | |
425 | 436 | | |
| 437 | + | |
| 438 | + | |
426 | 439 | | |
427 | 440 | | |
428 | 441 | | |
| |||
482 | 495 | | |
483 | 496 | | |
484 | 497 | | |
| 498 | + | |
485 | 499 | | |
486 | 500 | | |
487 | 501 | | |
| |||
0 commit comments