Skip to content

[test-improver] Improve tests for logger package#5577

Merged
lpcox merged 2 commits into
mainfrom
test-improver/logger-backward-compat-coverage-38634951726591fc
May 13, 2026
Merged

[test-improver] Improve tests for logger package#5577
lpcox merged 2 commits into
mainfrom
test-improver/logger-backward-compat-coverage-38634951726591fc

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

File Analyzed

  • Test Files: internal/logger/markdown_logger_test.go, internal/logger/server_file_logger_test.go
  • Package: internal/logger

Improvements Made

Increased Coverage

Eight backward-compatibility wrapper functions had 0% coverage. These are one-liner delegates that forward calls to the canonical LogXxxToMarkdown / LogXxxToServer functions. Adding tests for them verifies the delegation chain works correctly and ensures future refactors don't accidentally break the public API.

Functions now covered:

  • LogInfoMdLogInfoToMarkdown
  • LogWarnMdLogWarnToMarkdown
  • LogErrorMdLogErrorToMarkdown
  • LogDebugMdLogDebugToMarkdown
  • LogInfoWithServerLogInfoToServer
  • LogWarnWithServerLogWarnToServer
  • LogErrorWithServerLogErrorToServer
  • LogDebugWithServerLogDebugToServer

Coverage improvement:

  • Previous: 96.1%
  • New: 97.7%
  • Improvement: +1.6%

Test Design

Each new test:

  1. Initialises a real logger in a t.TempDir() directory (no side-effects on global state across test runs)
  2. Calls all four level wrappers with a formatted message
  3. Closes/flushes the logger so the file is written
  4. Reads the log file and asserts each expected message is present

Tests follow the existing patterns in the file (bound asserters, require.NoError for fatal errors, assert.Contains for content checks).

Test Execution

=== RUN   TestLogMdBackwardCompatWrappers
--- PASS: TestLogMdBackwardCompatWrappers (0.00s)
=== RUN   TestLogWithServerBackwardCompatWrappers
--- PASS: TestLogWithServerBackwardCompatWrappers (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/logger  0.296s  coverage: 97.7% of statements

Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • invalidhostthatdoesnotexist12345.com

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

network:
  allowed:
    - defaults
    - "invalidhostthatdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Improver · ● 2.2M ·

Add tests for the eight backward-compatibility wrappers that had 0%
coverage:
- LogInfoMd, LogWarnMd, LogErrorMd, LogDebugMd (markdown_logger.go)
- LogInfoWithServer, LogWarnWithServer, LogErrorWithServer, LogDebugWithServer
  (server_file_logger.go)

Each wrapper delegates to its canonical counterpart; the new tests
initialise a real logger in a temp dir, call each wrapper, flush/close,
and assert the expected message appears in the resulting log file.

Coverage for internal/logger improves from 96.1% → 97.7%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves test coverage in internal/logger by adding unit tests that exercise the legacy/backward-compatibility wrapper functions, ensuring they continue to delegate correctly to the canonical Log*ToMarkdown / Log*ToServer APIs.

Changes:

  • Add a new test covering LogInfoMd / LogWarnMd / LogErrorMd / LogDebugMd wrappers and verifying output is written to the markdown log file.
  • Add a new test covering LogInfoWithServer / LogWarnWithServer / LogErrorWithServer / LogDebugWithServer wrappers and verifying output is written to the per-server log file.
Show a summary per file
File Description
internal/logger/markdown_logger_test.go Adds a test that calls legacy Log*Md wrappers and asserts the expected messages are present in the markdown log file.
internal/logger/server_file_logger_test.go Adds a test that calls legacy Log*WithServer wrappers and asserts the expected messages are present in the per-server log file.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +388 to +398
err := InitMarkdownLogger(logDir, "gateway.md")
require.NoError(t, err)
defer CloseMarkdownLogger()

LogInfoMd("test", "md compat info %s", "msg")
LogWarnMd("test", "md compat warn %s", "msg")
LogErrorMd("test", "md compat error %s", "msg")
LogDebugMd("test", "md compat debug %s", "msg")

err = CloseMarkdownLogger()
require.NoError(t, err)
Comment on lines +475 to +487
err := InitServerFileLogger(logDir)
require.NoError(t, err)
defer CloseServerFileLogger()

serverID := "compat-server"

LogInfoWithServer(serverID, "test", "compat info %s", "msg")
LogWarnWithServer(serverID, "test", "compat warn %s", "msg")
LogErrorWithServer(serverID, "test", "compat error %s", "msg")
LogDebugWithServer(serverID, "test", "compat debug %s", "msg")

err = CloseServerFileLogger()
require.NoError(t, err)
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 13, 2026

@copilot address the review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

@copilot address the review feedback

Addressed in 01b3f00.

Copilot finished work on behalf of lpcox May 13, 2026 14:28
Copilot AI requested a review from lpcox May 13, 2026 14:28
@lpcox lpcox merged commit 4e7cdf8 into main May 13, 2026
16 checks passed
@lpcox lpcox deleted the test-improver/logger-backward-compat-coverage-38634951726591fc branch May 13, 2026 14:54
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.

3 participants