const { test } = require('node:test'); const assert = require('node:assert/strict'); const { createSessionizePoller } = require('../src/sessionize-poller'); test('polls events sequentially and isolates upstream failures', async () => { const calls = []; const failures = []; const poll = createSessionizePoller({ listEvents: async () => [{ id: 'first' }, { id: 'second' }], isBusy: () => false, syncEvent: async id => { calls.push(id); if (id === 'first') throw new Error('unavailable'); }, onError: (error, id) => failures.push(id) }); await poll(); assert.deepEqual(calls, ['first', 'second']); assert.deepEqual(failures, ['first']); }); test('does not overlap manual imports or another polling pass', async () => { let finish; let reads = 0; let busy = true; const pending = new Promise(resolve => { finish = resolve; }); const poll = createSessionizePoller({ listEvents: async () => { reads++; await pending; return []; }, isBusy: () => busy, syncEvent: async () => {}, onError: () => {} }); await poll(); assert.equal(reads, 0); busy = false; const first = poll(); await poll(); assert.equal(reads, 1); finish(); await first; await poll(); assert.equal(reads, 2); });