mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Adds a full dev-server preview system including: - Backend proxy/upgrade handler for dev server traffic - File-serving backend route with CSP headers - DevServerPreviewButton and HtmlArtifactPanel components - HTML artifact detection and preview in messages - File preview improvements with mobile support - Shared types and settings schema for dev server config - Comprehensive test coverage for all new code
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
|
|
const getGhCliEnvMock = vi.hoisted(() => vi.fn())
|
|
const getDevServerPortMock = vi.hoisted(() => vi.fn())
|
|
|
|
vi.mock('../../../src/services/credential-provider', () => ({
|
|
CredentialProvider: vi.fn().mockImplementation(() => ({ getGhCliEnv: getGhCliEnvMock })),
|
|
}))
|
|
|
|
vi.mock('../../../src/services/dev-server/manager', () => ({
|
|
getDevServerPort: getDevServerPortMock,
|
|
}))
|
|
|
|
import { createInternalShellEnvRoutes } from '../../../src/routes/internal/shell-env'
|
|
|
|
describe('internal shell-env routes', () => {
|
|
const mockDb = {} as never
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
getGhCliEnvMock.mockReturnValue({ GH_TOKEN: 'ghp', GITHUB_TOKEN: 'ghp' })
|
|
getDevServerPortMock.mockReturnValue(4321)
|
|
})
|
|
|
|
it('GET / merges gh env with the dev server port and forwards cwd', async () => {
|
|
const app = createInternalShellEnvRoutes(mockDb)
|
|
|
|
const res = await app.request('/?cwd=%2Frepo')
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(await res.json()).toEqual({
|
|
GH_TOKEN: 'ghp',
|
|
GITHUB_TOKEN: 'ghp',
|
|
OCM_DEV_SERVER_PORT: '4321',
|
|
})
|
|
expect(getGhCliEnvMock).toHaveBeenCalledWith({ cwd: '/repo' })
|
|
})
|
|
|
|
it('GET / returns only the dev server port when no GitHub credential exists', async () => {
|
|
getGhCliEnvMock.mockReturnValue({})
|
|
const app = createInternalShellEnvRoutes(mockDb)
|
|
|
|
const res = await app.request('/')
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(await res.json()).toEqual({ OCM_DEV_SERVER_PORT: '4321' })
|
|
})
|
|
})
|