session-timeline-lifecycle-state.spec.ts 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { expect, test } from "@playwright/test"
  2. import {
  3. assistantMessage,
  4. completedAssistantInfo,
  5. messageUpdated,
  6. partUpdated,
  7. reasoningPart,
  8. setupTimeline,
  9. shell,
  10. status,
  11. textPart,
  12. userMessage,
  13. } from "../performance/timeline-stability/fixture"
  14. for (const expanded of [false, true]) {
  15. test(`preserves shell user intent from a ${expanded ? "expanded" : "collapsed"} default`, async ({ page }) => {
  16. const id = `prt_shell_default_${expanded}`
  17. const timeline = await setupTimeline(page, {
  18. messages: [userMessage(), assistantMessage([shell(id, "completed", lines(3))])],
  19. settings: { shellToolPartsExpanded: expanded },
  20. })
  21. const trigger = page.locator(`[data-timeline-part-id="${id}"] [data-slot="collapsible-trigger"]`)
  22. await expect(trigger).toHaveAttribute("aria-expanded", String(expanded))
  23. await trigger.click()
  24. await expect(trigger).toHaveAttribute("aria-expanded", String(!expanded))
  25. await timeline.send(partUpdated(shell(id, "completed", lines(6))), 180)
  26. await timeline.send(partUpdated(textPart(`prt_sibling_${expanded}`, "Sibling content")), 180)
  27. await timeline.send(status("busy"), 100)
  28. await timeline.send(status("idle"), 250)
  29. await expect(trigger).toHaveAttribute("aria-expanded", String(!expanded))
  30. })
  31. }
  32. test("transitions thinking and hidden reasoning through busy to idle", async ({ page }) => {
  33. const reasoningID = "prt_reasoning_hidden"
  34. const assistant = assistantMessage([reasoningPart(reasoningID, "## Inspecting stability")], { completed: false })
  35. const timeline = await setupTimeline(page, {
  36. messages: [userMessage(), assistant],
  37. settings: { showReasoningSummaries: false },
  38. cpuRate: 4,
  39. })
  40. await timeline.send(status("busy"), 150)
  41. await expect(page.locator('[data-timeline-row="Thinking"]')).toBeVisible()
  42. await expect(page.getByText("Inspecting stability", { exact: true })).toBeVisible()
  43. await expect(page.locator(`[data-timeline-part-id="${reasoningID}"]`)).toHaveCount(0)
  44. await timeline.send(partUpdated(shell("prt_reasoning_shell", "running")), 160)
  45. await expect(page.locator('[data-timeline-row="Thinking"]')).toBeVisible()
  46. await timeline.send(partUpdated(shell("prt_reasoning_shell", "completed", "done")), 180)
  47. await timeline.send(messageUpdated(completedAssistantInfo(assistant.info)), 100)
  48. await timeline.send(status("idle"), 300)
  49. await expect(page.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
  50. await expect(page.locator(`[data-timeline-part-id="${reasoningID}"]`)).toHaveCount(0)
  51. })
  52. test("moves busy through retry and recovery to final idle content", async ({ page }) => {
  53. const assistant = assistantMessage([], { completed: false })
  54. const timeline = await setupTimeline(page, {
  55. messages: [
  56. userMessage(undefined, {
  57. summary: {
  58. diffs: [
  59. {
  60. file: "src/retry.ts",
  61. additions: 1,
  62. deletions: 1,
  63. patch: "@@ -1 +1 @@\n-export const retry = false\n+export const retry = true",
  64. },
  65. ],
  66. },
  67. }),
  68. assistant,
  69. ],
  70. })
  71. await timeline.send(status("busy"), 140)
  72. await expect(page.locator('[data-timeline-row="Thinking"]')).toBeVisible()
  73. await expect(page.locator('[data-timeline-row="DiffSummary"]')).toHaveCount(0)
  74. await timeline.send(status("retry"), 180)
  75. await expect(page.locator('[data-timeline-row="Retry"]')).toBeVisible()
  76. await expect(page.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
  77. await timeline.send(status("busy", 2), 180)
  78. await expect(page.locator('[data-timeline-row="Thinking"]')).toBeVisible()
  79. await timeline.send(partUpdated(textPart("prt_recovered", "Recovered response")), 140)
  80. await timeline.send(messageUpdated(completedAssistantInfo(assistant.info)), 100)
  81. await timeline.send(status("idle"), 350)
  82. await expect(page.locator('[data-timeline-row="Retry"]')).toHaveCount(0)
  83. await expect(page.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
  84. await expect(page.locator('[data-timeline-row="DiffSummary"]')).toBeVisible()
  85. })
  86. function lines(count: number) {
  87. return Array.from({ length: count }, (_, index) => `line ${index + 1}`).join("\n")
  88. }