terminal.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. useNavigate: () => () => undefined,
  7. useParams: () => ({}),
  8. }))
  9. mock.module("@opencode-ai/ui/context", () => ({
  10. createSimpleContext: () => ({
  11. use: () => undefined,
  12. provider: () => undefined,
  13. }),
  14. }))
  15. const mod = await import("./terminal")
  16. getWorkspaceTerminalCacheKey = mod.getWorkspaceTerminalCacheKey
  17. getLegacyTerminalStorageKeys = mod.getLegacyTerminalStorageKeys
  18. })
  19. describe("getWorkspaceTerminalCacheKey", () => {
  20. test("uses workspace-only directory cache key", () => {
  21. expect(getWorkspaceTerminalCacheKey("/repo")).toBe("/repo:__workspace__")
  22. })
  23. })
  24. describe("getLegacyTerminalStorageKeys", () => {
  25. test("keeps workspace storage path when no legacy session id", () => {
  26. expect(getLegacyTerminalStorageKeys("/repo")).toEqual(["/repo/terminal.v1"])
  27. })
  28. test("includes legacy session path before workspace path", () => {
  29. expect(getLegacyTerminalStorageKeys("/repo", "session-123")).toEqual([
  30. "/repo/terminal/session-123.v1",
  31. "/repo/terminal.v1",
  32. ])
  33. })
  34. })