fix(cli): ESM-compatible child_process import + execSync injection in git-staged.ts#79
Merged
Looted merged 2 commits intomodularize_improve_rules_improve_guidancefrom Mar 17, 2026
Conversation
…taged.ts Co-authored-by: Looted <6255880+Looted@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on modularizing improve rules and guidance
fix(cli): ESM-compatible child_process import + execSync injection in git-staged.ts
Mar 17, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI traceability “git-staged” utilities to be more testable and ESM-compatible by injecting the git execution function instead of relying on mutating the child_process module cache.
Changes:
- Switch
git-staged.tsfrom a defaultchild_processimport to a namedexecSyncimport and allow dependency injection of the exec function. - Add
escapePath()and use it when buildinggit diff/git showcommands. - Update the Bun test to pass a mock exec function into
getStagedFiles().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/cli/src/traceability/git-staged.ts | Refactors git command execution to accept an injected exec function and updates path escaping/quoting. |
| packages/cli/tests/traceability/traceability.test.ts | Updates staged-files test to use exec injection instead of mutating the module cache. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+18
to
+22
| type ExecFn = (cmd: string, opts: { encoding: "utf8" }) => string; | ||
|
|
||
| function runGit(cmd: string, exec: ExecFn): string { | ||
| try { | ||
| return child_process.execSync(cmd, { encoding: "utf8" }); | ||
| return exec(cmd, { encoding: "utf8" }); |
| } | ||
|
|
||
| function escapePath(p: string): string { | ||
| return p.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); |
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.
import child_process from "node:child_process"is invalid in Node ESM —node:child_processhas no default export, throwing at runtime in a"type": "module"package.Changes
import { execSync } from "node:child_process"replaces the broken default importgetStagedFilesnow accepts an optionalexec: ExecFn = execSyncparameter; all existing callers with no arguments are unaffectedrequire()cache mutation in favor of passing a mock exec directly —getStagedFiles(mockExec)escapePath()helper that escapes backslashes before double-quotes (previously only quotes were escaped, leaving paths with backslashes vulnerable to shell interpretation)📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.