import { beforeAll, afterAll } from 'bun:test'; import { mkdirSync, rmSync } from 'fs'; // Test directories export const TEST_DIR = './test-data'; export const BUNDLES_DIR = `${TEST_DIR}/bundles`; export const TEMP_DIR = `${TEST_DIR}/temp`; // Setup test environment beforeAll(() => { mkdirSync(BUNDLES_DIR, { recursive: true }); mkdirSync(TEMP_DIR, { recursive: true }); }); // Cleanup after all tests afterAll(() => { try { rmSync(TEST_DIR, { recursive: true, force: true }); } catch (error) { // Ignore cleanup errors } }); // Create a mock bundle index export function createMockIndex() { return { version: "1.0", last_bundle: 3, updated_at: new Date().toISOString(), total_size_bytes: 5000000, bundles: [ { bundle_number: 1, start_time: "2024-01-01T00:00:00.000Z", end_time: "2024-01-01T01:00:00.000Z", operation_count: 10000, did_count: 9500, hash: "abc123", content_hash: "def456", parent: "", compressed_hash: "ghi789", compressed_size: 1500000, uncompressed_size: 5000000, cursor: "", created_at: "2024-01-01T02:00:00.000Z", }, { bundle_number: 2, start_time: "2024-01-01T01:00:00.000Z", end_time: "2024-01-01T02:00:00.000Z", operation_count: 10000, did_count: 9600, hash: "jkl012", content_hash: "mno345", parent: "abc123", compressed_hash: "pqr678", compressed_size: 1600000, uncompressed_size: 5100000, cursor: "2024-01-01T01:00:00.000Z", created_at: "2024-01-01T03:00:00.000Z", }, { bundle_number: 3, start_time: "2024-01-01T02:00:00.000Z", end_time: "2024-01-01T03:00:00.000Z", operation_count: 10000, did_count: 9700, hash: "stu901", content_hash: "vwx234", parent: "jkl012", compressed_hash: "yza567", compressed_size: 1900000, uncompressed_size: 5200000, cursor: "2024-01-01T02:00:00.000Z", created_at: "2024-01-01T04:00:00.000Z", }, ], }; } // Create mock operations export function createMockOperations(count: number = 100) { const operations = []; for (let i = 0; i < count; i++) { operations.push({ did: `did:plc:${Math.random().toString(36).substring(7)}`, cid: `bafyrei${Math.random().toString(36).substring(7)}`, createdAt: new Date(Date.now() - i * 1000).toISOString(), operation: { type: "plc_operation", alsoKnownAs: i % 3 === 0 ? [`at://${i}.test`] : [], services: i % 2 === 0 ? { atproto_pds: { type: "AtprotoPersonalDataServer", endpoint: "https://bsky.social", }, } : {}, }, }); } return operations; } // Create a mock compressed bundle export async function createMockBundle(bundleNum: number, operations: any[]) { const jsonl = operations.map(op => JSON.stringify(op)).join('\n') + '\n'; const compressed = Bun.deflateSync(new TextEncoder().encode(jsonl)); return compressed; }