Skip to content

chore: add execProcess wrapper and refactor poetryUtils (Fixes #1239)#1240

Open
karthiknadig wants to merge 1 commit intomainfrom
chore/issue-1239
Open

chore: add execProcess wrapper and refactor poetryUtils (Fixes #1239)#1240
karthiknadig wants to merge 1 commit intomainfrom
chore/issue-1239

Conversation

@karthiknadig
Copy link
Member

@karthiknadig karthiknadig commented Feb 16, 2026

This PR adds an execProcess wrapper to childProcess.apis.ts and refactors poetryUtils.ts to use it, improving testability.

Changes:

  • Added execProcess function to src/common/childProcess.apis.ts as a wrapper around cp.exec with PYTHONUTF8 handling
  • Refactored src/managers/poetry/poetryUtils.ts to use execProcess instead of direct child_process import
  • Fixed a pre-existing regex bug in getPoetryVersion that didn't handle the space in Poetry 1.x version output format
  • Added unit tests in poetryUtils.unit.test.ts demonstrating the mocking pattern for execProcess

Testing:

  • All unit tests pass (660 passing)
  • Lint passes with no errors

Note: This is a partial implementation of #1239. The acceptance criteria for auditing fs imports is deferred to a future PR to keep this change focused.

For #1239

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves testability and consistency of child-process usage by introducing an execProcess() wrapper in src/common/childProcess.apis.ts and refactoring Poetry utilities to use it, while also fixing Poetry 1.x version parsing.

Changes:

  • Added execProcess() wrapper around cp.exec() in src/common/childProcess.apis.ts.
  • Refactored src/managers/poetry/poetryUtils.ts to use execProcess() instead of a direct child_process import + promisify.
  • Added unit tests covering getPoetryVersion() parsing and demonstrating stubbing execProcess().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/common/childProcess.apis.ts Adds execProcess() wrapper to centralize cp.exec usage and improve mockability.
src/managers/poetry/poetryUtils.ts Switches Poetry exec calls to the wrapper and adjusts version-regex parsing for Poetry 1.x output.
src/test/managers/poetry/poetryUtils.unit.test.ts Adds unit tests that stub childProcess.apis.execProcess() and validate version parsing.

Comment on lines +28 to +30
return {
stdout: result.stdout ?? '',
stderr: result.stderr ?? '',
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execProcess is documented/typed to return stdout/stderr as strings, but cp.exec can return Buffers when callers pass encoding: 'buffer' | null in options. As written, a Buffer will flow through (it’s not nullish) and can break callers that do string operations (e.g. .trim()). Consider forcing encoding: 'utf8' (or converting Buffer→string before returning) to make the wrapper’s contract true and avoid runtime type mismatches.

Suggested change
return {
stdout: result.stdout ?? '',
stderr: result.stderr ?? '',
const rawStdout = result.stdout ?? '';
const rawStderr = result.stderr ?? '';
return {
stdout: Buffer.isBuffer(rawStdout) ? rawStdout.toString('utf8') : rawStdout,
stderr: Buffer.isBuffer(rawStderr) ? rawStderr.toString('utf8') : rawStderr,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants