Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

fix(web): keep the credential wizard from stealing focus from a field the user picked (#103)

Robert0622c4b15d18d213
diff --git a/web/app/workbench.js b/web/app/workbench.js
index cdd8a1bf..4b11bdf2 100644
--- a/web/app/workbench.js
+++ b/web/app/workbench.js
@@ -593,6 +593,8 @@ function refreshCredentialWizardFoot(){
}
function focusCredentialWizard(){
const pane=$('#credentialWizard .credential-pane:not(.is-leaving)');
+ // Deferred calls must not pull focus back once the user is already in this pane, or typing lands in the wrong field.
+ if(pane?.contains(document.activeElement))return;
(pane?.querySelector('input, .credential-opt.is-selected:not(:disabled), .credential-opt:not(:disabled)')
||$('#credentialWizard [data-wizard-next]:not(:disabled), #credentialWizard [data-wizard-done]')
||$('#credentialWizard [data-wizard-close]:not(:disabled)')
diff --git a/webtest/tests/workbench-credentials.test.mjs b/webtest/tests/workbench-credentials.test.mjs
index 6440eade..7519d44f 100644
--- a/webtest/tests/workbench-credentials.test.mjs
+++ b/webtest/tests/workbench-credentials.test.mjs
@@ -28,6 +28,32 @@ test('credential wizard selects a provider, validates input, saves, and finishes
assert.ok(app.router.calls.some((call) => call.path === '/api/users/1/credentials'));
});
+test('credential wizard focuses the first field on its own but never pulls focus from a field the user picked', async (t) => {
+ const app = await loadApp();
+ t.after(app.close);
+ app.evaluate(`state.data.users[0].id=1;state.currentUser={...state.data.users[0],id:1,isGuest:false};state.data.users[0]=state.currentUser`);
+ await app.evaluate(`renderPersonalSettings()`);
+ app.evaluate(`openCredentialWizard()`);
+ const wizard = app.document.querySelector('#credentialWizard');
+ const pane = () => wizard.querySelector('.credential-pane:not(.is-leaving)');
+ const afterFocusTimers = () => new Promise((resolve) => setTimeout(resolve, 300));
+ wizard.querySelector('[data-wizard-kind="codexApiKey"]').click();
+ wizard.querySelector('[data-wizard-next]').click();
+ await afterFocusTimers();
+ assert.equal(app.document.activeElement, pane().querySelector('input[name="secret"]'));
+
+ wizard.querySelector('[data-wizard-back]').click();
+ wizard.querySelector('[data-wizard-next]').click();
+ const baseURL = pane().querySelector('input[name="extra"]');
+ baseURL.focus();
+ await afterFocusTimers();
+ assert.equal(app.document.activeElement, baseURL);
+ baseURL.value = 'not-a-url';
+ baseURL.dispatchEvent(new app.window.Event('input', { bubbles: true }));
+ assert.match(pane().querySelector('[data-credential-hint="extra"]').textContent, /http:\/\//);
+ assert.equal(pane().querySelector('input[name="secret"]').value, '');
+});
+
test('credential panel filters, expands, validates, reveals secrets, and confirms deletion', async (t) => {
const app = await loadApp();
t.after(app.close);