Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /jhoetter_hof-engine /tests /test_web_session_view.py
| """Unit tests for web session phase + API extras.""" | |
| from hof.browser.web_session_view import ( | |
| build_web_session_view_extras, | |
| compute_web_session_phase, | |
| infer_user_gate, | |
| ) | |
| def test_phase_idle_is_succeeded() -> None: | |
| d = {"status": "idle", "messages": []} | |
| assert compute_web_session_phase(d) == "succeeded" | |
| ex = build_web_session_view_extras(d) | |
| assert ex["phase"] == "succeeded" | |
| assert ex["status_label"] == "Completed" | |
| assert ex.get("phase_hint") is None | |
| def test_phase_stopped_is_cancelled() -> None: | |
| d = {"status": "stopped", "messages": []} | |
| assert compute_web_session_phase(d) == "cancelled" | |
| def test_phase_timed_out() -> None: | |
| d = {"status": "timed_out", "messages": []} | |
| assert compute_web_session_phase(d) == "timed_out" | |
| def test_phase_error_and_poll_error() -> None: | |
| d = {"status": "error", "messages": [], "failure_code": "cloud_error", "failure_message": "x"} | |
| assert compute_web_session_phase(d) == "failed" | |
| ex = build_web_session_view_extras(d) | |
| assert ex["failure_code"] == "cloud_error" | |
| def test_phase_running_with_login_summary_heuristic() -> None: | |
| d = { | |
| "status": "running", | |
| "messages": [ | |
| { | |
| "summary": "Need to complete login on this page", | |
| "role": "ai", | |
| "type": "browser_action", | |
| } | |
| ], | |
| } | |
| assert infer_user_gate(d) == (True, "summary_heuristic") | |
| assert compute_web_session_phase(d) == "waiting_for_user" | |
| ex = build_web_session_view_extras(d) | |
| assert ex["phase"] == "waiting_for_user" | |
| assert ex["status_label"] == "Needs you" | |
| assert ex["phase_hint"] == "summary_heuristic" | |
| def test_phase_waiting_structured_type_from_message_type() -> None: | |
| d = { | |
| "status": "running", | |
| "messages": [ | |
| { | |
| "summary": "Waiting", | |
| "role": "ai", | |
| "type": "human_verification_step", | |
| } | |
| ], | |
| } | |
| assert infer_user_gate(d) == (True, "structured_type") | |
| assert compute_web_session_phase(d) == "waiting_for_user" | |
| ex = build_web_session_view_extras(d) | |
| assert ex["phase_hint"] == "structured_type" | |
| def test_login_in_data_only_does_not_trigger_tier_b() -> None: | |
| d = { | |
| "status": "running", | |
| "messages": [ | |
| { | |
| "summary": "Parsing page", | |
| "data": '{"redirect":"/login","user":"x"}', | |
| "role": "ai", | |
| "type": "browser_action", | |
| } | |
| ], | |
| } | |
| assert infer_user_gate(d) == (False, None) | |
| assert compute_web_session_phase(d) == "running" | |
| def test_phase_running_plain() -> None: | |
| d = { | |
| "status": "running", | |
| "messages": [{"summary": "Clicking search box", "role": "ai", "type": "browser_action"}], | |
| } | |
| assert compute_web_session_phase(d) == "running" | |
| def test_checkpoints_surface() -> None: | |
| d = { | |
| "status": "running", | |
| "messages": [], | |
| "checkpoints": ["Open page", "Click login"], | |
| "cloud_step_count": 3, | |
| } | |
| ex = build_web_session_view_extras(d) | |
| assert ex["checkpoint_count"] == 2 | |
| assert ex["checkpoint_last"] == "Click login" | |
| assert ex["cloud_step_count"] == 3 | |
Xet Storage Details
- Size:
- 3.25 kB
- Xet hash:
- e45228f9ae9bbf896ab5b1d1267042ef4c2b3bb77322b239ba828db105c3f18b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.