mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-23 21:53:27 +00:00
fix(tui): avoid premature environment sync (#44270)
This commit is contained in:
parent
95235df4c8
commit
b190b778d4
3 changed files with 36 additions and 1 deletions
|
|
@ -1101,6 +1101,9 @@ export function createData(config: CreateDataInput) {
|
|||
get(sessionID: string) {
|
||||
return store.session.info[sessionID]
|
||||
},
|
||||
creating(sessionID: string) {
|
||||
return creating.has(sessionID)
|
||||
},
|
||||
remember(info: SessionInfo) {
|
||||
setStore("session", "info", info.id, reconcile(info))
|
||||
sync.complete(`session:${info.id}`)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { test } from "bun:test"
|
||||
import { expect, test } from "bun:test"
|
||||
import { createRoot } from "solid-js"
|
||||
import { createData, type CreateDataInput } from "../src/solid"
|
||||
import { OpenCode, type OpenCodeEvent, type SessionInfo } from "../src/promise"
|
||||
|
|
@ -72,6 +72,37 @@ test("revalidates after an event overtakes an active session read", async () =>
|
|||
}
|
||||
})
|
||||
|
||||
test("reports optimistic sessions as creating until the request settles", async () => {
|
||||
const release = Promise.withResolvers<void>()
|
||||
const api = OpenCode.make({
|
||||
baseUrl: "http://opencode.local",
|
||||
fetch: async (input, init) => {
|
||||
const request = input instanceof Request ? input : new Request(input, init)
|
||||
if (!request.url.endsWith("/api/session")) throw new Error(`Unexpected request: ${request.url}`)
|
||||
await release.promise
|
||||
return Response.json({ data: session(0) })
|
||||
},
|
||||
})
|
||||
const event: CreateDataInput["event"] = {
|
||||
on: () => () => {},
|
||||
listen: () => () => {},
|
||||
}
|
||||
const setup = createRoot((dispose) => ({
|
||||
data: createData({ api: () => api, directory: "/project", event, connection: { status: () => "connected" } }),
|
||||
dispose,
|
||||
}))
|
||||
|
||||
try {
|
||||
const created = setup.data.session.create({ id: "ses_refresh", location: { directory: "/project" } })
|
||||
expect(setup.data.session.creating(created.id)).toBe(true)
|
||||
release.resolve()
|
||||
await created.request
|
||||
expect(setup.data.session.creating(created.id)).toBe(false)
|
||||
} finally {
|
||||
setup.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
async function wait(check: () => boolean) {
|
||||
const started = Date.now()
|
||||
while (!check()) {
|
||||
|
|
|
|||
|
|
@ -486,6 +486,7 @@ function App(props: { pair?: DialogPairCredentials }) {
|
|||
if (route.data.type !== "session") return
|
||||
const session = data.session.get(route.data.sessionID)
|
||||
if (!session) return
|
||||
if (data.session.creating(session.id)) return
|
||||
if (session.location.workspaceID !== undefined || terminalEnvironment.variables === undefined) return
|
||||
void client.api.session
|
||||
.environment({ sessionID: session.id, variables: terminalEnvironment.variables })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue