Docs/Skills and code/tests/
tests/rating-evidence.test.js
import test from "node:test";
import assert from "node:assert/strict";
import { parseCalendarDay, calendarAgeDays, classifyDateWindow, isSnapshotDue, selectSnapshotCohort, breakoutEligibility } from "../src/analysis/rating-evidence.js";
const now = new Date("2026-10-12T12:00:00.000Z");
test("calendar dates are parsed as UTC calendar days without timezone drift", () => {
assert.equal(parseCalendarDay("2026-09-01").toISOString(), "2026-09-01T00:00:00.000Z");
assert.equal(parseCalendarDay("2026-02-30"), null);
assert.equal(parseCalendarDay("3 weeks ago"), null);
});
test("recent and baseline windows are disjoint and anchored to UTC day", () => {
assert.equal(classifyDateWindow("2026-10-12", now), "recent");
assert.equal(calendarAgeDays("2026-07-14", now), 90);
assert.equal(classifyDateWindow("2026-07-14", now), "recent");
assert.equal(classifyDateWindow("2026-07-13", now), "baseline");
assert.equal(classifyDateWindow("2024-10-11", now), "outside");
assert.equal(classifyDateWindow(null, now), "unknown");
});
test("snapshot freshness guard respects age and force", () => {
assert.equal(isSnapshotDue(null, 24, now), true);
assert.equal(isSnapshotDue("2026-10-12T00:00:00.000Z", 24, now), false);
assert.equal(isSnapshotDue("2026-10-11T00:00:00.000Z", 24, now), true);
assert.equal(isSnapshotDue("2026-10-12T11:59:00.000Z", 24, now, true), true);
});
test("fixed cohort is selected before freshness filter and bounded per channel", () => {
const rows = [
{ video_id: "a1", channel_url: "a", published_at_normalized: "2026-10-10", latest_snapshot_at: "2026-10-12T00:00:00.000Z" },
{ video_id: "a2", channel_url: "a", published_at_normalized: "2026-10-09", latest_snapshot_at: null },
{ video_id: "a3", channel_url: "a", published_at_normalized: "2026-10-08", latest_snapshot_at: null },
{ video_id: "b1", channel_url: "b", published_at_normalized: "2026-10-11", latest_snapshot_at: null },
{ video_id: "b2", channel_url: "b", published_at_normalized: "2026-05-01", latest_snapshot_at: null }
];
const result = selectSnapshotCohort(rows, { scope: "recent", perChannel: 2, limit: 10, minAgeHours: 24, now });
assert.equal(result.cohortCount, 3);
assert.deepEqual(result.selected.map(v => v.video_id).sort(), ["a2", "b1"]);
});
test("snapshot cohort separates baseline from recent and can include unknown dates in all scope", () => {
const rows = [
{ video_id: "recent", channel_url: "a", published_at_normalized: "2026-10-01" },
{ video_id: "old", channel_url: "a", published_at_normalized: "2026-01-01" },
{ video_id: "unknown", channel_url: "a", published_at_normalized: null, published_at: "2 months ago" }
];
assert.equal(selectSnapshotCohort(rows, { scope: "recent", perChannel: 5, limit: 10, minAgeHours: 0, now, force: true }).cohortCount, 1);
assert.equal(selectSnapshotCohort(rows, { scope: "baseline", perChannel: 5, limit: 10, minAgeHours: 0, now, force: true }).cohortCount, 1);
assert.equal(selectSnapshotCohort(rows, { scope: "all", perChannel: 0, limit: 10, minAgeHours: 0, now, force: true }).cohortCount, 3);
});
test("breakout eligibility reports missing recent and baseline evidence separately", () => {
assert.deepEqual(breakoutEligibility(3, 3), { eligible: true, missingRecent: 0, missingBaseline: 0 });
assert.deepEqual(breakoutEligibility(5, 1), { eligible: false, missingRecent: 0, missingBaseline: 2 });
});
test("month/year precision estimates are excluded from recent and baseline snapshot cohorts", () => {
const rows = [
{ video_id: "exact-recent", channel_url: "a", published_at_normalized: "2026-10-10", published_at_precision: "exact_day" },
{ video_id: "estimated-month", channel_url: "a", published_at_normalized: "2026-09-15", published_at_precision: "estimated_month" },
{ video_id: "estimated-year", channel_url: "a", published_at_normalized: "2026-01-01", published_at_precision: "estimated_year" },
{ video_id: "exact-baseline", channel_url: "a", published_at_normalized: "2026-04-01", published_at_precision: "exact_day" }
];
const recent = selectSnapshotCohort(rows, { scope: "recent", perChannel: 5, limit: 10, minAgeHours: 0, now, force: true });
const baseline = selectSnapshotCohort(rows, { scope: "baseline", perChannel: 5, limit: 10, minAgeHours: 0, now, force: true });
assert.deepEqual(recent.selected.map(v => v.video_id), ["exact-recent"]);
assert.deepEqual(baseline.selected.map(v => v.video_id), ["exact-baseline"]);
});
Shown as it is in the repository at build time (2026-11-03); the home directory appears as <home>. If this page and the file differ, the file is right. Back to the catalogue.