openspec(fix-cognito-signin): button-based token copy after prompt() truncation

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-07 11:56:13 +01:00
co-authored by Cursor
parent 5ebdc2c3c1
commit b0024c1b74
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -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/<repo>/.git/credentials`) — the current relative `.git/credentials` resolves against the worktree root, where `.git` is a file, so pushes from `.worktree/<topic>` 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/<topic>` (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.
- **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. For user-facing snippets, keep one command and hand the value over via `prompt(msg, value)` (pre-selected, Ctrl+C). Test console snippets in Firefox too, not only via CDP/Chromium.
- **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. Do not use `prompt(msg, value)` either: Chromium cuts the default value off at 2,000 chars, and reCAPTCHA tokens are ~2,450–2,700. For user-facing snippets, keep one command that adds a page button whose click calls `navigator.clipboard.writeText(value)`. Test console snippets in Firefox too, not only via CDP/Chromium.
- **Cursor's embedded browser replaces `alert`/`confirm`/`prompt` with logging stubs** (`[CursorBrowser] Dialog suppressed`, history in `window.__cursorDialogConfig.dialogHistory`). A missing dialog there says nothing about real browsers; read the history to check the arguments, and have a human check the native dialog.
- **`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.
@@ -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, 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). A two-command version (store in a global, then `copy()` it) works but adds a step for users who rarely open DevTools, so it was rejected. The README instead keeps one command that opens `prompt()` with the token as the default value. The native dialog shows it selected, so Ctrl+C / Cmd+C copies it, with no reliance on console helpers. The command also `console.log`s the token as a fallback for browsers that block dialogs. Cursor's embedded browser suppresses dialogs, so the native dialog must be checked by hand in Firefox and Chrome (task 4.1). The CDP check only confirmed that `prompt` received the full token. 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). A two-command version (store in a global, then `copy()` it) works but adds a step for users who rarely open DevTools, so it was rejected. `prompt(msg, token)` was also rejected. Chromium cuts a prompt's default value off at 2,000 characters (the maintainer's test copied exactly 2,000), and tokens run to about 2,450–2,700. The README keeps one command that adds a fixed **Click to copy your PerfectDraft token** button to the page. Its click handler calls `navigator.clipboard.writeText(token)`: the click is the user activation and page focus the Clipboard API needs, so there is no length cap and no console helper involved. The command also `console.log`s the token as a fallback. In Cursor's embedded browser the write fails with "Document is not focused" because the view never has OS focus. The real-browser check is task 4.1. The CDP check only confirmed that `prompt` received the full token. 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.
+1 -1
View File
@@ -18,7 +18,7 @@
## 4. README
- [ ] 4.1 Keep step 2 to one command that logs the token and opens `prompt()` with it pre-selected (DevTools `copy()` cannot copy an async result in Firefox or Chromium); test the native dialog 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
- [ ] 4.1 Keep step 2 to one command that logs the token and adds a "Click to copy" button using `navigator.clipboard.writeText` (DevTools `copy()` cannot copy an async result in Firefox or Chromium, and Chromium truncates `prompt()` defaults at 2,000 chars); test in Firefox and Chrome/Edge that the clipboard receives the full token; 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