refactor(tui): extract standalone package (#31193)
This commit is contained in:
@@ -3,12 +3,11 @@ import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { afterEach, expect, spyOn, test } from "bun:test"
|
||||
import { createRoot } from "solid-js"
|
||||
import { EditorContextProvider, useEditorContext } from "@opencode-ai/tui/context/editor"
|
||||
import { EditorContextProvider, useEditorContext, type EditorIntegration } from "@opencode-ai/tui/context/editor"
|
||||
import { tmpdir } from "../../fixture/fixture"
|
||||
import { FakeWebSocket } from "../../lib/websocket"
|
||||
import { TestTuiEnvironmentProvider } from "../../fixture/tui-environment"
|
||||
import { TuiPlatformProvider, type TuiPlatform } from "@opencode-ai/tui/platform"
|
||||
import { discoverEditorConnection } from "../../../src/cli/tui/platform"
|
||||
import { TestTuiContexts } from "../../fixture/tui-environment"
|
||||
import { discoverEditorConnection } from "@opencode-ai/tui/editor"
|
||||
|
||||
const originalClaudePort = process.env.CLAUDE_CODE_SSE_PORT
|
||||
const originalOpencodePort = process.env.OPENCODE_EDITOR_SSE_PORT
|
||||
@@ -36,17 +35,14 @@ function mountEditorContext(WebSocketImpl?: typeof WebSocket) {
|
||||
|
||||
const value = process.env.CLAUDE_CODE_SSE_PORT || process.env.OPENCODE_EDITOR_SSE_PORT
|
||||
return (
|
||||
<TestTuiEnvironmentProvider
|
||||
<TestTuiContexts
|
||||
cwd={process.cwd()}
|
||||
paths={{ home: os.homedir() }}
|
||||
editor={{ port: value ? Number.parseInt(value, 10) : undefined }}
|
||||
>
|
||||
<TuiPlatformProvider value={platform}>
|
||||
<EditorContextProvider WebSocketImpl={WebSocketImpl}>
|
||||
<EditorContextProvider integration={editorService} WebSocketImpl={WebSocketImpl}>
|
||||
<Consumer />
|
||||
</EditorContextProvider>
|
||||
</TuiPlatformProvider>
|
||||
</TestTuiEnvironmentProvider>
|
||||
</TestTuiContexts>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -56,16 +52,8 @@ function mountEditorContext(WebSocketImpl?: typeof WebSocket) {
|
||||
}
|
||||
}
|
||||
|
||||
const platform: TuiPlatform = {
|
||||
files: {
|
||||
readText: (file) => Bun.file(file).text(),
|
||||
readBytes: (file) => Bun.file(file).bytes(),
|
||||
mime: () => Promise.resolve("application/octet-stream"),
|
||||
},
|
||||
editor: {
|
||||
open: () => Promise.resolve(undefined),
|
||||
connection: discoverEditorConnection,
|
||||
},
|
||||
const editorService: EditorIntegration = {
|
||||
connection: discoverEditorConnection,
|
||||
}
|
||||
|
||||
function createWebSocketImpl(...sockets: FakeWebSocket[]) {
|
||||
|
||||
Reference in New Issue
Block a user