location.test.ts 1.4 KB

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