Skip to content

test: cover lib/getBuildContext, getCurrentBranch, getGitHubRepoUrl - #389

Open
hivecommons-hive[bot] wants to merge 1 commit into
mainfrom
quality/test-lib-env-helpers
Open

hivecommons-hive[bot] wants to merge 1 commit into
mainfrom
quality/test-lib-env-helpers

Conversation

@hivecommons-hive

Copy link
Copy Markdown

Test Improvement

lib/getBuildContext.ts, lib/getCurrentBranch.ts, and lib/getGitHubRepoUrl.ts had no unit tests (the only existing suite in the repo is lib/remarkRewriteLinks/index.test.mts). These helpers compute the Docusaurus build context, including the asset base URL used for deploy-preview links, so an incorrect precedence or regex change here silently breaks links without any test failing.

Adds node:test suites (consistent with the existing lib/remarkRewriteLinks/index.test.mts style) covering:

  • getCurrentBranch: HEAD/BRANCH/GITHUB_HEAD_REF/GITHUB_REF_NAME precedence and the git-plumbing fallback
  • getGitHubRepoUrl: SSH and HTTPS remote URL normalization (with/without .git), REPOSITORY_URL precedence over git, and the unparsed-input fallback
  • getBuildContext: production vs. deploy-preview branching and the resulting assetBranch/assetRepo/assetBaseUrl

getBuildContext.ts's own imports of getCurrentBranch/getGitHubRepoUrl lacked file extensions, which the project's own npm run test:unit (node --experimental-strip-types) cannot resolve — this silently made the file untestable under the project's existing test runner. Added the .ts extensions so the new tests can run; npm run docus:build still succeeds unchanged.

Verified locally: npm run test:unit (32/32 passing, up from 16), npx prettier --check, npx cspell, and npm run docus:build.


Filed by quality agent (hold-gated mode). Human review required.

— hive: agent=quality backend=copilot model=claude-opus-4-6

These three modules compute the Docusaurus build context (deploy-preview
branch/repo detection and the resulting asset base URL) and had no unit
coverage. Add node:test suites exercising the env-var precedence rules
in getCurrentBranch, the SSH/HTTPS URL normalization and REPOSITORY_URL
fallback in getGitHubRepoUrl, and the production/deploy-preview branching
in getBuildContext.

getBuildContext.ts imported its sibling modules without file extensions,
which node --experimental-strip-types (the project's own test:unit
runner) cannot resolve. Add the .ts extensions so the new tests, and any
future ones, can actually run; docusaurus build still resolves these
extensionless-or-not imports fine, so this does not change build output.

Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive

Copy link
Copy Markdown
Author

Important

Held for human review 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.

Hive will keep the hold label until a human removes it. 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 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cncf-techdocs ready!

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

Choose a reason for hiding this comment

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

Read the tree at the PR head and verified the claims locally — this looks correct to me.

What I checked:

  • The only non-test change is lib/getBuildContext.ts:1-2, adding .ts extensions to the two relative imports. tsconfig.json already sets allowImportingTsExtensions: true at base, so the editor/type experience is unaffected, and the sole runtime caller (docusaurus.config.ts:7) is untouched. The netlify deploy-preview check (a full site build) is green on this head, confirming docus:build still resolves the extensioned imports.
  • Ran npm ci && npm run test:unit at head 58335be: 32/32 pass, up from 16 at base — matches the PR body exactly. Without the extension change, node --experimental-strip-types cannot resolve ./getCurrentBranch, so the new getBuildContext.test.mts genuinely requires it.
  • Test assertions match the actual precedence in the sources: HEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME (lib/getCurrentBranch.ts:4-10) and REPOSITORY_URL-before-git with SSH/HTTPS normalization (lib/getGitHubRepoUrl.ts:4-24). Env save/restore in each suite is correct and leak-free.

One low-severity note (not a blocker): the two git-fallback tests in lib/getGitHubRepoUrl.test.mts:40-55 assert the origin remote matches …/techdocs$. That holds in this repo's checkouts and CI, but would fail in a fork cloned under a renamed remote. Acceptable as-is; worth knowing if these tests ever flake.

No security, scope, or docs concerns — the diff does exactly what the body says. I'm not able to approve; a maintainer's sign-off is still needed (the PR carries the hold label by design).

— hive: agent=reviewer backend=copilot model=claude-fable-5

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant