- platform/ → ont_platform/ rename
Python 내장 platform 모듈과 이름 충돌. numpy/scipy가 platform.machine() 호출 시
우리 패키지를 가져와 AttributeError. ont_platform으로 변경하고 pyproject.toml,
ont_platform/**, tests/** import 경로 모두 업데이트.
- ont_platform/config.py: lenient LLM builder 추가
LM Studio/vLLM 등 OpenAI-호환 로컬 서버가 임의 모델 식별자(예: deepseek-r1-distill-
qwen-7b)를 쓸 수 있도록 OntoCast의 OpenAIModel enum validation을 Pydantic
model_construct로 우회. ToolConfig() 생성 시 충돌을 막기 위해 LLM_MODEL_NAME을
잠시 비웠다가 lenient 인스턴스로 교체.
- ont_platform/api/deps.py: ToolBox 초기화를 asyncio.to_thread로 격리
LLMTool.create()가 내부에서 asyncio.run()을 부르는데 lifespan/테스트가 이미
async 컨텍스트라 이중 loop 충돌. 별도 스레드에서 sync 생성자 실행.
- 테스트 인프라 정비
* tests/integration/test_api_smoke.py: TestClient 구버전 starlette 호환을 위해
lifespan='off' 대신 app.router.lifespan_context = noop 패턴 적용.
* tests/unit/test_convert_document.py, test_select_ontology.py: ontocast.agent
__init__.py가 re-export한 함수가 서브모듈을 가리는 문제로 sys.modules에서
실제 모듈 객체 직접 추출.
* tests/e2e/conftest.py: .env 자동 로드 + provider별 skip 조건 (Ollama는
LLM_API_KEY 불필요).
* tests/e2e/test_phase0_full_pipeline.py: provider별 키 분기,
HDBSCAN 클러스터링이 동작하도록 fixture 페이로드 16문장으로 확장.
- vendored OntoCast 버그 수정 3건 (VENDORED_MODIFICATIONS.md 기록):
* agent/render_ontology.py: render_ontology_fresh()의 .format() 호출에 누락된
ontology_prefix 인자 추가 (Bootstrap 단계에서 KeyError: 'ontology_prefix').
* stategraph/node_factories.py: render_ontology/render_facts 노드의
state.model_copy(deep=True)로 budget_tracker가 deep-copy되어 root state의
BudgetTracker가 영원히 0인 채로 남던 버그 수정. 원본 인스턴스 공유로 변경.
- 문서 갱신
README.md (Phase 0.7 부분완료 + ont_platform 폴더 이름),
docs/phases/PHASE0_ACCEPTANCE_GATE.md (검증 이력 + Ollama/LM Studio 옵션),
.env.example (LM Studio/Ollama/OpenAI 세 옵션 명시).
검증
- unit + integration 26/26 통과.
- e2e (LM Studio + Qwen3-8B / DeepSeek-R1-Distill-Qwen-7B): 워크플로우 끝까지
실행 + 5번 LLM 호출 + LangGraph 전 노드 traceable 확인. 7-8B 로컬 모델은
strict structured output(Turtle RDF in JSON) 한계로 ontology/facts TTL 자동
생성 부분 성공. 클라우드 LLM 환경에서 재검증 필요.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
"""E2E test configuration.
|
|
|
|
These tests are SKIPPED by default unless a valid LLM provider is configured.
|
|
The repo's `.env` file is auto-loaded so the same settings used by the app
|
|
also drive the test run.
|
|
|
|
Provider별 통과 조건:
|
|
- openai : `LLM_API_KEY` 필요 (LM Studio 등 OpenAI-호환 로컬 서버는 더미 키도 OK)
|
|
- ollama : 별도 키 불필요 (로컬 데몬만 동작하면 됨)
|
|
|
|
To run:
|
|
pytest tests/e2e -m e2e
|
|
|
|
LLM 호출이 실제로 일어남. OpenAI 클라우드는 비용 발생, 로컬 LLM은 무료.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
for p in (REPO_ROOT, REPO_ROOT / "vendored" / "ontocast"):
|
|
if str(p) not in sys.path:
|
|
sys.path.insert(0, str(p))
|
|
|
|
# Auto-load .env so e2e tests pick up the same LLM settings as the app.
|
|
_env_path = REPO_ROOT / ".env"
|
|
if _env_path.exists():
|
|
try:
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv(_env_path, override=False)
|
|
except ImportError:
|
|
# python-dotenv가 없으면 직접 간단 파싱.
|
|
for line in _env_path.read_text(encoding="utf-8").splitlines():
|
|
line = line.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
key, _, value = line.partition("=")
|
|
os.environ.setdefault(key.strip(), value.strip())
|
|
|
|
|
|
def _llm_configured() -> bool:
|
|
"""Provider별로 e2e 실행 가능 여부 판단."""
|
|
provider = (os.environ.get("LLM_PROVIDER") or "openai").lower()
|
|
if provider == "ollama":
|
|
# Ollama는 별도 API 키 불필요.
|
|
return True
|
|
# openai 또는 OpenAI-호환 로컬 서버 — 더미 키라도 들어 있어야 OK.
|
|
return bool(os.environ.get("LLM_API_KEY"))
|
|
|
|
|
|
def pytest_collection_modifyitems(
|
|
config: pytest.Config, items: list[pytest.Item]
|
|
) -> None:
|
|
"""Skip e2e tests unless the LLM provider is properly configured."""
|
|
if _llm_configured():
|
|
return
|
|
provider = (os.environ.get("LLM_PROVIDER") or "openai").lower()
|
|
skip_marker = pytest.mark.skip(
|
|
reason=(
|
|
f"E2E tests require LLM provider config. "
|
|
f"Provider={provider!r}, LLM_API_KEY={'set' if os.environ.get('LLM_API_KEY') else 'missing'}."
|
|
)
|
|
)
|
|
for item in items:
|
|
if "tests/e2e" in str(item.fspath).replace("\\", "/"):
|
|
item.add_marker(skip_marker)
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
|
config.addinivalue_line(
|
|
"markers",
|
|
"e2e: end-to-end test that requires a real LLM and may cost money",
|
|
)
|