Repository navigation
studio/frontend: hide Current password input on first boot - #5545
Conversation
PR #5490 added a third Current password input to the change-password form so the admin-forced must_change_password reset path could supply a current password (the bootstrap is empty in that path). The side effect is that the dominant first-boot UX, which has window.__UNSLOTH_BOOTSTRAP__ present and silently fed into currentPassword, now shows three visible inputs instead of the two it had before. Render the Current password input only when window.__UNSLOTH_BOOTSTRAP__ is absent. The loadBootstrap effect already seeds the password state from the bootstrap and currentPassword keeps the bootstrap fallback, so handleSubmit sees the same value as before. On admin-forced resets where the bootstrap is undefined, the Current password input still appears so the user can type their actual current password. Verified end-to-end against a local install via UNSLOTH_STUDIO_HOME + install.sh --local with Playwright driving the page: bootstrap present renders two inputs (New, Confirm) and completes change-password into /chat; bootstrap suppressed via a non-configurable property descriptor init script renders the three inputs (Current, New, Confirm) and keeps the #5490 fix intact.
There was a problem hiding this comment.
Code Review
This pull request modifies the AuthForm component to conditionally render the 'Current password' input field. By introducing the hasBootstrapPassword constant, the form now detects if a bootstrap password is provided by the backend and hides the current password field accordingly, facilitating a smoother first-boot experience. As there are no review comments provided, I have no further feedback to offer.
Pure-source pytest covering the change-password JSX contract. No
browser, no Studio boot, no JS toolchain -- runs on any CI runner.
Complements the Playwright probe in tests/studio/playwright_chat_ui.py
which exercises the same contract end to end.
Pins seven invariants with explicit failure reasons:
1. hasBootstrapPassword is derived from window.__UNSLOTH_BOOTSTRAP__
so a future swap to a localStorage flag or prop cannot silently
drift from the backend's _inject_bootstrap contract in
studio/backend/main.py.
2. Exactly one !hasBootstrapPassword conditional exists; multiple
would split rendering into branches these tests cannot reason
about.
3. The Current password input sits inside that conditional, so it
never renders on first boot (the regression PR #5490 introduced
and that this fix reverses).
4. The New password input sits outside it, so it always renders in
change-password mode (admin-forced reset still works).
5. Confirm password: same as New.
6. The change-password JSX subtree declares exactly current /
new / confirm; a fourth password input would almost certainly
break the 2-input first-boot contract.
7. The login JSX subtree declares exactly one password input.
Verified the tests fail loudly on the pre-fix auth-form.tsx at
c4575ca (5/7 fail with descriptive reasons) and pass on the fixed
version (7/7).
|
Additional commit on this branch: The Playwright runtime side was also exercised on real
The staging workflows install Studio with |
Summary
#5490 added a third Current password input to the change-password form so the admin-forced
must_change_passwordreset path could supply a current password (the bootstrap is empty in that path). The side effect is that the dominant first-boot UX, wherewindow.__UNSLOTH_BOOTSTRAP__is injected by the backend and silently fed intocurrentPassword, now shows three visible inputs instead of the two it had before that PR.Render the Current password input only when
window.__UNSLOTH_BOOTSTRAP__?.passwordis absent. TheloadBootstrapeffect already seeds thepasswordstate from the bootstrap andcurrentPasswordkeeps the bootstrap fallback, sohandleSubmitsees the same value as before. On admin-forced resets where the bootstrap is undefined, the Current password input still appears so the user can type their actual current password.Net effect:
must_change_passwordreset (bootstrap absent): three inputs, keeps studio/frontend: wire logout, singleflight refresh, shared 422 helper, current-password input #5490's fix intact.Security
UI-only change. What goes on the wire is unchanged:
handleSubmitstill POSTs{ current_password, new_password }to/api/auth/change-passwordwith the bootstrap-derived access token, the backend still validatescurrent_passwordagainst the stored hash, and the form-level guards (invalidChangePasswordForm, theif (!currentPassword)short-circuit) are untouched. The bootstrap value is not newly exposed; it was already inwindow.__UNSLOTH_BOOTSTRAP__and on disk atstudio/auth/.bootstrap_password. Before #5490 the bootstrap password was never written into a visible form field, and this PR restores that posture on first boot (the eye toggle in #5490's input could reveal the bootstrap password as plaintext; the dot-rendered length already leaked character count). CSP nonce wiring on the inline bootstrap script is unchanged.Test plan
Installed locally with
bash install.sh --localagainstUNSLOTH_STUDIO_HOME=$WS/studioand drove the page with Playwright.npm run typecheckcleannpm run buildclean (frontend rebuilt byinstall.sh --local)document.querySelectorAll('input[type="password"]').length === 2, IDsnew-passwordandconfirm-password, no#current-passwordin the DOM/chatwith the Studio sidebar (Chat, Compare, Train, Recipes, Export, Account).POST /api/auth/change-passwordand the chainedPOST /api/auth/loginboth 200; zero console errorswindow.__UNSLOTH_BOOTSTRAP__as a non-writable, non-configurable property before navigation): three inputs render,#current-passwordpresent with label "Current password",#new-passwordand#confirm-passwordstill present, submit button stays disabled until all three are filled