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) 원인을 서버 기록에 남긴다.
194 lines
6.3 KiB
Python
194 lines
6.3 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from datetime import date
|
|
|
|
from .services.llm_pricing import estimate_reference_cost
|
|
|
|
|
|
class LlmPricingTest(unittest.TestCase):
|
|
def test_agy_gemini_36_is_unavailable_before_model_release(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.6-flash-high",
|
|
tokens_in=1_000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 7, 20),
|
|
)
|
|
|
|
self.assertIsNone(estimate)
|
|
|
|
def test_agy_gemini_36_rate_starts_on_model_release_date(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.6-flash-high",
|
|
tokens_in=1_000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 7, 21),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.00225)
|
|
self.assertIn("2026-07-21~2026-08-12", estimate.rate_label)
|
|
self.assertTrue(estimate.rate_id.endswith("@2026-07-21"))
|
|
|
|
def test_agy_gemini_reasoning_suffix_uses_base_model_standard_rate(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.6-flash-high",
|
|
tokens_in=35_703,
|
|
tokens_out=1_129,
|
|
priced_at=date(2026, 7, 31),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.062022)
|
|
self.assertIn("Gemini 3.6 Flash", estimate.rate_label)
|
|
|
|
def test_agy_gemini_36_uses_introductory_rate_from_august_13(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.6-flash-medium",
|
|
tokens_in=35_703,
|
|
tokens_out=1_129,
|
|
priced_at=date(2026, 8, 13),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.031011)
|
|
self.assertIn("2026-12-31까지", estimate.rate_label)
|
|
|
|
def test_agy_gemini_37_uses_introductory_rate_and_reasoning_suffix(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.7-flash-high",
|
|
tokens_in=115_950,
|
|
tokens_out=4_407,
|
|
priced_at=date(2026, 8, 28),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.10348875)
|
|
self.assertIn("Gemini 3.7 Flash", estimate.rate_label)
|
|
|
|
def test_agy_gemini_37_is_unavailable_before_model_release(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.7-flash-high",
|
|
tokens_in=1_000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 8, 12),
|
|
)
|
|
|
|
self.assertIsNone(estimate)
|
|
|
|
def test_agy_gemini_37_switches_to_standard_rate_in_2027(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gemini-3.7-flash-low",
|
|
tokens_in=115_950,
|
|
tokens_out=4_407,
|
|
priced_at=date(2027, 1, 1),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.2069775)
|
|
self.assertIn("2027-01-01부터", estimate.rate_label)
|
|
|
|
def test_codex_credit_rate_accounts_for_cached_input(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="codex_cli",
|
|
model="gpt-5.6-terra",
|
|
tokens_in=12,
|
|
cached_input_tokens=2,
|
|
tokens_out=3,
|
|
priced_at=date(2026, 8, 28),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.0000705)
|
|
self.assertIn("크레딧 환산", estimate.rate_label)
|
|
|
|
def test_openai_api_gpt_5_6_terra_standard_rate(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="openai",
|
|
model="gpt-5.6-terra",
|
|
tokens_in=1_000_000,
|
|
tokens_out=100_000,
|
|
priced_at=date(2026, 10, 25),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 3.20)
|
|
self.assertIn("openai-api-gpt-5.6-terra-standard@2026-07-30", estimate.rate_id)
|
|
|
|
def test_openai_api_gpt_5_6_terra_accounts_for_cached_input(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="openai",
|
|
model="gpt-5.6-terra",
|
|
tokens_in=1_000_000,
|
|
cached_input_tokens=200_000,
|
|
tokens_out=100_000,
|
|
priced_at=date(2026, 10, 25),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 2.84)
|
|
|
|
def test_openai_api_gpt_5_6_terra_is_unavailable_before_price_start(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="openai",
|
|
model="gpt-5.6-terra",
|
|
tokens_in=1_000_000,
|
|
tokens_out=100_000,
|
|
priced_at=date(2026, 7, 29),
|
|
)
|
|
|
|
self.assertIsNone(estimate)
|
|
|
|
def test_openai_api_gpt_5_6_terra_matches_dated_suffix(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="openai",
|
|
model="gpt-5.6-terra-2026-08-01",
|
|
tokens_in=1_000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 10, 25),
|
|
)
|
|
|
|
self.assertIsNotNone(estimate)
|
|
assert estimate is not None
|
|
self.assertEqual(estimate.cost_usd, 0.0032)
|
|
|
|
def test_openai_other_model_does_not_invent_a_price(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="openai",
|
|
model="gpt-5.6-sol",
|
|
tokens_in=1_000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 10, 25),
|
|
)
|
|
|
|
self.assertIsNone(estimate)
|
|
|
|
def test_unknown_model_does_not_invent_a_price(self) -> None:
|
|
estimate = estimate_reference_cost(
|
|
provider="agy_cli",
|
|
model="gpt-oss-120b-medium",
|
|
tokens_in=1000,
|
|
tokens_out=100,
|
|
priced_at=date(2026, 8, 28),
|
|
)
|
|
|
|
self.assertIsNone(estimate)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|