/** * ping-pong workflow test — validates engine can run workflows. * * 小橘 🍊 (NEKO Team) */ import { afterEach, describe, expect, it } from 'bun:test'; import { mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { createStore, createWorkflowRule } from '@uncaged/pulse'; import { pingPong } from './ping-pong.js'; describe('ping-pong workflow', () => { let tmpDir: string; afterEach(() => { if (tmpDir) rmSync(tmpDir, { recursive: true, force: true }); }); it('START → pong → END', async () => { tmpDir = mkdtempSync(join(tmpdir(), 'engine-test-')); const store = createStore({ eventsDbPath: join(tmpDir, 'test.db'), objectsDir: join(tmpDir, 'objects'), }); const rule = createWorkflowRule(pingPong, store); // Trigger const hash = await store.putObject('ping'); await store.appendEvent({ occurredAt: Date.now(), kind: 'ping-pong.__start__', key: 't1', hash, }); const r1 = await rule.tick(); expect(r1.executed).toMatchObject([{ topicId: 't1', role: 'pong' }]); expect(r1.executed[0].content).toBe('pong: ping'); // No more work const r2 = await rule.tick(); expect(r2.executed).toEqual([]); store.close(); }); });