|
@@ -5,7 +5,10 @@ const emptyObject = new Set(["/global/config", "/config", "/provider/auth", "/mc
|
|
|
|
|
|
|
|
export interface MockServerConfig {
|
|
export interface MockServerConfig {
|
|
|
protocol?: "v1" | "v2"
|
|
protocol?: "v1" | "v2"
|
|
|
- provider: unknown
|
|
|
|
|
|
|
+ provider: unknown | (() => unknown)
|
|
|
|
|
+ integrationMethods?: Record<string, unknown[]>
|
|
|
|
|
+ onConnectKey?: (input: { integrationID: string; body: unknown }) => void
|
|
|
|
|
+ onInstanceDispose?: () => void
|
|
|
directory: string
|
|
directory: string
|
|
|
project: unknown
|
|
project: unknown
|
|
|
sessions: ({ id: string } & Record<string, unknown>)[]
|
|
sessions: ({ id: string } & Record<string, unknown>)[]
|
|
@@ -31,7 +34,6 @@ export async function mockOpenCodeServer(page: Page, config: MockServerConfig) {
|
|
|
const cursors = new Map<string, string>()
|
|
const cursors = new Map<string, string>()
|
|
|
let nextCursor = 0
|
|
let nextCursor = 0
|
|
|
const staticRoutes: Record<string, unknown> = {
|
|
const staticRoutes: Record<string, unknown> = {
|
|
|
- "/provider": config.provider,
|
|
|
|
|
"/path": {
|
|
"/path": {
|
|
|
state: config.directory,
|
|
state: config.directory,
|
|
|
config: config.directory,
|
|
config: config.directory,
|
|
@@ -75,6 +77,18 @@ export async function mockOpenCodeServer(page: Page, config: MockServerConfig) {
|
|
|
if (path === "/api/health" && config.protocol === "v2")
|
|
if (path === "/api/health" && config.protocol === "v2")
|
|
|
return json(route, { healthy: true, version: "2.0.0", pid: 1 })
|
|
return json(route, { healthy: true, version: "2.0.0", pid: 1 })
|
|
|
if (path === "/experimental/capabilities") return json(route, { backgroundSubagents: true })
|
|
if (path === "/experimental/capabilities") return json(route, { backgroundSubagents: true })
|
|
|
|
|
+ if (path === "/provider")
|
|
|
|
|
+ return json(route, typeof config.provider === "function" ? config.provider() : config.provider)
|
|
|
|
|
+ if (path === "/provider/auth") return json(route, config.integrationMethods ?? {})
|
|
|
|
|
+ const legacyAuth = path.match(/^\/auth\/([^/]+)$/)?.[1]
|
|
|
|
|
+ if (legacyAuth && route.request().method() === "PUT") {
|
|
|
|
|
+ config.onConnectKey?.({ integrationID: legacyAuth, body: route.request().postDataJSON() })
|
|
|
|
|
+ return json(route, true)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (path === "/instance/dispose" && route.request().method() === "POST") {
|
|
|
|
|
+ config.onInstanceDispose?.()
|
|
|
|
|
+ return json(route, true)
|
|
|
|
|
+ }
|
|
|
if (path === "/permission")
|
|
if (path === "/permission")
|
|
|
return json(route, typeof config.permissions === "function" ? config.permissions() : (config.permissions ?? []))
|
|
return json(route, typeof config.permissions === "function" ? config.permissions() : (config.permissions ?? []))
|
|
|
if (path === "/question")
|
|
if (path === "/question")
|
|
@@ -130,8 +144,11 @@ export async function mockOpenCodeServer(page: Page, config: MockServerConfig) {
|
|
|
location: location(config),
|
|
location: location(config),
|
|
|
data: { id: integration, name: integration, methods: [{ type: "key", label: "API key" }], connections: [] },
|
|
data: { id: integration, name: integration, methods: [{ type: "key", label: "API key" }], connections: [] },
|
|
|
})
|
|
})
|
|
|
- if (/^\/api\/integration\/[^/]+\/connect\/key$/.test(path) && route.request().method() === "POST")
|
|
|
|
|
|
|
+ const integrationConnect = path.match(/^\/api\/integration\/([^/]+)\/connect\/key$/)?.[1]
|
|
|
|
|
+ if (integrationConnect && route.request().method() === "POST") {
|
|
|
|
|
+ config.onConnectKey?.({ integrationID: integrationConnect, body: route.request().postDataJSON() })
|
|
|
return route.fulfill({ status: 204, headers: { "access-control-allow-origin": "*" } })
|
|
return route.fulfill({ status: 204, headers: { "access-control-allow-origin": "*" } })
|
|
|
|
|
+ }
|
|
|
if (path === "/api/project") return json(route, [config.project])
|
|
if (path === "/api/project") return json(route, [config.project])
|
|
|
if (path === "/api/project/current")
|
|
if (path === "/api/project/current")
|
|
|
return json(route, { id: (config.project as { id?: string }).id, directory: config.directory })
|
|
return json(route, { id: (config.project as { id?: string }).id, directory: config.directory })
|