import { describe, it, expect } from 'vitest'; import { checkCoverage, checkRegistration } from './observer-coverage-checker.mjs'; describe('checkCoverage', () => { it('flags recent commits but zero episodes', () => { const r = checkCoverage(0, 7); expect(r.ok).toBe(false); expect(r.detail).toContain('0 observer episodes'); }); it('is ok when episodes exist', () => { expect(checkCoverage(5, 7).ok).toBe(true); }); it('is ok when there is no recent git activity', () => { expect(checkCoverage(0, 0).ok).toBe(true); }); }); describe('checkRegistration', () => { const goodSettings = { hooks: { Stop: [{ hooks: [{ type: 'command', command: 'node tools/observer-stop-hook.mjs' }] }] }, }; it('is ok when the Stop-hook is registered and post-commit exists', () => { const r = checkRegistration(goodSettings, true); expect(r.ok).toBe(true); }); it('flags a missing Stop-hook registration', () => { const r = checkRegistration({ hooks: { Stop: [] } }, true); expect(r.ok).toBe(false); expect(r.detail).toContain('observer-stop-hook NOT registered'); }); it('flags a missing post-commit hook', () => { const r = checkRegistration(goodSettings, false); expect(r.ok).toBe(false); expect(r.detail).toContain('post-commit'); }); it('handles an empty settings object', () => { expect(checkRegistration({}, false).ok).toBe(false); }); });