今日已更新 223 条资讯 | 累计 41900 条内容
关于我们

Freeze returncode, Streams, and TimeoutExpired Before One Wrapper Extract

Dakota Huang 2026年09月11日 08:20 1 次阅读 来源:Dev.to

Extracting a command wrapper without a result snapshot breaks callers. Characterization tests must freeze returncode, streams, and timeout first. The smallest safe change starts after that freeze. Callers depend on exit codes and stream types together. They also depend on TimeoutExpired instead of CalledProcessError. A rewrite that simplifies subprocess.run will break those callers. Why success tests fail this refactor A green happy-path test proves almost nothing useful here. It ignores stderr text, non-zero codes, and encoding. It also ignores timeout class names after the extract. Consider a wrapper used by a local build script. The wrapper mixes check, text, and shell flags. One extract without pins will change exception types. What the snapshot must record Record these fields for every fixture command below. argv or shell string actually passed through returncode as an integer, including zero stdout type, bytes or str, plus text stderr type, bytes or str, plus text exception class name, or a JSON null timeout value in seconds, or null text flag, encoding name, and check flag env keys the wrapper actually reads Skip cwd in this harness on purpose today. Path drift is a different failure class entirely. This article freezes process results and exception names only. Artifact: a frozen result record The artifact is a JSON record plus a pytest reader. The record is the source of truth here. The extract may proceed only after tests stay green. Use this proposed layout in a local repo. Rename files to match the messy module. Treat the layout as an unexecuted example. tests/characterization/subprocess_records/ python_ok.json python_exit_2.json python_timeout.json tests/characterization/test_run_job_record.py tools/record_run_job.py Label this as an unexecuted local example only. Adapt names to the messy module under change. Step 1: isolate one wrapper Do not start with a package-wide cleanup pass. Pick one function that still calls subprocess.run. Copy its signature in

本文内容来源于互联网,版权归原作者所有
查看原文