Files
mrleo1nidandClaude Opus 5.5 ef29b85320
ci / api / api (push) Successful in 27s
ci / recommender / recommender (push) Successful in 1m0s
ci / docker / docker (образы собираются — их сервер собирает сам при обновлении) (push) Successful in 1m26s
feat(rec): audio analyzer and My Wave v1 engine (M4)
- migration 00006: track features and embeddings (pgvector, HNSW),
  analysis queue filled by a trigger on new tracks, wave sessions and
  impressions, recommender profiles, model versions
- analyzer basic-1 (ADR-014): ffmpeg decode, three 30 s excerpts,
  256-d timbre/rhythm embedding, tempo by onset autocorrelation, key,
  loudness, energy, danceability, acousticness, intro length; worker
  with SKIP LOCKED claims, retries and re-analysis on version change
- wave engine v1: candidates (session/taste similarity, fresh,
  liked artists, rediscover, popular, exploration, seed), filters
  (dislikes, played in 3 h, already served), heuristic score, activity
  and mood fit from contexts.yaml with relaxing thresholds, MMR with
  one track per artist, exploration share, session vector updated by
  reactions and a change of course after three skips
- POST /internal/wave/batch with the catalog index cached in memory
  and the session kept in Redis

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 12:20:55 +03:00

67 lines
2.1 KiB
Python

from fastapi.testclient import TestClient
from pipu_rec.api.app import create_app
from pipu_rec.settings import Settings
async def ok() -> None:
return None
async def down() -> None:
raise ConnectionError("connection refused")
def client(checks=None) -> TestClient: # type: ignore[no-untyped-def]
settings = Settings(internal_token="secret", PIPU_VERSION="1.2.3")
return TestClient(create_app(settings, checks))
def test_healthz() -> None:
r = client().get("/healthz")
assert r.status_code == 200
assert r.json() == {"status": "ok"}
def test_readyz_all_up() -> None:
r = client({"postgres": ok, "redis": ok}).get("/readyz")
assert r.status_code == 200
assert r.json() == {"status": "ok", "checks": {"postgres": "ok", "redis": "ok"}}
def test_readyz_dependency_down() -> None:
r = client({"postgres": ok, "redis": down}).get("/readyz")
assert r.status_code == 503
assert r.json()["checks"]["redis"] == "fail"
def test_readyz_dependency_hangs(monkeypatch) -> None: # type: ignore[no-untyped-def]
import asyncio
from pipu_rec.api import app as app_module
async def hang() -> None:
await asyncio.sleep(10)
monkeypatch.setattr(app_module, "CHECK_TIMEOUT_S", 0.05)
r = client({"postgres": ok, "redis": hang}).get("/readyz")
assert r.status_code == 503
assert r.json()["checks"] == {"postgres": "ok", "redis": "fail"}
def test_internal_status_requires_token() -> None:
c = client()
assert c.get("/internal/status").status_code == 401
assert c.get("/internal/status", headers={"Authorization": "Bearer wrong"}).status_code == 401
r = c.get("/internal/status", headers={"Authorization": "Bearer secret"})
assert r.status_code == 200
assert r.json()["version"] == "1.2.3"
def test_wave_batch_requires_token_and_service() -> None:
body = {"user_id": "u", "session_id": "s"}
assert client().post("/internal/wave/batch", json=body).status_code == 401
r = client().post("/internal/wave/batch", json=body, headers={"Authorization": "Bearer secret"})
assert r.status_code == 503