Skip to content

fix(shell): Preserve verbatim stdout in log files and ShellRun.stdout#18

Merged
EspenAlbert merged 3 commits into
mainfrom
stdout-capture-fix
May 29, 2026
Merged

fix(shell): Preserve verbatim stdout in log files and ShellRun.stdout#18
EspenAlbert merged 3 commits into
mainfrom
stdout-capture-fix

Conversation

@EspenAlbert

@EspenAlbert EspenAlbert commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Writes subprocess stdout/stderr line-for-line to .stdout.log / .stderr.log instead of piping through Rich console.log (which wrapped long lines and broke single-line JSON).
  • Strips ANSI escape codes on log write when ansi_content=True; Rich record buffer keeps raw ANSI for HTML export.
  • parse_output reads stdout / stderr directly instead of collapsing via stdout_one_line.

Why

terraform show -json emits one long JSON line. Rich wrapping in the log file corrupted it before tfdo could parse it. The run data layout doc already describes log files as verbatim subprocess output; this restores that contract.

Reviewer notes

  • Log file content: Plain text with ANSI stripped when ansi_content=True (terraform/kubectl). Live event callbacks (ShellRunStdOutput) still carry raw subprocess lines for display.
  • Not breaking for JSON consumers: parse_output and tfdo show_plan_json benefit immediately; no tfdo changes required.
  • stdout_one_line unchanged: Still collapses lines for callers like terraform --version; no longer used inside parse_output.
  • HTML logs: Still sourced from the Rich record buffer, not the raw log file. HTML dump on completion remains a follow-up (skip_html_log_files todo).

Test plan

  • just pre-commit-ask
  • Manual: tfdo a on a plan with long JSON; confirm no Invalid JSON: control character and single-line terraform.stdout.log

@codecov-commenter

codecov-commenter commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.89%. Comparing base (a82afdb) to head (9c07b9d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
ask_shell/_internal/models.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
+ Coverage   85.60%   85.89%   +0.29%     
==========================================
  Files          21       21              
  Lines        2049     2042       -7     
==========================================
  Hits         1754     1754              
+ Misses        295      288       -7     

☔ View full report in Codecov by Sentry.
📢 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.

@EspenAlbert EspenAlbert changed the title todo update me with the PR title for branch stdout-capture-fix fix(shell): Preserve verbatim stdout in log files and ShellRun.stdout May 29, 2026
@EspenAlbert EspenAlbert marked this pull request as ready for review May 29, 2026 10:46
@EspenAlbert EspenAlbert merged commit 89d8af4 into main May 29, 2026
18 checks passed
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