"""Self-check for the coding-agent wrapper (no XMPP server needed).""" from xmpp_cli_bridge.agent import PROMPT from xmpp_cli_bridge.__main__ import make_handler # replicates agent.py's I/O shape: startup prompt, then "(N) > " AGENT_LIKE = ( "import sys\nsys.stdout.write('> ');sys.stdout.flush()\n" "for line in sys.stdin:\n" " sys.stdout.write('turn: ' + line + '(42) > ')\n" " sys.stdout.flush()\n" ) def test_prompt_matches_both_forms(): assert PROMPT.search("reply text\n> ") assert PROMPT.search("reply text\n(78412) > ") # a reply merely containing '>' is not matched as the prompt m = PROMPT.search("a > b\n> ") assert m and m.end() == len("a > b\n> ") def test_agent_like_roundtrip(): h = make_handler( ["python3", "-c", AGENT_LIKE], {"a@b"}, prompt=PROMPT, max_wait=5 ) # startup prompt drained, token-usage-style prompt stripped assert h("list files", "a@b") == "turn: list files\n" assert h("second", "a@b") == "turn: second\n"