|
|
@@ -1,4 +1,12 @@
|
|
|
// @vitest-environment jsdom
|
|
|
+// Assembled keyless snapshots of the New Session flow under the agent-parity
|
|
|
+// model: startup auto-connects the recent Workspace's blank session when one
|
|
|
+// exists; without any Workspace the composer is locked in the pure view
|
|
|
+// state until one is chosen. Picking one materializes the full Session+Agent
|
|
|
+// (reuse-or-create of the workspace's blank session), the first ACCEPTED
|
|
|
+// prompt flips blank and surfaces the session in lists, and failures leave
|
|
|
+// no client-side transaction state: a failed attach keeps the view state
|
|
|
+// locked, a rejected prompt keeps the session blank with the draft restored.
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
import { join } from 'node:path'
|
|
|
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
|
|
@@ -93,25 +101,12 @@ function boot(search: string): void {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-/** Recreate the built client graph while preserving browser-persistent state. */
|
|
|
-function refresh(search: string): void {
|
|
|
- act(() => { unmount?.() })
|
|
|
- unmount = undefined
|
|
|
- cleanup()
|
|
|
- delete win.__DSH_BOOT__
|
|
|
- delete win.__ModuleLoader__
|
|
|
- delete (globalThis as Record<string, unknown>).__fxTiming
|
|
|
- document.body.innerHTML = ''
|
|
|
- document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
|
|
- boot(search)
|
|
|
-}
|
|
|
-
|
|
|
/** Collapse decorative whitespace while preserving the text a user sees. */
|
|
|
function visibleText(element: Element): string {
|
|
|
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
|
|
}
|
|
|
|
|
|
-/** Identify the interactive Workspace chip by its menu contract. */
|
|
|
+/** Identify the interactive Workspace chip (view state or blank-session hero) by its menu contract. */
|
|
|
function workspaceChip(): HTMLElement {
|
|
|
const chip = screen.getAllByRole('button', { name: 'Choose workspace' })
|
|
|
.find(element => element.getAttribute('aria-haspopup') === 'menu')
|
|
|
@@ -119,210 +114,242 @@ function workspaceChip(): HTMLElement {
|
|
|
return chip
|
|
|
}
|
|
|
|
|
|
-/** Edit the runtime-owned controlled input and assert the same-tick echo:
|
|
|
- * a deferred echo makes React roll the textarea back mid-IME-composition,
|
|
|
- * committing partial keystrokes (e.g. Pinyin "nihao" leaking as "nnini h…"). */
|
|
|
+/** The locked view-state composer (no session yet). */
|
|
|
+async function findLockedComposer(): Promise<HTMLTextAreaElement> {
|
|
|
+ return await screen.findByPlaceholderText(
|
|
|
+ 'Choose a workspace to start', {}, { timeout: 10_000 },
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+/** The live blank-session hero composer (session materialized). */
|
|
|
+async function findHeroComposer(): Promise<HTMLTextAreaElement> {
|
|
|
+ return await screen.findByPlaceholderText(
|
|
|
+ 'Describe what you want to build', {}, { timeout: 10_000 },
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+/** Edit the machine-owned controlled input and assert the same-tick echo. */
|
|
|
function setComposerText(composer: HTMLElement, value: string): void {
|
|
|
fireEvent.change(composer, { target: { value } })
|
|
|
expect((composer as HTMLTextAreaElement).value).toBe(value)
|
|
|
}
|
|
|
|
|
|
-it('starts a writable page-local draft without inventing a sidebar Workspace', async () => {
|
|
|
+/** Drive the picker's create flow: chip → Create workspace → name dialog. */
|
|
|
+async function createWorkspaceViaPicker(name: string): Promise<void> {
|
|
|
+ fireEvent.click(workspaceChip())
|
|
|
+ fireEvent.click(await screen.findByRole('menuitem', { name: 'Create workspace' }))
|
|
|
+ fireEvent.click(await screen.findByRole('menuitem', { name: 'Create a new workspace' }))
|
|
|
+ const dialog = await screen.findByRole('dialog', { name: 'Create a new workspace' })
|
|
|
+ fireEvent.change(within(dialog).getByRole('textbox', { name: 'New workspace name' }), {
|
|
|
+ target: { value: name },
|
|
|
+ })
|
|
|
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Create workspace' }))
|
|
|
+}
|
|
|
+
|
|
|
+/** Pick an existing Workspace row from the chip menu. */
|
|
|
+async function pickWorkspace(title: string): Promise<void> {
|
|
|
+ fireEvent.click(workspaceChip())
|
|
|
+ fireEvent.click(await screen.findByRole('menuitem', { name: title }))
|
|
|
+}
|
|
|
+
|
|
|
+it('locks the composer in the New Session view state until a Workspace is chosen', async () => {
|
|
|
boot('?fixture=empty')
|
|
|
|
|
|
- const composer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
+ const composer = await findLockedComposer()
|
|
|
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- setComposerText(composer, 'keep this local')
|
|
|
|
|
|
expect({
|
|
|
headline: visibleText(screen.getByText("Let's start building")),
|
|
|
- workspaceDraft: visibleText(workspaceChip()),
|
|
|
+ chip: visibleText(workspaceChip()),
|
|
|
+ composerDisabled: composer.disabled,
|
|
|
+ sendDisabled: screen.getByRole<HTMLButtonElement>('button', { name: 'Send message' }).disabled,
|
|
|
sidebar: visibleText(tree),
|
|
|
- composerDisabled: (composer as HTMLTextAreaElement).disabled,
|
|
|
- prompt: (composer as HTMLTextAreaElement).value,
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "composerDisabled": false,
|
|
|
+ "chip": "New Workspace",
|
|
|
+ "composerDisabled": true,
|
|
|
"headline": "Let's start building",
|
|
|
- "prompt": "keep this local",
|
|
|
+ "sendDisabled": true,
|
|
|
"sidebar": "No sessions yet",
|
|
|
- "workspaceDraft": "workspace",
|
|
|
}
|
|
|
`)
|
|
|
})
|
|
|
|
|
|
-it('creates a real empty Workspace immediately and focuses its Session draft', async () => {
|
|
|
- boot('?fixture=empty')
|
|
|
+it('selects the recent Workspace and opens its blank Session on first load', async () => {
|
|
|
+ boot('?fixture')
|
|
|
|
|
|
- await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
- const workspaceSection = screen.getByText('Workspaces').parentElement
|
|
|
- if (workspaceSection === null) throw new Error('Workspace section missing')
|
|
|
- fireEvent.click(within(workspaceSection).getByRole('button', { name: 'Create workspace' }))
|
|
|
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Create workspace' }))
|
|
|
- fireEvent.click(await screen.findByRole('menuitem', { name: 'Create a new workspace' }))
|
|
|
+ const composer = await findHeroComposer()
|
|
|
+ const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
+ await waitFor(() => { expect(within(tree).getByText('4 sessions')).toBeDefined() }, { timeout: 10_000 })
|
|
|
|
|
|
- const dialog = await screen.findByRole('dialog', { name: 'Create a new workspace' })
|
|
|
- fireEvent.change(within(dialog).getByRole('textbox', { name: 'New workspace name' }), {
|
|
|
- target: { value: 'nova' },
|
|
|
- })
|
|
|
- fireEvent.click(within(dialog).getByRole('button', { name: 'Create workspace' }))
|
|
|
+ expect({
|
|
|
+ chip: visibleText(workspaceChip()),
|
|
|
+ composerDisabled: composer.disabled,
|
|
|
+ blankRow: within(tree).getByText('New Session').textContent,
|
|
|
+ }).toMatchInlineSnapshot(`
|
|
|
+ {
|
|
|
+ "blankRow": "New Session",
|
|
|
+ "chip": "fixture",
|
|
|
+ "composerDisabled": false,
|
|
|
+ }
|
|
|
+ `)
|
|
|
+})
|
|
|
+
|
|
|
+it('creating a Workspace materializes and lists its selected blank Session', async () => {
|
|
|
+ boot('?fixture=empty')
|
|
|
|
|
|
- const tree = await screen.findByRole('tree', { name: 'Sessions' })
|
|
|
+ await findLockedComposer()
|
|
|
+ await createWorkspaceViaPicker('nova')
|
|
|
+
|
|
|
+ // The pick connected the workspace: full Session+Agent exists, composer live.
|
|
|
+ const composer = await findHeroComposer()
|
|
|
+ const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() })
|
|
|
+ expect(within(tree).getByText('New Session')).toBeDefined()
|
|
|
const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
- const draft = within(tree).getByText('New session').closest('[role="treeitem"]')
|
|
|
- if (group === null || draft === null) throw new Error('created Workspace projection missing')
|
|
|
+ if (group === null) throw new Error('created Workspace projection missing')
|
|
|
|
|
|
expect({
|
|
|
+ composerDisabled: composer.disabled,
|
|
|
+ chip: visibleText(workspaceChip()),
|
|
|
workspace: visibleText(group),
|
|
|
- draft: visibleText(draft),
|
|
|
- draftSelected: draft.getAttribute('aria-selected'),
|
|
|
- composerWorkspace: visibleText(workspaceChip()),
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "composerWorkspace": "nova",
|
|
|
- "draft": "New session",
|
|
|
- "draftSelected": "true",
|
|
|
+ "chip": "nova",
|
|
|
+ "composerDisabled": false,
|
|
|
"workspace": "nova1 session",
|
|
|
}
|
|
|
`)
|
|
|
})
|
|
|
|
|
|
-it('drops the page-local draft on refresh while retaining real Workspaces and Sessions', async () => {
|
|
|
- boot('?fixture')
|
|
|
+it('New Session reuses the Workspace blank session and converts the single visible row', async () => {
|
|
|
+ boot('?fixture=empty')
|
|
|
|
|
|
- const composer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
+ await findLockedComposer()
|
|
|
+ await createWorkspaceViaPicker('nova')
|
|
|
+ await findHeroComposer()
|
|
|
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- setComposerText(composer, 'discard this page-local draft')
|
|
|
- const beforeGroup = within(tree).getByText('4 sessions').closest('[role="treeitem"]')
|
|
|
- if (beforeGroup === null) throw new Error('fixture Workspace projection missing before refresh')
|
|
|
+ await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
|
|
|
|
|
- const before = {
|
|
|
- workspace: visibleText(beforeGroup),
|
|
|
- draft: visibleText(within(tree).getByText('New session')),
|
|
|
- prompt: (composer as HTMLTextAreaElement).value,
|
|
|
- }
|
|
|
+ // New Session resolves through the recent Workspace and reuses its blank
|
|
|
+ // session in place: no locked interlude, no second entity.
|
|
|
+ fireEvent.click(screen.getByRole('button', { name: 'New session' }))
|
|
|
+ const composer = await findHeroComposer()
|
|
|
+ await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
|
|
|
|
|
- refresh('?fixture')
|
|
|
+ setComposerText(composer, 'first light')
|
|
|
+ fireEvent.keyDown(composer, { key: 'Enter' })
|
|
|
|
|
|
- const refreshedComposer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
- const refreshedTree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- const afterGroup = within(refreshedTree).getByText('4 sessions').closest('[role="treeitem"]')
|
|
|
- if (afterGroup === null) throw new Error('fixture Workspace projection missing after refresh')
|
|
|
+ // Conversion: the accepted prompt flips blank without adding a second row.
|
|
|
+ await screen.findByText('first light', { exact: true }, { timeout: 10_000 })
|
|
|
+ await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
|
|
+ const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
+ if (group === null) throw new Error('converted Session projection missing')
|
|
|
|
|
|
expect({
|
|
|
- before,
|
|
|
- after: {
|
|
|
- workspace: visibleText(afterGroup),
|
|
|
- replacementDraft: visibleText(within(refreshedTree).getByText('New session')),
|
|
|
- prompt: (refreshedComposer as HTMLTextAreaElement).value,
|
|
|
- },
|
|
|
+ workspace: visibleText(group),
|
|
|
+ promptVisible: screen.getByText('first light', { exact: true }).textContent,
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "after": {
|
|
|
- "prompt": "",
|
|
|
- "replacementDraft": "New session",
|
|
|
- "workspace": "fixture4 sessions",
|
|
|
- },
|
|
|
- "before": {
|
|
|
- "draft": "New session",
|
|
|
- "prompt": "discard this page-local draft",
|
|
|
- "workspace": "fixture4 sessions",
|
|
|
- },
|
|
|
+ "promptVisible": "first light",
|
|
|
+ "workspace": "nova1 session",
|
|
|
}
|
|
|
`)
|
|
|
})
|
|
|
|
|
|
-it('keeps a published Session with only cwd membership evidence in Ungrouped', async () => {
|
|
|
+it('a failed Workspace attach recovers by reusing the published blank session', async () => {
|
|
|
boot('?fixture&fixtureAttach=fail')
|
|
|
|
|
|
- const composer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
- setComposerText(composer, 'keep this cwd-only session')
|
|
|
- fireEvent.click(screen.getByRole('button', { name: 'Send message' }))
|
|
|
+ // The rejected startup connect surfaces the locked view state first: the
|
|
|
+ // failure leaves no client-side transaction state to unwind.
|
|
|
+ await findLockedComposer()
|
|
|
|
|
|
+ // The host published the session before rejecting attachment (blank, with
|
|
|
+ // the workspace cwd), so the next connect — retry or manual pick — reuses
|
|
|
+ // it instead of minting a duplicate, and the hero opens on it.
|
|
|
+ await pickWorkspace('fixture')
|
|
|
+ const composer = await findHeroComposer()
|
|
|
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- await waitFor(() => { expect(within(tree).getByText('Ungrouped')).toBeDefined() }, { timeout: 10_000 })
|
|
|
- const workspaceGroup = within(tree).getByText('3 sessions').closest('[role="treeitem"]')
|
|
|
- const ungroupedGroup = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
- const ungroupedSection = ungroupedGroup?.parentElement
|
|
|
- if (workspaceGroup === null || ungroupedGroup === null || ungroupedSection === null || ungroupedSection === undefined) {
|
|
|
- throw new Error('Workspace or Ungrouped projection missing')
|
|
|
- }
|
|
|
- const session = within(ungroupedSection).getByRole('treeitem', { selected: true })
|
|
|
- const retained = screen.getByDisplayValue('keep this cwd-only session')
|
|
|
+ const group = within(tree).getByText('3 sessions').closest('[role="treeitem"]')
|
|
|
+ if (group === null) throw new Error('fixture Workspace projection missing')
|
|
|
|
|
|
expect({
|
|
|
- workspace: visibleText(workspaceGroup),
|
|
|
- ungrouped: visibleText(ungroupedGroup),
|
|
|
- session: within(session).getByText('fixture', { exact: true }).textContent,
|
|
|
- sessionSelected: session.getAttribute('aria-selected'),
|
|
|
- prompt: (retained as HTMLTextAreaElement).value,
|
|
|
+ headline: visibleText(screen.getByText("Let's start building")),
|
|
|
+ composerDisabled: composer.disabled,
|
|
|
+ chip: visibleText(workspaceChip()),
|
|
|
+ workspace: visibleText(group),
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "prompt": "keep this cwd-only session",
|
|
|
- "session": "fixture",
|
|
|
- "sessionSelected": "true",
|
|
|
- "ungrouped": "Ungrouped1 session",
|
|
|
+ "chip": "fixture",
|
|
|
+ "composerDisabled": false,
|
|
|
+ "headline": "Let's start building",
|
|
|
"workspace": "fixture3 sessions",
|
|
|
}
|
|
|
`)
|
|
|
})
|
|
|
|
|
|
-it('materializes the automatic Workspace and Session on the first successful send', async () => {
|
|
|
- boot('?fixture=empty')
|
|
|
+it('a rejected first prompt keeps the session blank and the draft in the machine', async () => {
|
|
|
+ boot('?fixture=empty&fixturePrompt=reject')
|
|
|
|
|
|
- const composer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
- setComposerText(composer, 'build a lighthouse')
|
|
|
+ await findLockedComposer()
|
|
|
+ await createWorkspaceViaPicker('nova')
|
|
|
+ const composer = await findHeroComposer()
|
|
|
+
|
|
|
+ setComposerText(composer, 'do not lose this')
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Send message' }))
|
|
|
|
|
|
+ const alert = await screen.findByRole('alert', {}, { timeout: 10_000 })
|
|
|
+ // Failure restore rides the machine (no pendingPrompt transaction): the
|
|
|
+ // draft returns to the same resident textarea one render later. The
|
|
|
+ // attempt flips the composer out of the hero (engaging = retry chrome),
|
|
|
+ // but acceptance never happened: the session row stays New Session.
|
|
|
+ const retained = await screen.findByDisplayValue('do not lose this')
|
|
|
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
|
|
- await screen.findByText('build a lighthouse', { exact: true }, { timeout: 10_000 })
|
|
|
const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
- const session = within(tree).getByRole('treeitem', { selected: true })
|
|
|
- if (group === null) throw new Error('materialized Workspace projection missing')
|
|
|
+ if (group === null) throw new Error('rejected-send Workspace projection missing')
|
|
|
|
|
|
expect({
|
|
|
+ error: visibleText(alert),
|
|
|
+ prompt: (retained as HTMLTextAreaElement).value,
|
|
|
+ blankRow: within(tree).getByText('New Session').textContent,
|
|
|
workspace: visibleText(group),
|
|
|
- session: within(session).getByText('workspace', { exact: true }).textContent,
|
|
|
- sessionSelected: session.getAttribute('aria-selected'),
|
|
|
- promptVisible: screen.getByText('build a lighthouse', { exact: true }).textContent,
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "promptVisible": "build a lighthouse",
|
|
|
- "session": "workspace",
|
|
|
- "sessionSelected": "true",
|
|
|
- "workspace": "workspace1 session",
|
|
|
+ "blankRow": "New Session",
|
|
|
+ "error": "fixture: prompt rejected before acceptance (agent-busy)",
|
|
|
+ "prompt": "do not lose this",
|
|
|
+ "workspace": "nova1 session",
|
|
|
}
|
|
|
`)
|
|
|
})
|
|
|
|
|
|
-it('keeps the published Workspace, Session, and unsent prompt after rejection', async () => {
|
|
|
- boot('?fixture=empty&fixturePrompt=reject')
|
|
|
+it('switching Workspace before the first message carries the draft to the new blank session', async () => {
|
|
|
+ boot('?fixture')
|
|
|
|
|
|
- const composer = await screen.findByPlaceholderText('Describe what you want to build', {}, { timeout: 10_000 })
|
|
|
- setComposerText(composer, 'do not lose this')
|
|
|
- fireEvent.click(screen.getByRole('button', { name: 'Send message' }))
|
|
|
+ const composer = await findHeroComposer()
|
|
|
+ setComposerText(composer, 'carry me')
|
|
|
|
|
|
- const alert = await screen.findByRole('alert', {}, { timeout: 10_000 })
|
|
|
- const retained = screen.getByDisplayValue('do not lose this')
|
|
|
+ // Switch = session switch: the new workspace's blank session takes over,
|
|
|
+ // the typed draft moves machine-to-machine, the old blank stays hidden.
|
|
|
+ await createWorkspaceViaPicker('nova')
|
|
|
+ await waitFor(() => { expect(visibleText(workspaceChip())).toBe('nova') }, { timeout: 10_000 })
|
|
|
+ const carried = await screen.findByDisplayValue('carry me')
|
|
|
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
|
|
- await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() })
|
|
|
- const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
- const session = within(tree).getByRole('treeitem', { selected: true })
|
|
|
- if (group === null) throw new Error('rejected-send Workspace projection missing')
|
|
|
+ const fixtureGroup = within(tree).getByText('3 sessions').closest('[role="treeitem"]')
|
|
|
+ const novaGroup = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
|
|
+ if (fixtureGroup === null || novaGroup === null) throw new Error('Workspace projections missing after switch')
|
|
|
|
|
|
expect({
|
|
|
- workspace: visibleText(group),
|
|
|
- session: within(session).getByText('workspace', { exact: true }).textContent,
|
|
|
- error: visibleText(alert),
|
|
|
- prompt: (retained as HTMLTextAreaElement).value,
|
|
|
+ chip: visibleText(workspaceChip()),
|
|
|
+ prompt: (carried as HTMLTextAreaElement).value,
|
|
|
+ fixtureWorkspace: visibleText(fixtureGroup),
|
|
|
+ novaWorkspace: visibleText(novaGroup),
|
|
|
}).toMatchInlineSnapshot(`
|
|
|
{
|
|
|
- "error": "Message send failed: agent-busy: fixture: prompt rejected before acceptance",
|
|
|
- "prompt": "do not lose this",
|
|
|
- "session": "workspace",
|
|
|
- "workspace": "workspace1 session",
|
|
|
+ "chip": "nova",
|
|
|
+ "fixtureWorkspace": "fixture3 sessions",
|
|
|
+ "novaWorkspace": "nova1 session",
|
|
|
+ "prompt": "carry me",
|
|
|
}
|
|
|
`)
|
|
|
})
|