test: add pytest verification suite and gitea ci workflow
All checks were successful
CI / test (push) Successful in 48s
All checks were successful
CI / test (push) Successful in 48s
This commit is contained in:
53
tests/test_storage.py
Normal file
53
tests/test_storage.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from pathlib import Path
|
||||
|
||||
from src.storage import HistoryDB
|
||||
|
||||
|
||||
def test_history_db_job_and_events_roundtrip(tmp_path: Path) -> None:
|
||||
db = HistoryDB(tmp_path / "screenjob_test.db")
|
||||
job_id = "job_test_001"
|
||||
db.create_job(
|
||||
job_id=job_id,
|
||||
objective="Open example.com",
|
||||
model="gpt-5.4-mini",
|
||||
created_at="2026-05-27T00:00:00Z",
|
||||
safety_override=False,
|
||||
disabled_tools=["click"],
|
||||
)
|
||||
db.add_event(
|
||||
job_id=job_id,
|
||||
ts="2026-05-27T00:00:01Z",
|
||||
step=1,
|
||||
event_type="tool_called",
|
||||
payload={"tool": "see_screen"},
|
||||
)
|
||||
db.update_job(
|
||||
job_id,
|
||||
status="completed",
|
||||
ended_at="2026-05-27T00:00:02Z",
|
||||
result="Done",
|
||||
steps=2,
|
||||
estimated_cost_usd=0.1234,
|
||||
)
|
||||
|
||||
job = db.get_job(job_id)
|
||||
assert job is not None
|
||||
assert job["status"] == "completed"
|
||||
assert job["model"] == "gpt-5.4-mini"
|
||||
assert job["disabled_tools"] == ["click"]
|
||||
assert job["usage"]["estimated_cost_usd"] == 0.1234
|
||||
|
||||
events = db.get_job_events(job_id, limit=10)
|
||||
assert len(events) == 1
|
||||
assert events[0]["event_type"] == "tool_called"
|
||||
assert events[0]["payload"]["tool"] == "see_screen"
|
||||
|
||||
jobs = db.list_jobs(limit=10)
|
||||
assert len(jobs) == 1
|
||||
assert jobs[0]["job_id"] == job_id
|
||||
|
||||
stats = db.stats()
|
||||
assert stats["total_jobs"] == 1
|
||||
assert stats["completed_jobs"] == 1
|
||||
assert abs(stats["total_estimated_cost"] - 0.1234) < 1e-9
|
||||
|
||||
Reference in New Issue
Block a user