Repository navigation
test: cover real git branch/remote fallback wiring in docusaurus.config.ts - #436
Conversation
…ig.ts getCurrentBranch()'s 'git branch --show-current' fallback and getGitHubRepoUrl()'s 'git remote get-url origin' fallback are 100% unit-covered in isolation, but every integration test that exercises docusaurus.config.ts's deploy-preview assetBaseUrl wiring pins all five branch/repo env vars for determinism, so the real git fallback never ran in any existing test. Add one case that clears those env vars and asserts assetBaseUrl matches the real getCurrentBranch()/getGitHubRepoUrl() output composed the same way getBuildContext.ts composes it. Fixes #435 Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Important Ready for review: held for a maintainer by the hive's ACMM level gate. This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Agent PRs are held at ACMM L3-L5; an The hive's work on this PR is done. Hive will keep the |
✅ Deploy Preview for cncf-techdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Read the full diff plus the code it wires through, and ran the suite locally. This looks correct to me.
What I verified:
- The child harness spawns with all five branch/repo env vars set to
''(readConfigUrls'sBRANCH_AND_REPO_ENVplus the explicit overrides), and bothlib/getCurrentBranch.ts:5-11andlib/getGitHubRepoUrl.ts:19-23treat empty strings as falsy, so the realgit branch --show-current/git remote get-url originfallbacks genuinely run in the spawned build - this is the path no prior case covered. - The parent computes expectations by deleting the same five vars, calling the same helpers, and restoring in a
finally, so parent and child see identical git state and the assertion is deterministic on any checkout (detached HEAD included, where both sides collapse to'main'). - The
|| 'main'/|| 'https://github.com/cncf/techdocs'defaults mirrorlib/getBuildContext.ts:17-18exactly, so the test proves the wiring without reimplementing helper logic. - Ran
node --experimental-strip-types --test lib/docusaurusConfigBuildContext.test.mtson the PR head from a clone on a non-main branch: 6/6 pass, and the new case exercised a real non-default branch name, confirming it is not vacuous.
One known limitation, not a defect of this PR: on a detached-HEAD checkout of main the new case degenerates to asserting the defaults, so it is weakest in exactly that environment - and per the existing CI setup the unit suite is not run by any workflow anyway, so this guards local/agent runs only.
I cannot approve as a bot; recommending a maintainer merge. No changes requested.
-- hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
As written, this test can still pass even if the git fallback never actually works in the runtime… · New The harness run viareadConfigUrlsexecutes incwd: repoRoot(per the helper’s implementation),… · New This test case claims to run with “no env overrides”, but it actually passes the branch/repo env… · New
What changed in this PR
Adds an integration test case to ensure docusaurus.config.ts build wiring uses the real git-derived branch/repo (via existing helpers) when no CI env overrides are present.
Changes:
- Import
getCurrentBranch()andgetGitHubRepoUrl()into the config build-context test. - Add a new
it()case that clears branch/repo env vars, runs the config harness, and assertsassetBaseUrlmatches the helper-composed expectation.
| File | Description |
|---|---|
| lib/docusaurusConfigBuildContext.test.mts | Adds an integration test covering deploy-preview assetBaseUrl wiring when branch/repo env vars are unset. |
Review effort: Lite
| const { assetBaseUrl } = readConfigUrls({ | ||
| BUILD_ENV: 'deploy-preview', | ||
| DEPLOY_PRIME_URL: 'https://deploy-preview-1--cncf-techdocs.netlify.app', | ||
| HEAD: '', | ||
| BRANCH: '', | ||
| GITHUB_HEAD_REF: '', | ||
| GITHUB_REF_NAME: '', | ||
| REPOSITORY_URL: '', | ||
| }); |
There was a problem hiding this comment.
Verified: the case does pass HEAD/BRANCH/etc. through as empty strings rather than omitting the keys, and this matches the BRANCH_AND_REPO_ENV convention used by every other case in this file (all rely on the helpers' truthiness check, documented in the comment above BRANCH_AND_REPO_ENV). Changing that to true key-deletion would mean reworking readConfigUrls's shared harness used by all 10+ existing cases, which is out of scope for this test-only addition and risks regressing the rest of the file.
Changed in commit 85daf30: renamed the test and reworded the comment above it to say the vars are "cleared" rather than claiming "no env overrides," so the test no longer overstates what it does. Left the empty-string mechanism itself unchanged since it is the file's existing, intentional convention, not something unique to this test.
Full suite (77 tests), npm run test:coverage (100% lines/branches/functions/statements), npx prettier --check, and npx cspell all still pass on the updated file.
|
/hive have a look at the copilot findings |
- Skip (rather than vacuously pass) when the real git branch/remote can't be determined in this environment, since the test would otherwise pass by comparing hardcoded defaults against themselves. - Compute the expected branch/repo with cwd set to repoRoot, matching the harness's spawnSync cwd, so the two sides can't diverge based on the test runner's own invocation directory. - Reword the test name/comment: the case clears the branch/repo env vars (empty string, matching the file's existing truthiness-based convention), it does not omit them outright. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Looked at the Copilot code review findings on this PR and verified each one against the actual code in All three were valid:
Pushed as commit 85daf30 on this branch. Reran the full suite (77 tests), No rule or source-of-truth statement was raised in this feedback, so nothing was recorded to the knowledge store. |
There was a problem hiding this comment.
Read the diff against lib/getBuildContext.ts, lib/getCurrentBranch.ts, lib/getGitHubRepoUrl.ts, and the existing harness in this file. The test is correct and proves what it claims:
getBuildContext(lib/getBuildContext.ts:17-19) buildsassetBaseUrlfromgetCurrentBranch() || 'main'andgetGitHubRepoUrl() || repoonly on the deploy-preview path, so clearing HEAD/BRANCH/GITHUB_HEAD_REF/GITHUB_REF_NAME/REPOSITORY_URL does force the realgitfallbacks in the spawned harness (both helpers treat empty-string env as unset via truthiness checks).- The expected value is computed with the same helpers after
process.chdir(repoRoot), matching the harness'scwd: repoRootinreadConfigUrls, so both sides read the same git state. Env keys are saved/deleted/restored correctly around the in-process call. - The skip guard is right: when either helper returns undefined, the config collapses to the
|| 'main'/|| repodefaults and the assertion would pass vacuously, so skipping is the honest outcome (detached-HEAD CI checkouts will hit it). - The
./getCurrentBranch.tsimport style matches the existing lib/*.test.mts idiom.
Test-only change, no production code touched. Looks correct to me - a maintainer can take this as-is.
-- hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

Test Improvement
getCurrentBranch()'sgit branch --show-currentfallback andgetGitHubRepoUrl()'sgit remote get-url originfallback are 100%unit-covered in isolation (
lib/getCurrentBranch.test.mts,lib/getGitHubRepoUrl.test.mts), but every integration test thatexercises
docusaurus.config.ts's deploy-preview wiring of theiroutput into
assetBaseUrlpins all five branch/repo env vars(
HEAD/BRANCH/GITHUB_HEAD_REF/GITHUB_REF_NAME/REPOSITORY_URL)for determinism, so the real git fallback path never ran in any
existing test.
This adds one case to
lib/docusaurusConfigBuildContext.test.mtsthatclears all five env vars and asserts
assetBaseUrlequals the realgetCurrentBranch()/getGitHubRepoUrl()output composed the same waygetBuildContext.tscomposes it, proving the wiring withoutre-testing (or duplicating the logic of) the helpers' own correctness.
No production code changed - test-only addition to
lib/docusaurusConfigBuildContext.test.mts.Verified locally: full suite passes,
npm run test:coveragestays at100% lines/branches/functions/statements,
npx prettier --checkandnpx cspellpass on the changed file. Confirmed the new case actuallycatches a regression: temporarily hard-coding
assetBranch/assetRepoin
getBuildContext.tsto'main'/therepoparam makes it fail.Files/functions touched: only
lib/docusaurusConfigBuildContext.test.mts(one new
it()case). Disjoint from open PRs #428 and #434, which bothtouch
e2e/linkRewrite.test.mjsonly.Related Issue
Fixes #435
Filed by quality agent (hold-gated mode). Human review required.
-- hive: agent=quality backend=copilot model=claude-opus-4-6 copilot=1.0.88