algolia-local-dev-loop
Configure Algolia local development with separate dev index, mocking, and testing. Use when setting up a development environment, configuring test workflows, or establishing a fast iteration cycle with Algolia. Trigger: "algolia dev setup", "algolia local development", "algolia dev environment", "test algolia locally".
What this skill does
# Algolia Local Dev Loop
## Overview
Set up a fast, reproducible local development workflow for Algolia. Use separate dev indices, mock the client in tests, and iterate without touching production data.
## Prerequisites
- Completed `algolia-install-auth` setup
- Node.js 18+ with npm/pnpm
- Vitest or Jest for testing
## Instructions
### Step 1: Environment-Based Index Names
```typescript
// src/algolia/config.ts
import { algoliasearch } from 'algoliasearch';
const ENV = process.env.NODE_ENV || 'development';
// Each environment gets its own index prefix
export function indexName(base: string): string {
if (ENV === 'production') return base;
return `${ENV}_${base}`; // e.g., "development_products"
}
export const client = algoliasearch(
process.env.ALGOLIA_APP_ID!,
process.env.ALGOLIA_ADMIN_KEY!
);
```
### Step 2: Seed Script for Dev Data
```typescript
// scripts/seed-algolia.ts
import { client, indexName } from '../src/algolia/config';
const SEED_DATA = [
{ objectID: 'prod-1', name: 'Widget A', category: 'tools', price: 29.99 },
{ objectID: 'prod-2', name: 'Widget B', category: 'tools', price: 49.99 },
{ objectID: 'prod-3', name: 'Gadget C', category: 'electronics', price: 199.99 },
];
async function seed() {
const idx = indexName('products');
// replaceAllObjects atomically swaps index content
const { taskID } = await client.replaceAllObjects({
indexName: idx,
objects: SEED_DATA,
});
await client.waitForTask({ indexName: idx, taskID });
// Configure settings for the dev index
await client.setSettings({
indexName: idx,
indexSettings: {
searchableAttributes: ['name', 'category'],
attributesForFaceting: ['category', 'filterOnly(price)'],
customRanking: ['asc(price)'],
},
});
console.log(`Seeded ${SEED_DATA.length} records into ${idx}`);
}
seed().catch(console.error);
```
```json
{
"scripts": {
"seed:algolia": "npx tsx scripts/seed-algolia.ts",
"dev": "tsx watch src/index.ts",
"test": "vitest",
"test:watch": "vitest --watch"
}
}
```
### Step 3: Mock Algolia in Unit Tests
```typescript
// tests/algolia.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock the entire algoliasearch module
vi.mock('algoliasearch', () => ({
algoliasearch: vi.fn(() => ({
searchSingleIndex: vi.fn().mockResolvedValue({
hits: [
{ objectID: '1', name: 'Widget A', _highlightResult: {} },
],
nbHits: 1,
page: 0,
nbPages: 1,
}),
saveObjects: vi.fn().mockResolvedValue({ taskID: 123 }),
waitForTask: vi.fn().mockResolvedValue({}),
})),
}));
import { algoliasearch } from 'algoliasearch';
describe('Product Search', () => {
const client = algoliasearch('test-app-id', 'test-api-key');
it('returns matching products', async () => {
const { hits } = await client.searchSingleIndex({
indexName: 'development_products',
searchParams: { query: 'widget' },
});
expect(hits).toHaveLength(1);
expect(hits[0].name).toBe('Widget A');
});
});
```
### Step 4: Integration Test with Real API
```typescript
// tests/integration/algolia.integration.test.ts
import { describe, it, expect } from 'vitest';
import { algoliasearch } from 'algoliasearch';
describe.skipIf(!process.env.ALGOLIA_APP_ID)('Algolia Integration', () => {
const client = algoliasearch(
process.env.ALGOLIA_APP_ID!,
process.env.ALGOLIA_ADMIN_KEY!
);
const testIndex = `test_${Date.now()}_products`;
it('indexes and searches records', async () => {
// Index
const { taskID } = await client.saveObjects({
indexName: testIndex,
objects: [{ objectID: '1', name: 'Test Product' }],
});
await client.waitForTask({ indexName: testIndex, taskID });
// Search
const { hits } = await client.searchSingleIndex({
indexName: testIndex,
searchParams: { query: 'test' },
});
expect(hits.length).toBeGreaterThan(0);
// Cleanup
await client.deleteIndex({ indexName: testIndex });
});
});
```
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `Index does not exist` | Dev index not seeded | Run `npm run seed:algolia` |
| Test pollution | Shared index between tests | Use unique timestamped index names |
| Stale search results | Indexing not waited | Always `await client.waitForTask()` after writes |
| Mock not applied | Wrong import order | Ensure `vi.mock()` is before imports |
## Examples
### Clean Dev Index on Start
```typescript
// scripts/reset-dev-algolia.ts
import { client, indexName } from '../src/algolia/config';
async function reset() {
const idx = indexName('products');
try {
await client.deleteIndex({ indexName: idx });
console.log(`Deleted ${idx}`);
} catch (e) {
// Index may not exist yet — that's fine
}
}
reset().catch(console.error);
```
## Resources
- [Algolia JavaScript v5 Client](https://www.algolia.com/doc/libraries/javascript/v5/methods/search/)
- [Vitest Documentation](https://vitest.dev/)
- [tsx (TypeScript execute)](https://github.com/privatenumber/tsx)
## Next Steps
See `algolia-sdk-patterns` for production-ready code patterns.
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.