feat(runtime): capture step evidence in console
Tests / Test passed: 862

This commit is contained in:
2026-07-15 10:12:09 +08:00
parent 8d5b02e37f
commit ccde30e378
20 changed files with 594 additions and 53 deletions
+51
View File
@@ -1,5 +1,7 @@
from __future__ import annotations
from pathlib import Path
from core.models import Bounds, Scene, SceneElement, Task
from runtime.executor import Executor, ExecutorConfig
from runtime.planner import PlannedStep, Planner
@@ -112,3 +114,52 @@ def test_task_runner_stops_before_the_next_planned_action() -> None:
assert result.status == "failed"
assert result.failure_reason == "execution interrupted"
assert actions == ["tap"]
def test_task_runner_persists_action_evidence_and_raw_ocr(tmp_path) -> None:
scene = Scene(
width=10,
height=20,
elements=[],
ocr_elements=[
SceneElement(
id="ocr-001",
type="text",
text="Search",
bounds=Bounds(1, 2, 3, 4),
confidence=0.98,
source="ocr",
)
],
)
screenshots = iter(
[
b"planning",
b"before-action",
b"after-action",
b"completion-check",
]
)
timeline = Timeline(ArtifactStore(tmp_path / "history"))
runner = TaskRunner(
planner=ScriptedPlanner(
[PlannedStep(action="tap", description="tap search", args={})]
),
executor=Executor(
tools={"tap": lambda **kwargs: {"ok": True}},
config=ExecutorConfig(max_retries=1, backoff_seconds=0),
),
timeline=timeline,
config=TaskRunnerConfig(max_steps=2),
observer=lambda device_id: scene,
screenshot_provider=lambda device_id: next(screenshots),
)
result = runner.run(Task(goal="tap search", device_id="iphone-1"))
assert result.status == "completed"
record = timeline.read(result.id)[0]
assert Path(record["before_screenshot_path"]).read_bytes() == b"before-action"
assert Path(record["after_screenshot_path"]).read_bytes() == b"after-action"
assert record["tool_call"]["description"] == "tap search"
assert record["ocr_results"][0]["text"] == "Search"