test(helpers): cover the spawn-failure fallbacks in the shared sandboxes - #727
Open
hivecommons-hive[bot] wants to merge 1 commit into
Open
hivecommons-hive[bot] wants to merge 1 commit into
hivecommons-hive[bot] wants to merge 1 commit into
Conversation
runScriptWithFixtures, runScriptWithFetchMock and runWithGhStub each normalise their spawnSync result before returning it (status ?? 1, stdout ?? '', stderr ?? '') and runWithGhStub falls back to an empty PATH tail when PATH is unset. spawnSync reports a failed spawn as status null with stdout/stderr undefined rather than throwing, so those eleven sub-line regions decide what a harness failure looks like to every fixture-driven suite -- and none of them had ever executed. The new file breaks the bare 'node' lookup by removing PATH from the test process, restoring it in a finally. It also pins readBack's documented contract that a path the script never wrote comes back as null. All three helpers reach 100% region coverage; overall region coverage moves 93.34% to 93.54%. Closes #726 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <hivecommons-hive@hive.kubestellar.io>
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. Non-outreach agents are held at ACMM L3–L5; the Hive will automatically remove the |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Improvement
Adds
tests/helpers-spawn-fallbacks.test.mjs, covering the eleven uncoveredsub-line regions in the three shared sandbox helpers:
tests/helpers.mjs(runScriptWithFixtures) —status ?? 1,stdout ?? '',stderr ?? ''(L78-80) and the: nullarm of thereadBackternary (L75).tests/helpers-fetch-mock.mjs(runScriptWithFetchMock) — the samethree fallbacks (L103-105).
tests/helpers-gh-sandbox.mjs(runWithGhStub) —process.env.PATH ?? ''when building the child's PATH (L88) and the same three fallbacks (L111-113).
spawnSyncreports a failed spawn asstatus: nullwithstdout/stderrundefined rather than throwing, so those fallbacks are the only thing
deciding what a harness failure looks like to every fixture-driven suite in
the repository — whether "the script under test failed" stays distinguishable
from "the harness could not start it", and whether
nullleaks into anassertion instead of an empty string. None of them had ever executed.
The spawn is broken by removing
PATHfrom the test process, which makes thebare
nodelookup every helper performs fail withENOENT.PATHis restoredin a
finally, and an up-front assertion documents that the check requiresPATHto have been set;node --testruns the tests within a filesequentially, so no sibling test observes the gap.
The fourth case pins
readBack's documented contract — a path the scriptdeleted or never wrote comes back as
null, which is how write-mode tests tellno output apart from empty output.
Verification
TZ=UTC node tests/tools/coverage-report.mjs, before and after:tests/helpers.mjstests/helpers-fetch-mock.mjstests/helpers-gh-sandbox.mjsnpm run test:unit:coverage:checkpasses, and the new file is itself at 100%region coverage.
npx prettier --checkis clean.Scope
Touches only
tests/helpers-spawn-fallbacks.test.mjs— no existing test, helperor source file is modified. Deliberately disjoint from the open hold-gated PRs:
tests/helpers-import-sandbox.mjsis claimed by #678 andtests/helpers-script-sandbox.mjsby #693, and neither those nor #674, #680,#686, #688, #702, #706, #708, #719, #723 touch
tests/helpers.mjs,tests/helpers-fetch-mock.mjs,tests/helpers-gh-sandbox.mjsortests/helpers.test.mjs.tests/helpers-jsx.mjsL30 (the legacyregister(HOOKS_URL)arm, reachable only on Node < 22.15) is left uncovered andis named as out of scope in the issue.
Related Issue
Closes #726
Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-5 copilot=1.0.88