Repository navigation
fix(tools): use cross-spawn for Windows commands - #698
Conversation
Reviewer's GuideAPIUpdate the exported helper’s documented options type to match the synchronous spawn API.
ImplementationReplace shell-based invocation and manual Windows quoting with cross-spawn, while preserving output limits and enriching spawn failures without retaining a circular error reference.
ConfigurationAdd cross-spawn as a runtime dependency for the shared command helper.
TestsImport the helper and add real-process contract tests for command arguments, output, failures, timeouts, and Windows wrappers and npm shims.
Lock files and vendored codeUpdate the lockfile to record the runtime dependency.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/workflows/test.yml" line_range="43" />
<code_context>
+ # The full provider suite currently needs Linux-only tools (including skopeo).
+ # Exercise real native, batch, and npm-shim execution here, without mocking Windows.
+ - name: Test command invocation on Windows
+ run: npm run tests -- test/tools.test.js --grep "^invokeCommand"
+
test:
</code_context>
<issue_to_address>
**Windows validation job fails**
When the Windows workflow runs the focused test command, mocha matches the full test title, which starts with the outer suite title rather than `invokeCommand`; the anchored grep selects zero tests, and `fail-zero: true` makes the job fail instead of validating Windows command execution.
Use a grep pattern that matches the full nested test titles, such as `invokeCommand` without the start anchor.
</issue_to_address>
### Comment 2
<location path="src/tools.js" line_range="261" />
<code_context>
+ const result = spawn.sync(bin, args, {stdio: 'pipe', encoding: 'utf-8', ...opts})
+ // Unlike execFileSync, spawn.sync returns failures instead of throwing them.
+ if (result.error) {
+ throw Object.assign(result.error, result)
+ }
+ if (result.status !== 0) {
</code_context>
<issue_to_address>
**Spawn errors become circular**
When `spawn.sync` returns a non-null `result.error`, such as for a missing executable or timeout, `Object.assign(result.error, result)` copies `result.error` back onto that same object as its `error` property, so the thrown error contains a self-reference and `JSON.stringify` on it throws instead of reporting the command failure.
Copy the result fields onto the thrown error without copying its `error` property.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: .github/workflows/test.yml:43, src/tools.js:261
Replace blanket shell execution and pre-quoting with cross-spawn 7.0.6 for the shared Python, Maven, and Gradle invocation helper. Preserve synchronous stdout, thrown failures, environment handling, and the 10 MiB output buffer. Add real-process contract tests and focused Windows Node 22/24 CI. Keep the Python venv-placement change independent in PR guacsec#696. Implements TC-7561 Assisted-by: OpenCode (GPT-6.1 Sol) Signed-off-by: Adva Oren <aoren@redhat.com>
Keep unit CI on Linux; the shared integration workflow already has Windows and macOS runners. Retain Windows-only contract tests for manual runs; they remain skipped on Linux, not counted as passing. The initial Windows jobs failed during checkout of existing OCI fixture filenames containing colons, before any invocation tests ran. Do not include the proposed sparse-checkout workaround. Fix-specific native Windows results remain unverified. Implements TC-7561 Assisted-by: OpenCode (GPT-6.1 Sol) Signed-off-by: Adva Oren <aoren@redhat.com>
Exclude the nested error reference when enriching spawn failures so JSON serialization preserves diagnostic fields without a cycle. Cover missing executables and timeouts with real-process assertions. Implements TC-7561 Signed-off-by: Adva Oren <aoren@redhat.com>
Use ^7.0.6 for consumers while retaining the locked 7.0.6 version for reproducible repository installs. No resolved dependency changes. Implements TC-7561 Signed-off-by: Adva Oren <aoren@redhat.com>
e5b18c4 to
597c991
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #698 +/- ##
==========================================
+ Coverage 91.60% 91.64% +0.03%
==========================================
Files 44 44
Lines 11641 11644 +3
Branches 2349 2352 +3
==========================================
+ Hits 10664 10671 +7
+ Misses 977 973 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary
invokeCommand()helper, used by Python, Maven, Gradle, and other providers..binshims. Remove the blanketshell: trueand path pre-quoting; do not add a handwritten resolver or cmd.exe escaping implementation.This is independent of PR #696's Python venv-placement change (
b6d2f58), which is not included here. It supersedes the handwritten implementation in0724cb7; neither that implementation nor the premise that configurable TEMP content introduced a new exposure is retained. Maven and Gradle build-tool paths, wrappers, and arguments use the same corrected command boundary.Verification
npm run tests -- test/tools.test.js: 23 passing, 2 pending on Linux; the pending tests require Windows.npm run lint: 0 errors, 15 unchanged baseline warnings.npm run compile: passed.npm ls cross-spawn: runtime and deduplicated transitive copies are 7.0.6.main(ce9658d): 1,042 passing / 1 pending / 21 failing before; 1,047 passing / 3 pending / the same 21 failing after. All failing test names and extracted primary/cause errors match; no additional failures were observed. This is not a clean full-suite pass.Native Windows behavior for this fix remains unverified. The two Windows-only wrapper/shim tests are retained for manual execution and skipped on Linux, not counted as passing. The shared integration workflow tests the built CLI with its own scenarios; it does not run these Mocha tests.
The existing shared integration workflow has a Linux/Windows/macOS matrix, including Python, Maven, and Gradle. Recent integration runs were skipped; the caller runs them automatically only after a successful Test workflow, or manually. The latest pre-removal Test workflow for this PR failed; Linux Node 22 reported three
discoverMavenModulesfailures, whose names also occur in the local baseline. An older cross-platform run builtca3a598, not this fix, and is not evidence for this PR.Current shared scenarios do not explicitly enable Python venv creation, configure special-character temporary paths, or include Maven/Gradle wrapper fixtures. Targeted integration regression coverage remains follow-up work; existing Windows matrix coverage alone does not validate these cases.
The removed Windows unit jobs failed at checkout of unrelated existing OCI fixture filenames containing
:before invocation tests ran. The proposed sparse-checkout workaround was never committed or pushed.The implementation has had local self-review only; independent review is still required.
Implements TC-7561.
Summary by Sourcery
Fix cross-platform command execution by using cross-spawn and add contract coverage for process behavior and Windows command wrappers.
Bug Fixes:
Enhancements:
Build:
Tests: