models: align translation column naming + add token counts
Three recently-added tables (strategic_log_translations, indicator_summary_translations, csv_format_templates) drifted from the codebase's existing naming convention: - llm_model -> model - llm_cost_usd -> cost_usd - content_md -> content (on the two translation tables; csv_format doesn't have a content field) Also added prompt_tokens and completion_tokens to the three tables; they were silently dropped at write time despite LogResult exposing them. All writer call sites (ai_log_job, indicator_summary_job, llm_csv_parser) and reader call sites (api.py localized helpers) updated to match. Tests realigned. Migration 0025 uses batch_alter_table for SQLite compatibility. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
e4dc6d0071
commit
a6d686324c
8 changed files with 125 additions and 32 deletions
|
|
@ -22,8 +22,10 @@ def test_csv_format_template_model_columns():
|
|||
assert "first_seen_at" in cols
|
||||
assert "use_count" in cols
|
||||
assert "last_used_at" in cols
|
||||
assert "llm_model" in cols
|
||||
assert "llm_cost_usd" in cols
|
||||
assert "model" in cols
|
||||
assert "cost_usd" in cols
|
||||
assert "prompt_tokens" in cols
|
||||
assert "completion_tokens" in cols
|
||||
# Crucially, no user attribution.
|
||||
assert "user_id" not in cols
|
||||
assert "first_seen_user_id" not in cols
|
||||
|
|
@ -330,7 +332,7 @@ async def test_parse_with_llm_cache_miss_inserts_template(db_factory):
|
|||
assert tmpl.mapping["ticker_col"] == "Symbol"
|
||||
assert tmpl.broker_label == "Generic broker"
|
||||
assert tmpl.use_count == 1
|
||||
assert tmpl.llm_cost_usd == pytest.approx(0.0002)
|
||||
assert tmpl.cost_usd == pytest.approx(0.0002)
|
||||
# The crucial PII guarantee:
|
||||
assert not hasattr(tmpl, "user_id"), "sample row must not be linked to a user"
|
||||
|
||||
|
|
@ -365,8 +367,8 @@ async def test_parse_with_llm_cache_hit_skips_llm(db_factory):
|
|||
first_seen_at=utcnow(),
|
||||
last_used_at=utcnow(),
|
||||
use_count=1,
|
||||
llm_model="seed",
|
||||
llm_cost_usd=0.0,
|
||||
model="seed",
|
||||
cost_usd=0.0,
|
||||
))
|
||||
await session.commit()
|
||||
|
||||
|
|
@ -410,7 +412,7 @@ async def test_parse_with_llm_stale_mapping_raises_but_does_not_evict(db_factory
|
|||
mapping={"ticker_col": "Symbol", "qty_col": "Symbol"},
|
||||
preamble_rows=0, delimiter=",", broker_label=None,
|
||||
first_seen_at=utcnow(), last_used_at=utcnow(), use_count=1,
|
||||
llm_model="seed", llm_cost_usd=0.0,
|
||||
model="seed", cost_usd=0.0,
|
||||
))
|
||||
await session.commit()
|
||||
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ def test_strategic_log_translation_model_columns():
|
|||
cols = {c.name: c for c in inspect(StrategicLogTranslation).columns}
|
||||
assert "log_id" in cols
|
||||
assert "lang" in cols
|
||||
assert "content_md" in cols
|
||||
assert "content" in cols
|
||||
assert "generated_at" in cols
|
||||
assert "llm_model" in cols
|
||||
assert "llm_cost_usd" in cols
|
||||
assert "model" in cols
|
||||
assert "cost_usd" in cols
|
||||
assert cols["log_id"].nullable is False
|
||||
assert cols["lang"].nullable is False
|
||||
assert cols["content_md"].nullable is False
|
||||
assert cols["content"].nullable is False
|
||||
|
||||
|
||||
async def test_log_translation_fanout_no_active_non_en_users(db_factory, monkeypatch):
|
||||
|
|
@ -113,9 +113,9 @@ async def test_log_translation_fanout_italian_user(db_factory, monkeypatch):
|
|||
row = rows[0]
|
||||
assert row.log_id == log_id
|
||||
assert row.lang == "it"
|
||||
assert row.content_md.startswith("# Apertura")
|
||||
assert row.llm_model == "deepseek/deepseek-v4-flash"
|
||||
assert row.llm_cost_usd == pytest.approx(0.00002)
|
||||
assert row.content.startswith("# Apertura")
|
||||
assert row.model == "deepseek/deepseek-v4-flash"
|
||||
assert row.cost_usd == pytest.approx(0.00002)
|
||||
|
||||
|
||||
async def test_log_translation_fanout_per_language_failure_isolated(db_factory, monkeypatch):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue