397777089e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.7 KiB
JavaScript
72 lines
2.7 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { checkCoverage, checkRegistration, runCoverageChecker } from './observer-coverage-checker.mjs';
|
|
|
|
describe('checkCoverage', () => {
|
|
// COV-1 fix: the metric is driven by Stop-hook registration, NOT by recent
|
|
// commit volume. Comparing commits-to-episodes is wrong-unit + wrong-window
|
|
// (commits ≠ turns; a 14-day window mostly predates a freshly-registered
|
|
// hook). The honest signal is: "the hook is registered, so we expect
|
|
// episodes — if there are 0 this month, the hook is silently dead".
|
|
|
|
it('flags 0 episodes when the Stop-hook is registered', () => {
|
|
const r = checkCoverage(0, true);
|
|
expect(r.ok).toBe(false);
|
|
expect(r.detail).toContain('0');
|
|
expect(r.detail).toMatch(/registered|episode/i);
|
|
});
|
|
|
|
it('is ok when episodes exist and hook is registered', () => {
|
|
expect(checkCoverage(5, true).ok).toBe(true);
|
|
});
|
|
|
|
it('is ok when the hook is NOT registered (no expectation of episodes)', () => {
|
|
// If the hook was never installed in this repo, 0 episodes is correct,
|
|
// not a defect — silence here would have been a false alarm.
|
|
expect(checkCoverage(0, false).ok).toBe(true);
|
|
});
|
|
|
|
it('detail does NOT reference a commit-count ratio (drift hazard)', () => {
|
|
// The legacy "X episodes vs Y commits" wording implied commit≈episode is
|
|
// a target — misleading because commits=work-unit, episodes=turn-unit.
|
|
expect(checkCoverage(5, true).detail).not.toMatch(/commit/i);
|
|
expect(checkCoverage(0, true).detail).not.toMatch(/commit/i);
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|
|
|
|
describe('runCoverageChecker — missed surfacing', () => {
|
|
it('returns a missed field with totalMissed', () => {
|
|
const { missed } = runCoverageChecker();
|
|
expect(missed).toBeDefined();
|
|
expect(typeof missed.totalMissed).toBe('number');
|
|
expect(missed.byNode).toBeDefined();
|
|
expect(missed.byClassification).toBeDefined();
|
|
});
|
|
});
|