# Author: Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca from __future__ import annotations import pytest from agentic_valuation.agents.roles import DEFAULT_ROLE_IDS, OPTIONAL_ROLE_IDS, ROLES, SECTIONS, SHARED_PREAMBLE, get_role, placebo_roles, role_prompt_hashes, roles_for, shuffled_roles def test_catalogue_sizes(): assert len(DEFAULT_ROLE_IDS) == 12 and len(OPTIONAL_ROLE_IDS) == 8 assert len(ROLES) == 21 # 12 + 8 + generalist assert len(roles_for("default12")) == 12 and len(roles_for("all20")) == 20 and len(roles_for(["generalist"])) == 1 @pytest.mark.parametrize("rid", list(ROLES) + [f"placebo_{k}" for k in range(1, 13)]) def test_prompt_contract(rid): r = get_role(rid) sp = r.system_prompt() assert f"\nROLE_ID: {rid}\n" in sp assert sp.startswith(SHARED_PREAMBLE) # cacheable shared prefix first assert "simulated analytic role" in sp and "NOT a licensed" in sp assert "CAD" in sp and "VALUATION DATE" in sp and "information cutoff" in sp assert "Return ONLY one JSON object" in sp assert all(s in SECTIONS for s in r.visible_sections) and "subject" in r.visible_sections assert r.description def test_least_privilege_views(): assert get_role("building_condition").visible_sections == ("subject",) assert set(get_role("geospatial_risk").visible_sections) == {"subject", "geo", "market"} assert set(get_role("comparables").visible_sections) == {"subject", "comparables"} assert set(get_role("market_economist").visible_sections) == {"subject", "market"} for rid in ("underwriting", "data_auditor", "skeptic", "generalist"): assert set(get_role(rid).visible_sections) == set(SECTIONS) def test_prompts_are_stable_strings(): h1 = role_prompt_hashes() h2 = role_prompt_hashes() assert h1 == h2 and len(set(h1.values())) == len(h1) # distinct prompts, deterministic hashes def test_placebo_and_shuffled(): pl_ = placebo_roles(12) assert [r.id for r in pl_] == [f"placebo_{k}" for k in range(1, 13)] assert pl_[4].visible_sections == get_role("building_condition").visible_sections # view of default role 5 assert all(r.placebo for r in pl_) sh = shuffled_roles(seed=1) assert [r.id for r in sh] == list(DEFAULT_ROLE_IDS) assert sh == shuffled_roles(seed=1)