Repository navigation
test: cover getBuildContext repo/main fallback in the real e2e build - #445
Conversation
getBuildContext.ts's getCurrentBranch() || 'main' and getGitHubRepoUrl() || repo fallback branches were 100% unit-covered in isolation but never exercised by a real docusaurus build: every existing deploy-preview e2e case either sets GITHUB_REF_NAME / REPOSITORY_URL directly, or clears them while still running inside this checkout's real git repo, so the git fallback inside getCurrentBranch()/getGitHubRepoUrl() always returned a truthy value and the || fallbacks in getBuildContext.ts never ran. Adds a describe block that runs a deploy-preview build with every git-fallback env var cleared and GIT_DIR/GIT_WORK_TREE pointed at a nonexistent path, so the real git commands fail safely without touching this checkout's actual .git, then asserts the rewritten asset link falls back to the hard-coded repo constant and main branch. 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 chain at head 3c4521f, not just the diff; this looks correct to me.
- All five env vars are set to
'', which is falsy for the||chains inlib/getCurrentBranch.ts:5-11andlib/getGitHubRepoUrl.ts:19-23, so neither env branch fires. GIT_DIR/GIT_WORK_TREEpointed at a nonexistent path makes bothexecSync('git ...')calls throw (git honorsGIT_DIRover cwd discovery), landing in thecatch { return undefined; }atgetCurrentBranch.ts:19-21andgetGitHubRepoUrl.ts:30-32, without touching this checkout's real.git.- With both helpers returning
undefined,lib/getBuildContext.ts:17-18yields'main'and therepoargument, whichdocusaurus.config.ts:11hard-codes ashttps://github.com/cncf/techdocs- exactly what the assertion matches againstanalyses/2023/backstage/index.html(the.csvlink exists atanalyses/2023/backstage/index.md:18). - Nothing else in the build reads git:
docusaurus.config.tssets noshowLastUpdateTime/lastUpdateoptions, so the brokenGIT_DIRis confined to the two helpers.
One heads-up, not a defect: #444 appends a different describe block at the same end-of-file position in e2e/linkRewrite.test.mjs, so whichever of #444/#445 merges second will need a trivial rebase. The two cover opposite branches (git fallback succeeding vs. both detections failing) - I compared both diffs and they are complementary, not duplicates.
Test-only change, Refs #440 usage matches the tracker's folded-gap structure, and all checks are green. I cannot approve; a maintainer's sign-off is still needed.
-- hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the added deploy-preview repository and branch fallback coverage.
No open issues 🎉
What changed in this PR
Adds real-build coverage for the deploy-preview repository and branch defaults in getBuildContext.ts, complementing existing unit tests without changing production code.
Changes:
- Clears branch/repository environment inputs and points Git at a nonexistent path to force detection failures.
- Asserts that the generated CSV link uses
cncf/techdocsandmain, then removes the temporary build output.
| File | Description |
|---|---|
e2e/linkRewrite.test.mjs |
Adds a deploy-preview build test for repository and branch fallback behavior. |
Review effort: Balanced
# Conflicts: # e2e/linkRewrite.test.mjs
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.
|
There was a problem hiding this comment.
Read the diff against lib/getBuildContext.ts, lib/getCurrentBranch.ts, lib/getGitHubRepoUrl.ts, and docusaurus.config.ts. The test is correct:
- Pointing
GIT_DIR/GIT_WORK_TREEat a nonexistent path makes bothexecSync('git ...')calls throw, which thecatchblocks inlib/getCurrentBranch.ts:19-21andlib/getGitHubRepoUrl.ts:31-33convert toundefined, sogetBuildContext.ts:17-18takes its|| 'main'and|| repobranches. The asserted URL matches therepoconstant atdocusaurus.config.ts:11(https://github.com/cncf/techdocs). - Breaking git for the child build is safe here:
docusaurus.config.tssets noshowLastUpdateTime/showLastUpdateAuthor, andeditUrlis built from the staticrepostring, so nothing else in the build shells out to git. - Empty-string env clearing works because both helpers use
||chains. - Branch is up to date with main (includes the #441 merge).
This fills a real gap: every existing deploy-preview case either sets the env vars or runs inside a working checkout, so the hard-coded repo/main fallback was never exercised by a real build. Not a duplicate of #444, which covers the git-fallback success path; note both PRs insert a describe block at the same point after line 258 of e2e/linkRewrite.test.mjs, so whichever lands second will need a trivial rebase.
Looks correct to me; a maintainer can merge once satisfied.
-- hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
There was a problem hiding this comment.
Read the diff against the tree at merge-base. The mechanism checks out:
- Pointing
GIT_DIR/GIT_WORK_TREEat a nonexistent path makesgit branch --show-currentandgit remote get-url originfail; both helpers catch and returnundefined(lib/getCurrentBranch.ts:19-21,lib/getGitHubRepoUrl.ts:30-32), sogetBuildContext.ts:18-19's|| 'main'/|| repofallbacks are genuinely exercised by the real build. - I checked that nothing else under
lib/shells out to git, so theGIT_DIRoverride cannot break any other part of the Docusaurus build. - Empty-string env vars are falsy in both helpers, so the cleared vars correctly skip the env branches.
Coordination note: this PR and #444 insert their describe blocks at the same position in e2e/linkRewrite.test.mjs (after original line 258). They cover complementary branches (git fallback failing here, succeeding in #444) and both should land; the second one in will need a trivial rebase.
Test-only change, all checks green. Looks correct to me; a maintainer still needs to approve per the hold gate.
-- hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
Test Improvement
Adds a describe block to
e2e/linkRewrite.test.mjs(deploy-preview build falls back to repo/main when branch and remote detection both fail) that runs a deploy-previewdocusaurus buildwith every git-fallback env var cleared (HEAD/BRANCH/GITHUB_HEAD_REF/GITHUB_REF_NAME/REPOSITORY_URL) andGIT_DIR/GIT_WORK_TREEpointed at a nonexistent path, sogit branch --show-current/git remote get-url originfail safely (without touching this checkout's real.git), then asserts the rewritten.csvasset link falls back to the hard-codedrepoconstant andmainbranch.getBuildContext.ts'sgetCurrentBranch() || 'main'andgetGitHubRepoUrl() || repofallback branches were already 100% unit-covered (lib/getBuildContext.test.mts) but no e2e suite exercised them, since every existing deploy-preview case either sets the GitHub-Actions-style env vars directly or clears them while still running inside this checkout's real git repo (so the git fallback always returned a truthy value).Verified locally:
npm run test:e2epasses (13/13),npm run test:coveragestill reports 100/100/100/100,npm run check:format/check:spelling/test:unitall pass, andgit statusis clean after the run. e2e-only branch coverage ongetBuildContext.ts(npx c8 --include lib/getBuildContext.ts node --test 'e2e/**/*.test.mjs') rises from 69.23% to 84.61%; the remaining two branches (the BUILD_ENV-unset default and the isProd short-circuit) are unrelated to this fallback and already 100% unit-covered.No production code changed - test-only.
Related Issue
Refs #440 (that issue is a folded tracker for
e2e/linkRewrite.test.mjscoverage gaps; this PR covers thegetBuildContext.tsfallback-branch variant specifically, a distinct gap from the.mdx-stripping variant PR #441 addresses in the same tracked issue)Filed by quality agent (hold-gated mode). Human review required.
-- hive: agent=quality backend=copilot model=claude-opus-4-6 copilot=1.0.88