forked from Rockachopa/Timmy-time-dashboard
Merge PR #1491
Consolidate multimodal dashboard fixes and verifier syntax repair
This commit is contained in:
114
tests/test_visual_state_verifier.py
Normal file
114
tests/test_visual_state_verifier.py
Normal file
@@ -0,0 +1,114 @@
|
||||
"""Unit tests for scripts.visual_state_verifier."""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import scripts.visual_state_verifier as vsv
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
def test_missing_screenshot_returns_error() -> None:
|
||||
verifier = vsv.VisualStateVerifier()
|
||||
result = verifier.verify_state(
|
||||
screenshot_path="/nonexistent/screenshot.png",
|
||||
expected_state={"location": "Balmora"},
|
||||
game="morrowind",
|
||||
)
|
||||
assert result.status == vsv.VerificationStatus.ERROR
|
||||
assert not result.verified
|
||||
assert "not found" in result.details.lower()
|
||||
|
||||
|
||||
def test_morrowind_state_builder() -> None:
|
||||
state = vsv.VisualStateVerifier.morrowind_state(
|
||||
location="Balmora",
|
||||
health_min=50,
|
||||
has_weapon=True,
|
||||
nearby_npcs=["Caius Cosades"],
|
||||
)
|
||||
assert state["location"] == "Balmora"
|
||||
assert state["health_above"] == 50
|
||||
assert state["has_weapon"] is True
|
||||
assert state["nearby_npcs"] == ["Caius Cosades"]
|
||||
|
||||
|
||||
def test_morrowind_state_minimal() -> None:
|
||||
state = vsv.VisualStateVerifier.morrowind_state(location="Vivec")
|
||||
assert state == {"location": "Vivec"}
|
||||
|
||||
|
||||
def test_morrowind_state_with_extras() -> None:
|
||||
state = vsv.VisualStateVerifier.morrowind_state(
|
||||
location="Balmora",
|
||||
quest_complete=True,
|
||||
gold_min=1000,
|
||||
)
|
||||
assert state["quest_complete"] is True
|
||||
assert state["gold_min"] == 1000
|
||||
|
||||
|
||||
def test_prompt_includes_conditions() -> None:
|
||||
verifier = vsv.VisualStateVerifier()
|
||||
expected = {"location": "Balmora", "health_above": 50}
|
||||
prompt = verifier._build_prompt(expected, "Test context", "morrowind")
|
||||
assert "Balmora" in prompt
|
||||
assert "50" in prompt
|
||||
assert "Test context" in prompt
|
||||
assert "morrowind" in prompt
|
||||
|
||||
|
||||
def test_parse_analysis_returns_pending_for_raw() -> None:
|
||||
verifier = vsv.VisualStateVerifier()
|
||||
raw_analysis = json.dumps(
|
||||
{
|
||||
"prompt": "test prompt",
|
||||
"screenshot_path": "/tmp/test.png",
|
||||
"instruction": "Use vision_analyze",
|
||||
}
|
||||
)
|
||||
result = verifier._parse_analysis(raw_analysis, {}, "/tmp/test.png")
|
||||
assert result.status == vsv.VerificationStatus.UNCERTAIN
|
||||
assert not result.verified
|
||||
assert "Pending analysis" in result.details
|
||||
assert "/tmp/test.png" in result.details
|
||||
|
||||
|
||||
def test_parse_analysis_extracts_json() -> None:
|
||||
verifier = vsv.VisualStateVerifier()
|
||||
analysis = """
|
||||
The player appears to be in Balmora.
|
||||
Health looks good.
|
||||
|
||||
```json
|
||||
{
|
||||
"verified": true,
|
||||
"confidence": 0.85,
|
||||
"details": "Player is in Balmora with weapon equipped",
|
||||
"mismatches": []
|
||||
}
|
||||
```
|
||||
"""
|
||||
result = verifier._parse_analysis(analysis, {"location": "Balmora"}, "/tmp/test.png")
|
||||
assert result.status == vsv.VerificationStatus.VERIFIED
|
||||
assert result.verified
|
||||
assert result.confidence == 0.85
|
||||
assert result.mismatches == []
|
||||
|
||||
|
||||
def test_parse_analysis_handles_failures() -> None:
|
||||
verifier = vsv.VisualStateVerifier()
|
||||
analysis = """
|
||||
```json
|
||||
{
|
||||
"verified": false,
|
||||
"confidence": 0.9,
|
||||
"details": "Player is not in Balmora",
|
||||
"mismatches": ["location"]
|
||||
}
|
||||
```
|
||||
"""
|
||||
result = verifier._parse_analysis(analysis, {"location": "Balmora"}, "/tmp/test.png")
|
||||
assert result.status == vsv.VerificationStatus.FAILED
|
||||
assert not result.verified
|
||||
assert "location" in result.mismatches
|
||||
Reference in New Issue
Block a user