location.test.ts 1.5 KB

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