fix: align Responses messages and video exports

This commit is contained in:
chenmingxuan committed 2026-09-29 00:12:35 +08:00
1 parent e1e26772d9
commit c818a09a49
10 files changed
+277 -18

No files matched your search

+21 -10
View File
@@ -39,6 +39,14 @@ def mock_context():
return ctx
def _user_role_prompt(messages):
"""Return the instruction text and observation blocks sent to the model."""
assert len(messages) == 1
assert isinstance(messages[0], HumanMessage)
blocks = messages[0].content
return blocks[0]["text"], blocks[1:]
@pytest.mark.asyncio
async def test_summarizer_dispatch_and_caching(mock_context):
"""Verify non-blocking dispatch and summary generation."""
@@ -425,8 +433,8 @@ async def test_single_frame_dispatch_uses_single_image_prompt_variant(mock_conte
await summarizer.flush()
assert summarizer.has_summary(1)
system_text = str(captured[0][0].content)
human_text = str(captured[0][1].content)
system_text, human_blocks = _user_role_prompt(captured[0])
human_text = str(human_blocks)
assert "Exactly ONE screenshot" in system_text
assert "no independent post-action evidence" in system_text
assert "DECISION FRAME" in human_text
@@ -464,8 +472,8 @@ async def test_dual_frame_dispatch_keeps_transition_prompt(mock_context):
await summarizer.flush()
assert summarizer.has_summary(1)
system_text = str(captured[0][0].content)
human_text = str(captured[0][1].content)
system_text, human_blocks = _user_role_prompt(captured[0])
human_text = str(human_blocks)
assert "Before/After screenshots" in system_text
assert "--- [1] BEFORE ACTION SCREEN (Action Marked Visually in Red) ---" in human_text
assert "--- [2] AFTER ACTION SCREEN ---" in human_text
@@ -628,8 +636,8 @@ async def test_focus_block_and_provenance_marked_action_phrase_reach_the_lens(mo
await summarizer.flush()
assert summarizer.has_summary(3)
system_text = str(captured[0][0].content)
lead_text = captured[0][1].content[0]["text"]
system_text, human_blocks = _user_role_prompt(captured[0])
lead_text = human_blocks[0]["text"]
assert "# OPERATOR FOCUS" in system_text
assert "Absence is a fact" in system_text
assert lead_text.startswith(
@@ -643,7 +651,7 @@ async def test_focus_block_and_provenance_marked_action_phrase_reach_the_lens(mo
assert "User instruction at this step: Do not join any network yet." in lead_text
assert "expect it to read On." in lead_text
# The focus precedes the frames: context first, evidence second.
assert captured[0][1].content[1]["text"].startswith("--- [1] BEFORE ACTION SCREEN")
assert human_blocks[1]["text"].startswith("--- [1] BEFORE ACTION SCREEN")
@pytest.mark.asyncio
@@ -672,7 +680,8 @@ async def test_dispatch_without_focus_carries_no_focus_block(mock_context):
)
await summarizer.flush()
lead_text = captured[0][1].content[0]["text"]
_, human_blocks = _user_role_prompt(captured[0])
lead_text = human_blocks[0]["text"]
assert lead_text.startswith("Step 1 Physical Action: Tapped 'Search' at [500, 600]\n")
assert "(self-described)" not in lead_text
assert FOCUS_BLOCK_HEADER not in lead_text
@@ -706,7 +715,8 @@ async def test_single_frame_focus_label_forbids_describing_the_outcome(mock_cont
)
await summarizer.flush()
lead_text = captured[0][1].content[0]["text"]
_, human_blocks = _user_role_prompt(captured[0])
lead_text = human_blocks[0]["text"]
assert "the expected outcome is NOT in this frame and must not be described" in lead_text
assert "what screen change it expected" not in lead_text
# The focus text is released once the summary landed, like the frames.
@@ -798,7 +808,8 @@ async def test_verbatim_argument_line_appears_only_when_the_phrase_folds_argumen
lead_by_step = {}
for messages in captured:
text = messages[1].content[0]["text"]
_, human_blocks = _user_role_prompt(messages)
text = human_blocks[0]["text"]
lead_by_step[text.split(" ")[1]] = text
launch = lead_by_step["1"]
assert launch.startswith("Step 1 Physical Action: Launched app 'Settings'\nController Outcome:")