Repository navigation
[test-improver] Improve tests for logger - #16966
Conversation
TestInitLogFile_UnwritableDirectory hardcoded /root/nonexistent/directory and skipped when the directory was writable, so its outcome depended on the host's privileges. Replace it with a table-driven TestInitLogFile_DirectoryCreationFailures that forces MkdirAll to fail via a regular file used as a directory component, which fails for every user including root. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
An active finding remains because the new nested-file subtest duplicates existing coverage and should be removed or merged to avoid redundant test maintenance.
1 open issue
What changed in this PR
This PR improves logger test determinism by replacing a privilege-dependent unwritable-directory test with deterministic filesystem failure cases, without modifying production code.
Changes:
- Replaces the
/root-based test and skip behavior with table-driven directory-creation failure cases. - Uses regular files as path components to make failures consistent across users and environments.
- Verifies the expected error and nil file handle for each failure case.
| File | Description |
|---|---|
| internal/logger/global_state_test.go | Replaces the privilege-dependent log-directory failure test with deterministic table-driven filesystem failure cases and corresponding assertions. |
Review effort: Lite (adaptive)
| { | ||
| name: "log directory nested under a regular file", | ||
| setup: func(t *testing.T) string { | ||
| blocker := filepath.Join(t.TempDir(), "blocker") | ||
| require.NoError(t, os.WriteFile(blocker, []byte("x"), 0644)) | ||
| return filepath.Join(blocker, "nested", "logs") |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write, reaction, star, comment, branch, file, or PR was created in any part. Gaps:
No security regression observed; methodology gaps noted above are structural to this workflow's current toolset/auth configuration, not evidence of an mcpg enforcement failure.
|

File analyzed
internal/logger/global_state_test.go(implementation:internal/logger/fileutil.go)Improvement made
TestInitLogFile_UnwritableDirectoryhardcoded/root/nonexistent/directoryand calledt.Skipwhen the directory turned out to be writable. Its outcome depended on the host's privileges: it could silently skip on a root runner and was not a real assertion of the directory-failure path.Replaced it with a table-driven
TestInitLogFile_DirectoryCreationFailuresthat makesos.MkdirAllfail deterministically by using a regular file as a directory component (for both a direct and a nested log directory). This fails for every user, including root, so the test always runs and always asserts thefailed to create log directoryerror and a nil file handle.Coverage
internal/loggerbefore: 99.0% of statementsinternal/loggerafter: 99.0% of statements (unchanged; the change improves determinism, not line coverage)Verification
go test -count=3 ./internal/logger/→okTestInitLogFile_*run verbosely → all PASS, including both new subtestsgolangci-lint run --enable-only=testifylint ./internal/logger/→ 0 issuesgofmt -l→ cleango vet ./internal/logger/→ cleanmake agent-finished: format, build, golangci-lint, and all Go tests (go test ./...incl. integration) pass with zeroFAILlines. The run stops at the Rust guard step because the sandbox cannot reachindex.crates.io(SSL certificate name mismatch), which is unrelated to this Go-only test change.No production code was modified.
Warning
Firewall blocked 4 domains
The following domains were blocked by the firewall during workflow execution:
example.comnonexistent.localslow.example.comthishostdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.