Implements openspec/changes/auto-detect-gap-closure. Catalog now covers all 114 product IDs the integration can report (was 57). 22 IDs mapped onto existing entries, unlocking 20 keg photos that already shipped but were unreachable; 36 new entries added for beers the card did not know. Product ID 48061 was mapped to the wrong beer -- it is Northern Monk Faith, not A Little Faith -- so it now has its own entry. Detection precedence is explicit: beer_name override, then product ID, then reported keg name, then an honest no-keg state. Removes the fallback that displayed Leffe Blonde whenever detection failed, and prefers the card's curated name over the integration's product-listing name (12 labels). beer_name returns as an optional override, empty by default, which also un-orphans custom_beers. Cards on integrations without the keg sensors now get told to update rather than shown a wrong beer. _resolveEntities no longer latches on temperature alone. Adds npm run check:catalog to catch upstream catalog drift, the root cause of the original gap. Hardware verification (tasks 8.1-8.3) still outstanding. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Compares the card catalog's kegId coverage against a committed snapshot of the
|
|
// PerfectDraft integration's keg_catalog.json. The card joins against the
|
|
// integration on product ID, so a gap here is a keg that renders without its
|
|
// branding. Run via `npm run check:catalog`.
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, join } from "node:path";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const reference = JSON.parse(readFileSync(join(here, "keg-catalog.reference.json"), "utf8"));
|
|
const source = readFileSync(join(here, "..", "src", "beer-catalog.ts"), "utf8");
|
|
|
|
const upstream = reference.kegs;
|
|
|
|
// The catalog is one entry per line, which keeps this parse honest without
|
|
// pulling in a TypeScript parser just for a data check.
|
|
const entries = [];
|
|
for (const line of source.split("\n")) {
|
|
const slug = line.match(/slug: "(.*?)"/);
|
|
if (!slug) continue;
|
|
const name = line.match(/name: "(.*?)"/);
|
|
const kegId = line.match(/kegId: "(\d+)"/);
|
|
entries.push({ slug: slug[1], name: name?.[1] ?? "", kegId: kegId?.[1] });
|
|
}
|
|
|
|
const problems = [];
|
|
|
|
const seen = new Map();
|
|
for (const entry of entries) {
|
|
if (!entry.kegId) continue;
|
|
if (seen.has(entry.kegId)) {
|
|
problems.push(
|
|
`duplicate kegId ${entry.kegId}: "${seen.get(entry.kegId).slug}" and "${entry.slug}"`,
|
|
);
|
|
continue;
|
|
}
|
|
seen.set(entry.kegId, entry);
|
|
}
|
|
|
|
for (const [kegId, entry] of seen) {
|
|
if (!(kegId in upstream)) {
|
|
problems.push(`kegId ${kegId} on "${entry.slug}" is absent from the integration catalog`);
|
|
}
|
|
}
|
|
|
|
for (const [kegId, name] of Object.entries(upstream)) {
|
|
if (!seen.has(kegId)) {
|
|
problems.push(`product ID ${kegId} ("${name}") has no card catalog entry`);
|
|
}
|
|
}
|
|
|
|
const covered = Object.keys(upstream).filter((id) => seen.has(id)).length;
|
|
const total = Object.keys(upstream).length;
|
|
console.log(
|
|
`catalog: ${entries.length} entries, ${seen.size} mapped product IDs, ` +
|
|
`${covered}/${total} of the integration catalog covered ` +
|
|
`(upstream snapshot @ ${reference._upstreamCommit})`,
|
|
);
|
|
|
|
if (problems.length > 0) {
|
|
console.error(`\n${problems.length} problem(s):`);
|
|
for (const problem of problems.sort()) console.error(` - ${problem}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("catalog coverage is complete and consistent");
|