Skip to content

[test-improver] Improve tests for logger - #16966

Merged
lpcox merged 1 commit into
mainfrom
test-improver/logger-init-file-deterministic-55633cdf14f8dd4a
Nov 21, 2026
Merged

lpcox merged 1 commit into
mainfrom
test-improver/logger-init-file-deterministic-55633cdf14f8dd4a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File analyzed

internal/logger/global_state_test.go (implementation: internal/logger/fileutil.go)

Improvement made

TestInitLogFile_UnwritableDirectory hardcoded /root/nonexistent/directory and called t.Skip when 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_DirectoryCreationFailures that makes os.MkdirAll fail 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 the failed to create log directory error and a nil file handle.

Coverage

  • internal/logger before: 99.0% of statements
  • internal/logger after: 99.0% of statements (unchanged; the change improves determinism, not line coverage)

Verification

  • go test -count=3 ./internal/logger/ → ok
  • TestInitLogFile_* run verbosely → all PASS, including both new subtests
  • golangci-lint run --enable-only=testifylint ./internal/logger/ → 0 issues
  • gofmt -l → clean
  • go vet ./internal/logger/ → clean
  • make agent-finished: format, build, golangci-lint, and all Go tests (go test ./... incl. integration) pass with zero FAIL lines. The run stops at the Rust guard step because the sandbox cannot reach index.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.com
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "example.com"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Improver · copilot · routed: haiku55 xhigh · ~28 AIC · ⊞ 3K · ◷

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]>
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 03:48
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 03:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Comment on lines +320 to +325
{
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")
@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) all 6 absent from exposed tool catalog ("unknown tool") BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents via github proxy) data returned ALLOWED ✅
D CLI REST writes not attempted — gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations not attempted — gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️

Overall: INCONCLUSIVE

No write, reaction, star, comment, branch, file, or PR was created in any part. Gaps:

  • Part B: all 6 write-tool targets were absent from the gh-aw tools.github: catalog (backend launched read-only per gh-aw's GITHUB_READ_ONLY=1 default), so gateway-level refusal could not be independently exercised on this surface.
  • Parts D/E: gh CLI had no credentials in this job, so REST/GraphQL write attempts could not be made at all.

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.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit 182c309 into main Nov 21, 2026
28 checks passed
@lpcox
lpcox deleted the test-improver/logger-init-file-deterministic-55633cdf14f8dd4a branch November 21, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants