Repository navigation
test: cover runScriptInSandbox's spawn-failure fallbacks - #1215
Merged
Merged
Conversation
tests/helpers-script-sandbox.mjs was the one sandbox helper whose spawnSync normalisation no test reached, at 80.00% regions. Its five uncovered regions were all of it: the PATH tail it builds for the child, the status/stdout/stderr fallbacks, and realGitPath's last resort. tests/helpers-spawn-fallbacks.test.mjs already pins this contract for helpers.mjs, helpers-fetch-mock.mjs and helpers-gh-sandbox.mjs. This adds the matching file for runScriptInSandbox, which backs the five collect-*.test.mjs suites. Deleting PATH reaches 177 and 200-202. An empty PATH is needed for 229, because /bin/sh with no PATH in its environment falls back to a confstr default that still finds git. 96.67% regions after; the residual is the found.stdout ?? '' arm, which is unreachable while the lookup runs under shell: true. Signed-off-by: quality <quality@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 keep the |
This was referenced Oct 8, 2026
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
Closes #1214.
tests/helpers-script-sandbox.mjswas at 80.00% regions — the lowest of thesix
tests/helpers-*.mjssandbox modules. Its five uncovered regions were allof the normalisation it applies to the
spawnSyncresult before handing it to atest: the
process.env.PATH ?? ''tail it builds the child's PATH from (177),status ?? 1/stdout ?? ''/stderr ?? ''(200-202), andrealGitPath's(found.stdout ?? '').trim() || '/usr/bin/git'(229).tests/helpers-spawn-fallbacks.test.mjsalready pins exactly this contract forthe three other sandbox helpers —
runScriptWithFixtures,runScriptWithFetchMockandrunWithGhStub.runScriptInSandboxwas left out,and it is the helper backing the five
collect-*.test.mjssuites. SincespawnSyncreports a failed spawn asstatus: nullwithstdout/stderrundefined rather than throwing, those fallbacks are the whole difference between
"the script under test failed" and "the harness could not start it" — and a
regression there would leak
nullinto everycollect-*assertion instead.Adds
tests/helpers-script-sandbox-fallbacks.test.mjs, 4 tests reusing theestablished
withoutPathpattern from the existing file:PATHdeleted the helper's barenodelookup fails with ENOENT;statusis1,stdout/stderrare'',and
requestsis empty because a child that never started issued no fetch.directory, not from the child, so a fixture written before the spawn is still
read back and a path nothing wrote is still
null. That is what keeps aharness fault distinguishable from a script that produced nothing.
nullcontract on a normal run — the child ran and exited0, and adeclared output it never wrote comes back
null, not''.realGitPathfalls back to/usr/bin/git— deletingPATHis notenough here:
command -v gitruns under/bin/sh, and a shell with noPATHin its environment falls back to a confstr default that still finds
git(verified:
PATH= /bin/sh -c 'command -v git'exits127, while unsetting itdoes not). An empty
PATHis honoured as an empty search path, so the|| '/usr/bin/git'arm is taken. This matters becauserealGitPathisresolved before the git shim is prepended to PATH, so the shim delegates to
the real binary instead of recursing; an empty result would expand the shim's
exec "$ENDUSERS_REAL_GIT" "$@"to a bareexec "".Both helpers restore
PATHin afinally, andnode --testruns the testswithin a file sequentially, so no sibling test observes the gap.
Measured
npm run test:unit:coverage, node v26.10.0, TZ=UTC, run locally at593b9fe(this branch's base):
tests/helpers-script-sandbox.mjsAll-files regions 95.20 → 95.26. Full unit suite: 2090 tests, 0 failures.
npm run test:unit:coverage:checkexits 0; Prettier clean.Residual, deliberately left
The one region still uncovered is the
found.stdout ?? ''arm of 229. It isunreachable from the helper's surface: with
shell: true,spawnSynclaunches/bin/shby absolute path, so noPATHmanipulation can make that spawn failand leave
stdoutnullish. #1214's completion criterion names the|| '/usr/bin/git'arm specifically for this reason, so this PR closes it.Scope / overlap
Adds one new file and touches nothing else — no production code, no
package.json, no existing test. Checked against every open hold-gated PR:#1206 and #1213 are
scripts/lib/svg-active-content.mjs+tests/svg-active-content.test.mjs; #1203 is the e2e fixture overlay builds;#1207 is the
tests/tools/harness floor (its new per-file floor is scoped totests/tools/, and this file istests/helpers-script-sandbox.mjs, so thethreshold line is untouched); #1209 and #1211 are
tests/tools/e2e-coverage-report.mjs. No overlap with any of them.Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-5 copilot=1.0.88