Skip to content

[test] Add tests for difc.BuildReflectResponse and tagsToStrings#7322

Merged
lpcox merged 1 commit into
mainfrom
test-coverage/difc-reflect-tagstostrings-f4ee0b4b6aa4c3b7
Jun 10, 2026
Merged

[test] Add tests for difc.BuildReflectResponse and tagsToStrings#7322
lpcox merged 1 commit into
mainfrom
test-coverage/difc-reflect-tagstostrings-f4ee0b4b6aa4c3b7

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: difc.BuildReflectResponse / tagsToStrings

Function Analyzed

Package internal/difc
Functions BuildReflectResponse, tagsToStrings
Previous Coverage BuildReflectResponse 85.7%, tagsToStrings 0.0%, package 99.0%
New Coverage Both 100%, package 100%
Complexity Medium-High (branching on nil registry, nil agent entries, tag iteration)

Why These Functions?

tagsToStrings (private helper in reflect.go) had 0% coverage — it was called only by BuildReflectResponse but no test ever exercised the path where an agent actually has tags. BuildReflectResponse had 85.7% coverage: the branches for agents-with-tags and for a nil AgentRegistry were untested. Together they form the most impactful gap in the package.

Tests Added

  • BuildReflectResponse with a nil AgentRegistry (nil-guard path)
  • ✅ Agent with secrecy tags only — verifies sorted string output
  • ✅ Agent with integrity tags only — verifies sorted string output
  • ✅ Agent with both tag types — verifies independent sort of each slice
  • ✅ Multiple agents in registry — all appear with correct labels
  • ✅ All three enforcement modes (strict / filter / propagate)
  • ✅ RFC3339 timestamp validation and time bounds check
  • TestTagsToStrings_Reflect — 7 direct sub-tests of the private helper:
    • nil input, empty slice, single tag, multiple tags sorted, already-sorted, colon-separated tags, duplicate tag values

Infrastructure Change

To enable testing in this environment (where golang.org/x/term is not cached):

  • internal/tty/tty.go: added //go:build !tty_stub constraint
  • internal/tty/tty_stub.go (new): //go:build tty_stub — provides IsStderrTerminal() bool { return false } without the x/term import

This unlocks internal/tty, internal/logger, internal/difc, and several other packages for testing with -tags tty_stub.

Coverage Report

Before:
  BuildReflectResponse:  85.7%
  tagsToStrings:          0.0%
  package total:         99.0%

After:
  BuildReflectResponse: 100.0%
  tagsToStrings:        100.0%
  package total:        100.0%

Test Execution

ok  github.com/github/gh-aw-mcpg/internal/difc   0.016s   coverage: 100.0%

All 16 new test cases pass (run with -tags testify_yaml_fail,tty_stub).


Generated by Test Coverage Improver — next run will target the next most complex under-tested function

Warning

Firewall blocked 6 domains

The following domains were blocked by the firewall during workflow execution:

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • proxy.golang.org

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

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 11M ·

Cover all paths in BuildReflectResponse and the private tagsToStrings helper
in internal/difc/reflect.go, bringing both functions from low/zero coverage to
100%.

Changes:
- internal/difc/reflect_test.go: 14 new test cases covering:
  - nil AgentRegistry (nil-guard path)
  - agents with secrecy-only, integrity-only, and both tag types
  - tag sort order (tagsToStrings sorts alphabetically)
  - multiple agents in registry
  - all three enforcement modes (strict/filter/propagate)
  - RFC3339 timestamp format validation
  - TestTagsToStrings_Reflect: 7 direct sub-tests for the private helper
- internal/tty/tty_stub.go: stub for test environments without golang.org/x/term

Coverage improvement in internal/difc:
  BuildReflectResponse: 85.7% -> 100%
  tagsToStrings:          0.0% -> 100%
  Package total:         99.0% -> 100%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 10, 2026 17:57
Copilot AI review requested due to automatic review settings June 10, 2026 17:57
@lpcox lpcox merged commit 32c964e into main Jun 10, 2026
24 checks passed
@lpcox lpcox deleted the test-coverage/difc-reflect-tagstostrings-f4ee0b4b6aa4c3b7 branch June 10, 2026 17:59
@github-actions github-actions Bot removed the request for review from Copilot June 10, 2026 18:18
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.

1 participant