|
| 1 | +""" |
| 2 | +IX-HapticSight — Tests for built-in benchmark scenario catalogs. |
| 3 | +
|
| 4 | +These tests verify that the benchmark scenario catalog remains explicit, |
| 5 | +deterministic, and internally consistent. |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import sys |
| 10 | + |
| 11 | +# Make project packages importable without packaging/install |
| 12 | +sys.path.insert(0, os.path.abspath("src")) |
| 13 | + |
| 14 | +from ohip_bench.models import BenchmarkDomain # noqa: E402 |
| 15 | +from ohip_bench.scenarios import ( # noqa: E402 |
| 16 | + make_consent_catalog, |
| 17 | + make_core_catalog, |
| 18 | + make_safety_red_scenario, |
| 19 | + scenario_ids, |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +def test_make_safety_red_scenario_has_expected_shape(): |
| 24 | + scenario = make_safety_red_scenario() |
| 25 | + |
| 26 | + assert scenario.scenario_id == "safety-red-001" |
| 27 | + assert scenario.domain == BenchmarkDomain.SAFETY |
| 28 | + assert scenario.inputs["session"]["safety_level"] == "RED" |
| 29 | + assert scenario.inputs["consent"]["grant_explicit"] is True |
| 30 | + assert scenario.inputs["request"]["requires_contact"] is True |
| 31 | + |
| 32 | + expectation = scenario.expectation |
| 33 | + assert expectation.expected_status == "DENIED" |
| 34 | + assert expectation.expected_executable is False |
| 35 | + assert expectation.expected_fault_reason == "session_safety_red" |
| 36 | + assert expectation.expected_execution_status == "" |
| 37 | + |
| 38 | + |
| 39 | +def test_make_consent_catalog_contains_expected_scenarios(): |
| 40 | + catalog = make_consent_catalog() |
| 41 | + |
| 42 | + assert len(catalog) == 2 |
| 43 | + ids = scenario_ids(catalog) |
| 44 | + assert ids == [ |
| 45 | + "consent-approved-001", |
| 46 | + "consent-denied-001", |
| 47 | + ] |
| 48 | + |
| 49 | + approved = catalog[0] |
| 50 | + denied = catalog[1] |
| 51 | + |
| 52 | + assert approved.domain == BenchmarkDomain.CONSENT |
| 53 | + assert approved.expectation.expected_status == "APPROVED" |
| 54 | + assert approved.expectation.expected_executable is True |
| 55 | + assert approved.expectation.expected_execution_status == "ACCEPTED" |
| 56 | + |
| 57 | + assert denied.domain == BenchmarkDomain.CONSENT |
| 58 | + assert denied.expectation.expected_status == "DENIED" |
| 59 | + assert denied.expectation.expected_executable is False |
| 60 | + assert denied.expectation.expected_fault_reason == "consent_missing_or_invalid" |
| 61 | + |
| 62 | + |
| 63 | +def test_make_core_catalog_contains_consent_and_safety_cases(): |
| 64 | + catalog = make_core_catalog() |
| 65 | + |
| 66 | + assert len(catalog) == 3 |
| 67 | + |
| 68 | + ids = scenario_ids(catalog) |
| 69 | + assert ids == [ |
| 70 | + "consent-approved-001", |
| 71 | + "consent-denied-001", |
| 72 | + "safety-red-001", |
| 73 | + ] |
| 74 | + |
| 75 | + domains = [scenario.domain for scenario in catalog] |
| 76 | + assert domains == [ |
| 77 | + BenchmarkDomain.CONSENT, |
| 78 | + BenchmarkDomain.CONSENT, |
| 79 | + BenchmarkDomain.SAFETY, |
| 80 | + ] |
| 81 | + |
| 82 | + |
| 83 | +def test_catalog_scenarios_have_non_empty_titles_descriptions_and_tags(): |
| 84 | + catalog = make_core_catalog() |
| 85 | + |
| 86 | + for scenario in catalog: |
| 87 | + assert isinstance(scenario.title, str) |
| 88 | + assert scenario.title != "" |
| 89 | + assert isinstance(scenario.description, str) |
| 90 | + assert scenario.description != "" |
| 91 | + assert isinstance(scenario.tags, tuple) |
| 92 | + assert len(scenario.tags) >= 1 |
| 93 | + |
| 94 | + |
| 95 | +def test_scenario_ids_preserve_input_order(): |
| 96 | + catalog = make_core_catalog() |
| 97 | + reversed_catalog = list(reversed(catalog)) |
| 98 | + |
| 99 | + assert scenario_ids(catalog) == [ |
| 100 | + "consent-approved-001", |
| 101 | + "consent-denied-001", |
| 102 | + "safety-red-001", |
| 103 | + ] |
| 104 | + assert scenario_ids(reversed_catalog) == [ |
| 105 | + "safety-red-001", |
| 106 | + "consent-denied-001", |
| 107 | + "consent-approved-001", |
| 108 | + ] |
0 commit comments