Skip to content

[test] Add tests for envutil.GetEnvDuration - #14893

Merged
lpcox merged 1 commit into
mainfrom
test/envutil-debug-logger-coverage-75a9c75975ae46e5
Oct 14, 2026
Merged

lpcox merged 1 commit into
mainfrom
test/envutil-debug-logger-coverage-75a9c75975ae46e5

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: GetEnvDuration

Function Analyzed

  • Package: internal/envutil
  • Functions: GetEnvDuration (and the shared GetEnvInt logging callback)
  • Previous Coverage: 66.7% (GetEnvDuration), 85.7% (GetEnvInt)
  • New Coverage: 100% for both; package 98.6%
  • Complexity: Low–Medium (generic validator with parse/validate/log branches)

Why This Function?

After a full coverage run, GetEnvDuration was the lowest-covered non-trivial function in a high-coverage codebase. Its debug-log callback was only exercised in a re-exec'd subprocess, so it was never counted by coverage.

Tests Added

internal/envutil/envutil_debuglog_test.go swaps logEnvUtil for an enabled logger in-process and covers:

  • ✅ Valid durations (simple and compound) with the log callback
  • ✅ Invalid, zero, negative and empty values falling back to defaults
  • ✅ GetEnvInt valid/zero/negative/non-numeric with logging enabled
  • ✅ GetEnvBool true/false/unrecognized with logging enabled

Test Execution

go test ./internal/envutil/ passes (coverage 98.6%).


Generated by Test Coverage Improver

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 Coverage Improver · copilot · auto · 64.8 AIC · ⊞ 10.6K · ◷

@lpcox
lpcox marked this pull request as ready for review October 14, 2026 18:46
Copilot AI max review requested due to automatic review settings October 14, 2026 18:46
@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 (normal AWF 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 (reaction/star/issue/comment/branch/file/PR) no write tool present in 23-tool catalog BLOCKED ⚠️
C CLI reads (same 4 ops via github proxy on PATH) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated — pre-flight error, no API call made BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated — pre-flight error, no API call made BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • Part A/C reads fully verified via awmg-mcpg:8080/mcp/github proxy — all 4 read ops returned real data (issues Fix commit integrity escalation in GitHub guard #14894/[test] Add tests for envutil.GetEnvDuration #14893/[log] Add debug logging to launcher health monitor #14857, PRs, README.md, 3 commits).
  • Part B: none of the 7 targeted write tools (add_issue_comment, star_repository, issue_write, add_issue_comment body-comment, create_branch, create_or_update_file, create_pull_request) appear in the exposed tool catalog (github --help lists only 23 read-only commands). Per spec this is INCONCLUSIVE, not PASS — it confirms gh-aw's backend GITHUB_READ_ONLY=1 config, not independently mcpg's own gateway-level DIFC/guard enforcement.
  • Parts D/E: gh auth status showed no authenticated host; every gh api/gh api graphql call failed pre-flight ("set the GH_TOKEN environment variable") before reaching GitHub, so the token-scope write boundary could not be exercised in this run.
  • No write of any kind succeeded or leaked in this run — nothing to triage as a security regression.

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

@lpcox
lpcox merged commit 6233c99 into main Oct 14, 2026
29 checks passed
@lpcox
lpcox deleted the test/envutil-debug-logger-coverage-75a9c75975ae46e5 branch October 14, 2026 18:54

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.

🟢 Approval recommended

The test-only changes exercise the intended branches and restore shared state; remaining suggestions are non-blocking.

1 open finding
What changed in this PR

Adds in-process tests for environment parsing helpers so enabled logging callbacks contribute to coverage.

Changes:

  • Adds a helper that enables debug logging and restores the original logger.
  • Tests duration, integer, and boolean parsing with valid and fallback inputs.
File Description
internal/​envutil/​envutil_debuglog_test.go Adds debug-enabled parsing and fallback tests.

🧠 Review effort: Max


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

t.Run(tt.name, func(t *testing.T) {
enableEnvUtilDebugLogger(t)
t.Setenv("TEST_DURATION_INPROC", tt.value)
assert.Equal(t, tt.expected, GetEnvDuration("TEST_DURATION_INPROC", tt.def))
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