Problem
src/app/api/cron/run/route.ts and src/app/api/run/route.ts duplicate ~80 lines of identical logic: source fetching, dedup, Gemini analysis, findings insert, run status update. When one gets updated, the other drifts.
Goal
Extract a shared executeRun() function in src/lib/run-competitor.ts that both routes call. Each route only handles its own concerns (auth, request parsing, response format).
Scope
- New
src/lib/run-competitor.ts with shared run logic
- Simplify both API routes to thin wrappers
- Update tests accordingly
Problem
src/app/api/cron/run/route.tsandsrc/app/api/run/route.tsduplicate ~80 lines of identical logic: source fetching, dedup, Gemini analysis, findings insert, run status update. When one gets updated, the other drifts.Goal
Extract a shared
executeRun()function insrc/lib/run-competitor.tsthat both routes call. Each route only handles its own concerns (auth, request parsing, response format).Scope
src/lib/run-competitor.tswith shared run logic