Skip to content

Commit 92a89a6

Browse files
committed
add baseline safety net testing
1 parent 913b34b commit 92a89a6

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ jobs:
373373
print('WARNING: Could not find assert_ method call in assert_done')
374374
sys.exit(1)
375375
PYEOF
376+
377+
- name: Phase 0 regression safety net (unit)
378+
shell: bash
379+
run: |
380+
pytest tests/unit/test_agent_runtime_phase0.py -v
381+
382+
- name: Run full test suite
383+
shell: bash
384+
run: |
376385
pytest tests/ -v
377386
env:
378387
CI: true
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from __future__ import annotations
2+
3+
from unittest.mock import MagicMock
4+
5+
from sentience.agent_runtime import AgentRuntime
6+
from sentience.models import BBox, Element, VisualCues
7+
from sentience.verification import is_disabled, is_enabled, value_equals
8+
9+
10+
class MockBackend:
11+
"""Mock BrowserBackend implementation for unit tests."""
12+
13+
async def get_url(self) -> str:
14+
return "https://example.com"
15+
16+
async def refresh_page_info(self):
17+
return None
18+
19+
20+
class MockTracer:
21+
"""Mock Tracer for unit tests."""
22+
23+
def __init__(self) -> None:
24+
self.events: list[dict] = []
25+
26+
def emit(self, event_type: str, data: dict, step_id: str | None = None) -> None:
27+
self.events.append(
28+
{
29+
"type": event_type,
30+
"data": data,
31+
"step_id": step_id,
32+
}
33+
)
34+
35+
36+
def test_assert_state_predicates_use_snapshot_context() -> None:
37+
"""State-aware predicates should run against snapshot context."""
38+
backend = MockBackend()
39+
tracer = MockTracer()
40+
runtime = AgentRuntime(backend=backend, tracer=tracer)
41+
runtime.begin_step(goal="Test")
42+
43+
cues = VisualCues(is_primary=False, background_color_name=None, is_clickable=True)
44+
elements = [
45+
Element(
46+
id=1,
47+
role="button",
48+
text="Submit",
49+
importance=10,
50+
bbox=BBox(x=0, y=0, width=100, height=40),
51+
visual_cues=cues,
52+
disabled=False,
53+
),
54+
Element(
55+
id=2,
56+
role="textbox",
57+
text=None,
58+
importance=5,
59+
bbox=BBox(x=0, y=50, width=200, height=40),
60+
visual_cues=cues,
61+
value="hello",
62+
input_type="text",
63+
disabled=False,
64+
),
65+
Element(
66+
id=3,
67+
role="button",
68+
text="Disabled",
69+
importance=4,
70+
bbox=BBox(x=0, y=100, width=120, height=40),
71+
visual_cues=cues,
72+
disabled=True,
73+
),
74+
]
75+
76+
runtime.last_snapshot = MagicMock(url="https://example.com", elements=elements)
77+
78+
assert runtime.assert_(is_enabled("text~'Submit'"), label="enabled") is True
79+
assert runtime.assert_(is_disabled("text~'Disabled'"), label="disabled") is True
80+
assert runtime.assert_(value_equals("role=textbox", "hello"), label="value") is True
81+
assert len(runtime._assertions_this_step) == 3

0 commit comments

Comments
 (0)