Skip to content

fix: stop spawnCliCommand from re-printing accumulated output - #190

Closed
kwy404 wants to merge 1 commit into
Snapchat:mainfrom
kwy404:fix/cli-spawn-duplicated-output
Closed

kwy404 wants to merge 1 commit into
Snapchat:mainfrom
kwy404:fix/cli-spawn-duplicated-output

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Description

Root cause: in npm_modules/cli/src/utils/cliUtils.ts, spawnCliCommand appends every data chunk to the stdout / stderr buffers and then, when quiet is false, writes the whole buffer to process.stdout / process.stderr instead of the chunk it just received. Every new chunk therefore prints all previous output again. With stdio: 'pipe' and quiet: false (for example installAndroidApk and startAndroidActivity in deviceUtils.ts, which run adb install and adb shell am start), a command that writes first and later second shows first first second in the terminal.

Fix: write only the received chunk (data). The accumulated buffers returned in CommandResult are unchanged.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Documentation improvement
  • Performance optimization
  • Test improvement
  • Other (please describe)

Testing

  • Tests pass locally (bazel test //...)
  • Added/updated tests for changes (if applicable)
  • Tested on multiple platforms (iOS/Android/Web/macOS as applicable)
  • Manual testing performed (describe below)

Testing Details

Added src/utils/cliUtils.spec.ts, which runs echo first; sleep 0.5; echo second through spawnCliCommand with 'pipe' and quiet: false, and checks what was written to process.stdout.

Before the fix:

Expected 'first
first
second
' to be 'first
second
'.
1 spec, 1 failure

After the fix:

1 spec, 0 failures

npm test in npm_modules/cli has no new failures, and eslint and prettier pass on the changed files.

Checklist

  • Code follows project style guidelines
  • Documentation updated (if needed)
  • No breaking changes (or documented in description)
  • Commit messages follow conventional format
  • No secrets, API keys, or internal URLs included

Related Issues

None.

Additional Context

Two lines changed in cliUtils.ts, plus the new spec.

When quiet is false and stdio is piped, each data event wrote the whole
accumulated stdout/stderr buffer instead of the new chunk, so earlier
output was printed again every time the child wrote more. Write only the
received chunk.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉 Thanks for your first contribution to Valdi!

A maintainer will review your PR soon. Here are a few things to check while you wait:

  • ✅ All tests pass (bazel test //...)
  • ✅ Your changes follow our coding standards
  • ✅ You've added tests for your changes (if applicable)
  • ✅ You've updated documentation (if needed)

Ask in GitHub Discussions if you have questions!

@clholgat clholgat closed this in abcbd4b Oct 3, 2026
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.

1 participant