"""A matching ACP notification must not hide an earlier stdout violation. A scripted peer makes the invalid line and the valid notification available before the predicate runs, independently of daemon or adapter scheduling. """ import os from pathlib import Path import sys import tempfile import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "e2e")) from acp_support import AcpClient class AcpReaderTests(unittest.TestCase): def test_wait_for_rejects_malformed_stdout_before_matching_notification(self): with tempfile.TemporaryDirectory() as directory: executable = Path(directory, "peer") executable.write_text( f"#!{sys.executable}\n" "print('diagnostic on stdout')\n" """print('{"jsonrpc":"2.0","method":"session/update","params":{}}')\n""" ) executable.chmod(0o700) client = AcpClient(dict(os.environ, ALBEDO_TEST_CLI=str(executable))) self.addCleanup(client.kill) self.assertEqual(client.wait_exit(), 0) client.kill() # Drain the stdout reader before inspecting its messages. self.assertEqual(len(client.notifications("session/update")), 1) with self.assertRaisesRegex(AssertionError, "diagnostic on stdout"): client.wait_for(client.notifications)