Skip to content

test: cover add-frontmatter.mjs main() catch block and empty-frontmatter branch - #402

Merged
nate-double-u merged 2 commits into
mainfrom
quality/test-add-frontmatter-main-catch
Nov 13, 2026
Merged

nate-double-u merged 2 commits into
mainfrom
quality/test-add-frontmatter-main-catch

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

scripts/add-frontmatter.mjs was at 97% statements / 90.9% branch coverage
(lines 95-97, the main() catch block for an unrejected glob() call, and
line 60's falsy ternary branch for empty-but-present frontmatter). Both are
now covered:

  • Mocks the glob dependency via node:test's mock.module() to
    deterministically force main()'s own top-level try/catch, which is
    otherwise unreachable: glob() never rejects for missing or unreadable
    directories, so this branch could only be exercised by mocking the
    dependency, not by fixture files on disk.
  • Adds a fixture for frontmatter that is present but empty (no title, no
    other keys), covering the falsy side of the
    frontmatterWithoutTitle ? ... : '' ternary.
  • package.json's test:unit script gains the
    --experimental-test-module-mocks Node flag, required for
    mock.module(); no other script or production code changed.

npm run test:coverage now reports 100% statements/branches/functions/lines
across both lib/ and scripts/ (previously 100% for lib/, 97%/90.9%
for scripts/add-frontmatter.mjs).

Related Issue

N/A — found and fixed directly while re-verifying coverage after #401 merged.


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

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

…ter branch

- Mocks the glob dependency to deterministically exercise main()'s
  top-level try/catch, which was previously unreachable because glob()
  never rejects for missing/unreadable directories.
- Adds a fixture for frontmatter that exists but is empty, covering the
  falsy side of the frontmatterWithoutTitle ternary.
- Requires node's --experimental-test-module-mocks flag (added to
  test:unit) for mock.module() support.

scripts/add-frontmatter.mjs and lib/ now report 100% statement/branch/
function/line coverage under c8 (was 97%/90.9%/100%/97% for scripts/,
100%/100%/100%/100% for lib/).

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

Copy link
Copy Markdown
Contributor 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 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cncf-techdocs ready!

Name Link
🔨 Latest commit d038bc4
🔍 Latest deploy log https://app.netlify.com/projects/cncf-techdocs/deploys/6af66ebac5c32eaa3dd55197
😎 Deploy Preview https://deploy-preview-402--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 added testing Created by Hive for agent-filed issue provenance quality labels Nov 12, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
20aae69

ℹ️ Sentinel notice — informational; author is trusted (hive agent), merge is not blocked

Hive flagged this PR (author @hivecommons-hive[bot], head 20aae69eb481) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation — a maintainer should confirm the change is intended before it merges.

  • sensitive_path — changes 1 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • package.json

Hive did not add the sentinel-alert label because this author is trusted. The finding remains recorded for audit and the dashboard Security tab; set sentinel.trusted_authors_block: true to require the blocking label for trusted authors too.

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

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

Reviewed by reviewer — no findings.

Reviewer notes

Read the script and ran the suite locally — this looks correct to me.

Verified against the tree at head 20aae69:

  • Empty-frontmatter test (scripts/add-frontmatter.test.mjs:86-97): traced the fixture ---\n\n---\n… through frontmatterRegex in scripts/add-frontmatter.mjs:6 — it matches with an empty capture group, so hasFrontmatter is true and frontmatterWithoutTitle at add-frontmatter.mjs:57-59 trims to '', hitting the falsy side of the ternary on line 60 as claimed. The asserted output is what the script produces.
  • main() catch test (scripts/add-frontmatter.test.mjs:124-152): mock.module('glob') correctly intercepts the bare 'glob' specifier imported at add-frontmatter.mjs:2; the mocked rejection lands in main()'s catch (add-frontmatter.mjs:95-97), and process.exit/console.error are mocked and restored in a finally. The cache-busting query plus a setTimeout(0) tick handles the fact that top-level main() is not awaited. Other tests run the script via execFileSync in a child process, so the module mock cannot leak into them.
  • --experimental-test-module-mocks flag: added only to test:unit in package.json:40; no production script changes.

Ran npm ci && npm run test:unit on the PR head with Node 26: 48/48 pass, including both new tests. Note the repo's CI checks (format/link/spelling/markdown/netlify) don't run the unit suite, so the local run is the only execution evidence — all green.

No findings. The PR carries a hold label for human review per the quality lane's gating; nothing here should block that sign-off.

@nate-double-u
nate-double-u enabled auto-merge (squash) November 13, 2026 01:53
nate-double-u pushed a commit that referenced this pull request Nov 13, 2026
package.json's test:coverage script (added in #397) reported coverage
but never failed the build on regression: c8's defaults are 0% for
branches/functions/statements and 90% for lines. #396 deliberately
deferred adding thresholds until in-flight coverage PRs merged, to
avoid landing the gate red.

lib/ is now 100% across all four metrics (after #389/#392/#394/#401).
Only scripts/add-frontmatter.mjs remains below 100% branch coverage,
tracked by the still-open #402. Set thresholds at the currently
achieved levels (99/99/97/100) so the gate passes today and catches
any future regression; it can be tightened to --100 once #402 merges.

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

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@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 hold 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.

Co-authored-by: nate-double-u <4453979+nate-double-u@users.noreply.github.com>
auto-merge was automatically disabled November 13, 2026 01:58

Head branch was pushed to by a user without write access

Copilot AI requested a review from nate-double-u November 13, 2026 01:58
@nate-double-u
nate-double-u enabled auto-merge (squash) November 13, 2026 02:05
@nate-double-u
nate-double-u merged commit 3f7c75c into main Nov 13, 2026
9 checks passed
@nate-double-u
nate-double-u deleted the quality/test-add-frontmatter-main-catch branch November 13, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quality testing Created by Hive for agent-filed issue provenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants