1# Author: Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca2from __future__ import annotations34import pytest56from 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_roles789def test_catalogue_sizes():10 assert len(DEFAULT_ROLE_IDS) == 12 and len(OPTIONAL_ROLE_IDS) == 811 assert len(ROLES) == 21 # 12 + 8 + generalist12 assert len(roles_for("default12")) == 12 and len(roles_for("all20")) == 20 and len(roles_for(["generalist"])) == 1131415@pytest.mark.parametrize("rid", list(ROLES) + [f"placebo_{k}" for k in range(1, 13)])16def test_prompt_contract(rid):17 r = get_role(rid)18 sp = r.system_prompt()19 assert f"\nROLE_ID: {rid}\n" in sp20 assert sp.startswith(SHARED_PREAMBLE) # cacheable shared prefix first21 assert "simulated analytic role" in sp and "NOT a licensed" in sp22 assert "CAD" in sp and "VALUATION DATE" in sp and "information cutoff" in sp23 assert "Return ONLY one JSON object" in sp24 assert all(s in SECTIONS for s in r.visible_sections) and "subject" in r.visible_sections25 assert r.description262728def test_least_privilege_views():29 assert get_role("building_condition").visible_sections == ("subject",)30 assert set(get_role("geospatial_risk").visible_sections) == {"subject", "geo", "market"}31 assert set(get_role("comparables").visible_sections) == {"subject", "comparables"}32 assert set(get_role("market_economist").visible_sections) == {"subject", "market"}33 for rid in ("underwriting", "data_auditor", "skeptic", "generalist"):34 assert set(get_role(rid).visible_sections) == set(SECTIONS)353637def test_prompts_are_stable_strings():38 h1 = role_prompt_hashes()39 h2 = role_prompt_hashes()40 assert h1 == h2 and len(set(h1.values())) == len(h1) # distinct prompts, deterministic hashes414243def test_placebo_and_shuffled():44 pl_ = placebo_roles(12)45 assert [r.id for r in pl_] == [f"placebo_{k}" for k in range(1, 13)]46 assert pl_[4].visible_sections == get_role("building_condition").visible_sections # view of default role 547 assert all(r.placebo for r in pl_)48 sh = shuffled_roles(seed=1)49 assert [r.id for r in sh] == list(DEFAULT_ROLE_IDS)50 assert sh == shuffled_roles(seed=1)51