0c9661d694
Pure date math, 0 LLM calls. 5 Vitest tests GREEN (28/28 total). Per ADR-011 + spec §6.3. Modes: - check (default, lefthook): warn if last_read_at >= 54 weeks ago. - record: bump counter (invoked manually or by future read-tracking hook). isStale threshold is inclusive (>= 54 weeks) — spec «через 54 недели» means at-or-past 54 weeks fires the warn. Smoke run OK — current counter (period_start 2026-05-19) shows 0 weeks ago. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { isStale, weeksSince } from './observer-of-observer.mjs';
|
|
|
|
describe('weeksSince', () => {
|
|
it('returns 0 for now', () => {
|
|
const now = new Date('2026-05-19T00:00:00Z');
|
|
expect(weeksSince(now.toISOString(), now)).toBe(0);
|
|
});
|
|
|
|
it('returns 1 for 7 days ago', () => {
|
|
const past = new Date('2026-05-12T00:00:00Z');
|
|
const now = new Date('2026-05-19T00:00:00Z');
|
|
expect(weeksSince(past.toISOString(), now)).toBe(1);
|
|
});
|
|
|
|
it('returns 54+ for ~1 year ago', () => {
|
|
const past = new Date('2025-05-05T00:00:00Z');
|
|
const now = new Date('2026-05-19T00:00:00Z');
|
|
expect(weeksSince(past.toISOString(), now)).toBeGreaterThanOrEqual(54);
|
|
});
|
|
});
|
|
|
|
describe('isStale', () => {
|
|
it('false when last_read_at is recent', () => {
|
|
const counter = { last_read_at: '2026-05-12T00:00:00Z' };
|
|
const now = new Date('2026-05-19T00:00:00Z');
|
|
expect(isStale(counter, 54, now)).toBe(false);
|
|
});
|
|
|
|
it('true when last_read_at is >54 weeks ago', () => {
|
|
const counter = { last_read_at: '2025-05-05T00:00:00Z' };
|
|
const now = new Date('2026-05-19T00:00:00Z');
|
|
expect(isStale(counter, 54, now)).toBe(true);
|
|
});
|
|
});
|