Skip to content

test: cover getBuildContext repo/main fallback in the real e2e build - #445

Merged
nate-double-u merged 4 commits into
mainfrom
quality/test-build-context-fallback
Nov 24, 2026
Merged

nate-double-u merged 4 commits into
mainfrom
quality/test-build-context-fallback

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

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-preview docusaurus build with every git-fallback env var cleared (HEAD/BRANCH/GITHUB_HEAD_REF/GITHUB_REF_NAME/REPOSITORY_URL) and GIT_DIR/GIT_WORK_TREE pointed at a nonexistent path, so git branch --show-current/git remote get-url origin fail safely (without touching this checkout's real .git), then asserts the rewritten .csv asset link falls back to the hard-coded repo constant and main branch.

getBuildContext.ts's getCurrentBranch() || 'main' and getGitHubRepoUrl() || repo fallback 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:e2e passes (13/13), npm run test:coverage still reports 100/100/100/100, npm run check:format/check:spelling/test:unit all pass, and git status is clean after the run. e2e-only branch coverage on getBuildContext.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.mjs coverage gaps; this PR covers the getBuildContext.ts fallback-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

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>
@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 23, 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 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cncf-techdocs ready!

Name Link
🔨 Latest commit b3c1906
🔍 Latest deploy log https://app.netlify.com/projects/cncf-techdocs/deploys/6b05e36f4b8d27cec4bdd615
😎 Deploy Preview https://deploy-preview-445--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.

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 in lib/getCurrentBranch.ts:5-11 and lib/getGitHubRepoUrl.ts:19-23, so neither env branch fires.
  • GIT_DIR/GIT_WORK_TREE pointed at a nonexistent path makes both execSync('git ...') calls throw (git honors GIT_DIR over cwd discovery), landing in the catch { return undefined; } at getCurrentBranch.ts:19-21 and getGitHubRepoUrl.ts:30-32, without touching this checkout's real .git.
  • With both helpers returning undefined, lib/getBuildContext.ts:17-18 yields 'main' and the repo argument, which docusaurus.config.ts:11 hard-codes as https://github.com/cncf/techdocs - exactly what the assertion matches against analyses/2023/backstage/index.html (the .csv link exists at analyses/2023/backstage/index.md:18).
  • Nothing else in the build reads git: docusaurus.config.ts sets no showLastUpdateTime/lastUpdate options, so the broken GIT_DIR is 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

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

⚠️ Hold-gate mergeability: this PR has a real conflict with its base

This PR is hold-gated and has fallen behind its base branch. The hive tried to merge the base in to keep it mergeable while it waits on review, but that merge conflicts and the hive cannot resolve it automatically.

It will stay held and will NOT merge on its own even once reviewed — removing decision-needed alone will not be enough. Someone will need to merge or rebase the base branch in by hand (or resolve the conflict another way) before this PR can merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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/techdocs and main, 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
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

  • quality (2026-11-24 03:40 UTC): Rebased onto current main to resolve the real conflict in e2e/linkRewrite.test.mjs (the new .mdx-link describe block from a recently merged PR landed at the same end-of-file position). Re-ran the full e2e/linkRewrite.test.mjs suite locally after the merge: all 15 tests pass. No change to this PR's own test logic.

@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 diff against lib/getBuildContext.ts, lib/getCurrentBranch.ts, lib/getGitHubRepoUrl.ts, and docusaurus.config.ts. The test is correct:

  • Pointing GIT_DIR/GIT_WORK_TREE at a nonexistent path makes both execSync('git ...') calls throw, which the catch blocks in lib/getCurrentBranch.ts:19-21 and lib/getGitHubRepoUrl.ts:31-33 convert to undefined, so getBuildContext.ts:17-18 takes its || 'main' and || repo branches. The asserted URL matches the repo constant at docusaurus.config.ts:11 (https://github.com/cncf/techdocs).
  • Breaking git for the child build is safe here: docusaurus.config.ts sets no showLastUpdateTime/showLastUpdateAuthor, and editUrl is built from the static repo string, 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the added end-to-end coverage of default repository and branch fallback behavior.

No open issues 🎉

Review effort: Balanced

@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 diff against the tree at merge-base. The mechanism checks out:

  • Pointing GIT_DIR/GIT_WORK_TREE at a nonexistent path makes git branch --show-current and git remote get-url origin fail; both helpers catch and return undefined (lib/getCurrentBranch.ts:19-21, lib/getGitHubRepoUrl.ts:30-32), so getBuildContext.ts:18-19's || 'main' / || repo fallbacks are genuinely exercised by the real build.
  • I checked that nothing else under lib/ shells out to git, so the GIT_DIR override 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

@nate-double-u
nate-double-u merged commit 3cde87f into main Nov 24, 2026
9 checks passed
@nate-double-u
nate-double-u deleted the quality/test-build-context-fallback branch November 24, 2026 19:22
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.

2 participants