mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat: add bundle-based OCM mirror sync (#289)
* 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
This commit is contained in:
1 parent
bb1df259b6
commit
01e50a7019
34 files changed
+2060
-316
No files matched your search
@@ -1,8 +1,15 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { OpenCodeModelsEditor } from './OpenCodeModelsEditor'
|
||||
import type { ConfigProvider, ConfigModel } from './OpenCodeModelsEditor'
|
||||
import { settingsApi } from '../../api/settings'
|
||||
|
||||
vi.mock('../../api/settings', () => ({
|
||||
settingsApi: {
|
||||
discoverOpenCodeModels: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
const mockProviders: Record<string, ConfigProvider> = {
|
||||
openai: {
|
||||
@@ -351,3 +358,103 @@ describe('OpenCodeModelDialog', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('OpenCodeModelDialog — model discovery', () => {
|
||||
const discoveryProps = {
|
||||
open: true,
|
||||
onOpenChange: vi.fn(),
|
||||
onSubmit: vi.fn(),
|
||||
availableProviders: [],
|
||||
selectedProviderId: '',
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.mocked(settingsApi.discoverOpenCodeModels).mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.mocked(settingsApi.discoverOpenCodeModels).mockReset()
|
||||
})
|
||||
|
||||
it('shows a Discover button when a new API provider has a base URL', async () => {
|
||||
const { OpenCodeModelDialog } = await import('./OpenCodeModelDialog')
|
||||
render(<OpenCodeModelDialog {...discoveryProps} />)
|
||||
|
||||
const baseUrlInput = screen.getByPlaceholderText('e.g., https://api.openai.com/v1')
|
||||
fireEvent.change(baseUrlInput, { target: { value: 'http://localhost:1234' } })
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button', { name: /discover|refresh/i })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('discovers models and shows the count when Discover is clicked', async () => {
|
||||
vi.mocked(settingsApi.discoverOpenCodeModels).mockResolvedValue({
|
||||
models: ['gpt-4o', 'gpt-3.5-turbo'],
|
||||
cached: false,
|
||||
})
|
||||
const { OpenCodeModelDialog } = await import('./OpenCodeModelDialog')
|
||||
render(<OpenCodeModelDialog {...discoveryProps} />)
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('e.g., https://api.openai.com/v1'), {
|
||||
target: { value: 'http://localhost:1234' },
|
||||
})
|
||||
|
||||
const discoverButton = await screen.findByRole('button', { name: /discover|refresh/i })
|
||||
fireEvent.click(discoverButton)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/2 models found/i)).toBeInTheDocument()
|
||||
})
|
||||
expect(settingsApi.discoverOpenCodeModels).toHaveBeenCalledWith('http://localhost:1234', undefined, true)
|
||||
})
|
||||
|
||||
it('auto-populates config key and display name when selecting a discovered model', async () => {
|
||||
vi.mocked(settingsApi.discoverOpenCodeModels).mockResolvedValue({
|
||||
models: ['gpt-4o'],
|
||||
cached: false,
|
||||
})
|
||||
const { OpenCodeModelDialog } = await import('./OpenCodeModelDialog')
|
||||
render(<OpenCodeModelDialog {...discoveryProps} />)
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('e.g., https://api.openai.com/v1'), {
|
||||
target: { value: 'http://localhost:1234' },
|
||||
})
|
||||
|
||||
const discoverButton = await screen.findByRole('button', { name: /discover|refresh/i })
|
||||
fireEvent.click(discoverButton)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/1 model found/i)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
const providerModelInput = screen.getByPlaceholderText('e.g., MiniMax-M2.7')
|
||||
fireEvent.focus(providerModelInput)
|
||||
|
||||
const option = await screen.findByRole('button', { name: 'gpt-4o' })
|
||||
fireEvent.click(option)
|
||||
|
||||
const modelIdInput = document.querySelector('input[name="modelId"]') as HTMLInputElement
|
||||
const displayNameInput = document.querySelector('input[name="displayName"]') as HTMLInputElement
|
||||
expect(modelIdInput).toHaveValue('gpt-4o')
|
||||
expect(displayNameInput).toHaveValue('Gpt 4o')
|
||||
})
|
||||
|
||||
it('shows an error message when discovery fails', async () => {
|
||||
vi.mocked(settingsApi.discoverOpenCodeModels).mockRejectedValue(new Error('network error'))
|
||||
const { OpenCodeModelDialog } = await import('./OpenCodeModelDialog')
|
||||
render(<OpenCodeModelDialog {...discoveryProps} />)
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('e.g., https://api.openai.com/v1'), {
|
||||
target: { value: 'http://localhost:1234' },
|
||||
})
|
||||
|
||||
const discoverButton = await screen.findByRole('button', { name: /discover|refresh/i })
|
||||
fireEvent.click(discoverButton)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/failed to discover models/i)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user