Compare commits
4 commits
dee79420af
...
66f391bf60
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66f391bf60 | ||
|
|
151985809d | ||
|
|
b1461292ae | ||
|
|
16cd672fc4 |
2 changed files with 47 additions and 0 deletions
|
|
@ -2310,3 +2310,32 @@ def test_get_pipeline_logs_not_found(client):
|
||||||
r = client.get("/api/pipelines/9999/logs")
|
r = client.get("/api/pipelines/9999/logs")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json() == []
|
assert r.json() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_pipeline_logs_since_id_returns_pm_entries(client):
|
||||||
|
"""KIN-OBS-025: poll since_id возвращает PM-записи с role='pm' в extra_json."""
|
||||||
|
import json as _json
|
||||||
|
from core.db import init_db
|
||||||
|
from core import models
|
||||||
|
pid = _seed_pipeline(api_module.DB_PATH, task_id="P1-001")
|
||||||
|
conn = init_db(api_module.DB_PATH)
|
||||||
|
# Вставляем не-PM запись, которая будет отфильтрована
|
||||||
|
e0 = models.write_log(conn, pid, "Pipeline start")
|
||||||
|
# Вставляем PM-записи с ретроспективными ts
|
||||||
|
models.write_log(conn, pid, "PM start: task planning",
|
||||||
|
ts="2026-03-17T10:00:00", extra={"role": "pm"})
|
||||||
|
models.write_log(conn, pid, "PM done: 2 steps planned, success=True, cost=$0.0100, tokens=1000",
|
||||||
|
ts="2026-03-17T10:00:05",
|
||||||
|
extra={"role": "pm", "steps_count": 2, "tokens_used": 1000, "cost_usd": 0.01})
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
r = client.get(f"/api/pipelines/{pid}/logs?since_id={e0['id']}")
|
||||||
|
assert r.status_code == 200
|
||||||
|
logs = r.json()
|
||||||
|
assert len(logs) == 2
|
||||||
|
pm_roles = [log["extra_json"]["role"] for log in logs if log.get("extra_json")]
|
||||||
|
assert all(role == "pm" for role in pm_roles)
|
||||||
|
# Убеждаемся что PM done содержит метрики
|
||||||
|
done_log = next(log for log in logs if "PM done" in log["message"])
|
||||||
|
assert done_log["extra_json"]["steps_count"] == 2
|
||||||
|
assert done_log["extra_json"]["tokens_used"] == 1000
|
||||||
|
|
|
||||||
|
|
@ -843,6 +843,24 @@ def test_write_log_extra_dict_decoded(pipeline_conn):
|
||||||
assert entry["extra_json"]["model"] == "sonnet"
|
assert entry["extra_json"]["model"] == "sonnet"
|
||||||
|
|
||||||
|
|
||||||
|
def test_write_log_custom_ts_stored_exactly(pipeline_conn):
|
||||||
|
"""KIN-OBS-025: write_log с ts='...' сохраняет переданный timestamp без изменений (UTC-naive)."""
|
||||||
|
db, pid = pipeline_conn
|
||||||
|
custom_ts = "2026-03-17T10:00:05"
|
||||||
|
entry = models.write_log(db, pid, "PM start: task planning", ts=custom_ts, extra={"role": "pm"})
|
||||||
|
assert entry["ts"] == custom_ts
|
||||||
|
|
||||||
|
|
||||||
|
def test_write_log_no_ts_uses_db_default(pipeline_conn):
|
||||||
|
"""KIN-OBS-025: write_log без ts — таймстемп заполняется БД (не None)."""
|
||||||
|
db, pid = pipeline_conn
|
||||||
|
entry = models.write_log(db, pid, "Regular entry")
|
||||||
|
assert entry["ts"] is not None
|
||||||
|
# DB default — UTC-naive ISO string, no timezone suffix
|
||||||
|
assert "+" not in entry["ts"]
|
||||||
|
assert "Z" not in entry["ts"]
|
||||||
|
|
||||||
|
|
||||||
def test_get_pipeline_logs_since_id_zero_returns_all(pipeline_conn):
|
def test_get_pipeline_logs_since_id_zero_returns_all(pipeline_conn):
|
||||||
"""KIN-084: get_pipeline_logs(since_id=0) возвращает все записи."""
|
"""KIN-084: get_pipeline_logs(since_id=0) возвращает все записи."""
|
||||||
db, pid = pipeline_conn
|
db, pid = pipeline_conn
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue