test(desktop): scope API Key selector to exact label

The neutral "API Key" relabel made Playwright's default non-exact
getByLabel("API Key") resolve to two elements — the credential input
and the "Show API key" visibility toggle button — tripping strict-mode
violations across the persona/agent E2E and smoke specs (Desktop E2E
Integration + all four Desktop Smoke shards).

Pin the selector with { exact: true } so it resolves only to the input,
whose accessible name is exactly "API Key" (the required "*" marker is
aria-hidden and excluded from the accessible name). This also resolves
the Biome format error in onboarding-agent-defaults.spec.ts reported by
Desktop Core.

Signed-off-by: Atish Patel <atish@squareup.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Atish Patel
2026-07-19 18:19:23 -05:00
co-authored by Claude Opus 4.8
parent b96315456e
commit 83d01852a6
6 changed files with 19 additions and 11 deletions
@@ -180,7 +180,7 @@ test.describe("agent readiness gate screenshots", () => {
await selectProvider(page, "Anthropic");
await setCustomModel(page, "claude-opus-4-5");
await expect(page.getByLabel("API Key")).toBeVisible();
await expect(page.getByLabel("API Key", { exact: true })).toBeVisible();
await expect(page.getByTestId("persona-dialog-submit")).toBeDisabled({
timeout: 10_000,
});
@@ -218,7 +218,9 @@ test.describe("agent readiness gate screenshots", () => {
await openCreateDialog(page);
await selectProvider(page, "Anthropic");
await setCustomModel(page, "claude-opus-4-5");
await page.getByLabel("API Key").fill("sk-test-api-key-for-e2e");
await page
.getByLabel("API Key", { exact: true })
.fill("sk-test-api-key-for-e2e");
await expect(page.getByTestId("persona-dialog-submit")).toBeEnabled({
timeout: 5_000,
+3 -1
View File
@@ -134,7 +134,9 @@ test.describe("edit agent dialog", () => {
await pickDropdownOption(page, "edit-agent-model", "Custom model...");
await page.locator("#edit-agent-custom-model").fill("claude-opus-4-5");
// Anthropic requires a credential before save unlocks.
await page.getByLabel("API Key").fill("sk-test-edit-agent-e2e");
await page
.getByLabel("API Key", { exact: true })
.fill("sk-test-edit-agent-e2e");
const submit = page.getByTestId("edit-agent-dialog-submit");
await expect(submit).toBeEnabled({ timeout: 10_000 });
@@ -212,7 +212,7 @@ test.describe("global agent config screenshots", () => {
await openCreateDialog(page);
await customizeAgentAi(page);
await expect(page.getByLabel("API Key")).toBeVisible({
await expect(page.getByLabel("API Key", { exact: true })).toBeVisible({
timeout: 10_000,
});
await expect(
@@ -233,7 +233,7 @@ test.describe("global agent config screenshots", () => {
await openCreateDialog(page);
await customizeAgentAi(page);
await expect(page.getByLabel("API Key")).toHaveAttribute(
await expect(page.getByLabel("API Key", { exact: true })).toHaveAttribute(
"placeholder",
"Inherited from global config",
);
+4 -4
View File
@@ -329,7 +329,7 @@ test("persona model options follow the selected LLM provider", async ({
await selectDropdownOption(page, llmProvider, "OpenAI");
const dialog = page.getByRole("dialog");
await expect(dialog.getByLabel("API Key")).toBeVisible();
await expect(dialog.getByLabel("API Key", { exact: true })).toBeVisible();
await expect(
dialog.getByRole("button", { name: "Advanced", exact: true }),
).toHaveAttribute("aria-expanded", "false");
@@ -342,17 +342,17 @@ test("persona model options follow the selected LLM provider", async ({
.click();
await selectDropdownOption(page, llmProvider, "Anthropic");
await expect(dialog.getByLabel("API Key")).toBeVisible();
await expect(dialog.getByLabel("API Key", { exact: true })).toBeVisible();
await expect(model).toBeVisible();
await selectDropdownOption(page, llmProvider, "Gemini");
await expect(dialog.getByLabel("API Key")).toBeVisible();
await expect(dialog.getByLabel("API Key", { exact: true })).toBeVisible();
await expect(model).toBeVisible();
// Switch back to inherited defaults — per-agent provider, credential, and
// model controls disappear together.
await page.getByRole("tab", { name: "Use agent defaults" }).click();
await expect(llmProvider).not.toBeVisible();
await expect(dialog.getByLabel("API Key")).not.toBeVisible();
await expect(dialog.getByLabel("API Key", { exact: true })).not.toBeVisible();
await expect(model).not.toBeVisible();
});
+3 -1
View File
@@ -236,7 +236,9 @@ test("create agent supports parallelism and system prompt overrides", async ({
.getByRole("button", { name: "Custom model...", exact: true })
.click();
await page.getByLabel("Custom model ID").fill("claude-opus-4-5");
await page.getByLabel("API Key").fill("sk-test-api-key-for-e2e");
await page
.getByLabel("API Key", { exact: true })
.fill("sk-test-api-key-for-e2e");
const advancedToggle = page.getByRole("button", {
name: "Advanced",
@@ -153,7 +153,9 @@ test.describe("welcome and channel agent entry points", () => {
.getByRole("button", { name: "Custom model...", exact: true })
.click();
await page.getByLabel("Custom model ID").fill("claude-opus-4-5");
await page.getByLabel("API Key").fill("sk-test-api-key-for-e2e");
await page
.getByLabel("API Key", { exact: true })
.fill("sk-test-api-key-for-e2e");
await expect(page.getByTestId("persona-dialog-submit")).toBeEnabled();
await page.getByTestId("persona-dialog-submit").click();