Files
opencode-manager/backend/test/routes/internal/shell-env.test.ts
Chris Scott 9afd5f04d5 feat: add dev-server preview system with proxy, file serving, and HTML artifact preview
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
2026-06-21 14:37:53 -04:00

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' })
})
})