You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.9 KiB
3.9 KiB
| phase | plan | type |
|---|---|---|
| 18-api-route-tests | 5 | execute |
Purpose: Test model discovery and caching logic for multi-provider support. Output: Tests for /api/models route with mocked provider APIs and cache behavior.
<execution_context> ~/.claude/get-shit-done/workflows/execute-phase.md ~/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.mdRoute to test: @src/app/api/models/route.ts
Cache module to mock: @src/lib/providers/cache.ts
Task 1: Create models route tests for basic functionality src/app/api/models/__tests__/route.test.ts Create tests for /api/models route core functionality: - GET: Returns models from fal.ai when no Replicate key (fal.ai works without key) - GET: Returns models from both providers when both keys present - GET: Returns 400 when no providers available (Replicate needs key, fal.ai not tested) - GET: Filters by provider query param - GET: Filters by capabilities query param - GET: Searches by query param - GET: Returns cached=true when all from cache - GET: Returns cached=false when fresh fetchMock @/lib/providers/cache:
vi.mock("@/lib/providers/cache", () => ({
getCachedModels: vi.fn(),
setCachedModels: vi.fn(),
getCacheKey: vi.fn((provider, search) => `${provider}:${search || ""}`),
}));
Mock global fetch for provider API calls:
// Replicate models response
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({
results: [{ owner: "stability-ai", name: "sdxl", description: "SDXL" }],
next: null,
}),
});
// fal.ai models response
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({
models: [{
endpoint_id: "fal-ai/flux",
metadata: { display_name: "Flux", category: "text-to-image", description: "" },
}],
has_more: false,
}),
});
npm test -- src/app/api/models/__tests__/route.test.ts --testNamePattern="basic"
Basic models route tests pass covering filtering and caching
Task 2: Add models route tests for caching and error handling
src/app/api/models/__tests__/route.test.ts
Add caching and error tests to existing test file:
- GET: Returns cached models when available (no fetch)
- GET: Bypasses cache when refresh=true
- GET: Client-side filters Replicate models (caches full list, filters on read)
- GET: Handles partial provider failures gracefully
- GET: Returns 500 when all providers fail
- GET: Paginates through Replicate results (max 15 pages)
- GET: Paginates through fal.ai results (max 15 pages)
Test capability inference for Replicate:
- Video keywords (video, animate, motion) → text-to-video
- Image-to-video keywords (img2vid, i2v) → image-to-video
- Image keywords → text-to-image
Test fal.ai category mapping:
- Category maps directly to ModelCapability
- Non-relevant categories are filtered out
Test sorting:
- Models sorted by provider, then by name npm test -- src/app/api/models/tests/route.test.ts All models route tests pass covering caching, pagination, and error handling
<success_criteria>
- All tasks completed
- All verification checks pass
- Cache logic thoroughly tested
- Provider aggregation tested </success_criteria>