import test from 'node:test'; import assert from 'node:assert/strict'; import monitorModule from '../src/main/repository-monitor.cjs'; const { RepositoryMonitor } = monitorModule; test('repository monitor establishes a baseline and emits only on later changes', async () => { let revision = 1; const changes = []; const git = { status: async (localPath) => ({ localPath, revision }), statusFingerprint: (status) => String(status.revision) }; const store = { data: { preferences: { autoRefresh: true, repositoryPollSeconds: 2 } } }; const monitor = new RepositoryMonitor({ store, git, onChange: (change) => changes.push(change) }); monitor.setPaths(['/repo']); await monitor.tick(); assert.equal(changes.length, 0); revision = 2; await monitor.tick(); assert.equal(changes.length, 1); assert.equal(changes[0].reason, 'working-tree-changed'); monitor.pause('/repo'); revision = 3; await monitor.tick(); assert.equal(changes.length, 1); monitor.resume('/repo'); await monitor.tick(); assert.equal(changes.length, 2); }); test('repository monitor checks multiple repositories concurrently with a bounded worker pool', async () => { let active = 0; let peak = 0; const git = { status: async (localPath) => { active += 1; peak = Math.max(peak, active); await new Promise((resolve) => setTimeout(resolve, 15)); active -= 1; return { localPath, revision: 1 }; }, statusFingerprint: (status) => String(status.revision) }; const store = { data: { preferences: { autoRefresh: true, repositoryPollSeconds: 2 } } }; const monitor = new RepositoryMonitor({ store, git }); monitor.setPaths(Array.from({ length: 10 }, (_, index) => `/repo-${index}`)); await monitor.tick(); assert.equal(peak, 4); assert.equal(active, 0); assert.equal(monitor.fingerprints.size, 10); });