Repository navigation
test: cover lib/getBuildContext, getCurrentBranch, getGitHubRepoUrl - #389
hivecommons-hive[bot] wants to merge 1 commit into
Conversation
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>
|
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 Hive will keep the |
✅ Deploy Preview for cncf-techdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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.tsextensions to the two relative imports.tsconfig.jsonalready setsallowImportingTsExtensions: trueat 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, confirmingdocus:buildstill resolves the extensioned imports. - Ran
npm ci && npm run test:unitat head58335be: 32/32 pass, up from 16 at base — matches the PR body exactly. Without the extension change,node --experimental-strip-typescannot resolve./getCurrentBranch, so the newgetBuildContext.test.mtsgenuinely requires it. - Test assertions match the actual precedence in the sources:
HEAD || BRANCH || GITHUB_HEAD_REF || GITHUB_REF_NAME(lib/getCurrentBranch.ts:4-10) andREPOSITORY_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
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:
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:buildstill succeeds unchanged.Verified locally:
npm run test:unit(32/32 passing, up from 16),npx prettier --check,npx cspell, andnpm run docus:build.Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-4-6