|
| 1 | +/** |
| 2 | + * E2E spec for the create-agent "Run on" provider config fields. |
| 3 | + * |
| 4 | + * Pins the fix for the "Typewriter Eraser": WhereToRunSection's probe effect |
| 5 | + * used to depend on the whole draft, so every keystroke re-probed the |
| 6 | + * provider and every probe resolution reset providerConfig to schema |
| 7 | + * defaults — typing into a defaultless field (the k8s "Kubeconfig context") |
| 8 | + * looked completely dead, and the provider binary respawned in a loop. |
| 9 | + * |
| 10 | + * Covers: |
| 11 | + * - typing into a defaultless provider field sticks, and the provider is |
| 12 | + * probed exactly once for the selection (not once per keystroke) |
| 13 | + * - the config form is gated on probe resolution (no half-rendered form), |
| 14 | + * and defaults prefill exactly once when a slow probe lands |
| 15 | + * - switching provider → local → provider re-probes and resets cleanly |
| 16 | + * |
| 17 | + * The stale-closure merge on probe resolution (defaults beneath in-flight |
| 18 | + * typing) is unreachable through this UI because the fields render only |
| 19 | + * after the probe resolves; it is pinned at the unit level in |
| 20 | + * whereToRunIntent.test.mjs (applyProbeResult). |
| 21 | + */ |
| 22 | +import { expect, test } from "@playwright/test"; |
| 23 | + |
| 24 | +import { installMockBridge } from "../helpers/bridge"; |
| 25 | + |
| 26 | +type Page = import("@playwright/test").Page; |
| 27 | + |
| 28 | +const PROVIDER = { |
| 29 | + id: "kubernetes", |
| 30 | + binaryPath: "/mock/buzz-backend-kubernetes", |
| 31 | +}; |
| 32 | + |
| 33 | +const PROBE_RESULT = { |
| 34 | + ok: true, |
| 35 | + name: "kubernetes", |
| 36 | + version: "0.0.0-mock", |
| 37 | + config_schema: { |
| 38 | + type: "object", |
| 39 | + properties: { |
| 40 | + context: { |
| 41 | + type: "string", |
| 42 | + title: "Kubeconfig context", |
| 43 | + description: "Context from your kubeconfig.", |
| 44 | + }, |
| 45 | + namespace: { |
| 46 | + type: "string", |
| 47 | + title: "Namespace", |
| 48 | + default: "buzz-agents-mock01", |
| 49 | + }, |
| 50 | + }, |
| 51 | + required: ["namespace"], |
| 52 | + }, |
| 53 | +}; |
| 54 | + |
| 55 | +async function probeInvocations(page: Page): Promise<number> { |
| 56 | + return page.evaluate( |
| 57 | + () => |
| 58 | + ( |
| 59 | + window as Window & { __BUZZ_E2E_COMMANDS__?: string[] } |
| 60 | + ).__BUZZ_E2E_COMMANDS__?.filter( |
| 61 | + (command) => command === "probe_backend_provider", |
| 62 | + ).length ?? 0, |
| 63 | + ); |
| 64 | +} |
| 65 | + |
| 66 | +/** Open the create-agent dialog and select the mocked provider in "Run on". */ |
| 67 | +async function openCreateDialogOnProvider(page: Page) { |
| 68 | + await page.goto("/", { waitUntil: "domcontentloaded" }); |
| 69 | + await page.getByTestId("open-agents-view").click(); |
| 70 | + await page.getByTestId("new-agent-card").click(); |
| 71 | + await page.getByRole("menuitem", { name: "Create agent" }).click(); |
| 72 | + const dialog = page.getByTestId("persona-dialog"); |
| 73 | + await expect(dialog).toBeVisible({ timeout: 10_000 }); |
| 74 | + await dialog.locator("#agent-run-on").selectOption(PROVIDER.id); |
| 75 | + return dialog; |
| 76 | +} |
| 77 | + |
| 78 | +test("typing into a defaultless provider field sticks and probes only once", async ({ |
| 79 | + page, |
| 80 | +}) => { |
| 81 | + await installMockBridge(page, { |
| 82 | + backendProviders: [PROVIDER], |
| 83 | + backendProviderProbeResult: PROBE_RESULT, |
| 84 | + }); |
| 85 | + const dialog = await openCreateDialogOnProvider(page); |
| 86 | + |
| 87 | + const contextField = dialog.locator("#provider-cfg-context"); |
| 88 | + await expect(contextField).toBeVisible({ timeout: 10_000 }); |
| 89 | + // Defaults prefilled from the schema; context has none. |
| 90 | + await expect(dialog.locator("#provider-cfg-namespace")).toHaveValue( |
| 91 | + "buzz-agents-mock01", |
| 92 | + ); |
| 93 | + await expect(contextField).toHaveValue(""); |
| 94 | + |
| 95 | + await contextField.pressSequentially("prod-us-west", { delay: 20 }); |
| 96 | + await expect(contextField).toHaveValue("prod-us-west"); |
| 97 | + |
| 98 | + // One selection, one probe — keystrokes must not refire it. |
| 99 | + expect(await probeInvocations(page)).toBe(1); |
| 100 | +}); |
| 101 | + |
| 102 | +test("config fields render only after a slow probe resolves, with defaults", async ({ |
| 103 | + page, |
| 104 | +}) => { |
| 105 | + // The fields are gated on the probe result (draft.probedProvider), which is |
| 106 | + // what makes mid-flight typing unreachable through the UI — the stale-probe |
| 107 | + // merge seam (applyProbeResult) is pinned at the unit level instead. This |
| 108 | + // spec holds the gate: no half-rendered form before the probe lands, and |
| 109 | + // defaults appear exactly once when it does. |
| 110 | + await installMockBridge(page, { |
| 111 | + backendProviders: [PROVIDER], |
| 112 | + backendProviderProbeResult: PROBE_RESULT, |
| 113 | + backendProviderProbeDelayMs: 1_000, |
| 114 | + }); |
| 115 | + const dialog = await openCreateDialogOnProvider(page); |
| 116 | + |
| 117 | + // Pre-resolution: the security warning is up, the form is not. |
| 118 | + await expect(dialog.getByText("will receive your agent")).toBeVisible(); |
| 119 | + await expect(dialog.locator("#provider-cfg-context")).toHaveCount(0); |
| 120 | + |
| 121 | + // Post-resolution: fields render with schema defaults prefilled. |
| 122 | + await expect(dialog.locator("#provider-cfg-context")).toBeVisible({ |
| 123 | + timeout: 10_000, |
| 124 | + }); |
| 125 | + await expect(dialog.locator("#provider-cfg-namespace")).toHaveValue( |
| 126 | + "buzz-agents-mock01", |
| 127 | + ); |
| 128 | + expect(await probeInvocations(page)).toBe(1); |
| 129 | +}); |
| 130 | + |
| 131 | +test("provider → local → provider re-probes and resets the config", async ({ |
| 132 | + page, |
| 133 | +}) => { |
| 134 | + await installMockBridge(page, { |
| 135 | + backendProviders: [PROVIDER], |
| 136 | + backendProviderProbeResult: PROBE_RESULT, |
| 137 | + }); |
| 138 | + const dialog = await openCreateDialogOnProvider(page); |
| 139 | + |
| 140 | + const contextField = dialog.locator("#provider-cfg-context"); |
| 141 | + await expect(contextField).toBeVisible({ timeout: 10_000 }); |
| 142 | + await contextField.fill("stale-value"); |
| 143 | + |
| 144 | + await dialog.locator("#agent-run-on").selectOption("local"); |
| 145 | + await expect(contextField).toHaveCount(0); |
| 146 | + |
| 147 | + await dialog.locator("#agent-run-on").selectOption(PROVIDER.id); |
| 148 | + await expect(dialog.locator("#provider-cfg-context")).toBeVisible({ |
| 149 | + timeout: 10_000, |
| 150 | + }); |
| 151 | + // Fresh selection = fresh draft: the stale value must not leak back. |
| 152 | + await expect(dialog.locator("#provider-cfg-context")).toHaveValue(""); |
| 153 | + expect(await probeInvocations(page)).toBe(2); |
| 154 | +}); |
0 commit comments