Module-level _compact_for_echo_compare (strips ALL whitespace, \s+ -> '') so _is_visible_output_echo's endswith() suffix-match detects interim_assistant prose that only differs from visible token prose by line-break/paragraph formatting. Hoisted to module scope (importable) + behavior-based test (real token vs interim text equality). Codex SAFE (exact suffix match, not substring). 103 echo/journal tests. Co-authored-by: nesquena-hermes <agent@nesquena-hermes> Co-authored-by: franksong2702 <franksong2702@users.noreply.github.com>
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
from api.streaming import _compact_for_echo_compare
|
|
|
|
|
|
def test_streaming_initializes_one_run_journal_writer_per_stream():
|
|
src = Path("api/streaming.py").read_text(encoding="utf-8")
|
|
register_idx = src.index("register_active_run(")
|
|
writer_idx = src.index("RunJournalWriter(session_id, stream_id)", register_idx)
|
|
cancel_idx = src.index("cancel_event = threading.Event()", writer_idx)
|
|
|
|
assert "from api.run_journal import RunJournalWriter" in src
|
|
assert register_idx < writer_idx < cancel_idx
|
|
|
|
|
|
def test_streaming_journals_sse_events_before_queue_delivery():
|
|
src = Path("api/streaming.py").read_text(encoding="utf-8")
|
|
put_idx = src.index("def put(event, data):")
|
|
journal_idx = src.index("run_journal.append_sse_event(event, data)", put_idx)
|
|
queue_idx = src.index("q.put_nowait(queue_item)", put_idx)
|
|
block = src[put_idx:queue_idx]
|
|
|
|
assert put_idx < journal_idx < queue_idx
|
|
assert "Failed to append run journal event" in block
|
|
assert "queue_item = (event, data, event_id) if event_id and hasattr(q, \"subscribe_with_snapshot\") else (event, data)" in block
|
|
|
|
|
|
def test_visible_process_echo_compare_ignores_all_whitespace():
|
|
token_text = "先把 issue 4249 拉下来\n\n先看正文和评论"
|
|
interim_text = "先把 issue 4249 拉下来先看正文和评论"
|
|
|
|
assert _compact_for_echo_compare(token_text) == _compact_for_echo_compare(interim_text)
|