Move src/ → apps/server/ and packages/web/ → apps/web/ to adopt standard monorepo conventions (apps/ for runnable apps, packages/ for reusable libraries). Update all config files, shared package imports, test fixtures, and documentation to reflect new paths. Key fixes: - Update workspace config to ["apps/*", "packages/*"] - Update tsconfig.json rootDir/include for apps/server/ - Add apps/web/** to vitest exclude list - Update drizzle.config.ts schema path - Fix ensure-schema.ts migration path detection (3 levels up in dev, 2 levels up in dist) - Fix tests/integration/cli-server.test.ts import paths - Update packages/shared imports to apps/server/ paths - Update all docs/ files with new paths
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/**
|
|
* CassetteStore
|
|
*
|
|
* Reads and writes cassette files from a directory on disk.
|
|
* Each cassette is stored as a JSON file named after the 32-char key hash.
|
|
* Cassette files are intended to be committed to git — they are the
|
|
* "recorded interactions" that allow tests to run without real API calls.
|
|
*/
|
|
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import type { CassetteKey, CassetteEntry } from './types.js';
|
|
import { buildCassetteKey } from './key.js';
|
|
|
|
export class CassetteStore {
|
|
constructor(private readonly cassetteDir: string) {}
|
|
|
|
private pathFor(keyHash: string): string {
|
|
return join(this.cassetteDir, `${keyHash}.json`);
|
|
}
|
|
|
|
/**
|
|
* Look up a cassette by its key.
|
|
* Returns null if not found or if the file is corrupt.
|
|
*/
|
|
find(key: CassetteKey): CassetteEntry | null {
|
|
const hash = buildCassetteKey(key);
|
|
const path = this.pathFor(hash);
|
|
|
|
if (!existsSync(path)) return null;
|
|
|
|
try {
|
|
return JSON.parse(readFileSync(path, 'utf-8')) as CassetteEntry;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Save a cassette to disk. Creates the cassette directory if needed.
|
|
* Prints the cassette filename so it's visible during recording runs.
|
|
*/
|
|
save(key: CassetteKey, entry: CassetteEntry): void {
|
|
mkdirSync(this.cassetteDir, { recursive: true });
|
|
const hash = buildCassetteKey(key);
|
|
const path = this.pathFor(hash);
|
|
writeFileSync(path, JSON.stringify(entry, null, 2), 'utf-8');
|
|
console.log(`[cassette] recorded → ${hash}.json (${entry.recording.jsonlLines.length} lines)`);
|
|
}
|
|
}
|