fix(policy): use container-compatible imports (drop app. prefix)

프로덕션 컨테이너는 /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>
This commit is contained in:
Hyungi Ahn
2026-04-24 09:42:24 +09:00
parent c9e8dd0ba1
commit 99672292d3
14 changed files with 30 additions and 22 deletions
+11 -3
View File
@@ -2,19 +2,27 @@
실제 repo root 의 domain_policy.yaml 을 그대로 로드. 테스트가 캐시를 쓰지 않도록
각 테스트 시작 시 lru_cache 클리어.
Import path: 프로덕션 컨테이너 (/app cwd) 와 동일하게 무접두 스타일 사용
(`from policy.loader` 등). 로컬 pytest 는 아래 sys.path 추가로 app/ 를 root 처리.
"""
from __future__ import annotations
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
APP_DIR = REPO_ROOT / "app"
if str(APP_DIR) not in sys.path:
sys.path.insert(0, str(APP_DIR))
import pytest
from app.policy import loader as policy_loader
from app.policy import prompt_render
from policy import loader as policy_loader
from policy import prompt_render
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
DEFAULT_YAML = REPO_ROOT / "domain_policy.yaml"
+1 -1
View File
@@ -9,7 +9,7 @@ from __future__ import annotations
import pytest
from app.policy.audit import check_4b_output_violations
from policy.audit import check_4b_output_violations
# =====================================================================
+1 -1
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
import pytest
from app.ai.envelope import EscalationEnvelope
from ai.envelope import EscalationEnvelope
def test_envelope_round_trip():
+2 -2
View File
@@ -6,8 +6,8 @@ import pytest
import yaml
from pydantic import ValidationError
from app.policy import loader as policy_loader
from app.policy.schema import DomainPolicy
from policy import loader as policy_loader
from policy.schema import DomainPolicy
def test_default_yaml_loads(policy):
+2 -2
View File
@@ -4,8 +4,8 @@ from __future__ import annotations
import pytest
from app.policy import prompt_render
from app.policy.prompt_render import (
from policy import prompt_render
from policy.prompt_render import (
KNOWN_4B_TASKS,
KNOWN_26B_TASKS,
policy_version,
+1 -1
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
import pytest
from app.policy.routing import (
from policy.routing import (
REASON_FALLBACK_DOMAIN,
REASON_HIGH_IMPACT,
REASON_LONG_CONTEXT,
+1 -1
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
from app.policy.routing import decide_routing
from policy.routing import decide_routing
def test_deterministic_true_self_false_stays_high_impact(policy):
+2 -2
View File
@@ -4,8 +4,8 @@ from __future__ import annotations
import pytest
from app.policy.routing import RoutingDecision, decide_routing
from app.policy.shadow import InMemoryShadowLogger, ShadowLogger
from policy.routing import RoutingDecision, decide_routing
from policy.shadow import InMemoryShadowLogger, ShadowLogger
@pytest.fixture