feat(ui): dock repo and session tools in a desktop side panel

Add a docked desktop tool panel with an icon rail, driven by the shared panel URL param, and keep the mobile dialogs and drawers. Extract dialog bodies into reusable content components, rename the walkthrough dialog to a sheet, and make walkthrough generation asynchronous with client polling.
This commit is contained in:
Chris Scott committed 2026-10-07 23:58:56 -04:00
1 parent bdbcc60716
commit 485ab940aa
49 files changed
+2631 -1753

No files matched your search

+83 -20
View File
@@ -28,7 +28,7 @@ interface FakeSession {
function createFakeClient(sessions: Record<string, FakeSession>) {
const generateCalls: string[] = []
let reply = MODEL_REPLY
let generateImpl: () => Promise<string> = async () => MODEL_REPLY
const client = {
api: {
@@ -62,7 +62,7 @@ function createFakeClient(sessions: Record<string, FakeSession>) {
generate: {
text: vi.fn(async (input: { prompt: string }) => {
generateCalls.push(input.prompt)
return { text: reply }
return { text: await generateImpl() }
}),
},
},
@@ -72,8 +72,8 @@ function createFakeClient(sessions: Record<string, FakeSession>) {
return {
client,
generateCalls,
setReply: (next: string) => {
reply = next
setGenerateImpl: (impl: () => Promise<string>) => {
generateImpl = impl
},
}
}
@@ -102,10 +102,18 @@ describe('change walkthrough routes', () => {
const res = await app.request(`/change-walkthroughs/${SESSION_ID}`)
expect(res.status).toBe(200)
const body = (await res.json()) as { walkthrough: unknown; currentDiffHash: string | null; stale: boolean }
const body = (await res.json()) as {
walkthrough: unknown
currentDiffHash: string | null
stale: boolean
generating: boolean
error: unknown
}
expect(body.walkthrough).toBeNull()
expect(body.stale).toBe(false)
expect(body.currentDiffHash).toEqual(expect.any(String))
expect(body.generating).toBe(false)
expect(body.error).toBeNull()
})
it('GET returns 404 for a missing session', async () => {
@@ -115,30 +123,59 @@ describe('change walkthrough routes', () => {
await expect(res.json()).resolves.toMatchObject({ error: 'Session not found' })
})
it('POST creates a walkthrough and GET reads it back', async () => {
it('POST returns 202 while generating, then GET reads the walkthrough back', async () => {
let resolveGenerate: (text: string) => void = () => {}
fake.setGenerateImpl(() => new Promise<string>((resolve) => {
resolveGenerate = resolve
}))
const postRes = await app.request(`/change-walkthroughs/${SESSION_ID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
})
expect(postRes.status).toBe(201)
const created = (await postRes.json()) as { walkthrough: { summary: string; sessionId: string } }
expect(created.walkthrough.summary).toBe('A summary')
expect(postRes.status).toBe(202)
const body = (await postRes.json()) as { generating: boolean; walkthrough: unknown }
expect(body.generating).toBe(true)
expect(body.walkthrough).toBeNull()
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { walkthrough: { summary: string } }
expect(state.walkthrough.summary).toBe('A summary')
resolveGenerate(MODEL_REPLY)
await vi.waitFor(async () => {
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { walkthrough: { summary: string } | null; generating: boolean }
expect(state.generating).toBe(false)
expect(state.walkthrough?.summary).toBe('A summary')
})
})
it('POST accepts an empty body', async () => {
let resolveGenerate: (text: string) => void = () => {}
fake.setGenerateImpl(() => new Promise<string>((resolve) => {
resolveGenerate = resolve
}))
const res = await app.request(`/change-walkthroughs/${SESSION_ID}`, { method: 'POST' })
expect(res.status).toBe(201)
expect(res.status).toBe(202)
resolveGenerate(MODEL_REPLY)
await vi.waitFor(async () => {
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { walkthrough: unknown }
expect(state.walkthrough).not.toBeNull()
})
})
it('POST returns 200 without a second model call when changes are unchanged', async () => {
it('POST returns 200 with the stored walkthrough without a second model call', async () => {
await app.request(`/change-walkthroughs/${SESSION_ID}`, { method: 'POST' })
await vi.waitFor(async () => {
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { walkthrough: unknown }
expect(state.walkthrough).not.toBeNull()
})
const second = await app.request(`/change-walkthroughs/${SESSION_ID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -146,19 +183,35 @@ describe('change walkthrough routes', () => {
})
expect(second.status).toBe(200)
const body = (await second.json()) as { walkthrough: { summary: string }; generating: boolean }
expect(body.walkthrough.summary).toBe('A summary')
expect(body.generating).toBe(false)
expect(fake.generateCalls).toHaveLength(1)
})
it('POST regenerates when asked', async () => {
await app.request(`/change-walkthroughs/${SESSION_ID}`, { method: 'POST' })
await vi.waitFor(async () => {
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { walkthrough: unknown }
expect(state.walkthrough).not.toBeNull()
})
let resolveGenerate: (text: string) => void = () => {}
fake.setGenerateImpl(() => new Promise<string>((resolve) => {
resolveGenerate = resolve
}))
const res = await app.request(`/change-walkthroughs/${SESSION_ID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ regenerate: true }),
})
expect(res.status).toBe(201)
expect(fake.generateCalls).toHaveLength(2)
expect(res.status).toBe(202)
resolveGenerate(MODEL_REPLY)
await vi.waitFor(() => expect(fake.generateCalls).toHaveLength(2))
})
it('POST rejects an invalid body with 400', async () => {
@@ -192,13 +245,23 @@ describe('change walkthrough routes', () => {
await expect(res.json()).resolves.toMatchObject({ code: 'WALKTHROUGH_NO_TEXT_CHANGES' })
})
it('POST returns 502 with a code when the model response is unparseable', async () => {
fake.setReply('not json')
it('POST records an unparseable model reply that GET surfaces', async () => {
let resolveGenerate: (text: string) => void = () => {}
fake.setGenerateImpl(() => new Promise<string>((resolve) => {
resolveGenerate = resolve
}))
const res = await app.request(`/change-walkthroughs/${SESSION_ID}`, { method: 'POST' })
expect(res.status).toBe(202)
expect(res.status).toBe(502)
await expect(res.json()).resolves.toMatchObject({ code: 'WALKTHROUGH_UNPARSEABLE' })
resolveGenerate('not json')
await vi.waitFor(async () => {
const getRes = await app.request(`/change-walkthroughs/${SESSION_ID}`)
const state = (await getRes.json()) as { generating: boolean; error: { code?: string } | null }
expect(state.generating).toBe(false)
expect(state.error?.code).toBe('WALKTHROUGH_UNPARSEABLE')
})
})
it('POST returns 404 for a missing session', async () => {
@@ -383,6 +383,8 @@ describe('ChangeWalkthroughService', () => {
expect(state.walkthrough).toBeNull()
expect(state.stale).toBe(false)
expect(state.currentDiffHash).toBe(computeChangesHash(threeHunks))
expect(state.generating).toBe(false)
expect(state.error).toBeNull()
})
it('reports stale when the changes differ from the stored hash', async () => {
@@ -526,6 +528,79 @@ describe('ChangeWalkthroughService', () => {
await expect(service.generate('ses_missing', {})).rejects.toMatchObject({ status: 404 })
})
describe('startGeneration', () => {
const coveringReply = modelReply([{ title: 'A', explanation: 'x', hunkIds: ['f0h0', 'f0h1', 'f1h0'] }])
it('reports generating while the model call is pending, then the stored walkthrough', async () => {
let resolveGenerate: (text: string) => void = () => {}
fake.setGenerateImpl(() => new Promise<string>((resolve) => {
resolveGenerate = resolve
}))
const state = await service.startGeneration(SESSION_ID, {})
expect(state.generating).toBe(true)
expect(state.walkthrough).toBeNull()
expect(state.error).toBeNull()
resolveGenerate(coveringReply)
await vi.waitFor(async () => {
const settled = await service.getState(SESSION_ID)
expect(settled.generating).toBe(false)
expect(settled.walkthrough).not.toBeNull()
})
})
it('rejects with 409 when the session has no changes', async () => {
sessions[SESSION_ID]!.changes = []
await expect(service.startGeneration(SESSION_ID, {})).rejects.toMatchObject({
status: 409,
code: 'WALKTHROUGH_NO_CHANGES',
})
sessions[SESSION_ID]!.changes = threeHunks
expect((await service.getState(SESSION_ID)).error).toBeNull()
})
it('records an unparseable model failure on the state', async () => {
fake.setGenerateImpl(async () => 'not json')
await service.startGeneration(SESSION_ID, {})
await vi.waitFor(async () => {
const settled = await service.getState(SESSION_ID)
expect(settled.generating).toBe(false)
expect(settled.error).toMatchObject({ code: 'WALKTHROUGH_UNPARSEABLE' })
})
})
it('clears a previous error when a new generation starts', async () => {
fake.setGenerateImpl(async () => 'not json')
await service.startGeneration(SESSION_ID, {})
await vi.waitFor(async () => {
expect((await service.getState(SESSION_ID)).error).not.toBeNull()
})
fake.setGenerateImpl(() => new Promise<string>(() => {}))
const state = await service.startGeneration(SESSION_ID, { regenerate: true })
expect(state.generating).toBe(true)
expect(state.error).toBeNull()
})
it('clears the recorded error when the session is deleted', async () => {
fake.setGenerateImpl(async () => 'not json')
await service.startGeneration(SESSION_ID, {})
await vi.waitFor(async () => {
expect((await service.getState(SESSION_ID)).error).not.toBeNull()
})
service.handleEvent(sessionEvent('session.deleted', SESSION_ID))
expect((await service.getState(SESSION_ID)).error).toBeNull()
})
})
describe('handleEvent', () => {
const coveringReply = modelReply([{ title: 'A', explanation: 'x', hunkIds: ['f0h0', 'f0h1', 'f1h0'] }])