Skip to content

cmd,sync(fix): Harden git TTY/color and UTF-8 progress streams - #570

Open
tony wants to merge 5 commits into
masterfrom
fix/568-569-git-tty-color-and-utf8
Open

tony wants to merge 5 commits into
masterfrom
fix/568-569-git-tty-color-and-utf8

Conversation

@tony

@tony tony commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #568
Fixes #569

Summary

  • Fix credential prompt hangs on controlling terminals by defaulting GIT_TERMINAL_PROMPT=0 in Git.run().
  • Fix ANSI SGR pollution in GitBranchManager, GitReflogManager, and GitStashManager under color.ui=always.
  • Fix split multi-byte UTF-8 stderr chunks in run() using an incremental decoder.
  • Fix silent git fetch updates by streaming --progress in GitSync.update_repo() and GitSync.create_worktree().
  • Add libvt[pytest,syrupy] PTY, VT500 terminal, and .ambr screen/SGR snapshot tests on Python 3.12+.

Changes by area

Git commands and sync

  • src/libvcs/cmd/git.py: default GIT_TERMINAL_PROMPT=0 unless already configured, pass --no-color in branch, reflog, and stash list parsers, and forward log_in_real_time in Git.fetch().
  • src/libvcs/sync/git.py: pass progress=True and log_in_real_time=True to fetch() in GitSync.update_repo() and GitSync.create_worktree() when progress_callback is set.

Subprocess runner

  • src/libvcs/_internal/run.py: decode stderr callback chunks incrementally with backslashreplace error handling, including trailing incomplete sequences at EOF.

Dependencies, tests, and changelog

  • pyproject.toml, uv.lock: add libvt[pytest,syrupy]>=0.0.1a5,<0.1 and syrupy>=7.0.3 for Python 3.12+ test environments and allow unresolved libvt and syrupy imports when ty targets Python 3.11.
  • tests/sync/test_vt_subprocess.py, tests/sync/__snapshots__/test_vt_subprocess.ambr, tests/cmd/test_git.py, tests/_internal/test_run.py, tests/sync/test_git.py: cover isolated PTY 401 handling, color.ui=always list parsing, multi-byte UTF-8 boundary progress in libvt, GitSync fetch progress streaming, and boxed .ambr screen + SGR snapshots for PTY 401 errors, \r progress transitions/diffs, and split CJK/backslashreplace diagnostics.
  • CHANGES: document both fixes under the unreleased section.

Test plan

  • Ruff format, Ruff lint, and vendored signature checks
  • Type checks with ty targeting Python 3.11 and Python 3.15
  • Parallel pytest suite on Python 3.15 (pytest-xdist -n 2 --dist worksteal) including libvt PTY, VT500, and .ambr snapshot tests (test_git_tty_401_fails_fast_without_credential_prompt, test_git_tty_401_error_screen_snapshot, test_git_clone_and_update_progress_transition_snapshot, test_run_utf8_cjk_progress_and_backslashreplace_snapshot, test_run_utf8_boundary_progress_overwrites_in_vt_terminal, test_git_clone_color_ui_always_progress_renders_in_vt_terminal)
  • Cross-version pytest run on Python 3.11 verifying libvt/syrupy marker skip and non-VT regression tests (test_git_run_disables_terminal_prompt_by_default, test_git_parsers_strip_ansi_when_color_ui_always, test_run_callback_reassembles_utf8_across_read_boundary, test_update_repo_and_create_worktree_stream_fetch_progress)
  • Sphinx documentation build via just build-docs

tony added 3 commits December 1, 2026 18:56
why: Add real POSIX PTY and VT500 state-machine fixtures for testing
controlling-terminal prompts and carriage-return progress output on
Python 3.12+.

what:
- Add libvt[pytest]>=0.0.1a5,<0.1 with python_version >= '3.12' marker
  to dev and testing dependency groups
- Exempt libvt from uv exclude-newer cooldown
- Allow unresolved libvt imports in ty when checking Python 3.11
- Refresh uv.lock
why: Prevent unattended Git subprocesses from blocking on /dev/tty when
HTTPS remotes return 401 Unauthorized, and stop ANSI SGR sequences from
polluting parsed branch, reflog, and stash fields under color.ui=always.

what:
- Default GIT_TERMINAL_PROMPT=0 in Git.run() unless already set in env
  or os.environ
- Pass --no-color in GitBranchManager._ls(), GitReflogManager._ls(), and
  GitStashManager._ls()
- Add libvt PTY 401 tests and color.ui=always parser regression tests

Fixes #568
why: Multi-byte UTF-8 characters split across 128-byte stderr pipe reads
were decoded independently and corrupted into \xNN escapes in
ProgressCallback, while GitSync.update_repo() and
GitSync.create_worktree() omitted --progress and Git.fetch() dropped
log_in_real_time.

what:
- Decode stderr callback chunks with an incremental decoder and flush
  any incomplete trailing bytes at EOF via backslashreplace
- Forward log_in_real_time in Git.fetch()
- Pass progress=True and log_in_real_time=True to fetch in
  GitSync.update_repo() and GitSync.create_worktree() when
  progress_callback is set
- Document both fixes in CHANGES and add VT500 and sync regression tests

Fixes #569
@codspeed

codspeed Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 1 untouched benchmark


Comparing fix/568-569-git-tty-color-and-utf8 (85e5c96) with master (6e460ba)

Open in CodSpeed

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.37748% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.84%. Comparing base (6e460ba) to head (85e5c96).

Files with missing lines Patch % Lines
src/libvcs/cmd/git.py 65.21% 13 Missing and 3 partials ⚠️
src/libvcs/_internal/run.py 61.29% 9 Missing and 3 partials ⚠️
tests/cmd/test_git.py 98.70% 0 Missing and 1 partial ⚠️
tests/sync/test_vt_subprocess.py 99.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #570      +/-   ##
==========================================
+ Coverage   73.14%   73.84%   +0.69%     
==========================================
  Files          54       55       +1     
  Lines       12348    12793     +445     
  Branches     1761     1790      +29     
==========================================
+ Hits         9032     9447     +415     
- Misses       2486     2511      +25     
- Partials      830      835       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tony added 2 commits December 1, 2026 19:39
why: Copying os.environ into a new Python dict on every Git.run() call
forced subprocess.Popen to fsencode every host environment variable in
Python even on headless runners without a controlling /dev/tty, adding
~3.7ms of CPU instructions to GitSync.obtain() in CodSpeed simulation.

what:
- Cache controlling /dev/tty detection per PID in _has_controlling_tty()
  so headless callers keep env=None on subprocess.Popen, and use
  os.environb on POSIX when a controlling TTY is present
- Cache codecs.getincrementaldecoder lookups and instantiate the
  incremental stderr decoder lazily on the first non-empty stderr chunk
why: Pin terminal screen, cursor, soft-wrap, and SGR style spans for
PTY 401 failures, CR progress overwrites, and split UTF-8 stderr chunks
so regressions in stream framing or coloring fail visibly.

what:
- Add libvt[pytest,syrupy] and syrupy>=7.0.3 for Python 3.12+ test
  groups and allow unresolved syrupy imports in ty
- Snapshot 401 GitSync.obtain() and update_repo() PTY error screens
  with port and path scrubbing
- Snapshot clone/fetch CR progress transitions, diffs, and SGR spans
- Snapshot 128-byte split UTF-8 CJK progress and backslashreplace lines

This branch has not been deployed

No deployments
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.

_wait_with_deadline splits UTF-8 chunks and fetch drops progress Git omits GIT_TERMINAL_PROMPT=0 and --no-color in parsers

1 participant