From fc14abbefad9cb5cf9f53e778ef6b84136de04ea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 29 May 2026 17:56:36 +0000 Subject: [PATCH 1/2] Add tests for deriveAPIFromServerURL http scheme and edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- internal/envutil/github_coverage_test.go | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 internal/envutil/github_coverage_test.go diff --git a/internal/envutil/github_coverage_test.go b/internal/envutil/github_coverage_test.go new file mode 100644 index 00000000..82793e12 --- /dev/null +++ b/internal/envutil/github_coverage_test.go @@ -0,0 +1,83 @@ +// Package envutil tests: coverage for deriveAPIFromServerURL edge cases. +// +// The existing TestDeriveAPIFromServerURL in github_test.go covers only +// https:// scheme URLs. This file adds targeted coverage for: +// - http:// scheme with a .ghe.com hostname (GHEC tenant) +// - http:// scheme with a custom GHES hostname +// - empty URL (triggers the empty-host guard) +// - URL with a trailing slash (exercises the strings.TrimRight path) +package envutil + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// TestDeriveAPIFromServerURL_HTTPSchemeAndEdgeCases covers the branches in +// deriveAPIFromServerURL that are not exercised by the existing test suite: +// +// 1. The http (non-HTTPS) scheme is accepted for both GHEC and GHES hosts. +// 2. An empty URL returns "" because url.Parse("") sets Host to "". +// 3. A trailing "/" is stripped by strings.TrimRight before parsing, so the +// result must equal the no-trailing-slash equivalent. +func TestDeriveAPIFromServerURL_HTTPSchemeAndEdgeCases(t *testing.T) { + tests := []struct { + name string + serverURL string + expected string + }{ + { + // http scheme is explicitly allowed (lines 91-94 only reject + // schemes that are neither "http" nor "https"). + // GHEC tenant: prepend "copilot-api." subdomain. + name: "http scheme GHEC tenant derives copilot-api subdomain", + serverURL: "http://mycompany.ghe.com", + expected: "http://copilot-api.mycompany.ghe.com", + }, + { + // GHEC tenant with both http scheme and a port number. + name: "http scheme GHEC tenant with port", + serverURL: "http://mycompany.ghe.com:8080", + expected: "http://copilot-api.mycompany.ghe.com:8080", + }, + { + // http scheme is allowed for GHES hosts as well. + name: "http scheme GHES instance uses /api/v3 path", + serverURL: "http://github.example.com", + expected: "http://github.example.com/api/v3", + }, + { + // http scheme with GHES and an explicit port. + name: "http scheme GHES instance with port uses /api/v3 path", + serverURL: "http://github.example.com:9090", + expected: "http://github.example.com:9090/api/v3", + }, + { + // url.Parse("") succeeds but sets Host to "", which triggers the + // "err != nil || parsed.Host == ''" guard and returns "". + name: "empty URL returns empty string", + serverURL: "", + expected: "", + }, + { + // strings.TrimRight strips the trailing slash before url.Parse, so + // "https://github.com/" behaves identically to "https://github.com". + name: "github.com with trailing slash returns default API URL", + serverURL: "https://github.com/", + expected: DefaultGitHubAPIBaseURL, + }, + { + // Multiple trailing slashes are all stripped by TrimRight. + name: "GHES URL with multiple trailing slashes", + serverURL: "https://github.example.com///", + expected: "https://github.example.com/api/v3", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.expected, deriveAPIFromServerURL(tt.serverURL)) + }) + } +} From 8898e88a48c5284f85c187ce942c0989d70f9ad4 Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Fri, 29 May 2026 14:06:57 -0700 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- internal/envutil/github_coverage_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/envutil/github_coverage_test.go b/internal/envutil/github_coverage_test.go index 82793e12..50586a5e 100644 --- a/internal/envutil/github_coverage_test.go +++ b/internal/envutil/github_coverage_test.go @@ -28,8 +28,8 @@ func TestDeriveAPIFromServerURL_HTTPSchemeAndEdgeCases(t *testing.T) { expected string }{ { - // http scheme is explicitly allowed (lines 91-94 only reject - // schemes that are neither "http" nor "https"). + // http scheme is explicitly allowed; schemes other than "http" and + // "https" are rejected. // GHEC tenant: prepend "copilot-api." subdomain. name: "http scheme GHEC tenant derives copilot-api subdomain", serverURL: "http://mycompany.ghe.com",