Commit f49ebf6
authored
[test-improver] Improve tests for launcher MountPolicy (#11651)
## File analyzed
`internal/launcher/mount_policy_test.go` (tests for
`internal/launcher/mount_policy.go`)
The existing test file already uses testify assertions
(`require`/`assert`) consistently, so this pass focused on closing
coverage gaps in `mount_policy.go` rather than assertion-style cleanup.
## Improvements made
Added three targeted tests covering previously-uncovered branches:
- **`TestParseMountRootsSkipsEmptyEntries`** — covers the `entry == ""`
continue branch in `parseMountRoots`, ensuring blank entries from
stray/trailing commas in the `MCP_GATEWAY_ALLOWED_MOUNT_ROOTS` env var
are silently skipped.
- **`TestCanonicalizePathFilesystemRoot`** — covers the `parent ==
current` branch in `canonicalizePath`, where symlink resolution
traverses all the way to `/` without finding an existing ancestor.
- **`TestParseMountDeclarationRejectsEmptyModeOption`** — covers the
`opt == ""` branch in `parseMountDeclaration`'s mode-option loop,
triggered by a stray comma inside the mode segment (e.g. `"ro,,rw"`).
## Coverage before/after
- `mount_policy.go`: 96.0% → 97.8%
- `parseMountRoots`: 93.3% → 100.0%
- `parseMountDeclaration`: 95.8% → 100.0%
- Package `internal/launcher`: 97.4% → 97.8%
Remaining uncovered branches (`canonicalizePath`'s `!os.IsNotExist(err)`
path and `ValidateMount`'s source-canonicalization-error path) require
simulating filesystem permission errors and were left as-is to avoid
flaky/platform-dependent tests.
## Test output
```
go test -v ./internal/launcher/ -run 'TestParseMountRootsSkipsEmptyEntries|TestCanonicalizePathFilesystemRoot|TestParseMountDeclarationRejectsEmptyModeOption'
--- PASS: TestParseMountRootsSkipsEmptyEntries (0.00s)
--- PASS: TestCanonicalizePathFilesystemRoot (0.00s)
--- PASS: TestParseMountDeclarationRejectsEmptyModeOption (0.00s)
PASS
go test -count=3 ./internal/launcher/
ok github.com/github/gh-aw-mcpg/internal/launcher 140.583s
go vet ./internal/launcher/ # clean
gofmt -l internal/launcher/mount_policy_test.go # no output (already formatted)
```
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/32538135990)
· auto · 59.6 AIC · ⊞ 8.6K ·
[◷](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, model:
auto, id: 32538135990, workflow_id: test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/32538135990 -->
<!-- gh-aw-workflow-id: test-improver -->
<!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/test-improver -->1 file changed
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
387 | 425 | | |
388 | 426 | | |
389 | 427 | | |
| |||
0 commit comments