terminal.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { beforeAll, describe, expect, mock, test } from "bun:test"
  2. let getWorkspaceTerminalCacheKey: (dir: string) => string
  3. let getLegacyTerminalStorageKeys: (dir: string, legacySessionID?: string) => string[]
  4. beforeAll(async () => {
  5. mock.module("@solidjs/router", () => ({
  6. useParams: () => ({}),
  7. }))
  8. mock.module("@opencode-ai/ui/context", () => ({
  9. createSimpleContext: () => ({
  10. use: () => undefined,
  11. provider: () => undefined,
  12. }),
  13. }))
  14. const mod = await import("./terminal")
  15. getWorkspaceTerminalCacheKey = mod.getWorkspaceTerminalCacheKey
  16. getLegacyTerminalStorageKeys = mod.getLegacyTerminalStorageKeys
  17. })
  18. describe("getWorkspaceTerminalCacheKey", () => {
  19. test("uses workspace-only directory cache key", () => {
  20. expect(getWorkspaceTerminalCacheKey("/repo")).toBe("/repo:__workspace__")
  21. })
  22. })
  23. describe("getLegacyTerminalStorageKeys", () => {
  24. test("keeps workspace storage path when no legacy session id", () => {
  25. expect(getLegacyTerminalStorageKeys("/repo")).toEqual(["/repo/terminal.v1"])
  26. })
  27. test("includes legacy session path before workspace path", () => {
  28. expect(getLegacyTerminalStorageKeys("/repo", "session-123")).toEqual([
  29. "/repo/terminal/session-123.v1",
  30. "/repo/terminal.v1",
  31. ])
  32. })
  33. })