99672292d3
프로덕션 컨테이너는 /app 을 cwd 로 실행하고 import 는 `from api...`, `from core...`, `from workers...` 처럼 무접두 스타일을 사용한다. PR-A 내부 import 가 `from app.policy...`, `from app.ai.envelope` 로 되어 있어서 컨테이너에서 ModuleNotFoundError 발생. 변경: - app/policy/*.py: `from app.policy.X` → `from policy.X` - app/services/prompt_versions.py: lazy import 도 `from policy.prompt_render` - app/ai/envelope.py: 영향 없음 (내부 import 없음) - tests/policy/*.py: 모두 `from policy.X` / `from ai.envelope` 로 통일 - tests/policy/conftest.py: 로컬 pytest 용 sys.path.insert(app/) 추가 (MacBook 에서 repo-root 기준 실행 시 app/ 를 package root 로 취급) CI: pytest tests/policy/ -q → 98 passed (로컬, 동일 결과) 프로덕션: docker exec fastapi python -c "from policy.loader import load_policy" → OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
"""INV-1 — self_declare 는 ADD only. OFF 불가."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from policy.routing import decide_routing
|
|
|
|
|
|
def test_deterministic_true_self_false_stays_high_impact(policy):
|
|
"""INV-1 핵심: domain.high_impact=True + self_declare=False → high_impact_task=True 유지."""
|
|
# safety_reference 는 high_impact=true 인 도메인
|
|
decision = decide_routing(
|
|
subject_domain="safety_reference",
|
|
content_chars=1000,
|
|
deterministic_keyword_hits=["산업안전보건법"],
|
|
self_declared_high_impact=False, # 4B 가 "아니다" 말해도
|
|
self_declared_risk_flags=[],
|
|
confidence=0.95,
|
|
policy=policy,
|
|
)
|
|
assert decision.high_impact_task is True, (
|
|
"self_declare=False 로 high_impact 를 OFF 시킬 수 없어야 함 (INV-1 위반)"
|
|
)
|
|
assert decision.escalate_to_26b is True
|
|
|
|
|
|
def test_deterministic_false_self_true_becomes_high_impact(policy):
|
|
"""self_declare=True 는 ADD 기능 — deterministic 이 False 여도 high_impact 로 올림."""
|
|
# news_item 은 high_impact=false 인 도메인
|
|
decision = decide_routing(
|
|
subject_domain="news_item",
|
|
content_chars=500,
|
|
deterministic_keyword_hits=[],
|
|
self_declared_high_impact=True, # 4B 가 "위험하다" 신고
|
|
self_declared_risk_flags=[],
|
|
confidence=0.95,
|
|
policy=policy,
|
|
)
|
|
assert decision.high_impact_task is True
|
|
|
|
|
|
def test_deterministic_false_self_false_stays_low(policy):
|
|
"""둘 다 False 면 low."""
|
|
decision = decide_routing(
|
|
subject_domain="news_item",
|
|
content_chars=500,
|
|
deterministic_keyword_hits=[],
|
|
self_declared_high_impact=False,
|
|
self_declared_risk_flags=[],
|
|
confidence=0.95,
|
|
policy=policy,
|
|
)
|
|
assert decision.high_impact_task is False
|
|
# 에스컬레이션은 일어나지 않아야 함 (다른 조건 충족 없음)
|
|
assert decision.escalate_to_26b is False
|
|
|
|
|
|
def test_domain_high_impact_forces_escalation_regardless_of_self(policy):
|
|
"""safety_reference 같은 high_impact 도메인은 self_declare 여부와 무관하게 escalate."""
|
|
decision_true = decide_routing(
|
|
subject_domain="msds",
|
|
content_chars=1000,
|
|
self_declared_high_impact=True,
|
|
confidence=0.95,
|
|
policy=policy,
|
|
)
|
|
decision_false = decide_routing(
|
|
subject_domain="msds",
|
|
content_chars=1000,
|
|
self_declared_high_impact=False,
|
|
confidence=0.95,
|
|
policy=policy,
|
|
)
|
|
assert decision_true.escalate_to_26b is True
|
|
assert decision_false.escalate_to_26b is True
|
|
assert decision_true.high_impact_task is True
|
|
assert decision_false.high_impact_task is True
|