From 776504db350a49f6d7ddbe00f8b872bfc1b558f7 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 05:35:28 -0500 Subject: [PATCH] test: cover bare query-string href branch in the real e2e build rewriteHref()'s empty-path early return (if (!original) return href;) for a bare query/fragment destination like '?view=raw' was 100% unit-covered in isolation (lib/remarkRewriteLinks/index.test.mts: 'leaves a bare query/fragment href (empty path) untouched') but no e2e build exercised it through the real remark pipeline wired into a Docusaurus build. Every other e2e link in e2e/linkRewrite.test.mjs has a non-empty path, so a regression confined to this early return (e.g. one that started stripping the query string instead of leaving the href untouched) would pass every existing unit and e2e assertion. Adds a describe block that writes a temporary fixture containing such a link into the real content tree, runs a docusaurus build, and asserts the rewritten anchor still carries the untouched query string, removing the fixture afterward so no content change survives the test run. No production code changed - test-only. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- e2e/linkRewrite.test.mjs | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/e2e/linkRewrite.test.mjs b/e2e/linkRewrite.test.mjs index 03069482..352ec4d6 100644 --- a/e2e/linkRewrite.test.mjs +++ b/e2e/linkRewrite.test.mjs @@ -344,3 +344,60 @@ describe('production build rewrites .mdx link destinations end-to-end', () => { ); }); }); + +// `lib/remarkRewriteLinks/index.test.mts` unit-tests rewriteHref()'s bare +// query/fragment branch directly ("leaves a bare query/fragment href (empty +// path) untouched", asserting `rewriteHref('?view=raw', source) === +// '?view=raw'`), but no suite had exercised that branch through the real +// remark pipeline wired into a Docusaurus build: splitHref() returns an +// empty `path` only when the href is a query string with no leading path +// segment, so `if (!original) return href;` short-circuits before the +// cross-plugin/asset rewrite logic runs. Every other e2e link in this file +// has a non-empty path, so a regression that dropped or mis-handled this +// early return (e.g. one that started stripping the query string instead of +// leaving the href untouched) would pass every existing unit and e2e +// assertion. This suite writes a temporary fixture containing such a link +// into the real content tree so the genuine build exercises it, removing +// the fixture afterward so no content change survives the test run. +describe('production build leaves a bare query-string link destination untouched end-to-end', () => { + const fixture = path.join( + repoRoot, + 'analyses/2024/keda/e2e-bare-query-fixture.md', + ); + let outDir; + + before(async () => { + await writeFile( + fixture, + [ + '---', + 'title: E2E bare query-string fixture', + '---', + '', + '# E2E bare query-string fixture', + '', + 'See [raw view](?view=raw) for details.', + '', + ].join('\n'), + ); + outDir = await mkdtemp(path.join(tmpdir(), 'techdocs-e2e-bare-query-')); + execFileSync('npx', ['docusaurus', 'build', '--out-dir', outDir], { + cwd: repoRoot, + env: { ...process.env, BUILD_ENV: 'dev', DEPLOY_PRIME_URL: '' }, + stdio: 'inherit', + }); + }); + + after(async () => { + await unlink(fixture).catch(() => {}); + if (outDir) await rm(outDir, { recursive: true, force: true }); + }); + + it('leaves the bare query-string href unchanged instead of rewriting or stripping it', async () => { + const html = await readFile( + path.join(outDir, 'analyses/2024/keda/e2e-bare-query-fixture/index.html'), + 'utf-8', + ); + assert.match(html, /raw view<\/a>/); + }); +});