Skip to content

test: cover deploy-preview branch/repo wiring in e2e link-rewrite suite - #426

Open
hivecommons-hive[bot] wants to merge 2 commits into
mainfrom
quality/test-e2e-deploy-preview
Open

hivecommons-hive[bot] wants to merge 2 commits into
mainfrom
quality/test-e2e-deploy-preview

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

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 (npm run test:coverage). A regression in how docusaurus.config.ts wires their combined output (assetBaseUrl) into the rewritten .csv asset link during a real Netlify deploy preview would have passed both the unit suite and the existing e2e suite.

This adds a second docusaurus build in e2e/linkRewrite.test.mjs with BUILD_ENV=deploy-preview, a truthy DEPLOY_PRIME_URL, and deterministic GITHUB_REF_NAME/REPOSITORY_URL env vars (the same env vars getCurrentBranch()/getGitHubRepoUrl() already read for Netlify/GitHub Actions deploy previews), asserting the rendered .csv blob URL reflects the preview branch/repo instead of main.

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 cspell on 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

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>
@hivecommons-hive hivecommons-hive Bot added the ready-for-review Hive's work is done; a maintainer reviews, then removes this label to let it merge. label Nov 18, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

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 outreach PR that targets a repository this hive does not manage is held at every level because it publishes project-facing communication into someone else's project.

The hive's work on this PR is done. Hive will keep the ready-for-review label until a maintainer reviews the PR and removes it; it blocks merging the same way hold does. Operators can make a deliberate one-off release during an ACMM level change with release_level_holds=true, but level changes never release this hold automatically.

@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cncf-techdocs ready!

Name Link
🔨 Latest commit 8e136d6
🔍 Latest deploy log https://app.netlify.com/projects/cncf-techdocs/deploys/6afdc50c95d7011a09917062
😎 Deploy Preview https://deploy-preview-426--cncf-techdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread e2e/linkRewrite.test.mjs
// 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',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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',

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread e2e/linkRewrite.test.mjs
// 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',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
GITHUB_REF_NAME: 'e2e-preview-branch',
HEAD: '',
BRANCH: '',
GITHUB_HEAD_REF: '',
GITHUB_REF_NAME: 'e2e-preview-branch',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Hive's work is done; a maintainer reviews, then removes this label to let it merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] e2e suite never exercises the deploy-preview branch/repo wiring

1 participant