mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
* feat: add bundle-based OCM mirror sync * feat: add OpenCode model editor and HEAD-safe bundle import * fix: consolidate discovery-cache, batch bundle refs, remove dead code (#290) * fix: consolidate discovery-cache, batch bundle refs, remove dead code * refactor: consolidate discovery cache into generic discoverCached, extract spawnGit helper * feat: extract project-id-resolver, add CLI full-fallback prompt, wire lint into root scripts - Extract shared project-id-resolver for origin URL matching (replaces local-repo duplicates) - Add promptYesNo / confirmFullFallback to ocm CLI before slow full mirror - Backend: consolidate opencode-workspaces routes with project-id-resolver - Frontend: fix schedules prompt/global page navigation - CLI: add eslint config, lint/lint:fix scripts, fix no-fallthrough in ocm.ts - Root: wire CLI into build, test, typecheck, lint, lint:fix chains - Fix test lint issues (_code, const, require→import) * fix: replace polynomial regex with linear-time string ops in gitRemoteParts * feat: add divergence guards for push/pull, streaming bundle upload, server-side ancestry check - Backend: GET /:repoId/mirror/head (head+branch+dirty) and GET /:repoId/mirror/contains/:sha (ancestry check) - CLI: checkPushDivergence warns before overwriting server commits; checkPullDivergence warns before discarding local commits; both require confirm or --force - Bundle upload now streams from disk instead of buffering entire file in memory - Version visible in --help and default (no-arg) output - Version bump 0.1.5 → 0.2.0 * fix: show connecting message before fetching repos in default command * fix: update default command messages to reflect actual matching behavior
84 lines
2.7 KiB
TypeScript
84 lines
2.7 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 { gitRemoteProjectId } from '@opencode-manager/shared/project-id'
|
|
import { isGitMainCheckout, resolveProjectId } from './project-id-resolver'
|
|
|
|
const GIT_ENV = {
|
|
...process.env,
|
|
GIT_AUTHOR_NAME: 't',
|
|
GIT_AUTHOR_EMAIL: 't@t',
|
|
GIT_COMMITTER_NAME: 't',
|
|
GIT_COMMITTER_EMAIL: 't@t',
|
|
}
|
|
|
|
describe('resolveProjectId', () => {
|
|
let base: string
|
|
|
|
beforeAll(() => {
|
|
base = mkdtempSync(path.join(tmpdir(), 'oc-resolve-project-'))
|
|
})
|
|
|
|
afterAll(() => {
|
|
rmSync(base, { recursive: true, force: true })
|
|
})
|
|
|
|
it('returns null for a non-git directory', async () => {
|
|
const dir = mkdtempSync(path.join(base, 'non-git-'))
|
|
expect(await resolveProjectId(dir)).toBeNull()
|
|
})
|
|
|
|
it('prefers the normalized origin remote hash', async () => {
|
|
const dir = mkdtempSync(path.join(base, 'remote-'))
|
|
execSync(`git init -q "${dir}"`)
|
|
execSync(`git -C "${dir}" commit -q --allow-empty -m init`, { env: GIT_ENV })
|
|
execSync(`git -C "${dir}" remote add origin git@github.com:Acme/App.git`)
|
|
|
|
expect(await resolveProjectId(dir)).toBe(gitRemoteProjectId('git@github.com:Acme/App.git'))
|
|
})
|
|
|
|
it('falls back to the sorted first root commit when there is no remote', async () => {
|
|
const dir = mkdtempSync(path.join(base, 'root-'))
|
|
execSync(`git init -q "${dir}"`)
|
|
execSync(`git -C "${dir}" commit -q --allow-empty -m init`, { env: GIT_ENV })
|
|
|
|
const rootCommit = execSync(`git -C "${dir}" rev-list --max-parents=0 HEAD`).toString().trim()
|
|
expect(await resolveProjectId(dir)).toBe(rootCommit)
|
|
})
|
|
})
|
|
|
|
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)
|
|
})
|
|
})
|