Pi's bash tool (shellPath), bench dev and the board terminal run commands with pipe-note.sh: the exit code stays the last step's (no pipefail, so | head is still 0), and a failed earlier step of the final pipeline gets one stderr line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1002 B
Python
28 lines
1002 B
Python
"""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 <<EOF\nhi\nEOF', 0)):
|
|
self.assertEqual((run(command)[0], run(command)[2]), (code, ''), command)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|