⚡ Zero-dependency plcbundle library exclusively for Bun
1import { describe, test, expect, beforeEach } from 'bun:test';
2import { PLCBundle } from '../src/plcbundle';
3import { TEMP_DIR, createMockIndex, createMockOperations } from './setup';
4
5describe('CLI Commands', () => {
6 let detectModulePath: string;
7 let processModulePath: string;
8
9 beforeEach(async () => {
10 const bundle = new PLCBundle(TEMP_DIR);
11 const mockIndex = createMockIndex();
12 await bundle.saveIndex(mockIndex);
13
14 // Create test bundles
15 for (let i = 1; i <= 3; i++) {
16 const operations = createMockOperations(100);
17 const jsonl = operations.map(op => JSON.stringify(op)).join('\n') + '\n';
18 const compressed = Bun.zstdCompressSync(new TextEncoder().encode(jsonl));
19 await Bun.write(bundle.getBundlePath(i), compressed);
20 }
21
22 // Create test modules - use absolute paths
23 detectModulePath = `${process.cwd()}/${TEMP_DIR}/test-detect.ts`;
24 await Bun.write(detectModulePath, `
25 export function detect({ op }) {
26 return op.did.includes('test') ? ['test'] : [];
27 }
28 `);
29
30 processModulePath = `${process.cwd()}/${TEMP_DIR}/test-process.ts`;
31 await Bun.write(processModulePath, `
32 let count = 0;
33 export function process({ op }) {
34 count++;
35 }
36 `);
37 });
38
39 describe('detect command', () => {
40 test('module can be imported and has detect function', async () => {
41 const mod = await import(detectModulePath);
42 expect(mod.detect).toBeDefined();
43 expect(typeof mod.detect).toBe('function');
44
45 const result = mod.detect({ op: { did: 'test123' } });
46 expect(Array.isArray(result)).toBe(true);
47 });
48 });
49
50 describe('process command', () => {
51 test('module can be imported and has process function', async () => {
52 const mod = await import(processModulePath);
53 expect(mod.process).toBeDefined();
54 expect(typeof mod.process).toBe('function');
55 });
56 });
57
58 describe('module loading', () => {
59 test('detect module returns labels array', async () => {
60 const mod = await import(detectModulePath);
61
62 const result1 = mod.detect({ op: { did: 'did:plc:test123' } });
63 expect(result1).toContain('test');
64
65 const result2 = mod.detect({ op: { did: 'did:plc:abc' } });
66 expect(result2).toEqual([]);
67 });
68
69 test('process module executes without errors', async () => {
70 const mod = await import(processModulePath);
71
72 // Should not throw
73 mod.process({ op: { did: 'test' }, position: 0, bundle: 1, line: '{}' });
74 expect(true).toBe(true);
75 });
76 });
77});