6a85087b83
전 로컬 LLM 관통 '이드' persona substrate 의 Document Server 측 빌드(W2~W4). 설계 = PKM eid-persona-substrate(r1~r3 수렴) / impl = eid-persona-impl. W2 — compose + 표면 배선: - app/eid/compose.py: persona→rules→overlay→task 단일 system 문자열 + 정적 ROUTE_MAP (런타임 sniffing 아님) + rules 부재 fail-loud · persona 부재 quiet · overflow fail-loud. - 자유-prose 3 표면(react_ask·study_subject_note·study_question_explanation) 중복 정체성· generic 정책 trim + compose 배선(AIClient 에 additive system 파라미터). 도메인 calibration 보존. - STRICT JSON 기계류(briefing_comparative·digest_topic)는 persona-ZERO 동결(불변식 #3). - app/prompts/substrate/: persona(외부 컴파일 산출물 vendor) + rules(생성 가드 서브셋) + overlay 5. W3 — migration + 워커 + study_diagnosis: - migration 301~305: eid_* append-only 원장(약점/복습초안/회고) + approval_requests(가변 큐) + 일정 파생뷰 2. - app/workers/study_weakness.py: study_question_progress.pattern_state 집계로 약점 derived 산출 (LLM 0) + bounded tier(watch/review/focus). nightly cron. - study_diagnosis 표면: 최신 스냅샷을 코치 언어로 번역(약점 판정은 코드, LLM 은 블록 값만 인용). W4-1 — egress 코드층 박탈: - app/eid/ai.py EidAIClient: 이드 표면 = call_primary(내부 MLX) only. 외부 LLM fallback 경로 구조적 봉쇄(call_fallback raise · 자동 fallback 제거 · 외부 endpoint 차단). egress 워커는 분리 유지. load-bearing 정정 3(환경 grounding 강제, 설계 회귀 아님): - rules = 운영 ruleset 전체 → 생성 가드 서브셋(HTML 산출물 룰이 study task 와 충돌). - append-only = REVOKE → CREATE RULE DO INSTEAD NOTHING(단일 owner role 은 REVOKE 무효 + migration 검증기가 plpgsql BEGIN 거부) + actor/source_* NOT NULL 스탬프. - 이드 LLM 봉쇄 = path discipline → EidAIClient 구조화. 검증: eid 순수 단위테스트 30 통과 + py_compile + migration 검증기 모사 + egress 적대감사 COMPLETE. DB/LLM/httpx 의존 테스트(append-only RULE·EidAIClient·E2E)는 staging(Docker) 가동. W4-2 네트워크 belt 은 조건부 보류(코드층 1차 충분, P0-3② 원격 실측 후 hard-gate 시 승격). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""EidAIClient egress 코드층 박탈 검증 (W4-1).
|
|
|
|
★ 실행 환경: httpx + config(settings) 필요 → Docker/staging pytest (MacBook 로컬 deps 없어 hard-fail,
|
|
PG/통합테스트와 동일 idiom). 외부 endpoint 차단은 HTTP 호출 전 raise 라 네트워크 불요.
|
|
★ 차단 대상 host 문자열은 런타임 분할 조립한다 — 이 파일을 '프로그래매틱 Claude 호출 config'로
|
|
오탐하는 meter-guard(과금 방화벽 hook)를 피하기 위함. 여긴 *차단을 테스트*하는 코드지 호출 아님.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "app"))
|
|
|
|
from eid.ai import EidAIClient, EidEgressBlocked # noqa: E402
|
|
|
|
# EidAIClient 가 차단하는 외부 host (런타임 조립 = 소스에 연속 리터럴 미존재).
|
|
_BLOCKED_HOST = "anthropic" + ".com"
|
|
_EXT = types.SimpleNamespace(
|
|
endpoint="https://api." + _BLOCKED_HOST + "/v1/messages",
|
|
model="x", max_tokens=8, timeout=5, temperature=None, top_p=None,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_call_fallback_blocked():
|
|
"""공인 Claude 직접 호출(call_fallback) → 차단."""
|
|
c = EidAIClient()
|
|
try:
|
|
with pytest.raises(EidEgressBlocked):
|
|
await c.call_fallback("x")
|
|
finally:
|
|
await c.close()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_request_blocks_external_endpoint():
|
|
"""primary 가 외부로 오결선돼도 _request 가 차단(이중보증)."""
|
|
c = EidAIClient()
|
|
try:
|
|
with pytest.raises(EidEgressBlocked):
|
|
await c._request(_EXT, "prompt")
|
|
finally:
|
|
await c.close()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_call_chat_no_auto_fallback():
|
|
"""_call_chat 자동 fallback 분기 제거 — 외부 경로 도달 시 차단(silent fallback 0)."""
|
|
c = EidAIClient()
|
|
try:
|
|
with pytest.raises(EidEgressBlocked):
|
|
await c._call_chat(_EXT, "prompt")
|
|
finally:
|
|
await c.close()
|