mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix(ocm): make /ocm-move worktree moves safe and round-trippable
- Answer the old /mirror/target routes with a 410 upgrade message and serve the lookup at GET /mirror/checkouts; detect older Managers via the token probe (MANAGER_FEATURE_MISSING). - Create the move worktree and import the bundle in one call; worktree setup runs after the import and the worktree is removed on failure. - Never rewind a server branch: suffix the new worktree branch when the server branch has commits the local branch lacks, and skip both the source and target branch when updating refs. - Reuse clean <branch>-ocm[-N] worktrees and legacy worktree repo rows instead of creating new ones on every move. - Let ocm push/pull target the worktree on the local branch via a directory parameter on the mirror read routes; no tarball fallback for worktrees. - Share one sibling loader (listRepoSiblings), validate branch names, compare canonical paths in isDirectoryInUse, and cut redundant git work in the checkouts lookup and the CLI destination choice.
This commit is contained in:
1 parent
bd7c3e3fef
commit
67f70e9635
21 files changed
+1777
-517
No files matched your search
@@ -278,6 +278,50 @@ describe('ManagerApi feature support', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ManagerApi mirror routes', () => {
|
||||
const api = new ManagerApi(BASE_URL, 'tok')
|
||||
|
||||
it('maps a 401 from mirrorCheckouts to MANAGER_FEATURE_MISSING with the move message', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(errorResponse(401, JSON.stringify({ error: 'Unauthorized' })))
|
||||
.mockResolvedValueOnce(okResponse({ workspaces: [] }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
const error = await api.mirrorCheckouts(1, 'feature').catch((err) => err)
|
||||
|
||||
expect(error).toBeInstanceOf(ManagerApiError)
|
||||
expect((error as ManagerApiError).code).toBe(MANAGER_FEATURE_MISSING)
|
||||
expect((error as ManagerApiError).message).toContain('too old for /ocm-move worktrees')
|
||||
expect(isManagerRouteMissing(error)).toBe(true)
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, `${BASE_URL}/api/internal/opencode-workspaces`, {
|
||||
headers: { Authorization: 'Bearer tok' },
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the goal and multi-run feature message unchanged', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(errorResponse(401, JSON.stringify({ error: 'Unauthorized' })))
|
||||
.mockResolvedValueOnce(okResponse({ workspaces: [] }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
const error = await api.listMultiRuns(1).catch((err) => err)
|
||||
|
||||
expect((error as ManagerApiError).code).toBe(MANAGER_FEATURE_MISSING)
|
||||
expect((error as ManagerApiError).message).toContain('too old for ocm goals and multi-runs')
|
||||
})
|
||||
|
||||
it('sends the directory query on mirrorHead and mirrorContains', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(okResponse({}))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await api.mirrorHead(1, '/repos/work trees/repo')
|
||||
await api.mirrorContains(1, 'abc1234', '/repos/work trees/repo')
|
||||
|
||||
expect(new URL(String(fetchMock.mock.calls[0]![0])).searchParams.get('directory')).toBe('/repos/work trees/repo')
|
||||
expect(new URL(String(fetchMock.mock.calls[1]![0])).searchParams.get('directory')).toBe('/repos/work trees/repo')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isManagerRouteMissing', () => {
|
||||
const api = new ManagerApi(BASE_URL, 'tok')
|
||||
|
||||
|
||||
Reference in new issue
Block a user