Skip to content

[test-improver] Improve tests for cmd/flags_difc#4465

Merged
lpcox merged 1 commit intomainfrom
test-improver/flags-difc-test-improvements-b9a9f198a715ffca
Apr 24, 2026
Merged

[test-improver] Improve tests for cmd/flags_difc#4465
lpcox merged 1 commit intomainfrom
test-improver/flags-difc-test-improvements-b9a9f198a715ffca

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

File Analyzed

  • Test File: internal/cmd/flags_difc_test.go
  • Package: internal/cmd

Improvements Made

1. Better Testing Patterns

  • ✅ Replaced manual os.Setenv/defer/os.Unsetenv with t.Setenv in TestGetDefaultDIFCMode — cleaner, race-safe, and automatic cleanup

2. Increased Coverage

  • ✅ Added test for consecutive commas ("safeoutputs,,github") — covers the previously untested continue branch that skips empty parts after splitting
  • ✅ Added test for trailing comma ("safeoutputs,github,") — covers the same empty-part skip path from a different angle
  • ✅ Added test for tab character in server IDs — verifies whitespace detection beyond just space (the ContainsAny check covers " \t\n\r")
  • Previous Coverage (parseDIFCSinkServerIDs): 93.3%
  • New Coverage (parseDIFCSinkServerIDs): 100.0%

3. Cleaner & More Stable Tests

  • t.Setenv automatically restores env vars after each subtest, eliminating the manual save/restore pattern and making tests safer under parallelism

Test Execution

All cmd package tests pass:

ok  	github.com/github/gh-aw-mcpg/internal/cmd	0.125s	coverage: 46.7% of statements

(TestFetchAndFixSchema_NetworkError in the config package is a pre-existing failure unrelated to these changes.)

Why These Changes?

parseDIFCSinkServerIDs had a dead continue branch (for empty segments produced by consecutive or trailing commas) that was never exercised. Adding those test cases brings the function to 100% coverage and documents the expected parsing behavior. Switching to t.Setenv removes boilerplate and prevents tests from accidentally leaking environment state.


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.7M ·

- Use t.Setenv instead of manual os.Setenv/defer/os.Unsetenv in
  TestGetDefaultDIFCMode for cleaner test environment management
- Add test case for consecutive commas (empty parts after split) in
  TestParseDIFCSinkServerIDs, covering the previously untested continue
  branch that skips empty parts
- Add test case for trailing comma skipping empty part
- Add test case for tab character rejection in server IDs, testing
  whitespace detection beyond just space characters
- parseDIFCSinkServerIDs coverage: 93.3% → 100.0%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review April 24, 2026 14:59
Copilot AI review requested due to automatic review settings April 24, 2026 14:59
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

Improves the stability and branch coverage of DIFC-related CLI flag tests in internal/cmd, primarily by simplifying environment variable handling and adding missing edge-case parsing scenarios.

Changes:

  • Replaced manual env var save/restore logic with t.Setenv in TestGetDefaultDIFCMode.
  • Added coverage for empty-segment cases in parseDIFCSinkServerIDs (consecutive/trailing commas).
  • Added a test case to verify tab whitespace is rejected in server IDs.
Show a summary per file
File Description
internal/cmd/flags_difc_test.go Uses t.Setenv for cleaner env-var tests and adds cases to fully exercise sink server ID parsing edge cases.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 78ba390 into main Apr 24, 2026
20 of 21 checks passed
@lpcox lpcox deleted the test-improver/flags-difc-test-improvements-b9a9f198a715ffca branch April 24, 2026 15:49
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