mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Group pipeline runs into Langfuse sessions, tagged by trigger source
Each pipeline invocation (runAsync/searchAsync) now gets a fresh sessionId, wrapped via the new Tracer.runWithSession() (implemented with @langfuse/tracing's propagateAttributes, since v5 has no direct sessionId/tags option on startObservation) so it shows up in Langfuse's Sessions view. The session is also tagged with what triggered the run: "cron", "api-list", "api-trigger", "api-search". Verified: full test suite (79/79) passing, tsc/eslint clean, real docker compose build + container smoke test against /health.
This commit is contained in:
@@ -17,7 +17,7 @@ describe('RecommendationsController', () => {
|
||||
|
||||
const res = await app.inject({ method: 'GET', url: '/recommendations' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true }, { trigger: 'api-list' });
|
||||
});
|
||||
|
||||
it('GET /recommendations?count= and force_llm/force_tmdb override config', async () => {
|
||||
@@ -25,7 +25,7 @@ describe('RecommendationsController', () => {
|
||||
const app = makeApp({ RECOMMEND_COUNT: 10, LLM_ENABLED: false }, { runAsync } as unknown as RecommendationPipeline);
|
||||
|
||||
await app.inject({ method: 'GET', url: '/recommendations?count=3&force_llm=true' });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 3, useLlm: true });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 3, useLlm: true }, { trigger: 'api-list' });
|
||||
});
|
||||
|
||||
it('falls back to the configured count for a malformed or non-positive count query param', async () => {
|
||||
@@ -33,13 +33,13 @@ describe('RecommendationsController', () => {
|
||||
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 });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true }, { trigger: 'api-list' });
|
||||
|
||||
await app.inject({ method: 'GET', url: '/recommendations?count=-5' });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true }, { trigger: 'api-list' });
|
||||
|
||||
await app.inject({ method: 'GET', url: '/recommendations?count=0' });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true });
|
||||
expect(runAsync).toHaveBeenCalledWith({ count: 10, useLlm: true }, { trigger: 'api-list' });
|
||||
});
|
||||
|
||||
it('POST /recommendations/trigger auto-requests via Radarr when enabled', async () => {
|
||||
@@ -75,6 +75,6 @@ describe('RecommendationsController', () => {
|
||||
payload: { query: 'sci-fi like Blade Runner' },
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(searchAsync).toHaveBeenCalledWith('sci-fi like Blade Runner', 10);
|
||||
expect(searchAsync).toHaveBeenCalledWith('sci-fi like Blade Runner', 10, 'api-search');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ function makeTracer() {
|
||||
const tracer = {
|
||||
startTrace: vi.fn().mockReturnValue(trace),
|
||||
flush: vi.fn().mockResolvedValue(undefined),
|
||||
runWithSession: vi.fn().mockImplementation((_session: unknown, fn: () => unknown) => fn()),
|
||||
} as unknown as Tracer;
|
||||
return tracer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user