terminal-hidden.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { expect, test } from "@playwright/test"
  2. import { mockOpenCodeServer } from "../utils/mock-server"
  3. import { expectSessionTitle } from "../utils/waits"
  4. const directory = "C:/OpenCode/HiddenTerminalRegression"
  5. const projectID = "proj_hidden_terminal_regression"
  6. const sessionID = "ses_hidden_terminal_regression"
  7. const title = "Hidden terminal regression"
  8. test("unmounts the terminal panel while it is hidden", async ({ page }) => {
  9. await page.setViewportSize({ width: 1400, height: 900 })
  10. await mockOpenCodeServer(page, {
  11. protocol: "v2",
  12. directory,
  13. project: {
  14. id: projectID,
  15. worktree: directory,
  16. vcs: "git",
  17. name: "hidden-terminal-regression",
  18. time: { created: 1700000000000, updated: 1700000000000 },
  19. sandboxes: [],
  20. },
  21. provider: {
  22. all: [
  23. {
  24. id: "opencode",
  25. name: "OpenCode",
  26. models: { test: { id: "test", name: "Test", limit: { context: 200_000 } } },
  27. },
  28. ],
  29. connected: ["opencode"],
  30. default: { providerID: "opencode", modelID: "test" },
  31. },
  32. sessions: [
  33. {
  34. id: sessionID,
  35. slug: "hidden-terminal-regression",
  36. projectID,
  37. directory,
  38. title,
  39. version: "dev",
  40. time: { created: 1700000000000, updated: 1700000000000 },
  41. },
  42. ],
  43. pageMessages: () => ({ items: [] }),
  44. })
  45. await page.route("**/api/pty*", (route) =>
  46. route.fulfill({
  47. status: 200,
  48. contentType: "application/json",
  49. body: JSON.stringify({
  50. location: { directory, project: { id: projectID, directory } },
  51. data: {
  52. id: "pty_hidden_terminal",
  53. title: "Terminal 1",
  54. command: "cmd.exe",
  55. args: [],
  56. cwd: directory,
  57. status: "running",
  58. pid: 1,
  59. },
  60. }),
  61. }),
  62. )
  63. await page.route("**/api/pty/pty_hidden_terminal*", (route) =>
  64. route.fulfill({
  65. status: 200,
  66. contentType: "application/json",
  67. body: JSON.stringify({
  68. location: { directory, project: { id: projectID, directory } },
  69. data: {
  70. id: "pty_hidden_terminal",
  71. title: "Terminal 1",
  72. command: "cmd.exe",
  73. args: [],
  74. cwd: directory,
  75. status: "running",
  76. pid: 1,
  77. },
  78. }),
  79. }),
  80. )
  81. await page.route("**/api/pty/pty_hidden_terminal/connect-token*", (route) =>
  82. route.fulfill({
  83. status: 200,
  84. contentType: "application/json",
  85. body: JSON.stringify({
  86. location: { directory, project: { id: projectID, directory } },
  87. data: { ticket: "e2e-ticket", expires_in: 60 },
  88. }),
  89. }),
  90. )
  91. await page.routeWebSocket("**/api/pty/pty_hidden_terminal/connect", () => undefined)
  92. await page.goto(`/${base64Encode(directory)}/session/${sessionID}`)
  93. await expectSessionTitle(page, title)
  94. await page.keyboard.press("Control+Backquote")
  95. const panel = page.locator("#terminal-panel")
  96. await expect(panel).toHaveAttribute("aria-hidden", "false")
  97. await expect(page.locator('[data-component="terminal"]')).toBeVisible()
  98. await page.keyboard.press("Control+Backquote")
  99. await expect(panel).toHaveCount(0)
  100. await expect(page.locator('[data-component="terminal"]')).toHaveCount(0)
  101. await page.setViewportSize({ width: 1200, height: 700 })
  102. await expect(page.locator('[data-component="terminal"]')).toHaveCount(0)
  103. await page.keyboard.press("Control+Backquote")
  104. await expect(panel).toBeVisible()
  105. await expect(page.locator('[data-component="terminal"]')).toBeVisible()
  106. })
  107. function base64Encode(value: string) {
  108. return Buffer.from(value, "utf8").toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
  109. }