location.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 { Workspace } from "@opencode-ai/core/workspace"
  8. import { testEffect } from "./lib/effect"
  9. const workspaceID = Workspace.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. canonical: AbsolutePath.make("/main/repo"),
  21. vcs: { type: "git", store: AbsolutePath.make("/repo/.git") },
  22. }),
  23. commit: () => Effect.void,
  24. }),
  25. )
  26. const it = testEffect(AppNodeBuilder.build(Location.boundNode(ref), [[Project.node, projectLayer]]))
  27. describe("Location", () => {
  28. it.effect("resolves the current project and vcs information", () =>
  29. Effect.gen(function* () {
  30. const location = yield* Location.Service
  31. expect(location.directory).toBe(AbsolutePath.make("/repo/packages/app"))
  32. expect(location.workspaceID).toBe(workspaceID)
  33. expect(location.project.id).toBe(Project.ID.make("project"))
  34. expect(location.project.directory).toBe(AbsolutePath.make("/repo"))
  35. expect(location.project.canonical).toBe(AbsolutePath.make("/main/repo"))
  36. expect(location.vcs).toEqual({
  37. type: "git",
  38. store: AbsolutePath.make("/repo/.git"),
  39. })
  40. }),
  41. )
  42. })