location.test.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. directories: () => Effect.succeed([]),
  15. resolve: () =>
  16. Effect.succeed({
  17. id: Project.ID.make("project"),
  18. directory: AbsolutePath.make("/repo"),
  19. vcs: { type: "git", store: AbsolutePath.make("/repo/.git") },
  20. }),
  21. commit: () => Effect.void,
  22. }),
  23. )
  24. const it = testEffect(AppNodeBuilder.build(Location.boundNode(ref), [[Project.node, projectLayer]]))
  25. describe("Location", () => {
  26. it.effect("resolves the current project and vcs information", () =>
  27. Effect.gen(function* () {
  28. const location = yield* Location.Service
  29. expect(location.directory).toBe(AbsolutePath.make("/repo/packages/app"))
  30. expect(location.workspaceID).toBe(workspaceID)
  31. expect(location.project.id).toBe(Project.ID.make("project"))
  32. expect(location.project.directory).toBe(AbsolutePath.make("/repo"))
  33. expect(location.vcs).toEqual({
  34. type: "git",
  35. store: AbsolutePath.make("/repo/.git"),
  36. })
  37. }),
  38. )
  39. })