sync.test.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /** @jsxImportSource @opentui/solid */
  2. import { describe, expect, test } from "bun:test"
  3. import { tmpdir } from "../../../fixture/fixture"
  4. import { mount, wait } from "./sync-fixture"
  5. import type { GlobalEvent } from "@opencode-ai/sdk/v2"
  6. function branchEvent(branch: string, workspace?: string): GlobalEvent {
  7. return {
  8. directory: "/tmp/other",
  9. project: "proj_test",
  10. workspace,
  11. payload: {
  12. id: `evt_vcs_${branch}`,
  13. type: "vcs.branch.updated",
  14. properties: { branch },
  15. },
  16. }
  17. }
  18. describe("tui sync", () => {
  19. test("refresh scopes sessions by default and lists project sessions when disabled", async () => {
  20. await using tmp = await tmpdir()
  21. await Bun.write(`${tmp.path}/kv.json`, "{}")
  22. const { app, kv, sync, session } = await mount(undefined, tmp.path)
  23. try {
  24. expect(kv.get("session_directory_filter_enabled", true)).toBe(true)
  25. expect(session.at(-1)?.searchParams.get("scope")).toBeNull()
  26. expect(session.at(-1)?.searchParams.get("path")).toBe("packages/tui")
  27. kv.set("session_directory_filter_enabled", false)
  28. await sync.session.refresh()
  29. expect(session.at(-1)?.searchParams.get("scope")).toBe("project")
  30. expect(session.at(-1)?.searchParams.get("path")).toBeNull()
  31. } finally {
  32. app.renderer.destroy()
  33. }
  34. })
  35. test("vcs branch updates only apply for the active workspace", async () => {
  36. await using tmp = await tmpdir()
  37. await Bun.write(`${tmp.path}/kv.json`, "{}")
  38. const { app, emit, project, sync } = await mount(undefined, tmp.path)
  39. try {
  40. expect(sync.data.vcs?.branch).toBe("main")
  41. project.workspace.set("ws_a")
  42. emit(branchEvent("other", "ws_b"))
  43. await Bun.sleep(30)
  44. expect(sync.data.vcs?.branch).toBe("main")
  45. emit(branchEvent("feature", "ws_a"))
  46. await wait(() => sync.data.vcs?.branch === "feature")
  47. expect(sync.data.vcs?.branch).toBe("feature")
  48. } finally {
  49. app.renderer.destroy()
  50. }
  51. })
  52. })