project.test.ts 1.3 KB

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