Files
opencode-manager/backend/src/services/project-id-resolver.test.ts
T
Chris Scott b9236f7f20 feat(worktree): worktree tabs, server env vars, and multi-directory SSE (#240)
* loop: worktree-tabs-2 completed after 4 iterations

* loop: server-env-vars completed after 7 iterations

* feat(worktree): add worktree tabs and server env vars settings

* refactor(worktree): multi-directory SSE support and workspace chip row

* feat(workspace): collapsible workspace manager and sibling filtering

* feat(workspace): workspace creation endpoint, refactored workspace manager, and tests

* refactor(frontend): unify workspace label and remove dead code

- extract shared workspaceLabel helper into api/repos and reuse in
  WorkspaceManager and RepoDetail directoryLabels
- remove unused useSessions hook and subscribeToDirectory subscription
- drop redundant frontend workspace dedup now guaranteed by backend
- align WorktreeTabs empty-state test with create-workspace button
2026-05-30 19:44:07 -04:00

40 lines
1.3 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { mkdtempSync, rmSync } from 'fs'
import { tmpdir } from 'os'
import path from 'path'
import { execSync } from 'child_process'
import { isGitMainCheckout } from './project-id-resolver'
describe('isGitMainCheckout', () => {
let base: string
let mainRepo: string
let worktree: string
beforeAll(() => {
base = mkdtempSync(path.join(tmpdir(), 'oc-main-checkout-'))
mainRepo = path.join(base, 'main')
worktree = path.join(base, 'wt')
execSync(`git init -q "${mainRepo}"`)
execSync(`git -C "${mainRepo}" commit -q --allow-empty -m init`, {
env: { ...process.env, GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' },
})
execSync(`git -C "${mainRepo}" worktree add -q "${worktree}" -b feature`)
})
afterAll(() => {
rmSync(base, { recursive: true, force: true })
})
it('returns true for the main checkout', async () => {
expect(await isGitMainCheckout(mainRepo)).toBe(true)
})
it('returns false for a linked worktree', async () => {
expect(await isGitMainCheckout(worktree)).toBe(false)
})
it('returns false for a non-git directory', async () => {
expect(await isGitMainCheckout(base)).toBe(false)
})
})