From 66c131910767217544636147d174116200ca0475 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:27:40 -0500 Subject: [PATCH] test: cover deploy-preview branch/repo wiring in e2e link-rewrite suite 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> --- e2e/linkRewrite.test.mjs | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/e2e/linkRewrite.test.mjs b/e2e/linkRewrite.test.mjs index 31e46b6e..dc905cf8 100644 --- a/e2e/linkRewrite.test.mjs +++ b/e2e/linkRewrite.test.mjs @@ -62,3 +62,52 @@ describe('production build applies the link-rewrite plugins end-to-end', () => { ); }); }); + +// The production build above always resolves to the `main` branch/repo +// because `BUILD_ENV=dev` + a cleared `DEPLOY_PRIME_URL` keeps +// getBuildContext() out of deploy-preview mode. getCurrentBranch() and +// getGitHubRepoUrl() are 100% unit-covered in isolation +// (lib/getCurrentBranch.test.mts, lib/getGitHubRepoUrl.test.mts), but no +// suite asserted that docusaurus.config.ts's assetBaseUrl actually wires +// their deploy-preview output into the rewritten .csv link during a real +// build. This suite exercises exactly that path with deterministic env +// vars, so a regression in that wiring fails here even when the unit +// tests for each helper still pass in isolation. +describe('deploy-preview build wires branch/repo detection into the rewritten .csv link', () => { + let outDir; + + before(async () => { + outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-preview-')); + execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], { + cwd: repoRoot, + env: { + ...process.env, + BUILD_ENV: 'deploy-preview', + DEPLOY_PRIME_URL: 'https://deploy-preview-1--cncf-techdocs.netlify.app', + // Pin branch/repo detection to deterministic values instead of + // 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', + REPOSITORY_URL: 'https://github.com/example-org/example-repo', + }, + stdio: 'inherit', + }); + }); + + after(async () => { + if (outDir) await rm(outDir, { recursive: true, force: true }); + }); + + it('rewrites the .csv asset link to the preview branch and repo, not main', async () => { + const html = await readFile( + path.join(outDir, 'analyses/2023/backstage/index.html'), + 'utf-8', + ); + assert.match( + html, + /https:\/\/github\.com\/example-org\/example-repo\/blob\/e2e-preview-branch\/analyses\/2023\/backstage\/backstage-doc-survey\.csv/, + ); + assert.doesNotMatch(html, /\/blob\/main\//); + }); +});