8월 7일까지 워킹트리에만 남아 있던 미커밋 작업을 커밋한다. 여러 사본 폴더(worktree·clone)에 흩어져 있던 중간 스냅샷을 정리하기 전에 원본을 git 이력으로 고정하는 것이 목적이다. - contracts/routes/services: measurement, outcome_trajectory, rupture_repair, deliberate_practice, calibration_transfer, supervision_research, multimodal_alliance, continuous_improvement 계열 신규 모듈과 테스트 - infra/db/init: 07~16 마이그레이션(측정 기반~calibration transfer 실행) - apps/web: 세션 리뷰 카드·관리 화면·E2E 스펙 추가 - docs/ops: G0~G8 라이브 통합·배포·롤백 증거 문서와 evidence JSON/PNG - scripts: smoke·ledger·릴리스 에이전트·NAS 프리뷰 운영 스크립트 engine.public 로그 .bak과 apps/web/test-results 산출물은 커밋에서 제외했다.
143 lines
4.9 KiB
Python
143 lines
4.9 KiB
Python
"""Tests for the metadata-only G7 runtime evidence sampler."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
import importlib.util
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
RUNNER_PATH = Path(__file__).with_name("capture-g7-runtime-evidence.py")
|
|
|
|
|
|
def load_runner():
|
|
spec = importlib.util.spec_from_file_location("g7_runtime_evidence", RUNNER_PATH)
|
|
if spec is None or spec.loader is None:
|
|
raise RuntimeError("G7 runtime evidence sampler could not be loaded")
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def snapshot() -> dict[str, object]:
|
|
return {
|
|
"schema_version": "vignette.voice-runtime.v1",
|
|
"scope": "single_api_worker",
|
|
"privacy_boundary": "metadata_only_no_audio_transcript_or_session_ids",
|
|
"reset_supported": False,
|
|
"limits": {
|
|
"max_utterance_audio_bytes": 10 * 1024 * 1024,
|
|
"streaming_event_queue_max_items": 32,
|
|
"uvicorn_ws_max_queue": 4,
|
|
},
|
|
"process": {
|
|
"worker_instance_id": "a" * 24,
|
|
"pid": 1,
|
|
"platform": "linux",
|
|
"started_at_utc": "2026-08-07T00:00:00Z",
|
|
"uptime_seconds": 100.0,
|
|
"rss_bytes": 50_000_000,
|
|
"peak_rss_bytes": 55_000_000,
|
|
"cpu_user_seconds": 3.0,
|
|
"cpu_system_seconds": 1.0,
|
|
"threads": 4,
|
|
"open_file_descriptors": 12,
|
|
},
|
|
"counters": {
|
|
"active_websockets": 0,
|
|
"websocket_high_water": 2,
|
|
"websockets_opened_total": 5,
|
|
"active_streaming_provider_sessions": 0,
|
|
"streaming_provider_session_high_water": 1,
|
|
"streaming_provider_sessions_opened_total": 4,
|
|
"route_audio_buffer_bytes": 0,
|
|
"route_audio_buffer_high_water_bytes": 64000,
|
|
"audio_bytes_received_total": 200000,
|
|
"audio_overflow_rejections_total": 0,
|
|
"streaming_event_queue_items": 0,
|
|
"streaming_event_queue_high_water_items": 3,
|
|
"streaming_event_queue_saturation_total": 0,
|
|
"streaming_event_queue_wait_seconds_total": 0.0,
|
|
"provider_finalize_total": 4,
|
|
"provider_abort_total": 0,
|
|
"provider_fallback_total": 0,
|
|
"websocket_error_total": 0,
|
|
},
|
|
}
|
|
|
|
|
|
class G7RuntimeEvidenceTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls) -> None:
|
|
cls.runner = load_runner()
|
|
|
|
def test_capture_keeps_one_worker_and_metadata_only_high_water(self) -> None:
|
|
payload = snapshot()
|
|
calls = 0
|
|
|
|
def fetch(**_kwargs):
|
|
nonlocal calls
|
|
calls += 1
|
|
return copy.deepcopy(payload)
|
|
|
|
evidence = self.runner.capture_evidence(
|
|
url="https://api.example.test/admin/voice-runtime",
|
|
cookie_name="sid",
|
|
cookie_value="secret",
|
|
cookie_env="TEST_COOKIE",
|
|
samples=2,
|
|
interval_seconds=1.0,
|
|
timeout_seconds=5.0,
|
|
fetch=fetch,
|
|
sleep=lambda _seconds: None,
|
|
)
|
|
|
|
self.assertEqual(2, calls)
|
|
self.assertEqual("passed", evidence["status"])
|
|
self.assertEqual(2, evidence["samples_completed"])
|
|
self.assertEqual(2, evidence["high_water"]["websocket_high_water"])
|
|
serialized = str(evidence)
|
|
self.assertNotIn("secret", serialized)
|
|
self.assertFalse(evidence["cookie_value_logged"])
|
|
|
|
def test_worker_drift_fails_closed(self) -> None:
|
|
first = snapshot()
|
|
second = copy.deepcopy(first)
|
|
second["process"]["worker_instance_id"] = "b" * 24
|
|
values = iter((first, second))
|
|
|
|
with self.assertRaisesRegex(
|
|
self.runner.EvidenceFailure, "runtime_worker_drift"
|
|
):
|
|
self.runner.capture_evidence(
|
|
url="https://api.example.test/admin/voice-runtime",
|
|
cookie_name="sid",
|
|
cookie_value="secret",
|
|
cookie_env="TEST_COOKIE",
|
|
samples=2,
|
|
interval_seconds=1.0,
|
|
timeout_seconds=5.0,
|
|
fetch=lambda **_kwargs: next(values),
|
|
sleep=lambda _seconds: None,
|
|
)
|
|
|
|
def test_forbidden_fields_and_bad_bounds_are_rejected(self) -> None:
|
|
unsafe = snapshot()
|
|
unsafe["session_id"] = "forbidden"
|
|
with self.assertRaisesRegex(self.runner.EvidenceFailure, "forbidden_field"):
|
|
self.runner.validate_snapshot(unsafe)
|
|
for samples, interval, expected in (
|
|
(0, 1.0, "sample_count"),
|
|
(1, float("nan"), "sample_interval"),
|
|
(7200, 2.0, "capture_window"),
|
|
):
|
|
with self.subTest(expected=expected):
|
|
with self.assertRaisesRegex(self.runner.EvidenceFailure, expected):
|
|
self.runner.validate_capture_bounds(samples, interval)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|