[test] Add tests for envutil.deriveAPIFromServerURL — http scheme and edge cases#6708
Merged
lpcox merged 2 commits intoMay 29, 2026
Merged
Conversation
Cover the branches in internal/envutil/github.go that were not exercised by the existing TestDeriveAPIFromServerURL test suite: - http:// scheme with GHEC (.ghe.com) hostname — expects copilot-api subdomain - http:// scheme with GHEC + port - http:// scheme with GHES custom hostname — expects /api/v3 path - http:// scheme with GHES + port - Empty URL — triggers the 'parsed.Host == ""' guard, returns "" - github.com with trailing slash — exercises strings.TrimRight, same result - GHES URL with multiple trailing slashes — all stripped by TrimRight Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves unit coverage for internal/envutil URL derivation behavior without changing production code.
Changes:
- Adds table-driven tests for
http://GHEC and GHES server URL derivation. - Adds edge-case coverage for empty input and trailing slash normalization.
- Verifies existing constants and helper behavior through direct tests of
deriveAPIFromServerURL.
Show a summary per file
| File | Description |
|---|---|
internal/envutil/github_coverage_test.go |
Adds focused coverage for deriveAPIFromServerURL scheme handling and 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: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Coverage Improvement:
deriveAPIFromServerURLFunction Analyzed
internal/envutilderiveAPIFromServerURL(ingithub.go)internal/envutil/github.go(line 83)switchon hostname pattern, port extraction)Why This Function?
deriveAPIFromServerURLcontains several branches not exercised by the existingTestDeriveAPIFromServerURL(which only usedhttps://URLs):url.Parse("")succeeds but leavesHostempty, triggering theparsed.Host == ""early-return guard. This path was not covered.strings.TrimRight(serverURL, "/")strips trailing slashes before parsing. This normalisation was not verified.Tests Added
New file:
internal/envutil/github_coverage_test.go(redacted) scheme with GHEC.ghe.comhostname →copilot-api.` subdomain(redacted) scheme with GHES custom hostname →/api/v3` path""(empty-host guard)github.comwith trailing slash → same result as without (TrimRight branch)Coverage Report
Correctness Reasoning
Each new test case was traced manually through the function:
.ghe.com→ copilot-api, no port""""url.Parse("")→ Host=""→ early-returnhttps://github.com/DefaultGitHubAPIBaseURL/Generated by Test Coverage Improver
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.