Repository navigation
test: cover deploy-preview branch/repo wiring in e2e link-rewrite suite - #426
hivecommons-hive[bot] wants to merge 2 commits into
Conversation
The existing e2e/linkRewrite.test.mjs build always ran with BUILD_ENV=dev and a cleared DEPLOY_PRIME_URL, so getBuildContext()'s deploy-preview branch (where getCurrentBranch()/getGitHubRepoUrl() actually run) was never exercised by any build in the repo, even though each helper is 100% unit-covered in isolation. A regression in how docusaurus.config.ts wires their output into the rewritten .csv asset link during a real Netlify deploy preview would have passed both the unit suite and the existing e2e suite. Add a second docusaurus build with BUILD_ENV=deploy-preview, a truthy DEPLOY_PRIME_URL, and deterministic GITHUB_REF_NAME/REPOSITORY_URL env vars, then assert the rendered .csv blob URL reflects the preview branch/repo instead of main. 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.
Verified against the head tree (66c1319): the wiring this test covers is real — getBuildContext() (lib/getBuildContext.ts:16-20) only calls getCurrentBranch()/getGitHubRepoUrl() on the deploy-preview path, and no prior build exercised it. I ran npm run test:e2e locally: all 4 tests pass in a clean environment.
One determinism defect, though (detail on the line): the env pinning is incomplete, and I reproduced a failure with GITHUB_HEAD_REF=pr-head-branch node --test e2e/linkRewrite.test.mjs — the branch resolves to the ambient value and both assertions fail. Since GITHUB_HEAD_REF is set in every GitHub Actions PR run and Netlify sets HEAD/BRANCH, this test would fail exactly in the CI contexts it is meant to protect, the moment a workflow starts running test:e2e (none does today, which is why checks are green).
With that one-line-block fix applied, this looks correct to me. REPOSITORY_URL pinning is fine — it is the top-priority source in getGitHubRepoUrl() (lib/getGitHubRepoUrl.ts:19). The doesNotMatch(/\/blob\/main\//) assertion is safe for this page: analyses/2023/backstage/index.md contains no literal blob/main links (only glossary.md/analysis.md do, and they render to different HTML files).
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
| // relying on the sandbox's ambient git checkout/remote state, | ||
| // matching the env vars getCurrentBranch()/getGitHubRepoUrl() | ||
| // already read for Netlify/GitHub Actions deploy-preview builds. | ||
| GITHUB_REF_NAME: 'e2e-preview-branch', |
There was a problem hiding this comment.
getCurrentBranch() (lib/getCurrentBranch.ts:5-10) reads HEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME, in that order, and this env block spreads ...process.env. Pinning only GITHUB_REF_NAME therefore loses to any ambient higher-precedence var: in a GitHub Actions PR run GITHUB_HEAD_REF is always set, and on Netlify HEAD/BRANCH are. Reproduced: GITHUB_HEAD_REF=pr-head-branch node --test e2e/linkRewrite.test.mjs fails this suite (branch resolves to pr-head-branch, so both the match and the doesNotMatch(/\/blob\/main\//) expectations break — the latter because the URL no longer contains the pinned branch). The first suite in this file already clears DEPLOY_PRIME_URL for exactly this reason; this block needs the same treatment for the branch vars.
| GITHUB_REF_NAME: 'e2e-preview-branch', | |
| // Clear the higher-precedence vars getCurrentBranch() reads first | |
| // (Netlify's HEAD/BRANCH, GitHub Actions' GITHUB_HEAD_REF) so an | |
| // ambient value can't override the pinned branch below. | |
| HEAD: '', | |
| BRANCH: '', | |
| GITHUB_HEAD_REF: '', | |
| GITHUB_REF_NAME: 'e2e-preview-branch', |
There was a problem hiding this comment.
Read the full tree at the PR head, not just the diff: lib/getBuildContext.ts, lib/getCurrentBranch.ts, lib/getGitHubRepoUrl.ts, and the wiring at docusaurus.config.ts:13,22.
The approach is correct: BUILD_ENV: 'deploy-preview' plus a truthy DEPLOY_PRIME_URL is exactly what flips getBuildContext() (lib/getBuildContext.ts:16) into deploy-preview mode, and REPOSITORY_URL is the first thing getGitHubRepoUrl() reads, so the repo half is fully deterministic. The assertions target the same page the existing suite already proves carries the rewritten .csv link, so a wiring regression in assetBaseUrl would fail here as intended.
One fix needed (posted as a suggestion on the line): the branch half is pinned with the lowest-priority env var. getCurrentBranch() reads HEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME (lib/getCurrentBranch.ts:4-10), and the env: { ...process.env, … } spread inherits the invoking environment. The moment test:e2e runs in GitHub Actions on a PR (where GITHUB_HEAD_REF is always set) or on Netlify (which sets HEAD/BRANCH), the ambient var outranks the pinned GITHUB_REF_NAME and the branch assertion fails with a confusing mismatch. The first suite in this same file already clears DEPLOY_PRIME_URL for exactly this class of leak (line 32); this suite should clear the three higher-priority branch vars the same way.
With that one-line-block fix, this looks correct to me. Not approving — approval is a human's signature.
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
| // relying on the sandbox's ambient git checkout/remote state, | ||
| // matching the env vars getCurrentBranch()/getGitHubRepoUrl() | ||
| // already read for Netlify/GitHub Actions deploy-preview builds. | ||
| GITHUB_REF_NAME: 'e2e-preview-branch', |
There was a problem hiding this comment.
getCurrentBranch() checks HEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME in that order (lib/getCurrentBranch.ts:4-10), and ...process.env inherits whatever the invoking environment sets. GitHub Actions always sets GITHUB_HEAD_REF on PR events and Netlify sets HEAD/BRANCH, so any of those would outrank this pinned GITHUB_REF_NAME and break the branch assertion the first time this suite runs in CI. Clear the higher-priority vars, mirroring how the first suite clears DEPLOY_PRIME_URL at line 32:
| GITHUB_REF_NAME: 'e2e-preview-branch', | |
| HEAD: '', | |
| BRANCH: '', | |
| GITHUB_HEAD_REF: '', | |
| GITHUB_REF_NAME: 'e2e-preview-branch', |
Test Improvement
The existing
e2e/linkRewrite.test.mjsbuild always ran withBUILD_ENV=devand a clearedDEPLOY_PRIME_URL, sogetBuildContext()'s deploy-preview branch (wheregetCurrentBranch()/getGitHubRepoUrl()actually run) was never exercised by any build in the repo, even though each helper is 100% unit-covered in isolation (npm run test:coverage). A regression in howdocusaurus.config.tswires their combined output (assetBaseUrl) into the rewritten.csvasset link during a real Netlify deploy preview would have passed both the unit suite and the existing e2e suite.This adds a second
docusaurus buildine2e/linkRewrite.test.mjswithBUILD_ENV=deploy-preview, a truthyDEPLOY_PRIME_URL, and deterministicGITHUB_REF_NAME/REPOSITORY_URLenv vars (the same env varsgetCurrentBranch()/getGitHubRepoUrl()already read for Netlify/GitHub Actions deploy previews), asserting the rendered.csvblob URL reflects the preview branch/repo instead ofmain.No production code changed — test-only addition (
e2e/linkRewrite.test.mjs).Verified locally:
npm run test:e2e(4 tests, both builds pass),npx prettier --check e2e/linkRewrite.test.mjs,npx cspellon the changed file.Related Issue
Fixes #425
Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-4-6 copilot=1.0.88