Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,25 @@ test("add provider dialog: title and actions usable, body scrolls, focus returns
await expect(page.getByRole("button", { name: "AI Provider", exact: true })).toBeVisible();
await expect(addButton).toBeFocused();
});

// Issue #1377: the add action sits in the section header and the dialog fields use `Field`.
test("add provider: header button is reachable, dialog fields have accessible names", async ({ app }) => {
await app.launch(populated());
const page = app.page;
await page.getByRole("button", { name: "Settings", exact: true }).click();
await page.getByRole("button", { name: "AI Provider", exact: true }).click();
const addButton = page.getByRole("button", { name: "Add Provider", exact: true });
await expect(addButton).toHaveCount(1);
await addButton.focus();
await expect(addButton).toBeFocused();
await page.keyboard.press("Enter");

const dialog = page.getByRole("dialog", { name: "Add Provider" });
await expect(dialog).toBeVisible();
for (const name of ["Name", "API Key"]) {
await expect(dialog.getByLabel(name, { exact: false }).first()).toBeVisible();
}
await expect(dialog.getByRole("combobox").first()).toBeVisible();
await dialog.getByRole("button", { name: /Advanced/ }).click();
await expect(dialog.getByLabel(/Max. response length/).first()).toBeVisible();
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ for (const category of ["AI Provider", "MCP Server"]) {
await settings.getByRole("button", { name: "Add Provider", exact: true }).click();
const add = page.getByRole("dialog", { name: "Add Provider" });
await add.getByRole("button", { name: /Advanced/ }).click();
// The visual-order check reads unscrolled positions, so the open
// advanced section must fit without scrolling the dialog body.
await add.getByRole("button", { name: "+ Header", exact: true }).click();
const size = page.viewportSize();
if (size && size.width >= 1000) await page.setViewportSize({ width: size.width, height: 1000 });
await expectTabOrderFollowsVisualOrder(page, add);
await expectNoClippedText(add);
});
Expand Down Expand Up @@ -110,3 +114,34 @@ test("filter rules: Tab order, edit form and test panel, long values", async ({
await expectNoClippedText(ruleDialog);
await captureScreen(page, "filter-rules-edit");
});

// Issue #1377: both risk switches have accessible names, sit in the Tab order
// after the provider list and toggle with the keyboard.
test("settings: AI Provider risk switches are labelled, in Tab order and toggle", async ({ app }) => {
await app.launch({
...longContent(),
commands: {
...longContent().commands,
set_risk_second_opinion_settings: { result: null },
set_red_risk_always_confirm: { result: null },
},
});
const page = app.page;
const dialog = await openSettings(page, "AI Provider");
const second = dialog.getByRole("checkbox", { name: "Enable AI second opinion" });
const red = dialog.getByRole("checkbox", { name: "Always confirm on red risk" });
await expect(second).toBeVisible();
await expect(red).toBeVisible();
const before = await second.isChecked();
await second.focus();
await expect(second).toBeFocused();
await page.keyboard.press("Space");
await expect(second).toBeChecked({ checked: !before });
await page.keyboard.press("Tab");
// Focus moved on (not lost to body) and eventually reaches the second switch.
await expect(page.locator("body")).not.toBeFocused();
const redBefore = await red.isChecked();
await red.focus();
await page.keyboard.press("Space");
await expect(red).toBeChecked({ checked: !redBefore });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Issue #1377: review screenshots of the AI Provider settings and the add-provider dialog
// (SCREENSHOT_LABEL=before|after, SCREENSHOT_SCHEME=dark).
import { expect, openSettings, test } from "../support/app";
import { aiProvider, populated } from "../support/data";
import { captureScreen } from "../support/screenshots";

const scheme = process.env.SCREENSHOT_SCHEME === "dark" ? "dark" : "light";

test("review screenshots: AI provider settings and add dialog", async ({ app }) => {
await app.launch({
...populated(),
commands: { set_risk_second_opinion_settings: { result: null } },
aiProviders: [
aiProvider({ id: "p-1", displayName: "Primary", providerType: "generic_openai_compatible", baseUrl: "https://llm.example.com/v1", isActive: true }),
aiProvider({ id: "p-2", displayName: "Backup", baseUrl: null, isActive: false }),
],
});
const page = app.page;
if (scheme === "dark") await page.emulateMedia({ colorScheme: "dark" });
const dialog = await openSettings(page, "AI Provider");
await expect(dialog.getByText("Primary").first()).toBeVisible();
const second = dialog.getByRole("checkbox", { name: /second opinion/i }).first();
await second.check({ force: true });
await captureScreen(page, `settings-aiprovider-${scheme}`);

await dialog.getByRole("button", { name: "Add Provider", exact: true }).click();
const add = page.getByRole("dialog", { name: "Add Provider" });
await expect(add).toBeVisible();
await add.getByRole("button", { name: /Advanced/ }).click();
await captureScreen(page, `add-provider-dialog-${scheme}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
testAiProviderCredentials,
updateAiProvider,
} from "../api/api";
import { Button, Icon } from "./ui";
import { Button, Field, Icon } from "./ui";
import { DialogFrame } from "./ui/DialogFrame";
import { commandErrorText, translateErrorCode } from "../api/errorCodes";
import { effectiveApiKey, OLLAMA_BASE_URL } from "../lib/ollama";
Expand All @@ -29,7 +29,7 @@ import {
sameDiscoveryInputs,
shouldAutoDiscover,
} from "../lib/modelDiscoveryTrigger";
import { CARD_CLASS, FIELD_CLASS, LABEL_CLASS, LABEL_TEXT_CLASS } from "./aiProviderFormStyles";
import { CARD_CLASS, FIELD_CLASS } from "./aiProviderFormStyles";

const PROVIDER_TYPES: ProviderType[] = [
"openai",
Expand Down Expand Up @@ -315,9 +315,10 @@ export function AddAiProviderDialog({
</p>
)}
<section className={`${CARD_CLASS} space-y-3`}>
<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.type")}</span>
<Field label={t("aiProvider.type")}>
{(control) => (
<select
{...control}
ref={typeSelectRef}
value={form.providerType}
disabled={editing}
Expand All @@ -338,19 +339,21 @@ export function AddAiProviderDialog({
setCredentialTestResult(null);
setModelsAuthFailed(false);
}}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
>
{PROVIDER_TYPES.map((type) => (
<option key={type} value={type}>
{t(`aiProvider.providerTypes.${type}`)}
</option>
))}
</select>
</label>
)}
</Field>

<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.providerName")}</span>
<Field label={t("aiProvider.providerName")}>
{(control) => (
<input
{...control}
{...TECHNICAL_INPUT_PROPS}
type="text"
required
Expand All @@ -359,14 +362,38 @@ export function AddAiProviderDialog({
setNameEditedByUser(true);
setForm({ ...form, displayName: e.target.value });
}}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
/>
</label>
)}
</Field>

<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.model")}</span>
<div className="mt-1 flex gap-2">
<Field
label={t("aiProvider.model")}
help={
modelsEmpty || modelsFailed ? (
<>
{modelsEmpty && <span className="block">{t("aiProvider.modelDiscoveryEmptyHint")}</span>}
{modelsFailed && (
<>
<span className="block">{t("aiProvider.modelDiscoveryFailedHint")}</span>
{/* Spec 0069, Teil A5: translated reason when the error
* carries a known code, below the unchanged hint. */}
{modelsFailedCode && translateErrorCode(t, modelsFailedCode, "") && (
<span className="mt-0.5 block">
{translateErrorCode(t, modelsFailedCode, "")}
</span>
)}
</>
)}
</>
) : undefined
}
>
{(control) => (
<>
<div className="flex gap-2">
<input
{...control}
{...TECHNICAL_INPUT_PROPS}
type="text"
required
Expand Down Expand Up @@ -413,33 +440,15 @@ export function AddAiProviderDialog({
<option key={model} value={model} aria-label={model} />
))}
</datalist>
{modelsEmpty && (
<p className="mt-1 text-xs text-fg-subtle">{t("aiProvider.modelDiscoveryEmptyHint")}</p>
</>
)}
{modelsFailed && (
<>
<p className="mt-1 text-xs text-fg-subtle">{t("aiProvider.modelDiscoveryFailedHint")}</p>
{/* Spec 0069, Teil A5: zusätzlich der übersetzte Grund,
* wenn der Fehler einen bekannten Code trägt (z. B.
* AI_MODEL_NOT_FOUND, AI_LOCAL_PROVIDER_UNREACHABLE) —
* unter dem bisherigen, unveränderten Hinweis, nicht
* anstelle davon. `translateErrorCode` fällt bei
* unbekanntem Code auf den leeren String zurück, den wir
* hier explizit unterdrücken statt eine leere Box zu
* zeigen. */}
{modelsFailedCode && translateErrorCode(t, modelsFailedCode, "") && (
<p className="mt-0.5 text-xs text-fg-subtle">
{translateErrorCode(t, modelsFailedCode, "")}
</p>
)}
</>
)}
</label>
</Field>

{needsBaseUrl(form.providerType) && (
<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.baseUrl")}</span>
<Field label={t("aiProvider.baseUrl")}>
{(control) => (
<input
{...control}
{...TECHNICAL_INPUT_PROPS}
type="text"
required
Expand All @@ -450,22 +459,28 @@ export function AddAiProviderDialog({
setModelsAuthFailed(false);
}}
onBlur={handleDiscoveryFieldBlur}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
/>
</label>
)}
</Field>
)}

<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>
<Field
label={
<>
{t("aiProvider.apiKey")}
{/* Spec 0069, Teil B5: Ollama braucht keinen Key. */}
{form.providerType === "ollama" && (
<span className="ml-1 font-normal text-fg-subtle">
{t("aiProvider.apiKeyNotNeededForOllama")}
</span>
)}
</span>
</>
}
>
{(control) => (
<input
{...control}
{...TECHNICAL_INPUT_PROPS}
type="password"
required={!editing && form.providerType !== "ollama"}
Expand All @@ -482,9 +497,10 @@ export function AddAiProviderDialog({
setModelsAuthFailed(false);
}}
onBlur={handleDiscoveryFieldBlur}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
/>
</label>
)}
</Field>
{/* Issue #326: eigener Zustand für `AI_AUTH_FAILED` aus der
* Modellsuche, im selben roten Stil wie das Ergebnis von
* "Zugangsdaten testen" — nicht der generische Discovery-Hinweis. */}
Expand Down Expand Up @@ -666,28 +682,39 @@ export function AddAiProviderDialog({
</Button>
</div>

<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.attestationUrlLabel")}</span>
<Field label={t("aiProvider.attestationUrlLabel")}>
{(control) => (
<input
{...control}
{...TECHNICAL_INPUT_PROPS}
type="text"
placeholder={t("aiProvider.attestationUrlPlaceholder")}
value={form.attestationUrl ?? ""}
onChange={(e) =>
setForm({ ...form, attestationUrl: e.target.value || null })
}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
/>
</label>
)}
</Field>

{/* Spec 0065, Teil 4: optionaler max_tokens-Override, Default
* "Automatisch" (leer). Serverseitig nochmals validiert
* (`AiProviderConfigInput::validate_max_tokens_override`) —
* diese Prüfung ist nur die schnelle, clientseitige
* Rückmeldung. */}
<label className={LABEL_CLASS}>
<span className={LABEL_TEXT_CLASS}>{t("aiProvider.maxTokensOverrideLabel")}</span>
<Field
label={t("aiProvider.maxTokensOverrideLabel")}
help={t("aiProvider.maxTokensOverrideHint")}
error={
form.maxTokensOverride !== null && form.maxTokensOverride <= 0
? t("aiProvider.maxTokensOverrideMustBePositive")
: undefined
}
>
{(control) => (
<input
{...control}
type="number"
min={1}
placeholder={t("aiProvider.maxTokensOverridePlaceholder")}
Expand All @@ -699,17 +726,10 @@ export function AddAiProviderDialog({
maxTokensOverride: raw === "" ? null : Number(raw),
});
}}
className={`mt-1 w-full ${FIELD_CLASS}`}
className={`w-full ${FIELD_CLASS}`}
/>
<p className="mt-0.5 text-xs text-fg-subtle">
{t("aiProvider.maxTokensOverrideHint")}
</p>
{form.maxTokensOverride !== null && form.maxTokensOverride <= 0 && (
<p className="mt-0.5 text-xs text-danger-fg">
{t("aiProvider.maxTokensOverrideMustBePositive")}
</p>
)}
</label>
</Field>
</div>
)}
</div>
Expand Down
Loading
Loading