Files
bggpipe/scripts/record_fixtures.py
T
Eric Wagoner 10f65d8aba Credibility pass: comments state constraints, not development history
A skeptical-cloner review flagged the patterns that read as AI-iteration
residue: test comments and section headers narrating the review process
that produced them, "legacy format" framing in a days-old repo, shadow
re-imports appended without reading file headers, one genuine machine
leftover (FIXTURE_CACHE = FIXTURE_CACHE), and a few register slips.
Every history-narrating comment is rewritten as the timeless invariant
it was guarding, test sections are grouped by behavior, function-local
imports are hoisted, and the README loses its one marketing clause and
heaviest dash runs. No behavior changes; 176 tests unchanged and green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-02 15:08:22 -04:00

46 lines
1.5 KiB
Python

"""Record the BGG XML fixtures the test suite replays.
Runs the real resolve logic with the cache pointed at tests/fixtures/
bgg_cache/, so exactly the responses resolve needs get recorded (live,
rate-limited). Run once; commit the fixtures. Re-running only fetches
whatever is not already recorded.
Usage: uv run python scripts/record_fixtures.py
"""
from __future__ import annotations
import os
from pathlib import Path
from fixture_common import FIXTURE_CACHE
from bggpipe.bgg_client import BGGClient
from bggpipe.resolve import load_titles, resolve_entry
def main() -> None:
if not os.environ.get("BGG_API_TOKEN"):
raise SystemExit(
"BGG_API_TOKEN is not set. The XML API requires a registered "
"application token (https://boardgamegeek.com/applications). "
"Until one exists, the committed fixtures are the hand-crafted "
"stubs from scripts/write_stub_fixtures.py; delete "
f"{FIXTURE_CACHE} and re-run this script to replace them with "
"real recordings."
)
client = BGGClient(cache_dir=FIXTURE_CACHE)
for entry in load_titles(Path("tests/data/titles.json")):
row = resolve_entry(client, entry)
print(
f"{entry.title_raw!r}: {row.match_status} "
f"{row.bgg_name or '-'} ({row.bgg_id or '-'}) {row.version_status}"
)
print(f"\nFixtures recorded in {FIXTURE_CACHE}:")
for f in sorted(FIXTURE_CACHE.iterdir()):
print(f" {f.name}")
if __name__ == "__main__":
main()