First use case lands. The schema is intentionally flat — nine scalar fields, no nested arrays — because Ollama's structured-output guidance stays most reliable when the top level has only scalars, and every field we care about (bank_name, IBAN, period, opening/closing balance) can be rendered as one. Registration is explicit in `use_cases/__init__.py`, not a side effect of importing the use-case module. That keeps load order obvious and lets tests patch the registry without having to reload modules. `get_use_case(name)` is the one-liner adapters use; it raises `IX_001_001` with the offending name in `detail` when the lookup misses, which keeps log-scrape simple. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""Use-case registry: lookup, unknown-name error, first use case wired."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import BaseModel
|
|
|
|
from ix.errors import IXErrorCode, IXException
|
|
from ix.use_cases import REGISTRY, get_use_case
|
|
from ix.use_cases.bank_statement_header import BankStatementHeader, Request
|
|
|
|
|
|
def test_registry_has_bank_statement_header() -> None:
|
|
entry = REGISTRY["bank_statement_header"]
|
|
assert entry == (Request, BankStatementHeader)
|
|
|
|
|
|
def test_registry_entry_types_are_basemodel_subclasses() -> None:
|
|
req_cls, resp_cls = REGISTRY["bank_statement_header"]
|
|
assert issubclass(req_cls, BaseModel)
|
|
assert issubclass(resp_cls, BaseModel)
|
|
|
|
|
|
def test_get_use_case_returns_tuple() -> None:
|
|
req_cls, resp_cls = get_use_case("bank_statement_header")
|
|
assert req_cls is Request
|
|
assert resp_cls is BankStatementHeader
|
|
|
|
|
|
def test_get_use_case_unknown_name_raises_ix_001_001() -> None:
|
|
with pytest.raises(IXException) as exc_info:
|
|
get_use_case("no_such_use_case")
|
|
assert exc_info.value.code is IXErrorCode.IX_001_001
|
|
# The detail should include the bad name so logs aren't ambiguous.
|
|
assert "no_such_use_case" in (exc_info.value.detail or "")
|