"""Agent commands keep bash's exit code; a failed earlier step of the final pipeline is told on stderr.""" from pathlib import Path import subprocess import unittest SHELL = Path(__file__).resolve().parents[1] / 'agent/shell' def run(command): r = subprocess.run([str(SHELL), '-c', command], capture_output=True, text=True, timeout=30) return r.returncode, r.stdout, r.stderr class PipeNote(unittest.TestCase): def test_failed_middle_step_is_told_exit_code_unchanged(self): code, out, err = run('echo x | (cat; exit 3) | cat') self.assertEqual((code, out), (0, 'x\n')) self.assertIn('管道第 2 步退出码 3', err) def test_normal_commands_say_nothing(self): for command, code in (('yes | head -1', 0), ('true | true', 0), ('false', 1), ('exit 5', 5), ('cat <