fix(ui-13): login chip text reflects server error per status#122
Merged
Conversation
Closes the phase-4-dogfood "Could not sign in" diagnosis hygiene #5(a) (logged in PR #116's resolution block). Background: the login form JS handler in login.html unhid a static "Could not sign in." chip for every 4xx, regardless of cause. The dogfood diagnosis surfaced this as a real bias: a 403 (origin/CSRF mismatch) looked identical to a 401 to the operator, and the hypothesis order skewed toward credentials/rate-limit when the real cause was origin. Same trap for 429 (rate-limit) and 503 (auth-not-configured). Fix: the JS handler now reads the response body via r.text(), parses the canonical {"error":...} JSON, and renders the server's error phrase as the chip text via slot.textContent (capitalised + trailing period added). The JS never invents text; it only RENDERS what the server already declared. Fallback for non-JSON bodies keeps the generic "Could not sign in.". 413 ships plain text ("payload too large") so it gets a dedicated "Request too large." chip. §3-G online-guessing invariant preserved: 401 still shows the generic "Could not sign in." (server JSON: "could not sign in" → chip same after capitalisation), no username-vs-password leak. The chip-text status discrimination scopes to PRE-auth rejection paths (403/429/400/422/503) where there is no credential disclosure risk. Brief §3-E amended in-place to scope the generic-copy invariant to status 401 only and to seal the new discriminating shape for the pre-auth paths. Tests: - tests/test_ui_sw.py::test_login_html_chip_text_reflects_server_error_per_status — parses login.html and asserts: fallback string present, r.text() reads body, slot.textContent is assigned dynamically, 413 fallback present, data.error is the field consulted (not an invented status map). Suite: 18/18 in test_ui_sw.py, 52/52 in test_auth_server.py. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
1 task
VDP89
added a commit
that referenced
this pull request
May 16, 2026
Reconciles the cross-PR references that the individual fix PRs could not touch because they branched off main while the hygiene items only existed in PR #116's resolution block. Updates: - Hygiene #5(a) (login chip text per status) marked resolved by PR #122. - Hygiene #5(b) (`!unknown:` sentinel for direct loopback) marked resolved by PR #121. - Finding #3 sub-friction 3 (modal does not surface CLI command) marked resolved by PR #123. The "Outstanding sprint items" section is rewritten as "Sprint items closed 2026-05-16" — an audit trail of the five items addressed in one session, each linked to its landing PR. Adjacent housekeeping (the Karasu- → Karasu rename + PR #120 reference cleanup) is also captured for the historical record. Final line marks path C VPS deploy as unblocked at the code surface; remaining gate is operational (domain + VPS + caddy/Let's Encrypt per docs/deploy-runbook.md). Pure docs change — no code, no tests, no brief touched. Co-authored-by: Victor Del Puerto <VDP89@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
The JS handler in
login.htmlnow:r.text()(previously discarded).{"error":"..."}JSON.slot.textContent(capitalised first char + trailing period added).The JS never invents text. It only RENDERS what the server already declared.
§3-G online-guessing invariant preserved
401 still shows the generic "Could not sign in." (server JSON
{"error":"could not sign in"}→ chip same after capitalisation). No username-vs-password leak. The chip-text discrimination scopes to PRE-auth rejection paths (403/429/400/422/503) where there is no credential disclosure risk — the server cannot leak credentials before it has checked them.Files
src/karasu/ui/static/login.html— addedchipText(status, body)helper inside the existing inline handler.r.text()is now awaited so the body can drive the chip.tests/test_ui_sw.py::test_login_html_chip_text_reflects_server_error_per_status— parses login.html and pins: fallback string present,r.text()reads body,slot.textContentis assigned dynamically, 413 fallback present,data.erroris the field consulted (guards against a future drift to an invented status map).docs/ui/ui-13-design-brief.md— §3-E amended in-place to scope the generic-copy invariant to status 401 and seal the new pre-auth discriminating shape.What's NOT in this PR
test_login_html_emits_auth_granted_on_success— JS behavior validation belongs to a future browser-driven test layer if/when one lands.Test plan
pytest tests/test_ui_sw.py— 18/18 (17 pre-existing + 1 new)pytest tests/test_auth_server.py— 52/52 (no regression at the server boundary)Relation to other Phase 4 PRs
Independent of #116-#121. The new test only reads login.html source; it doesn't touch any other surface.
🤖 Generated with Claude Code