운영 점검 결함 수정: 감독 주기 충돌, 로그인 확인 지연, 비용 단가
Some checks failed
API contract / OpenAPI type drift (push) Failing after 6m30s
Some checks failed
API contract / OpenAPI type drift (push) Failing after 6m30s
- 감독·연구 생성 주기: 교육과정 공백·근거 묶음 제출 번호 지문이 저장 내용 전체(상태·불확실도·영향 학습자 수·근거 포인터)를 덮게 해, 9월 근거 링크 변경 뒤 매시 반복되던 제출 번호 충돌과 코호트 롤백을 없앤다. - 세션 복원: last_seen_at 갱신을 60초 간격으로 묶어 로그인 요청마다 생기던 확정 쓰기 2회를 줄인다. 관리자 권한 승격은 즉시 반영한다. - 비용: OpenAI API gpt-5.6-terra 공식 표준 단가(2026-07-30부터)를 참조 단가에 추가해 관리자 비용 화면의 $0 표시를 바로잡는다. - 음성 합성 실패(502) 원인을 서버 기록에 남긴다.
This commit is contained in:
parent
cc4a943ad8
commit
7facf961c5
8 changed files with 566 additions and 10 deletions
|
|
@ -1,11 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from contextlib import ExitStack
|
||||
from unittest import IsolatedAsyncioTestCase, TestCase
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from uuid import UUID
|
||||
from uuid import UUID, uuid5
|
||||
|
||||
from .contracts.supervision_research import LedgerEvidencePointer
|
||||
from .services import supervision_research_store
|
||||
from .services.supervision_research_producer import (
|
||||
_PRODUCER_NAMESPACE,
|
||||
_canonical_hash,
|
||||
_load_attention_rows,
|
||||
_signal_id,
|
||||
derive_attention_signals,
|
||||
derive_manifest_input,
|
||||
produce_all_active_cohorts_once,
|
||||
|
|
@ -542,3 +549,267 @@ class SupervisionResearchProducerCycleTest(IsolatedAsyncioTestCase):
|
|||
self.assertFalse(result["clinical_claim_allowed"])
|
||||
append_attention.assert_awaited_once()
|
||||
append_gap.assert_awaited_once()
|
||||
|
||||
@staticmethod
|
||||
def _off_track_trajectory_rows() -> dict[str, list[Mapping[str, object]]]:
|
||||
return {
|
||||
"trajectory_rows": [
|
||||
{
|
||||
"learner_id": LEARNER_A,
|
||||
"revision_id": UUID("70000000-0000-0000-0000-000000000001"),
|
||||
"anchor_session_id": SESSION_A,
|
||||
"revision_no": 1,
|
||||
"assessment": {
|
||||
"sessions": [
|
||||
{
|
||||
"session_no": 1,
|
||||
"status": "off_track",
|
||||
"axes": [{"uncertainty": 0.5}],
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
],
|
||||
"rupture_rows": [],
|
||||
"calibration_rows": [],
|
||||
"transfer_rows": [],
|
||||
"practice_rows": [],
|
||||
}
|
||||
|
||||
async def _run_gap_cycle(self, *, route_hint: str | None) -> dict[str, object]:
|
||||
append_attention = AsyncMock(
|
||||
return_value={"submission_id": UUID(int=1), "snapshot_id": UUID(int=2)}
|
||||
)
|
||||
append_gap = AsyncMock(
|
||||
return_value={"submission_id": UUID(int=3), "gap_snapshot_id": UUID(int=4)}
|
||||
)
|
||||
conn = AsyncMock()
|
||||
patches = [
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_attention_rows",
|
||||
AsyncMock(return_value=self._off_track_trajectory_rows()),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_manifest_rows",
|
||||
AsyncMock(return_value={}),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer.supervision_research_store.append_attention_snapshot",
|
||||
append_attention,
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer.supervision_research_store.append_curriculum_gap",
|
||||
append_gap,
|
||||
),
|
||||
]
|
||||
if route_hint is not None:
|
||||
patches.append(
|
||||
patch(
|
||||
"app.services.supervision_research_producer._route",
|
||||
return_value=route_hint,
|
||||
)
|
||||
)
|
||||
with ExitStack() as stack:
|
||||
for one_patch in patches:
|
||||
stack.enter_context(one_patch)
|
||||
await produce_supervision_cycle(conn, cohort_id="cohort-a")
|
||||
return append_gap.await_args.kwargs
|
||||
|
||||
async def test_gap_submission_id_changes_when_evidence_route_changes(
|
||||
self,
|
||||
) -> None:
|
||||
"""신호 번호는 같고 근거 포인터의 route_hint만 달라지면 공백 제출 번호도 달라야 한다."""
|
||||
old = await self._run_gap_cycle(route_hint="/teacher/sessions/old-route")
|
||||
new = await self._run_gap_cycle(
|
||||
route_hint="/teach/session/new-route/review"
|
||||
)
|
||||
|
||||
self.assertNotEqual(old["submission_id"], new["submission_id"])
|
||||
self.assertNotEqual(old["gap_snapshot_id"], new["gap_snapshot_id"])
|
||||
|
||||
async def test_gap_submission_is_idempotent_for_identical_input(self) -> None:
|
||||
first = await self._run_gap_cycle(route_hint=None)
|
||||
second = await self._run_gap_cycle(route_hint=None)
|
||||
|
||||
self.assertEqual(first["submission_id"], second["submission_id"])
|
||||
self.assertEqual(first["gap_snapshot_id"], second["gap_snapshot_id"])
|
||||
|
||||
@staticmethod
|
||||
def _manifest_rows() -> dict[str, list[Mapping[str, object]]]:
|
||||
return {
|
||||
domain: [
|
||||
{
|
||||
"event_id": UUID(f"60000000-0000-0000-0000-{index:012d}"),
|
||||
"learner_id": LEARNER_A,
|
||||
"session_id": SESSION_A,
|
||||
}
|
||||
]
|
||||
for index, domain in enumerate(
|
||||
("alliance", "rupture", "transfer", "calibration"), start=1
|
||||
)
|
||||
}
|
||||
|
||||
async def _run_manifest_cycle(self, *, route_hint: str | None) -> dict[str, object]:
|
||||
append_manifest = AsyncMock(
|
||||
return_value={"submission_id": UUID(int=5), "manifest_id": UUID(int=6)}
|
||||
)
|
||||
conn = AsyncMock()
|
||||
patches = [
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_attention_rows",
|
||||
AsyncMock(
|
||||
return_value={
|
||||
"trajectory_rows": [],
|
||||
"rupture_rows": [],
|
||||
"calibration_rows": [],
|
||||
"transfer_rows": [],
|
||||
"practice_rows": [],
|
||||
}
|
||||
),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_manifest_rows",
|
||||
AsyncMock(return_value=self._manifest_rows()),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer.supervision_research_store.append_phase3_manifest",
|
||||
append_manifest,
|
||||
),
|
||||
]
|
||||
if route_hint is not None:
|
||||
patches.append(
|
||||
patch(
|
||||
"app.services.supervision_research_producer._route",
|
||||
return_value=route_hint,
|
||||
)
|
||||
)
|
||||
with ExitStack() as stack:
|
||||
for one_patch in patches:
|
||||
stack.enter_context(one_patch)
|
||||
await produce_supervision_cycle(conn, cohort_id="cohort-a")
|
||||
return append_manifest.await_args.kwargs
|
||||
|
||||
async def test_manifest_submission_id_changes_when_evidence_route_changes(
|
||||
self,
|
||||
) -> None:
|
||||
"""근거 묶음도 신호(이벤트) 번호는 같고 route_hint만 달라지면 제출 번호가 달라야 한다."""
|
||||
old = await self._run_manifest_cycle(route_hint="/teacher/sessions/old-route")
|
||||
new = await self._run_manifest_cycle(
|
||||
route_hint="/teach/session/new-route/review"
|
||||
)
|
||||
|
||||
self.assertNotEqual(old["submission_id"], new["submission_id"])
|
||||
self.assertNotEqual(old["manifest_id"], new["manifest_id"])
|
||||
|
||||
async def test_manifest_submission_is_idempotent_for_identical_input(
|
||||
self,
|
||||
) -> None:
|
||||
first = await self._run_manifest_cycle(route_hint=None)
|
||||
second = await self._run_manifest_cycle(route_hint=None)
|
||||
|
||||
self.assertEqual(first["submission_id"], second["submission_id"])
|
||||
self.assertEqual(first["manifest_id"], second["manifest_id"])
|
||||
|
||||
async def test_new_cycle_appends_new_submission_when_old_route_already_stored(
|
||||
self,
|
||||
) -> None:
|
||||
"""운영에 저장된 옛 링크 행이 있어도 새 주기는 충돌 없이 새 번호로 append한다.
|
||||
|
||||
2026-09-09 커밋(1306c524)으로 `_route()` 근거 링크 형식이 바뀌기 전에는
|
||||
교육과정 공백 제출 번호 지문이 신호 번호만 덮어서, 내용(route)만 바뀐
|
||||
재실행이 같은 제출 번호에 다른 내용을 넣어 SupervisionResearchConflictError로
|
||||
충돌했다. 수정 후에는 포인터 내용까지 지문에 들어가므로 새 번호로
|
||||
충돌 없이 append된다.
|
||||
"""
|
||||
revision_id = UUID("70000000-0000-0000-0000-000000000001")
|
||||
old_pointer = LedgerEvidencePointer(
|
||||
ledger="outcome_trajectory_revision",
|
||||
event_id=str(revision_id),
|
||||
session_id=str(SESSION_A),
|
||||
route_hint=f"/teacher/sessions/{SESSION_A}",
|
||||
)
|
||||
old_signal_id = _signal_id("trajectory", revision_id, "off_track")
|
||||
old_gap_fingerprint = _canonical_hash(
|
||||
["competency.outcome_monitoring", "coverage", [old_signal_id]]
|
||||
)
|
||||
old_submission_id = uuid5(
|
||||
_PRODUCER_NAMESPACE, f"gap-submission:cohort-a:{old_gap_fingerprint}"
|
||||
)
|
||||
old_gap_snapshot_id = uuid5(
|
||||
_PRODUCER_NAMESPACE, f"gap-snapshot:cohort-a:{old_gap_fingerprint}"
|
||||
)
|
||||
|
||||
conn = _FakeCurriculumGapConn()
|
||||
await supervision_research_store.append_curriculum_gap(
|
||||
conn,
|
||||
submission_id=old_submission_id,
|
||||
gap_snapshot_id=old_gap_snapshot_id,
|
||||
cohort_id="cohort-a",
|
||||
competency_id="competency.outcome_monitoring",
|
||||
gap_kind="coverage",
|
||||
status="monitoring",
|
||||
uncertainty=0.5,
|
||||
affected_learner_count=1,
|
||||
evidence=[(LEARNER_A, old_pointer)],
|
||||
)
|
||||
|
||||
append_attention = AsyncMock(
|
||||
return_value={"submission_id": UUID(int=1), "snapshot_id": UUID(int=2)}
|
||||
)
|
||||
with (
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_attention_rows",
|
||||
AsyncMock(return_value=self._off_track_trajectory_rows()),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer._load_manifest_rows",
|
||||
AsyncMock(return_value={}),
|
||||
),
|
||||
patch(
|
||||
"app.services.supervision_research_producer.supervision_research_store.append_attention_snapshot",
|
||||
append_attention,
|
||||
),
|
||||
):
|
||||
result = await produce_supervision_cycle(conn, cohort_id="cohort-a")
|
||||
|
||||
self.assertEqual(len(result["curriculum_gaps"]), 1)
|
||||
gap_result = result["curriculum_gaps"][0]
|
||||
self.assertFalse(gap_result["idempotent_replay"])
|
||||
self.assertNotEqual(gap_result["submission_id"], old_submission_id)
|
||||
self.assertNotEqual(gap_result["gap_snapshot_id"], old_gap_snapshot_id)
|
||||
|
||||
|
||||
class _FakeCurriculumGapConn:
|
||||
"""교육과정 공백 제출 번호 충돌 검사만 재현하는 최소 모의 커넥션."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.gap_rows: dict[UUID, tuple[UUID, str]] = {}
|
||||
self.pointer_rows: dict[UUID, str] = {}
|
||||
|
||||
async def execute(self, query: str, *args: object) -> None:
|
||||
if "pg_advisory_xact_lock" in query:
|
||||
return
|
||||
if "INSERT INTO app.supervision_evidence_pointer" in query:
|
||||
pointer_id = args[0]
|
||||
content_hash = args[8]
|
||||
self.pointer_rows.setdefault(pointer_id, content_hash)
|
||||
return
|
||||
if "INSERT INTO app.supervision_curriculum_gap_snapshot" in query:
|
||||
gap_snapshot_id, submission_id, content_hash = args[0], args[1], args[2]
|
||||
self.gap_rows[submission_id] = (gap_snapshot_id, content_hash)
|
||||
return
|
||||
raise AssertionError(f"unexpected execute: {query}")
|
||||
|
||||
async def fetchrow(self, query: str, *args: object) -> Mapping[str, object] | None:
|
||||
if "app.supervision_curriculum_gap_snapshot" in query:
|
||||
submission_id = args[0]
|
||||
if submission_id in self.gap_rows:
|
||||
gap_snapshot_id, content_hash = self.gap_rows[submission_id]
|
||||
return {"gap_snapshot_id": gap_snapshot_id, "content_hash": content_hash}
|
||||
return None
|
||||
if "app.supervision_evidence_pointer" in query:
|
||||
pointer_id = args[0]
|
||||
if pointer_id in self.pointer_rows:
|
||||
return {"content_hash": self.pointer_rows[pointer_id]}
|
||||
return None
|
||||
raise AssertionError(f"unexpected fetchrow: {query}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue