fix(hooks): count X as active only when both AUTH_TOKEN and CT0 are set (#396)#475
fix(hooks): count X as active only when both AUTH_TOKEN and CT0 are set (#396)#475harjothkhara wants to merge 2 commits into
Conversation
…et (mvanhorn#396) check-config.sh's SessionStart "N sources active" line counted X whenever AUTH_TOKEN was present: HAS_X="${ENV_AUTH_TOKEN:-${AUTH_TOKEN:-}}" But X cookie search is only functional when both AUTH_TOKEN and CT0 are configured — the pipeline gates on both (setup_wizard.py's `x_method="cookies"` branch, env.py), and `--diagnose` omits X from available_sources when CT0 is missing. So a half-configured X (auth_token only, no ct0) was reported as an active source, inflating the count and telling users a dead source was live. Require both cookies for the cookie path; the XAI API path (XAI_API_KEY) is unchanged. The post-research counter (lib/quality_nudge.py) is unaffected — it already corrects via the run's x_error signal, which the pre-run hook does not have, so credential presence is all the hook can rely on. Added 4 regression tests in tests/test_last_run_state.py covering auth_token-only, auth_token+ct0, ct0-only, and xai-only. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Greptile SummaryThis PR fixes a source-counting bug in the
Confidence Score: 5/5Safe to merge — the change is a narrowly scoped fix to a cosmetic counter with no impact on runtime data or authentication logic. The shell change is minimal and self-contained: two new variable reads and a two-condition guard replace a single assignment. The XAI path and all other source counters are untouched. The four new tests exercise every credential combination using a delta approach that is robust to environment variation, and prior review feedback (context-manager cleanup, full env-var stripping) has been incorporated. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "test(hooks): make X source-count tests e..." | Re-trigger Greptile |
Addresses Greptile review on mvanhorn#475: - The env-sanitization pass omitted BSKY_HANDLE and EXA_API_KEY, and yt-dlp (detected via PATH, not an env var) couldn't be stripped at all — so the hardcoded 3/4 expected counts would fail on any machine where those were set or yt-dlp was installed. - Assertions are now delta-based: X's contribution = count(with X creds) − count(no-X baseline). Anything constant between the two runs (yt-dlp, bsky, exa, scrapecreators) cancels, so the tests assert only the 0/1 that X adds. - The env strip list still drops the X-determining vars (AUTH_TOKEN, CT0, XAI_API_KEY) plus BSKY_HANDLE/EXA_API_KEY for clarity. - Switched the temp-dir helper from tempfile.mkdtemp() (leaked a dir per call) to a tempfile.TemporaryDirectory() context manager, matching the existing tests in this file. Verified passing both normally and under a hostile env (leaked BSKY_HANDLE/EXA_API_KEY/AUTH_TOKEN/CT0 + a stub yt-dlp on PATH). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks for the review — both points addressed in d7fbda1 (test-only; the
|
Summary
Addresses part 2 of #396. The SessionStart hook's
N sources activeline counted X as active wheneverAUTH_TOKENwas set, even withoutCT0:HAS_X="${ENV_AUTH_TOKEN:-${AUTH_TOKEN:-}}"But X cookie search only works when both
AUTH_TOKENandCT0are present — the pipeline gates on both (setup_wizard.py'sx_method="cookies"branch,env.py), and--diagnoseomits X fromavailable_sourceswhenCT0is missing. So a half-configured X (auth_token only) was reported as a live source, inflating the count and telling users a dead source was active.Changes
hooks/scripts/check-config.sh— require bothAUTH_TOKENandCT0for the X cookie path. The XAI API path (XAI_API_KEY) is unchanged.tests/test_last_run_state.py— 4 regression tests (auth_token-only → not counted, auth_token+ct0 → counted, ct0-only → not counted, xai-only → counted).The post-research counter (
lib/quality_nudge.py) is intentionally left as-is: it already corrects via the run'sx_errorsignal, which the pre-run hook does not have, so credential presence is all the hook can rely on.Before / after
With
SETUP_COMPLETE=1andAUTH_TOKENset but noCT0:Adding
CT0then correctly bumps it to 4.Testing
uv run --python 3.13 --with pytest python -m pytest -q --ignore=tests/test_bird_x.py→ all green. (test_bird_x.pyfails onmaintoo — unrelated local Node ESM issue.)bash -n hooks/scripts/check-config.sh→ syntax OK.Notes
This touches a different region of
check-config.sh(source counting, ~line 118) than the in-flight exit-code PRs (#471/#430/#425) and the Windows-perms PR (#467), so it should merge without conflict.Related Issues
Addresses #396 (part 2 — source counting). The template wording in part 1 no longer appears in
SKILL.md/setup_wizard.pyon currentmain.