diff --git a/PROJECT_HYGIENE.md b/PROJECT_HYGIENE.md index fbac9a3..2c4051c 100644 --- a/PROJECT_HYGIENE.md +++ b/PROJECT_HYGIENE.md @@ -199,7 +199,7 @@ When the user corrects your approach, append a one-line rule here before ending - **TODO — own OpenSpec change: persist Cognito-refreshed tokens back to the config entry.** `PerfectDraftApiClient.refresh_access_token()` updates `_access_token`/`_id_token` in memory only, so every HA restart reloads the stale access token and burns a wasted 401-plus-refresh round trip before the first successful poll. Harmless today because the refresh token is what actually gates reauth and Cognito's `REFRESH_TOKEN_AUTH` never issues a new one, so nothing is lost — just wasteful. Deferred out of `fix-reauth-flow` to keep that diff surgical. - **TODO — housekeeping, after `fix-cognito-signin` / `add-keg-48180` ship: take the GitHub token out of the `github` remote URLs** in both this repo and `Hassio-PerfectDraftPro-Component`. Not a leak (never committed; `.git/` is untracked), but `git remote -v` prints it. Order matters: first change `credential.helper` to an **absolute** path (`store --file=/home/rick/Lab/Dev//.git/credentials`) — the current relative `.git/credentials` resolves against the worktree root, where `.git` is a file, so pushes from `.worktree/` only reach `github` (whose URL carries the token); pushing to `origin` from a worktree fails with "unable to open .git/credentials: Not a directory". Until fixed, push agent branches from the main checkout: `git push origin agent/` (no branch switch needed). Then strip the URL, run `git ls-remote github` from a worktree to prove auth, and update the `AGENTS.md` helper command to the absolute form. - **Config-flow tests run in `.venv-test` (main checkout) on the system Python 3.14** with `pytest-homeassistant-custom-component==0.13.375` (core 2026.10.4). Run them from a worktree as `../../.venv-test/bin/pytest tests/`. Do not pin a harness that needs Python 3.12: there is no 3.12 and no C compiler on the dev host, so old numpy cannot build. -- **In Chromium's DevTools console, `copy()` only exists while the typed command is evaluating** — inside a `.then` or after any `await` it is `undefined`. Capture it up front: `(c => promise.then(t => c(t)))(copy)`. Verified 2026-11-07 via CDP `replMode` + `includeCommandLineAPI`. +- **DevTools `copy()` cannot copy an async result in any browser.** Chromium removes `copy` once the typed command returns (`undefined` in `.then`/after `await`); Firefox's `copy()` only sets a `helperResult` read when evaluation returns, so a later call silently copies nothing — and a captured `copy` reference "works" in Chromium tests while failing in Firefox. Store the value in a global in one command, then `copy(global)` in a second. Test console snippets in Firefox too, not only via CDP/Chromium. - **`gh` is not installed; use the GitHub REST API with `curl`.** Get the token with `printf 'protocol=https\nhost=github.com\n\n' | git credential fill`. The token is fine-grained: since 2026-11-07 it has Issues and Pull requests read/write in addition to admin/push. A `403 Resource not accessible by personal access token` means a permission is missing on the token, not a bad token. - **TODO — own OpenSpec change + release: remove pour-count-based keg detection** from `PerfectDraftKegFreshnessSensor` in `sensor.py`: trigger (a) `pours == 0 && kegVolume > 5.5 && last_pours != 0`, plus the `_last_pours` field and its restore/exposure/rebaseline. It can false-fire on a power cycle while the keg is above ~92% full, and adds nothing the volume triggers (b/c) and the Mark Keg Changed button don't already cover. diff --git a/openspec/changes/fix-cognito-signin/design.md b/openspec/changes/fix-cognito-signin/design.md index 386f53a..49d51aa 100644 --- a/openspec/changes/fix-cognito-signin/design.md +++ b/openspec/changes/fix-cognito-signin/design.md @@ -49,7 +49,7 @@ reCAPTCHA Enterprise tokens are single-use, so the token is spent either way. As Home Assistant fills error placeholders from `description_placeholders`. Every `async_show_form` for `user`, `reauth_confirm` and `token` passes `{"reason": ...}`, with an empty string when there is no error, so no form can render a literal `{reason}`. The reason is the Cognito `message`, with any trailing period removed (the string supplies punctuation) and truncated to 200 characters. It is also logged at error level, as today. The log contains the Cognito error body only, never the request. **README: copy to the clipboard instead of printing the token.** -`copy()` is a DevTools console utility in Chrome, Edge, Firefox and Safari. Chromium only exposes it while the typed command is evaluating; inside the `.then` callback it is already gone (verified 2026-11-07: `typeof copy` is `"function"` synchronously and `"undefined"` after any await or callback). So the snippet captures it up front: `(c => grecaptcha.enterprise.execute(…).then(t => { c(t); console.log('Token copied to clipboard') }))(copy)`. The captured reference stays callable. Users no longer have to select a 2,600-character string, and nothing scrolls past. A sentence notes that the command should be run once at the console prompt, not as a "Live expression", which re-runs it continuously. That is the most likely explanation for #13's stream of tokens. +`copy()` is a DevTools console utility in Chrome, Edge, Firefox and Safari, but only works while the typed command is still evaluating, and the token arrives asynchronously. In Chromium, `copy` is `undefined` inside a `.then` or after an `await` (verified 2026-11-07). In Firefox, `copy()` only records a `helperResult` that the console reads when evaluation returns (`eval-with-debugger.js`: `helperResult: helpers.getHelperResult()`), so a later call logs nothing and copies nothing (reported by the maintainer 2026-11-07). The README therefore uses two commands: the first stores the token in `window.pdToken` and prints "Token ready. Now run: copy(pdToken)", and the second runs `copy(pdToken)` synchronously. The fallback is evaluating `pdToken` and copying the printed string by hand. Users no longer have to select a 2,600-character string, and nothing scrolls past. A sentence notes that the command should be run once at the console prompt, not as a "Live expression", which re-runs it continuously. That is the most likely explanation for #13's stream of tokens. **Tests: stdlib-only for the client, existing harness for the flow.** `tests/test_api_authenticate.py` loads `api.py` without Home Assistant and drives a fake session. It covers the request shape, success, a challenge, each rejection kind, non-JSON bodies, other statuses and `ClientError`. `tests/test_config_flow.py` gains one test per error key, covering the form each lands on and the placeholder. It also gains a check that every config error key used in `config_flow.py` exists in both translation files, mirroring the existing abort-reason check. diff --git a/openspec/changes/fix-cognito-signin/tasks.md b/openspec/changes/fix-cognito-signin/tasks.md index 1af69b9..a8b01be 100644 --- a/openspec/changes/fix-cognito-signin/tasks.md +++ b/openspec/changes/fix-cognito-signin/tasks.md @@ -18,7 +18,7 @@ ## 4. README -- [ ] 4.1 Change the step 2 snippet to copy the token (via a `copy` reference captured before the promise, since Chromium removes `copy` once the command returns) plus a "Token copied to clipboard" log line; reword steps 4–5 to "paste it"; add one sentence to run it once at the console prompt (not as a Live expression) and a fallback line using `console.log(t)`; verify the snippet runs in a browser console on the en-gb login page and the clipboard holds a ~2,600-char token +- [ ] 4.1 Change step 2 to two commands — store the token in `window.pdToken` and print "Token ready. Now run: copy(pdToken)", then `copy(pdToken)` — because neither Chromium nor Firefox can `copy()` from an async callback; test in Firefox and Chrome/Edge; reword steps 4–5 to "paste it"; add one sentence to run it once at the console prompt (not as a Live expression) and a fallback line using `console.log(t)`; verify the snippet runs in a browser console on the en-gb login page and the clipboard holds a ~2,600-char token ## 5. On-device verification and version