project.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. const opencodeFile = path.join(tmp.path, ".git", "opencode")
  18. const fileExists = await Bun.file(opencodeFile).exists()
  19. expect(fileExists).toBe(false)
  20. })
  21. test("should handle git repository with commits", async () => {
  22. await using tmp = await tmpdir({ git: true })
  23. const project = await Project.fromDirectory(tmp.path)
  24. expect(project).toBeDefined()
  25. expect(project.id).not.toBe("global")
  26. expect(project.vcs).toBe("git")
  27. expect(project.worktree).toBe(tmp.path)
  28. const opencodeFile = path.join(tmp.path, ".git", "opencode")
  29. const fileExists = await Bun.file(opencodeFile).exists()
  30. expect(fileExists).toBe(true)
  31. })
  32. })