Fix final review findings: key leak, model fallback, error resilience, docs

- ApiClient: strip query string from ApiError messages so API keys
  (e.g. TMDb's api_key query param) never leak into 500 response
  bodies or logs.
- LlmTool: accept an optional defaultModel, wired from AppConfig's
  LLM_MODEL, so Langfuse prompts that omit a model config fall back
  to the configured LLM rather than silently requesting gpt-4o-mini.
- RecommendationPipeline: restore the Go original's graceful
  degradation — library/Radarr fetch failures, per-suggestion TMDb
  resolution failures, and per-signal TMDb similarity/recommendation
  failures are now logged and skipped instead of aborting the whole
  run (applies to both runInternal and searchAsync).
- RecommendationsController: validate the ?count= query param
  (must be a positive integer) instead of silently producing NaN.
- Commit the Langfuse prompt definitions (langfuse/*.prompt.json) and
  add a README covering setup, prompt seeding, cache invalidation,
  and the HTTP API surface — the branch was not otherwise runnable by
  anyone but the author.
This commit is contained in:
2026-08-12 21:40:09 +02:00
parent f26a5d72b2
commit ae8bfaa2eb
12 changed files with 388 additions and 16 deletions

View File

@@ -28,6 +28,20 @@ describe('RecommendationsController', () => {
expect(runAsync).toHaveBeenCalledWith({ count: 3, useLlm: true });
});
it('falls back to the configured count for a malformed or non-positive count query param', async () => {
const runAsync = vi.fn().mockResolvedValue([]);
const app = makeApp({ RECOMMEND_COUNT: 10, LLM_ENABLED: true }, { runAsync } as unknown as RecommendationPipeline);
await app.inject({ method: 'GET', url: '/recommendations?count=abc' });
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
await app.inject({ method: 'GET', url: '/recommendations?count=-5' });
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
await app.inject({ method: 'GET', url: '/recommendations?count=0' });
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
});
it('POST /recommendations/trigger auto-requests via Radarr when enabled', async () => {
const recs = [{ title: 'Dune', year: 2021, tmdbId: 1, reason: 'r' }];
const runAsync = vi.fn().mockResolvedValue(recs);