location.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect } from "bun:test"
  2. import { Effect, Layer } from "effect"
  3. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  4. import { Location } from "@opencode-ai/core/location"
  5. import { Project } from "@opencode-ai/core/project"
  6. import { AbsolutePath } from "@opencode-ai/core/schema"
  7. import { WorkspaceV2 } from "@opencode-ai/core/workspace"
  8. import { testEffect } from "./lib/effect"
  9. const workspaceID = WorkspaceV2.ID.make("wrk_test")
  10. const ref = { directory: AbsolutePath.make("/repo/packages/app"), workspaceID }
  11. const projectLayer = Layer.succeed(
  12. Project.Service,
  13. Project.Service.of({
  14. list: () => Effect.succeed([]),
  15. directories: () => Effect.succeed([]),
  16. resolve: () =>
  17. Effect.succeed({
  18. id: Project.ID.make("project"),
  19. directory: AbsolutePath.make("/repo"),
  20. vcs: { type: "git", store: AbsolutePath.make("/repo/.git") },
  21. }),
  22. commit: () => Effect.void,
  23. }),
  24. )
  25. const it = testEffect(AppNodeBuilder.build(Location.boundNode(ref), [[Project.node, projectLayer]]))
  26. describe("Location", () => {
  27. it.effect("resolves the current project and vcs information", () =>
  28. Effect.gen(function* () {
  29. const location = yield* Location.Service
  30. expect(location.directory).toBe(AbsolutePath.make("/repo/packages/app"))
  31. expect(location.workspaceID).toBe(workspaceID)
  32. expect(location.project.id).toBe(Project.ID.make("project"))
  33. expect(location.project.directory).toBe(AbsolutePath.make("/repo"))
  34. expect(location.vcs).toEqual({
  35. type: "git",
  36. store: AbsolutePath.make("/repo/.git"),
  37. })
  38. }),
  39. )
  40. })