import { expect, type Page, test } from "@playwright/test"; import type { Bot } from "@rakazo/contracts"; import { activeBotId, captureScreenshot, completeOnboarding, rpc, signup } from "./helpers"; async function openCapabilities(page: Page) { await page.getByTestId("bot-settings-trigger").click(); const settings = page.getByTestId("bot-settings"); await expect(settings).toBeVisible(); await settings.getByText("Advanced", { exact: true }).click(); const capabilities = settings.getByTestId("bot-capabilities"); await capabilities.scrollIntoViewIfNeeded(); return { settings, capabilities }; } test("bot settings edit capability tags and the built-in tool allowlist", async ({ page, }, testInfo) => { const stamp = Date.now(); await signup(page, `capabilities-${stamp}@rakazo.test`, "password12", "Capabilities"); await completeOnboarding(page); const botId = activeBotId(page); const { settings, capabilities } = await openCapabilities(page); await capabilities.getByLabel("Tags").fill("research, writing, research"); await expect(capabilities.getByRole("checkbox")).toHaveCount(0); await capabilities.getByRole("switch", { name: "Limit built-in tools" }).click(); const tools = capabilities.getByRole("group", { name: "Limit built-in tools" }); await tools.getByRole("checkbox", { name: "web_fetch", exact: true }).click(); await tools.getByRole("checkbox", { name: "web_search", exact: true }).click(); await tools.getByRole("checkbox", { name: "remember", exact: true }).click(); await tools.getByRole("checkbox", { name: "remember", exact: true }).click(); await expect(tools.getByRole("checkbox", { name: "web_search", exact: true })).toBeChecked(); await expect(tools.getByRole("checkbox", { name: "shell", exact: true })).not.toBeChecked(); await captureScreenshot(page, testInfo, "bot-capabilities-settings"); const saved = page.waitForResponse( (response) => response.url().includes("/rpc/bots/update") && response.ok(), ); await settings.getByRole("button", { name: "Save", exact: true }).click(); await saved; expect(await rpc(page, "bots/get", { botId })).toMatchObject({ tags: ["research", "writing"], restrictBuiltinTools: true, allowedBuiltinTools: ["web_search", "web_fetch"], }); await page.reload(); const reopened = await openCapabilities(page); await expect(reopened.capabilities.getByLabel("Tags")).toHaveValue("research, writing"); await expect( reopened.capabilities.getByRole("switch", { name: "Limit built-in tools" }), ).toBeChecked(); const reopenedTools = reopened.capabilities.getByRole("group", { name: "Limit built-in tools", }); await expect( reopenedTools.getByRole("checkbox", { name: "web_fetch", exact: true }), ).toBeChecked(); await expect( reopenedTools.getByRole("checkbox", { name: "remember", exact: true }), ).not.toBeChecked(); await captureScreenshot(page, testInfo, "bot-capabilities-persisted"); });