project.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, test } from "bun:test"
  2. import { Project } from "../../src/project/project"
  3. import { Log } from "../../src/util/log"
  4. import { $ } from "bun"
  5. import path from "path"
  6. import { tmpdir } from "../fixture/fixture"
  7. Log.init({ print: false })
  8. describe("Project.fromDirectory", () => {
  9. test("should handle git repository with no commits", async () => {
  10. await using tmp = await tmpdir()
  11. await $`git init`.cwd(tmp.path).quiet()
  12. const project = await Project.fromDirectory(tmp.path)
  13. expect(project).toBeDefined()
  14. expect(project.id).toBe("global")
  15. expect(project.vcs).toBe("git")
  16. expect(project.worktree).toBe(tmp.path)
  17. expect(project.vcsDir).toBe(path.join(tmp.path, ".git"))
  18. const opencodeFile = path.join(tmp.path, ".git", "opencode")
  19. const fileExists = await Bun.file(opencodeFile).exists()
  20. expect(fileExists).toBe(false)
  21. })
  22. test("should handle git repository with commits", async () => {
  23. await using tmp = await tmpdir({ git: true })
  24. const project = await Project.fromDirectory(tmp.path)
  25. expect(project).toBeDefined()
  26. expect(project.id).not.toBe("global")
  27. expect(project.vcs).toBe("git")
  28. expect(project.worktree).toBe(tmp.path)
  29. const opencodeFile = path.join(tmp.path, ".git", "opencode")
  30. const fileExists = await Bun.file(opencodeFile).exists()
  31. expect(fileExists).toBe(true)
  32. })
  33. })