|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +const APP_URL = process.env.E2E_APP_URL || "http://localhost:3001"; |
| 4 | + |
| 5 | +async function goToCreateTab(page) { |
| 6 | + await page.goto(`${APP_URL}/workbench`, { waitUntil: "load" }); |
| 7 | + await expect(page.getByTestId("workbench-page-title")).toBeVisible(); |
| 8 | + await page.getByTestId("workbench-tab-create").click(); |
| 9 | + await expect(page.getByTestId("workbench-create-agent-button")).toBeVisible(); |
| 10 | +} |
| 11 | + |
| 12 | +test.describe("Improve Prompt button", () => { |
| 13 | + test("button is visible and disabled when prompt is empty", async ({ page }) => { |
| 14 | + await goToCreateTab(page); |
| 15 | + |
| 16 | + const btn = page.getByTestId("workbench-improve-prompt-button"); |
| 17 | + await expect(btn).toBeVisible(); |
| 18 | + await expect(btn).toBeDisabled(); |
| 19 | + }); |
| 20 | + |
| 21 | + test("button enables when prompt has text", async ({ page }) => { |
| 22 | + await goToCreateTab(page); |
| 23 | + |
| 24 | + const btn = page.getByTestId("workbench-improve-prompt-button"); |
| 25 | + await expect(btn).toBeDisabled(); |
| 26 | + |
| 27 | + await page.getByTestId("workbench-agent-system-prompt-input").fill("list all tickets"); |
| 28 | + await expect(btn).toBeEnabled(); |
| 29 | + }); |
| 30 | + |
| 31 | + test("button works with mocked API", async ({ page }) => { |
| 32 | + // Mock the improve-prompt endpoint |
| 33 | + await page.route("**/api/workbench/improve-prompt", async (route) => { |
| 34 | + await route.fulfill({ |
| 35 | + status: 200, |
| 36 | + contentType: "application/json", |
| 37 | + body: JSON.stringify({ |
| 38 | + improved_prompt: |
| 39 | + "You are a ticket analysis agent.\n\n## Goal\nList and summarize all open tickets.\n\n## Steps\n1. Use csv_list_tickets to retrieve all tickets.\n2. Filter by status.\n3. Produce a summary.\n\n## Output\nReturn a markdown summary.", |
| 40 | + }), |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + await goToCreateTab(page); |
| 45 | + |
| 46 | + // Type a basic prompt |
| 47 | + const promptInput = page.getByTestId("workbench-agent-system-prompt-input"); |
| 48 | + await promptInput.fill("list all tickets"); |
| 49 | + |
| 50 | + // Click improve |
| 51 | + const btn = page.getByTestId("workbench-improve-prompt-button"); |
| 52 | + await btn.click(); |
| 53 | + |
| 54 | + // Prompt should be replaced with the improved version |
| 55 | + await expect(promptInput).toHaveValue(/You are a ticket analysis agent/); |
| 56 | + await expect(promptInput).toHaveValue(/## Steps/); |
| 57 | + }); |
| 58 | + |
| 59 | + test("template + improve workflow screenshot", async ({ page }) => { |
| 60 | + // Mock the improve endpoint |
| 61 | + await page.route("**/api/workbench/improve-prompt", async (route) => { |
| 62 | + await route.fulfill({ |
| 63 | + status: 200, |
| 64 | + contentType: "application/json", |
| 65 | + body: JSON.stringify({ |
| 66 | + improved_prompt: |
| 67 | + "You are an expert Knowledge Base author specializing in IT support.\n\n## Goal\nCreate a comprehensive, reusable KBA from patterns found across related tickets.\n\n## Steps\n1. Use csv_search_tickets_with_details to find tickets matching the user's topic.\n2. Identify common symptoms across tickets.\n3. Determine the root cause from resolution notes.\n4. Write step-by-step resolution instructions.\n\n## Output Format\n- **Title**: Concise, searchable\n- **Symptoms**: Bullet list of what users experience\n- **Cause**: Root cause explanation\n- **Resolution**: Numbered steps\n- **Related Tickets**: INC numbers analyzed\n\n## Constraints\n- Only reference tickets you actually retrieved.\n- Do not fabricate resolution steps.", |
| 68 | + }), |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + await goToCreateTab(page); |
| 73 | + |
| 74 | + // Select a template first |
| 75 | + const templateSelect = page.getByTestId("workbench-template-select"); |
| 76 | + await templateSelect.click(); |
| 77 | + await page.getByText("KBA from Multiple Tickets").click(); |
| 78 | + |
| 79 | + // Wait for form to populate |
| 80 | + await expect( |
| 81 | + page.getByTestId("workbench-agent-system-prompt-input"), |
| 82 | + ).not.toHaveValue(""); |
| 83 | + |
| 84 | + // Take screenshot before improvement |
| 85 | + await page.screenshot({ |
| 86 | + path: "screenshot-improve-prompt-before.png", |
| 87 | + fullPage: true, |
| 88 | + }); |
| 89 | + |
| 90 | + // Click improve |
| 91 | + await page.getByTestId("workbench-improve-prompt-button").click(); |
| 92 | + |
| 93 | + // Wait for improved prompt |
| 94 | + await expect( |
| 95 | + page.getByTestId("workbench-agent-system-prompt-input"), |
| 96 | + ).toHaveValue(/## Steps/); |
| 97 | + |
| 98 | + // Take screenshot after improvement |
| 99 | + await page.screenshot({ |
| 100 | + path: "screenshot-improve-prompt-after.png", |
| 101 | + fullPage: true, |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments