diff --git a/web-ui/e2e/background-reopen.spec.ts b/web-ui/e2e/background-reopen.spec.ts index 7383d3b5..4fc61732 100644 --- a/web-ui/e2e/background-reopen.spec.ts +++ b/web-ui/e2e/background-reopen.spec.ts @@ -3,7 +3,7 @@ /** * E2E: a reopened deck follows its chat's work, on each agent engine. * - * A deck is made from New Deck in a slow turn (`[slow=]`), and its tab is closed once the deck + * A deck is made from the home composer in a slow turn (`[slow=]`), and its tab is closed once the deck * opens. When the turn ended while no tab was open, opening the deck again shows the prompt once * and the whole reply, with no Stop button; a reload shows the same (the server has nothing * running, and the history comes from `.chat.json`). When the turn still runs, the reopened deck @@ -23,12 +23,18 @@ async function useEngine(page: Page, baseURL: string, engine: "v2" | "v3") { expect(switched.status()).toBe(200) } -/** Send `message` from New Deck on a new page, and wait until its deck opens. */ +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { + await page.goto("/decks") + const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +/** Send `message` from the home composer on a new page, and wait until its deck opens. */ async function startDeck(context: BrowserContext, message: string, deckId: string): Promise { const page = await context.newPage() - await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() - await page.getByRole("textbox", { name: "Chat message input" }).fill(message) + await (await homeComposer(page)).fill(message) await page.getByRole("button", { name: "Send message" }).click() await expect(page.getByRole("log", { name: "Chat messages" })).toContainText("Creating your deck", { timeout: 15_000 }) await expect(page).toHaveURL((url) => url.hash === `#${deckId}`, { timeout: 15_000 }) diff --git a/web-ui/e2e/compose-async.spec.ts b/web-ui/e2e/compose-async.spec.ts index f66d72f2..a778a1a9 100644 --- a/web-ui/e2e/compose-async.spec.ts +++ b/web-ui/e2e/compose-async.spec.ts @@ -38,10 +38,17 @@ async function send(page: Page, message: string) { await page.getByRole("button", { name: "Send message" }).click() } -/** New Deck, then a dispatching prompt; resolves once the deck's chat opened and the compose card shows. */ -async function startCompose(page: Page, prompt: string, deckId: string) { +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() + const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +/** A dispatching prompt from the home composer; resolves once the deck's chat opened and the compose card shows. */ +async function startCompose(page: Page, prompt: string, deckId: string) { + await homeComposer(page) await send(page, prompt) const chatLog = page.getByRole("log", { name: "Chat messages" }) await expect(chatLog).toContainText("The composers are on it.", { timeout: 20_000 }) diff --git a/web-ui/e2e/compose-card.spec.ts b/web-ui/e2e/compose-card.spec.ts index 8cade7d6..3ee4464f 100644 --- a/web-ui/e2e/compose-card.spec.ts +++ b/web-ui/e2e/compose-card.spec.ts @@ -16,10 +16,16 @@ async function useEngine(page: Page, baseURL: string, engine: "v2" | "v3") { expect(switched.status()).toBe(200) } -async function composeCard(page: Page, engine: "v2" | "v3") { +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +async function composeCard(page: Page, engine: "v2" | "v3") { + const input = await homeComposer(page) await input.fill(`Compose a two-part deck on ${engine}`) await page.getByRole("button", { name: "Send message" }).click() diff --git a/web-ui/e2e/continue-session.spec.ts b/web-ui/e2e/continue-session.spec.ts index 57da5543..ef970f70 100644 --- a/web-ui/e2e/continue-session.spec.ts +++ b/web-ui/e2e/continue-session.spec.ts @@ -18,10 +18,17 @@ async function useEngine(page: Page, baseURL: string, engine: "v2" | "v3") { expect(switched.status()).toBe(200) } -/** A new chat's picker, open. */ -async function openPicker(page: Page) { +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() + const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +/** The home conversation's picker, open. */ +async function openPicker(page: Page) { + await homeComposer(page) await page.getByRole("button", { name: "Attach file or snippet" }).click() await page.getByRole("button", { name: "Continue from a kiro session" }).click() const dialog = page.getByRole("dialog", { name: "Continue from a kiro session" }) diff --git a/web-ui/e2e/deck-creation.spec.ts b/web-ui/e2e/deck-creation.spec.ts index c4818faf..b70c9dbc 100644 --- a/web-ui/e2e/deck-creation.spec.ts +++ b/web-ui/e2e/deck-creation.spec.ts @@ -3,7 +3,7 @@ /** * E2E: deck creation happy path (roadmap 2-5b-4), on each agent engine. * - * Deck list → New Deck → send a chat message → stub agent creates a deck + * Home screen → type into its composer and send → stub agent creates a deck * and streams tool events → UI navigates to the workspace and shows the * slide preview. Exercises the full Local-mode stack: React UI, Next.js * API routes, ACP process manager and engine adapters, SSE bridge, and @@ -21,10 +21,11 @@ async function createDeck(page: Page, engine: "v2" | "v3") { await page.goto("/decks") await expect(page.getByRole("heading", { name: "Decks" })).toBeVisible() - // Open the new-deck chat panel - await page.getByRole("button", { name: "New Deck" }).click() + // The home composer, at the stage of the home screen (no New Deck there); it takes the + // focus once the page has hydrated + await expect(page.getByRole("button", { name: "New Deck" })).toHaveCount(0) const input = page.getByRole("textbox", { name: "Chat message input" }) - await expect(input).toBeVisible() + await expect(input).toBeFocused({ timeout: 30_000 }) // Send a message await input.fill(`Create a deck about end-to-end testing on ${engine}`) diff --git a/web-ui/e2e/deck-reload.spec.ts b/web-ui/e2e/deck-reload.spec.ts index 32e9b625..765bbd64 100644 --- a/web-ui/e2e/deck-reload.spec.ts +++ b/web-ui/e2e/deck-reload.spec.ts @@ -4,7 +4,7 @@ * E2E: a deck keeps its conversation on a reload and a direct link. * * The stub agent creates a deck through the chat. Opening it from the deck list shows that - * conversation in the deck's chat tab; so does reloading the page and opening `/decks/#` + * conversation in the deck's chat sheet; so does reloading the page and opening `/decks/#` * in a new tab (the hash is read after mount, so the first render matches the prerendered * page). Along the way it checks the Local wording: the search box searches decks by name, * and the deck header has no private / internal visibility chip (a Cloud feature). @@ -15,6 +15,14 @@ const DECK_ID = "e2e-v3-deck" const DECK_NAME = "E2E Test Deck (v3)" const PROMPT = "Create a deck that survives a reload" +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { + await page.goto("/decks") + const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + /** The deck's chat shows the earlier conversation. */ async function expectConversation(page: Page) { const chatLog = page.getByRole("log", { name: "Chat messages" }) @@ -27,9 +35,7 @@ test("a deck opened from the list keeps its conversation on reload and on a dire expect(engine.status()).toBe(200) // A deck with a saved conversation - await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() - await page.getByRole("textbox", { name: "Chat message input" }).fill(PROMPT) + await (await homeComposer(page)).fill(PROMPT) await page.getByRole("button", { name: "Send message" }).click() await expect(page.getByRole("log", { name: "Chat messages" })).toContainText("Done! Your deck is ready.", { timeout: 30_000 }) await expect(page).toHaveURL(new RegExp(`#${DECK_ID}$`), { timeout: 15_000 }) diff --git a/web-ui/e2e/mcp-deck-open.spec.ts b/web-ui/e2e/mcp-deck-open.spec.ts index 2f8b0e22..95b0a8d8 100644 --- a/web-ui/e2e/mcp-deck-open.spec.ts +++ b/web-ui/e2e/mcp-deck-open.spec.ts @@ -4,7 +4,7 @@ * E2E: a deck an MCP client made, opened by its direct link (`sdpm open ` opens * `/decks/#`), on each agent engine. * - * The deck has deck.json and specs/ but no `.session`, as an MCP client leaves it. Its chat tab + * The deck has deck.json and specs/ but no `.session`, as an MCP client leaves it. Its chat sheet * opens empty; the first turn runs in a new session whose first prompt names the deck * (`Current deck: `, from the stub's trace) and shows no "no Kiro session" notice. The turn * saves `.session`, and a reload shows the conversation (it continues from then on). @@ -50,9 +50,10 @@ for (const engine of ["v3", "v2"] as const) { await page.goto(`/decks/#${deckId}`) const chatLog = page.getByRole("log", { name: "Chat messages" }) - // The prerendered page shows the New chat's input until the hash is read after hydration; - // type only once the deck's own chat tab (labelled with the loaded deck's name) is there. - await expect(page.getByRole("button", { name: `MCP-made deck (${deckId})`, exact: true })).toBeVisible({ timeout: 30_000 }) + // The prerendered page shows the home composer until the hash is read after hydration; + // type only once the deck is open (its bar shows the loaded deck's name; a name without a + // folder timestamp shows as it is) and its chat sheet is the only input. + await expect(page.getByRole("heading", { name: `MCP-made deck (${deckId})`, exact: true })).toBeVisible({ timeout: 30_000 }) await expect(page.getByRole("textbox", { name: "Chat message input" })).toBeVisible() await expect(chatLog).not.toContainText("51") diff --git a/web-ui/e2e/model-picker.spec.ts b/web-ui/e2e/model-picker.spec.ts index 283abe74..68c3398d 100644 --- a/web-ui/e2e/model-picker.spec.ts +++ b/web-ui/e2e/model-picker.spec.ts @@ -3,7 +3,7 @@ /** * E2E: the Local chat's model and effort, on each agent engine (stub-agent.mjs's models). * - * New Deck → send → the pill shows the session's model once the turn ended → choose a model + * The home composer → send → the pill shows the session's model once the turn ended → choose a model * (and on V3 an effort) → the next message runs on it (the stub says which in its reply) → a * reload still shows it (the session keeps it). V2 offers no effort. Each test sets the engine * first: the one an earlier spec left is not known. A cross-site PUT is refused. @@ -26,9 +26,16 @@ const DECK_URL = { v2: /#e2e-v2-deck$/, v3: /#e2e-v3-deck$/ } as const const pill = (page: Page) => page.getByRole("button", { name: /^Model:/ }) -async function firstTurn(page: Page, engine: "v2" | "v3") { +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() + const input = page.getByRole("textbox", { name: "Chat message input" }) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +async function firstTurn(page: Page, engine: "v2" | "v3") { + await homeComposer(page) await send(page, `A deck about models on ${engine}`) const chatLog = page.getByRole("log", { name: "Chat messages" }) await expect(chatLog).toContainText("Done! Your deck is ready.", { timeout: 30_000 }) diff --git a/web-ui/e2e/multi-chat.spec.ts b/web-ui/e2e/multi-chat.spec.ts index 5e2623d6..c34057d0 100644 --- a/web-ui/e2e/multi-chat.spec.ts +++ b/web-ui/e2e/multi-chat.spec.ts @@ -1,14 +1,25 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 /** - * E2E: several Local chats at once, on each agent engine. + * E2E: one conversation per screen, and several Local chats at once. * - * Two decks are made at once from two pages, one of them in a long turn: both decks appear, and - * their `.session` files show where the chats run (the stub's session ids are - * `stub---`): one stub process each, on both engines (kiro-cli's V3 agent server - * runs one turn at a time per process, so chats do not share one). Stop for a chat while its kiro-cli starts, sent alone (`POST /api/agent/stop`, as - * another tab would): the invoke answers a stream that ends with no data, and no prompt ran (its - * deck is never made). Runs on V3, then V2; ends on V3, the sandbox's engine. + * One conversation per screen (V3; the layout does not depend on the engine): + * - The home screen is the composer at the stage; a message makes the conversation fill the + * first screenful, with the deck list below it. + * - The home conversation stays when a deck is opened and the list is shown again; only the home + * screen's New chat clears it. + * - A deck's sheet holds only that deck's conversation, without tabs or New chat; closed, it opens + * again from Chat in the deck's bar. + * - A deck the home conversation makes keeps that conversation (the same element, still + * streaming), and the home screen is blank again. + * + * Several chats at once, on each engine: two decks are made at once from two pages, one of them + * in a long turn: both decks appear, and their `.session` files show where the chats run (the + * stub's session ids are `stub---`): one stub process each, on both engines + * (kiro-cli's V3 agent server runs one turn at a time per process, so chats do not share one). + * Stop for a chat while its kiro-cli starts, sent alone (`POST /api/agent/stop`, as another tab + * would): the invoke answers a stream that ends with no data, and no prompt ran (its deck is never + * made). Runs on V3, then V2; ends on V3, the sandbox's engine. */ import { randomUUID } from "crypto" import fs from "fs" @@ -23,12 +34,22 @@ async function useEngine(page: Page, baseURL: string, engine: "v2" | "v3") { expect(switched.status()).toBe(200) } -/** A new chat on its own page, with `message` sent. */ -async function startChat(page: Page, message: string) { +/** The home composer, ready to type into: it takes the focus once the page has hydrated. */ +async function homeComposer(page: Page) { await page.goto("/decks") - await page.getByRole("button", { name: "New Deck" }).click() const input = page.getByRole("textbox", { name: "Chat message input" }) - await input.fill(message) + await expect(input).toBeFocused({ timeout: 30_000 }) + return input +} + +async function send(page: Page, message: string) { + await page.getByRole("textbox", { name: "Chat message input" }).fill(message) + await page.getByRole("button", { name: "Send message" }).click() +} + +/** A new chat on its own page, with `message` sent from the home composer. */ +async function startChat(page: Page, message: string) { + await (await homeComposer(page)).fill(message) await page.getByRole("button", { name: "Send message" }).click() await expect(page.getByRole("log", { name: "Chat messages" })).toContainText("Creating your deck", { timeout: 15_000 }) } @@ -42,6 +63,113 @@ async function stubPid(deckId: string): Promise { return id.split("-")[2] } +/** The rail's Decks item, or the logo: both go back to the list in place. */ +async function backToList(page: Page, via: "rail" | "logo" = "rail") { + const decks = page.getByRole("link", { name: "Decks", exact: true }) + await (via === "rail" ? decks.filter({ hasText: "Decks" }) : decks.filter({ hasNotText: "Decks" })).click() + await expect(page).toHaveURL((url) => url.hash === "") +} + +/** A deck with no conversation yet, under a name of its own (the stub names all of its decks alike). */ +function seedDeck(deckId: string, name: string) { + const dir = deckDir(deckId) + fs.rmSync(dir, { recursive: true, force: true }) + fs.mkdirSync(path.join(dir, "slides"), { recursive: true }) // nosemgrep: path-join-resolve-traversal — constant deck ids in the sandbox + fs.writeFileSync(path.join(dir, "deck.json"), JSON.stringify({ name })) // nosemgrep: path-join-resolve-traversal — constant deck ids in the sandbox +} + +test.describe("one conversation per screen", () => { + const SEEDED = { id: "e2e-single-seeded", name: "Single chat seeded deck" } + const MADE = "e2e-v3-single-made" + test.beforeEach(async ({ page, baseURL }) => { await useEngine(page, baseURL!, "v3") }) + test.afterAll(async ({ request, baseURL }) => { + await request.post("/api/agent/stop", { data: {}, headers: { Origin: baseURL! } }) + for (const deckId of [SEEDED.id, MADE]) fs.rmSync(deckDir(deckId), { recursive: true, force: true }) + }) + + test("the home conversation stays across a deck and back, and only New chat clears it; a deck's sheet is its own", async ({ page }) => { + seedDeck(SEEDED.id, SEEDED.name) + const chatLog = page.getByRole("log", { name: "Chat messages" }) + const stageTitle = page.getByRole("heading", { name: "What are we presenting?" }) + const newChat = page.getByRole("button", { name: "New chat" }) + + // The stage: the composer and its title, the deck list below, no New Deck and no New chat. + await homeComposer(page) + await expect(stageTitle).toBeVisible() + await expect(page.getByRole("heading", { name: "Decks" })).toBeVisible() + await expect(page.getByRole("button", { name: "New Deck" })).toHaveCount(0) + await expect(newChat).toHaveCount(0) + + // A message: the conversation takes the screen, New chat shows, the deck list follows below. + await send(page, "[chat] What is 17 × 3?") + await expect(chatLog).toContainText("51", { timeout: 15_000 }) + await expect(stageTitle).toBeHidden() + await expect(newChat).toBeVisible() + await expect(page.getByRole("heading", { name: "Decks" })).toBeAttached() + + // Open a deck: its sheet has only its own (empty) conversation, no tabs and no New chat. + await page.getByText(SEEDED.name).first().click() + await expect(page).toHaveURL(new RegExp(`#${SEEDED.id}$`)) + const sheet = page.locator("aside", { has: chatLog }) + await expect(chatLog).toBeVisible() + await expect(chatLog).not.toContainText("What is 17 × 3?") + await expect(newChat).toHaveCount(0) + await expect(sheet.getByRole("tab")).toHaveCount(0) + + // Closed, the sheet opens again from Chat in the deck's bar. + const openChat = page.getByRole("button", { name: "Open chat" }) + await expect(openChat).toHaveCount(0) + await page.getByRole("button", { name: "Close chat panel" }).click() + await expect(sheet).toHaveAttribute("data-open", "false") + await openChat.click() + await expect(sheet).toHaveAttribute("data-open", "true") + await expect(openChat).toHaveCount(0) + await expect(chatLog).toBeVisible() + await expect(chatLog).not.toContainText("What is 17 × 3?") + + // Back to the list: the home conversation is still there. + await backToList(page) + await expect(chatLog).toContainText("What is 17 × 3?") + await expect(chatLog).toContainText("51") + + // The logo goes back in place too: no reload, the conversation stays. + await page.evaluate(() => { (window as unknown as { __noReload: boolean }).__noReload = true }) + await page.getByText(SEEDED.name).first().click() + await expect(page).toHaveURL(new RegExp(`#${SEEDED.id}$`)) + await backToList(page, "logo") + expect(await page.evaluate(() => (window as unknown as { __noReload?: boolean }).__noReload)).toBe(true) + await expect(chatLog).toContainText("What is 17 × 3?") + + // New chat clears it: the stage again. + await newChat.click() + await expect(stageTitle).toBeVisible() + await expect(page.getByText("What is 17 × 3?")).toHaveCount(0) + await expect(newChat).toHaveCount(0) + }) + + test("a deck the home conversation makes keeps that conversation, and the home screen is blank again", async ({ page }) => { + const prompt = `[slow=10] deck=${MADE.replace("e2e-v3-", "")}` + const chatLog = page.getByRole("log", { name: "Chat messages" }) + await startChat(page, prompt) + // Mark the conversation's element: the deck's sheet must show this same one, not a new mount. + await chatLog.evaluate((el) => { el.setAttribute("data-e2e-home-chat", "") }) + + await expect(page).toHaveURL(new RegExp(`#${MADE}$`), { timeout: 15_000 }) + await expect(chatLog).toHaveAttribute("data-e2e-home-chat", "") + // Still streaming the same turn, the prompt shown once. + await expect(chatLog).toContainText(" 10", { timeout: 30_000 }) + await expect(chatLog.getByText(prompt, { exact: true })).toHaveCount(1) + await expect(page.getByRole("button", { name: "Stop generation" })).toHaveCount(0, { timeout: 15_000 }) + await expect(chatLog).toHaveAttribute("data-e2e-home-chat", "") + + // The home screen is blank again. + await backToList(page) + await expect(page.getByRole("heading", { name: "What are we presenting?" })).toBeVisible() + await expect(page.getByRole("textbox", { name: "Chat message input" })).toHaveValue("") + await expect(page.getByText(prompt, { exact: true })).toHaveCount(0) + }) +}) + for (const engine of ["v3", "v2"] as const) { test.describe(`several chats (${engine})`, () => { test.beforeEach(async ({ page, baseURL }) => { await useEngine(page, baseURL!, engine) }) diff --git a/web-ui/src/app/(authenticated)/decks/page.tsx b/web-ui/src/app/(authenticated)/decks/page.tsx index 5c4e8ffb..6f8cf799 100644 --- a/web-ui/src/app/(authenticated)/decks/page.tsx +++ b/web-ui/src/app/(authenticated)/decks/page.tsx @@ -95,7 +95,9 @@ export default function DecksPage() { }), [agentIsLoading]) // Home screen: a blank chat is the composer at the top (stage); once it has messages the // conversation fills the first screenful and the deck list follows below it (center). - const [chatLayout, setChatLayout] = useState("sheet") + // Starts as the stage, the shell's own first layout on the home screen, so the prerendered + // page already lays out the home screen (no deck-screen frame or New Deck until hydration). + const [chatLayout, setChatLayout] = useState("stage") const pageLayout: ChatLayout = ws.isWorkspace ? "sheet" : chatLayout const focusComposer = useCallback(() => chatRef.current?.focus(), []) const openChatSheet = useCallback(() => ws.setChatOpen(true), [ws]) diff --git a/web-ui/src/components/AppShell.tsx b/web-ui/src/components/AppShell.tsx index 90f43a2b..d9ec7132 100644 --- a/web-ui/src/components/AppShell.tsx +++ b/web-ui/src/components/AppShell.tsx @@ -40,6 +40,14 @@ interface AppShellProps { } export function AppShell({ children, deckName, onBack, onNavDecks }: AppShellProps) { + // The logo and the rail's Decks item go to the list in place, so the home conversation stays + // (a plain link to /decks/ would load the page anew). On a deck: back to the list; on the + // home screen with a conversation: scroll to the list below it. + const onDecksClick = onBack + ? (e: React.MouseEvent) => { e.preventDefault(); onBack() } + : onNavDecks + ? (e: React.MouseEvent) => { e.preventDefault(); onNavDecks() } + : undefined const t = useTranslations("appShell") const { user, signOut } = useAuth() const pathname = usePathname() @@ -120,7 +128,7 @@ export function AppShell({ children, deckName, onBack, onNavDecks }: AppShellPro )}