sync.test.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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("roots")).toBeNull()
  26. expect(session.at(-1)?.searchParams.get("scope")).toBeNull()
  27. expect(session.at(-1)?.searchParams.get("path")).toBe("packages/tui")
  28. kv.set("session_directory_filter_enabled", false)
  29. await sync.session.refresh()
  30. expect(session.at(-1)?.searchParams.get("scope")).toBe("project")
  31. expect(session.at(-1)?.searchParams.get("path")).toBeNull()
  32. expect(session.at(-1)?.searchParams.get("roots")).toBeNull()
  33. } finally {
  34. app.renderer.destroy()
  35. }
  36. })
  37. test("vcs branch updates only apply for the active workspace", async () => {
  38. await using tmp = await tmpdir()
  39. await Bun.write(`${tmp.path}/kv.json`, "{}")
  40. const { app, emit, project, sync } = await mount(undefined, tmp.path)
  41. try {
  42. expect(sync.data.vcs?.branch).toBe("main")
  43. project.workspace.set("ws_a")
  44. emit(branchEvent("other", "ws_b"))
  45. await Bun.sleep(30)
  46. expect(sync.data.vcs?.branch).toBe("main")
  47. emit(branchEvent("feature", "ws_a"))
  48. await wait(() => sync.data.vcs?.branch === "feature")
  49. expect(sync.data.vcs?.branch).toBe("feature")
  50. } finally {
  51. app.renderer.destroy()
  52. }
  53. })
  54. })