testing local-first datastores
1import { readFile, readdir, stat } from 'fs/promises';
2import { join } from 'path';
3import { generateCharts } from './harness/chart.js';
4import type { StoreBenchmarkResults } from './harness/types.js';
5
6const RESULTS_DIR = 'results';
7
8async function main() {
9 const args = process.argv.slice(2);
10 let runDir: string;
11
12 if (args[0]) {
13 runDir = args[0];
14 } else {
15 // Find most recent benchmark directory
16 const entries = await readdir(RESULTS_DIR);
17 const dirs: string[] = [];
18
19 for (const entry of entries) {
20 const path = join(RESULTS_DIR, entry);
21 const s = await stat(path);
22 if (s.isDirectory() && entry.startsWith('benchmark-')) {
23 dirs.push(entry);
24 }
25 }
26
27 dirs.sort().reverse();
28
29 if (dirs.length === 0) {
30 console.error('No benchmark results found in results/');
31 process.exit(1);
32 }
33
34 runDir = join(RESULTS_DIR, dirs[0]);
35 console.log(`Using most recent results: ${runDir}`);
36 }
37
38 // Load results
39 const jsonFile = join(runDir, 'results.json');
40 const data = JSON.parse(await readFile(jsonFile, 'utf-8'));
41 const results: StoreBenchmarkResults[] = data.results;
42
43 console.log(`Loaded ${results.length} store results: ${results.map(r => r.storeName).join(', ')}`);
44
45 // Generate charts in the same directory
46 console.log('Generating charts...');
47 const chartFiles = await generateCharts(results, runDir);
48 console.log(`Generated ${chartFiles.length} files in ${runDir}/`);
49}
50
51main().catch((err) => {
52 console.error('Failed:', err);
53 process.exit(1);
54});