Files
bggpipe/tests/test_config.py
T
Eric Wagoner 08b741671d Re-audit round 4: 5 blind reviewers over the new surface — 24 fixes, +28 tests
The findings clustered exactly where prediction said: the unreviewed web
layer. The big ones: decisions made while an extract/resolve job runs
are now refused with a 409 (the job's end-of-run rewrite from a
start-of-run snapshot would silently revert them); a cross-origin guard
blocks preflight-free mutations from hostile webpages (bodyless run
triggers, cross-site photo form posts); the JobRunner sets terminal
status in a finally catching BaseException (a greenlet death could
wedge every future run behind 409s) and writes tracebacks into the
visible job log; and a boot token lets clients accept the revision
reset after a server restart instead of freezing forever.

Even the thrice-audited core yielded one HIGH: an unvetoed bare
typo-read sibling of a confident row duplicated its add when the game
wasn't in the collection — diff now treats it as satisfied. Second-copy
adds carry a flag through to_add.csv and the upload log so verify
honestly reports them unverifiable instead of OK. Also: merged_into
chains collapse transitively; diff/enrich treat a BGG queue timeout
like a missing token; enrich prunes orphaned games.json keys; the
wizard shell-quotes .env values and creates the file 0600 from the
first byte; fsio stats the tmp inode before replace and uses unique tmp
names; an explicit missing --config errors; storage state is
owner-only; extract re-extracts corrupt caches, aborts on 3 identical
failures, and exits nonzero when nothing succeeded; torn JSON artifacts
degrade with in-browser warnings instead of 500ing every page; photo
uploads are atomic with cache-invalidation ordered first; the pipeline
page computes `running` before the buttons that depend on it; the
photo dropzone alerts on network failure; and lost-contact banners
clear on recovery everywhere.

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

57 lines
1.9 KiB
Python

"""Config loading: toml knobs, env-only username, unknown-key warning."""
from __future__ import annotations
from pathlib import Path
from bggpipe.config import Config, load_config
def test_defaults_when_no_file(tmp_path, monkeypatch):
# no config.toml in cwd and no explicit path -> defaults (an EXPLICIT
# missing path errors instead; see the dedicated test)
monkeypatch.delenv("BGG_USERNAME", raising=False)
monkeypatch.chdir(tmp_path)
cfg = load_config()
assert cfg == Config()
assert cfg.cache_dir == Path("data/bgg_cache")
def test_reads_toml(tmp_path, monkeypatch):
monkeypatch.delenv("BGG_USERNAME", raising=False)
p = tmp_path / "config.toml"
p.write_text('data_dir = "elsewhere"\nrate_limit_seconds = 3\n')
cfg = load_config(p)
assert cfg.data_dir == Path("elsewhere")
assert cfg.rate_limit_seconds == 3.0
assert cfg.matches_path == Path("elsewhere/matches.csv")
def test_username_comes_from_env_only(tmp_path, monkeypatch):
# the account has exactly one home: BGG_USERNAME in the environment —
# a bgg_username key in config.toml is deliberately ignored
p = tmp_path / "config.toml"
p.write_text('bgg_username = "from_toml"\n')
monkeypatch.setenv("BGG_USERNAME", "from_env")
assert load_config(p).bgg_username == "from_env"
monkeypatch.delenv("BGG_USERNAME")
assert load_config(p).bgg_username == ""
def test_unknown_toml_keys_warn(tmp_path, monkeypatch):
# a typo'd knob must not silently fall back to defaults
import pytest
monkeypatch.delenv("BGG_USERNAME", raising=False)
p = tmp_path / "config.toml"
p.write_text('photo_dir = "oops"\n')
with pytest.warns(UserWarning, match="photo_dir"):
load_config(p)
def test_explicit_missing_config_errors_instead_of_silent_defaults(tmp_path):
import pytest
with pytest.raises(FileNotFoundError, match="does not exist"):
load_config(tmp_path / "nope.toml")