mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +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
144 lines
3.6 KiB
TypeScript
144 lines
3.6 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { mkdtempSync, mkdirSync, rmSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { spawnSync } from 'child_process'
|
|
import { resolveTarget, type TargetRepo } from '../src/resolve-target'
|
|
|
|
const LAST = {
|
|
repoId: 99,
|
|
name: 'last-repo',
|
|
directory: '/manager/last',
|
|
branch: 'main',
|
|
}
|
|
|
|
function gitInit(dir: string): void {
|
|
mkdirSync(dir, { recursive: true })
|
|
spawnSync('git', ['init'], { cwd: dir, stdio: 'ignore' })
|
|
}
|
|
|
|
describe('resolveTarget', () => {
|
|
let tmp: string
|
|
|
|
beforeEach(() => {
|
|
tmp = mkdtempSync(join(tmpdir(), 'resolve-target-'))
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(tmp, { recursive: true, force: true })
|
|
})
|
|
|
|
const repo = (id: number, projectId: string, name = `repo-${id}`): TargetRepo => ({
|
|
repoId: id,
|
|
name,
|
|
branch: 'main',
|
|
directory: `/manager/${name}`,
|
|
projectId,
|
|
})
|
|
|
|
it('returns cwd-match when local project id matches exactly one Manager repo', () => {
|
|
const dir = join(tmp, 'work')
|
|
gitInit(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: 'project-a',
|
|
repos: [repo(1, 'project-a', 'my-repo'), repo(2, 'project-b')],
|
|
last: LAST,
|
|
})
|
|
|
|
expect(result.kind).toBe('cwd-match')
|
|
if (result.kind === 'cwd-match') {
|
|
expect(result.repo.repoId).toBe(1)
|
|
expect(result.repo.name).toBe('my-repo')
|
|
}
|
|
})
|
|
|
|
it('returns cwd-ambiguous when multiple Manager repos share the project id', () => {
|
|
const dir = join(tmp, 'work')
|
|
gitInit(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: 'project-a',
|
|
repos: [repo(1, 'project-a', 'a'), repo(2, 'project-a', 'b')],
|
|
last: LAST,
|
|
})
|
|
|
|
expect(result.kind).toBe('cwd-ambiguous')
|
|
if (result.kind === 'cwd-ambiguous') {
|
|
expect(result.matches).toHaveLength(2)
|
|
expect(result.localProjectId).toBe('project-a')
|
|
}
|
|
})
|
|
|
|
it('returns local(no-match) in a git repo when no project id matches (even if last is set)', () => {
|
|
const dir = join(tmp, 'work')
|
|
gitInit(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: 'project-a',
|
|
repos: [repo(1, 'project-b')],
|
|
last: LAST,
|
|
})
|
|
|
|
expect(result.kind).toBe('local')
|
|
if (result.kind === 'local') {
|
|
expect(result.reason).toBe('no-match')
|
|
expect(result.repoRoot).toContain('work')
|
|
}
|
|
})
|
|
|
|
it('returns local(no-match) in a git repo when the local project id cannot be resolved', () => {
|
|
const dir = join(tmp, 'work')
|
|
gitInit(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: null,
|
|
repos: [repo(1, 'project-a')],
|
|
last: LAST,
|
|
})
|
|
|
|
expect(result.kind).toBe('local')
|
|
if (result.kind === 'local') {
|
|
expect(result.reason).toBe('no-match')
|
|
}
|
|
})
|
|
|
|
it('returns last when not in a git repo and last is set', () => {
|
|
const dir = join(tmp, 'not-git')
|
|
mkdirSync(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: null,
|
|
repos: [repo(1, 'project-a')],
|
|
last: LAST,
|
|
})
|
|
|
|
expect(result.kind).toBe('last')
|
|
if (result.kind === 'last') {
|
|
expect(result.repo.repoId).toBe(LAST.repoId)
|
|
}
|
|
})
|
|
|
|
it('returns local(no-target) when not in a git repo and no last', () => {
|
|
const dir = join(tmp, 'not-git')
|
|
mkdirSync(dir)
|
|
|
|
const result = resolveTarget({
|
|
cwd: dir,
|
|
localProjectId: null,
|
|
repos: [repo(1, 'project-a')],
|
|
})
|
|
|
|
expect(result.kind).toBe('local')
|
|
if (result.kind === 'local') {
|
|
expect(result.reason).toBe('no-target')
|
|
expect(result.repoRoot).toBeNull()
|
|
}
|
|
})
|
|
})
|