Tell a broken source apart from a stale one
CI failed on Infinity Nikki yielding no events, and was wrong to. Its snapshot parses to six events; every one of them had ended by the morning the build ran. The parser is fine — `--now 2026-08-14` gives six, today gives none — and the page simply has nothing current left on it. eventCount is counted after expired events are dropped, so "this parser has stopped reading a redesigned page" and "this page's events have all finished" arrived as the same zero. Only the first means our code is wrong, and only the first should redden a build. So the feed now records what each document yields parsed as of its own capture date, before expiry, and the check fails on that instead. Nikki cannot refresh itself out of this, either: docs/SOURCES.md records that Fandom refuses the Actions runner. A lane with an empty calendar is a real problem, but it is a refresh problem, so it is reported on the build log and left visible rather than thrown. parsedCount is nullable and defaulted, never required: the client validates the whole feed with safeParse and the service worker serves the last feed it downloaded, so a required field would have made every cached feed fail validation and taken the offline promise with it. Null also covers a source whose bytes were never confirmed live — there is no date to parse "as of", and a build is not failed on missing information. The rule moved to shared/feed.ts. A test did pin the old one, by grepping the workflow for the string — which proved the check existed, never that it was right. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
96d5230f29
commit
ef109f224b
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import {
|
||||
brokenSources,
|
||||
freshness,
|
||||
staleSources,
|
||||
STALE_AFTER_MS,
|
||||
type SourceHealth,
|
||||
} from "../src/shared/feed.ts";
|
||||
@@ -30,6 +32,8 @@ function source(
|
||||
url: "https://example.test/events",
|
||||
lastSuccessAt,
|
||||
eventCount: 3,
|
||||
|
||||
parsedCount: 3,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,3 +118,57 @@ describe("freshness", () => {
|
||||
expect(freshness([], NOW)).toEqual({ refreshedAt: null, stale: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe("telling a broken source from a stale one", () => {
|
||||
// CI failed on Infinity Nikki yielding nothing, and the check was wrong to.
|
||||
// Its snapshot parses to seven events; every one of them had simply ended by
|
||||
// the day the build ran. `eventCount` is measured after expiry, so "our
|
||||
// parser broke" and "this source has nothing current left" arrived as the
|
||||
// same zero — and only the first is a reason to redden a build.
|
||||
const health = (over: Partial<SourceHealth>): SourceHealth => ({
|
||||
sourceId: "nikki-fandom-events",
|
||||
game: "nikki" as GameId,
|
||||
url: "https://example.test/nikki",
|
||||
lastSuccessAt: "2026-08-19T00:00:00.000Z",
|
||||
eventCount: 0,
|
||||
parsedCount: 7,
|
||||
...over,
|
||||
});
|
||||
|
||||
test("a source that parsed nothing is broken", () => {
|
||||
// The failure this check exists for: a page changed shape and the parser
|
||||
// now reads it as empty. Nothing to publish and nothing to expire.
|
||||
expect(brokenSources([health({ parsedCount: 0 })]).map((s) => s.sourceId)).toEqual([
|
||||
"nikki-fandom-events",
|
||||
]);
|
||||
});
|
||||
|
||||
test("a source whose events have all ended is not broken", () => {
|
||||
// The Nikki case exactly. The parser did its job; the calendar moved past
|
||||
// everything the page still lists.
|
||||
expect(brokenSources([health({})])).toEqual([]);
|
||||
});
|
||||
|
||||
test("a healthy source is neither", () => {
|
||||
const ok = health({ eventCount: 5, parsedCount: 5 });
|
||||
expect(brokenSources([ok])).toEqual([]);
|
||||
expect(staleSources([ok])).toEqual([]);
|
||||
});
|
||||
|
||||
test("a source with nothing current left is reported as stale", () => {
|
||||
// Worth saying out loud — a lane showing an empty calendar is a real
|
||||
// problem — but it is a refresh problem, not a code one, so it is
|
||||
// reported rather than thrown.
|
||||
expect(staleSources([health({})]).map((s) => s.sourceId)).toEqual([
|
||||
"nikki-fandom-events",
|
||||
]);
|
||||
});
|
||||
|
||||
test("a feed that never recorded the count is not called broken", () => {
|
||||
// An older feed — one the service worker cached before this field existed
|
||||
// — says nothing either way, and absence of information is not evidence of
|
||||
// a fault.
|
||||
expect(brokenSources([health({ parsedCount: null })])).toEqual([]);
|
||||
expect(staleSources([health({ parsedCount: null })])).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user