fix(onboarding): rehydrate plain-select fallback so saved model isn't reset to option[0]

Codex gate finding on #5031: when _mountSearchableModelSelect is absent the
fallback returns the old plain <select>, but the post-render rehydration
(modelSel.value = ONBOARDING.form.model) was removed — so a saved/default model
that isn't the first option would be silently replaced by option[0] on render.
Restore the rehydration in an else branch + add a regression test.

Co-authored-by: rodboev <rodboev@users.noreply.github.com>
This commit is contained in:
nesquena-hermes 2026-06-27 04:33:02 +00:00
parent 88911448ff
commit 0a32fb899f
2 changed files with 20 additions and 0 deletions

View file

@ -369,6 +369,12 @@ function _renderOnboardingBody(){
selectedValue:ONBOARDING.form.model,
onModelChange:(value)=>{ ONBOARDING.form.model=(value||'').trim(); },
});
}else{
// Fallback path (searchable picker unavailable): rehydrate the plain
// <select> so a saved/default model that isn't the first option isn't
// silently replaced by option[0] on render.
const modelSel=$('onboardingModelSelect');
if(modelSel && ONBOARDING.form.model) modelSel.value=ONBOARDING.form.model;
}
return;
}

View file

@ -611,6 +611,20 @@ def test_onboarding_non_custom_provider_mounts_searchable_model_picker():
assert "customInputId:'onboardingModelInput'" in js
def test_onboarding_plain_select_fallback_rehydrates_saved_model():
"""When the searchable picker helper is unavailable, the plain <select>
fallback must still rehydrate ONBOARDING.form.model so a saved/default
model that isn't the first option isn't silently replaced by option[0]."""
js = (REPO / "static" / "onboarding.js").read_text(encoding="utf-8")
# The mount block must have an else branch that restores the plain select value.
mount_idx = js.find("if(modelPickerRoot && typeof _mountSearchableModelSelect")
assert mount_idx != -1
after_mount = js[mount_idx:mount_idx + 900]
assert "}else{" in after_mount or "} else {" in after_mount
assert "const modelSel=$('onboardingModelSelect')" in after_mount
assert "modelSel.value=ONBOARDING.form.model" in after_mount
def test_onboarding_custom_provider_text_input_branch_stays_intact():
js = (REPO / "static" / "onboarding.js").read_text(encoding="utf-8")
assert "ONBOARDING.form.provider==='custom'" in js