Skip to content

Expand parser GitHub host unit coverage and harden host-repo assertions - #46926

Merged
pelikhan merged 11 commits into
mainfrom
copilot/testify-expert-improve-test-quality-yet-again
Jul 21, 2026
Merged

Expand parser GitHub host unit coverage and harden host-repo assertions#46926
pelikhan merged 11 commits into
mainfrom
copilot/testify-expert-improve-test-quality-yet-again

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

pkg/parser/github_host_test.go covered only part of GetGitHubHostForRepo behavior and had no direct coverage for GetGitHubHost env-priority and normalization rules. This update fills those gaps and aligns subtest assertions with fail-fast testify usage.

  • GetGitHubHost behavior coverage

    • Added a new table-driven TestGetGitHubHost for:
      • env precedence (GITHUB_SERVER_URL > GITHUB_ENTERPRISE_HOST > GITHUB_HOST > GH_HOST)
      • implicit https:// normalization
      • trailing-slash normalization
      • public fallback when all host env vars are unset
  • GetGitHubHostForRepo edge-case coverage

    • Added explicit case for non-fallback owner with empty enterprise host (acme/repo -> https://github.com)
    • Kept explicit public-org coverage including microsoft/*
  • Assertion semantics

    • Replaced assert.Equal with require.Equal inside the subtest loop to stop each failing subtest immediately.
  • Build-tag alignment

    • Removed //go:build !integration from this file since tests are pure env/unit behavior.
host := GetGitHubHostForRepo(tt.owner, tt.repo)
require.Equal(t, tt.expectedHost, host, "GetGitHubHostForRepo(%q, %q)", tt.owner, tt.repo)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pi.dev

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

network:
  allowed:
    - defaults
    - "pi.dev"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · 16.7 AIC · ⌖ 10.4 AIC · ⊞ 7K ·
Comment /souschef to run again


Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pi.dev

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

network:
  allowed:
    - defaults
    - "pi.dev"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · 20.6 AIC · ⌖ 6.84 AIC · ⊞ 7K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for GetGitHubHost in github_host_test.go Expand parser GitHub host unit coverage and harden host-repo assertions Jul 20, 2026
Copilot AI requested a review from pelikhan July 20, 2026 21:56
@github-actions

Copy link
Copy Markdown
Contributor

🔍 PR Triage — Run §29791496271

Field Value
Category test
Risk 🟢 low
Score 32/100 (impact 12 + urgency 8 + quality 12)
Action auto_merge (needs undraft)

Rationale: Pure test-only change (1 file). Adds coverage for GetGitHubHost env-priority/normalization. No production code changes. Auto-merge once undrafted and CI passes.

Generated by 🔧 PR Triage Agent · 40.1 AIC · ⌖ 6.65 AIC · ⊞ 5.6K ·

@pelikhan
pelikhan marked this pull request as ready for review July 21, 2026 03:35
Copilot AI review requested due to automatic review settings July 21, 2026 03:35
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (73 additions found, threshold is 100).

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

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.

Pull request overview

Expands parser unit coverage for GitHub host resolution and fallback behavior.

Changes:

  • Adds host normalization, fallback, and partial precedence tests.
  • Adds empty-enterprise-host coverage.
  • Uses fail-fast assertions and removes the integration build tag.
Show a summary per file
File Description
pkg/parser/github_host_test.go Expands host-resolution tests and updates assertion behavior.

Review details

Tip

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

Comments suppressed due to low confidence (1)

pkg/parser/github_host_test.go:39

  • This case leaves GH_HOST empty, so the GITHUB_HOST > GH_HOST priority rule remains untested despite the PR claiming full env-priority coverage. Set GH_HOST to a distinct value so reversing those two checks fails the test.
			name:           "trailing slash stripped",
			serverURL:      "",
			enterpriseHost: "",
			githubHost:     "acme.ghe.com/",
			ghHost:         "",
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread pkg/parser/github_host_test.go Outdated
Comment on lines +27 to +31
name: "host without scheme gets https prefix",
serverURL: "",
enterpriseHost: "acme.ghe.com",
githubHost: "",
ghHost: "",

@github-actions github-actions Bot 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.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 22.1 AIC · ⌖ 4.28 AIC · ⊞ 5K

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

🚨 Test Quality Score: 88/100 — Excellent (but FAILED due to guideline violation)

Analyzed 10 test scenario(s) across 2 test functions: 10 design, 0 implementation, 1 violation.

📊 Metrics (10 scenarios in 2 test functions)
Metric Value
Analyzed 10 scenarios (Go: 10, JS: 0)
✅ Design 10 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 6 (60%)
Duplicate clusters 0
Inflation N/A (test-only PR)
🚨 Violations 1
Test File Classification Issues
TestGetGitHubHost (5 rows) github_host_test.go design_test / high_value Missing build tag; assertions lack descriptive failure context
TestGetGitHubHostForRepo_PublicOrgFallback (5 rows) github_host_test.go design_test / high_value Missing build tag
⚠️ Flagged Tests (1 violation, 1 warning)

github_host_test.go (line 1)Hard violation: file is missing the mandatory //go:build tag on line 1. All new Go test files must declare either //go:build !integration or //go:build integration as the very first line. Add //go:build !integration before the package parser declaration.

TestGetGitHubHost — Assertion-message warning: require.Equal(t, tt.expectedHost, host) lacks a descriptive failure context message. Consider: require.Equal(t, tt.expectedHost, host, "GetGitHubHost() mismatch for case: %s", tt.name).

Verdict

Failed. Hard guideline violation: pkg/parser/github_host_test.go is missing the required //go:build tag on line 1. The behavioral coverage itself is excellent (100% design tests, good edge-case spread across env-var priority and public-org fallback logic). Fix the build tag and assertion messages to pass.

References: §29798944323

🧪 Test quality analysis by Test Quality Sentinel · 30.1 AIC · ⌖ 9.77 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot 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.

❌ Test Quality Sentinel: 88/100. Hard guideline violation: pkg/parser/github_host_test.go missing required //go:build tag on line 1. Review flagged tests in the comment above.

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /tdd — two observations on test isolation and coverage completeness.

📋 Key Themes & Highlights

Issues

  • Env isolation gap (line 120): TestGetGitHubHostForRepo_PublicOrgFallback clears GITHUB_SERVER_URL, GITHUB_ENTERPRISE_HOST, and GH_HOST but never clears GITHUB_HOST. A pre-existing GITHUB_HOST in a CI environment could cause the new "empty gheHost falls back to public for non-fallback owner" case to pass for the wrong reason.
  • Missing normalisation edge case (line 23): TestGetGitHubHost has no case where GITHUB_SERVER_URL already includes https://, leaving a potential double-prefix regression undetected.

Positive Highlights

  • ✅ Clean table-driven structure with good case names
  • t.Setenv used throughout — safe parallel test execution
  • require.Equal upgrade is the right call for fail-fast loop semantics
  • ✅ Build-tag removal is correct: these are pure unit tests with no I/O

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 34.8 AIC · ⌖ 4.62 AIC · ⊞ 6.7K
Comment /matt to run again

Comments that could not be inline-anchored

pkg/parser/github_host_test.go:120

[/tdd] GITHUB_HOST env var is never cleared in the subtest setup, so a pre-existing GITHUB_HOST in CI could silently override tt.gheHost=&quot;&quot; and produce a false pass on the empty-gheHost fallback case.

<details>
<summary>💡 Suggested fix</summary>

Add a t.Setenv for GITHUB_HOST alongside the other resets:

t.Setenv(&quot;GITHUB_SERVER_URL&quot;, &quot;&quot;)
t.Setenv(&quot;GITHUB_ENTERPRISE_HOST&quot;, tt.gheHost)
t.Setenv(&quot;GITHUB_HOST&quot;, &quot;&quot;)   // ← add this
t.Setenv(&quot;GH_HOST&quot;, &quot;&quot;)

Without it the n…

pkg/parser/github_host_test.go:23

[/tdd] No test case covers GITHUB_SERVER_URL already containing https:// — without it, a regression in NormalizeGitHubHostURL that double-prefixes would go undetected.

<details>
<summary>💡 Suggested additional test case</summary>

{
    name:         &quot;GITHUB_SERVER_URL with existing https scheme is not double-prefixed&quot;,
    serverURL:    &quot;(acme.ghe.com/redacted)&quot;,
    expectedHost: &quot;(acme.ghe.com/redacted)&quot;,
},

This guards against a common URL normalisation regression.

<…

@github-actions github-actions Bot 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.

Review: Expand parser GitHub host unit coverage

Non-blocking — the added tests are correct and well-structured; two gaps in coverage are worth addressing.

Findings

Missing priority-ordering tests (medium): Each of the new subtests sets only one env var at a time. No case exercises two env vars simultaneously to verify the documented precedence order (e.g. GITHUB_ENTERPRISE_HOST beats GITHUB_HOST). A reordering of the implementation's env-var slice would pass all tests silently.

No scheme-already-present test (low): In real CI, GITHUB_SERVER_URL is always a full URL ((redacted)). The NormalizeGitHubHostURL guard that prevents double-prefixing is untested in this file.

Both are straightforward additions to the existing table.

🔎 Code quality review by PR Code Quality Reviewer · 41.1 AIC · ⌖ 4.65 AIC · ⊞ 5.6K
Comment /review to run again

githubHost: "github-host.ghe.com",
ghHost: "gh-host.ghe.com",
expectedHost: "https://acme.ghe.com/redacted",
},

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.

Missing priority-ordering assertions: only the top-priority env var is tested in competition; no case has two or more vars set simultaneously to verify that GITHUB_ENTERPRISE_HOST beats GITHUB_HOST and GITHUB_HOST beats GH_HOST. A silent reordering of the env-var slice in the implementation would pass all current tests.

💡 Suggested additions
{
    name:           "GITHUB_ENTERPRISE_HOST beats GITHUB_HOST",
    serverURL:      "",
    enterpriseHost: "enterprise.ghe.com",
    githubHost:     "github-host.ghe.com",
    ghHost:         "gh-host.ghe.com",
    expectedHost:   "(enterprise.ghe.com/redacted)",
},
{
    name:           "GITHUB_HOST beats GH_HOST",
    serverURL:      "",
    enterpriseHost: "",
    githubHost:     "github-host.ghe.com",
    ghHost:         "gh-host.ghe.com",
    expectedHost:   "(githubhost.ghe.com/redacted)",
},

The implementation iterates ["GITHUB_SERVER_URL", "GITHUB_ENTERPRISE_HOST", "GITHUB_HOST", "GH_HOST"] in order — any reordering regression would be invisible with only single-variable cases.

enterpriseHost: "acme.ghe.com",
githubHost: "",
ghHost: "",
expectedHost: "https://acme.ghe.com",

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.

No test for scheme-already-present input: the GITHUB_SERVER_URL wins over others case uses a bare hostname (acme.ghe.com/redacted). In real CI, GITHUB_SERVER_URL is always set as a full URL like (acme.ghe.com/redacted). There is no test verifying that NormalizeGitHubHostURL does not double-prefix such a value to (https/redacted)://acme.ghe.com.

💡 Suggested addition
{
    name:         "GITHUB_SERVER_URL already has https scheme",
    serverURL:    "(acme.ghe.com/redacted)",
    expectedHost: "(acme.ghe.com/redacted)",
},

NormalizeGitHubHostURL has a HasPrefix("https://") guard, but this path has zero test coverage in this file.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address the open review feedback below, and rerun checks once updates are pushed.

Unresolved review feedback:

Current blocking signal:

  • Test Quality Sentinel failed on missing //go:build tag and suggested adding assertion context in pkg/parser/github_host_test.go.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pi.dev

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

network:
  allowed:
    - defaults
    - "pi.dev"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · 16.7 AIC · ⌖ 10.4 AIC · ⊞ 7K ·
Comment /souschef to run again

Copilot AI and others added 2 commits July 21, 2026 04:14
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
- Add //go:build !integration to match package convention
- Replace normalisation-only cases with real precedence tests:
  "GITHUB_ENTERPRISE_HOST wins over GITHUB_HOST and GH_HOST" populates
  all three lower-priority vars so a wrong ordering would be caught
- "GITHUB_HOST wins over GH_HOST" likewise sets GH_HOST to a different
  value to verify the ordering holds

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address the open review feedback below, and rerun checks once updates are pushed.

Unresolved review feedback:...

Done in the latest commit. Both issues are addressed:

  1. Missing //go:build !integration tag — added to match every other unit test in the package.
  2. Weak precedence tests (lines 27–31 and 35) — replaced the two normalization-only cases with real precedence tests that populate all lower-priority env vars with distinct values:
    • "GITHUB_ENTERPRISE_HOST wins over GITHUB_HOST and GH_HOST" sets githubHost and ghHost to different values so a wrong ordering would fail.
    • "GITHUB_HOST wins over GH_HOST" sets ghHost to a different value for the same reason.

Local make fmt, make agent-report-progress-no-test, and the targeted tests all pass.

Copilot AI requested a review from gh-aw-bot July 21, 2026 04:18
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot review all uses of GH_HOST, GH_ENTERPRISE_HOST, ... in other helpers and refactor to use same unified resolution

Copilot AI and others added 4 commits July 21, 2026 04:49
- Add IsAnyGitHubHostEnvVarSet() to pkg/parser/github.go as the canonical
  helper for checking if any host env var is explicitly set
- Add isAnyGitHubHostEnvVarSet() shim to pkg/cli/github.go delegating to
  the parser function; remove the duplicate local version from engine_secrets.go
- Replace os.Getenv("GH_HOST") == "" bypass checks in compile_orchestrator.go,
  add_interactive_orchestrator.go, and setup_repository.go with
  isAnyGitHubHostEnvVarSet() so all four host env vars are respected
- Simplify importAuthGHHost() to use getGitHubHost() + isAnyGitHubHostEnvVarSet()
  instead of reading only GH_HOST; update GHE auth tests to set/clear all four
  env vars explicitly and add coverage for GITHUB_ENTERPRISE_HOST and
  GITHUB_SERVER_URL
- Extend detectGHESDeployment() to check all four env vars
  (GITHUB_SERVER_URL > GITHUB_ENTERPRISE_HOST > GITHUB_HOST > GH_HOST)
  instead of only GITHUB_SERVER_URL and GH_HOST

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ffix

- importAuthGHHost: add manual strip fallback for the defensive parse-failure
  branch; switch from u.Host to u.Hostname() so port numbers are excluded
  from the returned hostname
- detectGHESDeployment: replace strings.TrimRight(host, "/") with
  strings.TrimSuffix(host, "/") to remove exactly one trailing slash rather
  than all trailing '/' characters

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…arse error, remove unreachable fallback

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review all uses of GH_HOST, GH_ENTERPRISE_HOST, ... in other helpers and refactor to use same unified resolution

Done. All scattered direct env var reads (GH_HOST, GITHUB_ENTERPRISE_HOST, GITHUB_HOST, GITHUB_SERVER_URL) have been unified through a single resolution path (GetGitHubHost / isAnyGitHubHostEnvVarSet):

  • pkg/parser/github.go: Added exported IsAnyGitHubHostEnvVarSet() helper
  • pkg/cli/github.go: Added isAnyGitHubHostEnvVarSet() shim delegating to the parser
  • pkg/cli/engine_secrets.go: Removed the local duplicate isAnyGitHubHostEnvVarSet()
  • pkg/cli/compile_orchestrator.go, add_interactive_orchestrator.go, setup_repository.go: Replaced single-var GH_HOST bypass checks with isAnyGitHubHostEnvVarSet()
  • pkg/cli/import_url_fetcher.go: Rewrote importAuthGHHost() to use getGitHubHost() + url.Hostname() (unified priority, port-safe)
  • pkg/cli/init.go: Extended detectGHESDeployment() to iterate all 4 env vars; fixed TrimRightTrimSuffix

New test coverage added for all three lower-priority env vars (GITHUB_ENTERPRISE_HOST, GITHUB_SERVER_URL, GITHUB_HOST) in import_url_fetcher_test.go.

@pelikhan
pelikhan enabled auto-merge (squash) July 21, 2026 05:04
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address the failed checks listed below , review any remaining unresolved feedback , rerun checks once the branch is up to date

Failed checks:

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pi.dev

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

network:
  allowed:
    - defaults
    - "pi.dev"

See Network Configuration for more information.

Generated by 👨‍🍳 PR Sous Chef · 20.6 AIC · ⌖ 6.84 AIC · ⊞ 7K ·
Comment /souschef to run again

The isAnyGitHubHostEnvVarSet() replacement broke three existing tests
because GITHUB_SERVER_URL is always set in CI (to https://github.com),
which caused the git-remote auto-detection block to be skipped entirely.

The bypass condition should only apply to GH_HOST because:
- GH_HOST is the env var the gh CLI uses to configure its target host
- GITHUB_SERVER_URL/GITHUB_ENTERPRISE_HOST/GITHUB_HOST are informational
  automation vars that should not prevent local git remote detection

Revert compile_orchestrator.go, setup_repository.go, and
add_interactive_orchestrator.go to os.Getenv("GH_HOST") checks.

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
auto-merge was automatically disabled July 21, 2026 05:39

Head branch was pushed to by a user without write access

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address the failed checks listed below , review any remaining unresolved feedback , rerun checks once the branch is up to date

Failed checks:...

Fixed in the latest commit. Root cause: the isAnyGitHubHostEnvVarSet() refactor broadened the git-remote auto-detection bypass to include all four host env vars, but GITHUB_SERVER_URL is always set in CI (to https://github.com), which caused the bypass to fire and skip the git-remote detection entirely.

The fix reverts compile_orchestrator.go, setup_repository.go, and add_interactive_orchestrator.go to the original os.Getenv("GH_HOST") guard — only GH_HOST should bypass remote detection since it's the env var that configures the gh CLI's target host. GITHUB_SERVER_URL and the other vars are informational automation vars that should not prevent local git remote detection. All five previously failing tests now pass locally.

@pelikhan
pelikhan merged commit af31d0b into main Jul 21, 2026
23 checks passed
@pelikhan
pelikhan deleted the copilot/testify-expert-improve-test-quality-yet-again branch July 21, 2026 06:37
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.15

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.

[testify-expert] Improve Test Quality: pkg/parser/github_host_test.go

4 participants