@ -47,9 +47,10 @@ def test_append_auto_terms_dedupes(tmp_path):
{ " role " : " support " , " term " : " surgical tech " , " reason " : " r " } ,
{ " role " : " non_clinical " , " term " : " revenue cycle " , " reason " : " " } ,
{ " role " : " target " , " term " : " dentist " , " reason " : " already a code default " } ,
{ " role " : " non_clinical " , " term " : " the " , " reason " : " generic stopword " } ,
]
_ , added = role_audit . append_auto_terms ( proposals , path = path )
assert added == 2 # duplicate + code-default terms skipped
assert added == 2 # duplicate + code-default + stopword terms skipped
_ , added2 = role_audit . append_auto_terms ( proposals , path = path )
assert added2 == 0
@ -73,3 +74,66 @@ def test_run_audit_writes_report(monkeypatch, tmp_path):
assert " Role audit " in path . read_text ( encoding = " utf-8 " )
assert entries [ 0 ] [ " title " ] == " Orthodontic Clinician I "
assert parsed [ " proposals " ] == [ ]
# ── Engine daily hook ────────────────────────────────────────────────────────
def test_engine_role_audit_applies_only_safe_roles ( monkeypatch , tmp_path ) :
from gimme_job . proactive . engine import ProactiveEngine , ProactiveRunResult
from gimme_job . proactive . plan import ProactivePlan
report = tmp_path / " role-audit-2026-09-13.md "
parsed = {
" items " : [ ] ,
" proposals " : [
{ " role " : " support " , " term " : " surgical tech " , " reason " : " " } ,
{ " role " : " target " , " term " : " clinician " , " reason " : " " } ,
] ,
}
monkeypatch . setattr (
role_audit , " run_audit " , lambda * a , * * k : ( report , parsed , [ { " title " : " x " } ] )
)
applied = { }
def fake_append ( proposals , path = None ) :
applied [ " proposals " ] = proposals
return tmp_path / " auto.yaml " , len ( proposals )
monkeypatch . setattr ( role_audit , " append_auto_terms " , fake_append )
engine = ProactiveEngine ( global_config = None )
result = ProactiveRunResult ( )
engine . _run_role_audit ( ProactivePlan ( ) , result )
assert result . role_audit_path == str ( report )
assert [ p [ " term " ] for p in applied [ " proposals " ] ] == [ " surgical tech " ]
def test_engine_role_audit_disabled ( monkeypatch ) :
from gimme_job . proactive . engine import ProactiveEngine , ProactiveRunResult
from gimme_job . proactive . plan import ProactivePlan
def boom ( * a , * * k ) :
raise AssertionError ( " run_audit should not be called " )
monkeypatch . setattr ( role_audit , " run_audit " , boom )
plan = ProactivePlan ( )
plan . role_audit . enabled = False
engine = ProactiveEngine ( global_config = None )
result = ProactiveRunResult ( )
engine . _run_role_audit ( plan , result )
assert result . role_audit_path is None
def test_engine_role_audit_skips_without_candidates ( monkeypatch ) :
from gimme_job . proactive . engine import ProactiveEngine , ProactiveRunResult
from gimme_job . proactive . plan import ProactivePlan
def no_candidates ( * a , * * k ) :
raise ValueError ( " no candidates logged for this date " )
monkeypatch . setattr ( role_audit , " run_audit " , no_candidates )
engine = ProactiveEngine ( global_config = None )
result = ProactiveRunResult ( )
engine . _run_role_audit ( ProactivePlan ( ) , result )
assert result . role_audit_path is None