mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(client): register running sessions missed while disconnected (#53012)
This commit is contained in:
committed by
GitHub
Unverified
parent
8b813d362c
commit
f6991636a5
@@ -652,6 +652,11 @@ export function createData(config: CreateDataInput) {
|
||||
})
|
||||
activeUpdates = undefined
|
||||
setStore("session", "active", reconcile(Object.fromEntries(snapshot)))
|
||||
// Sessions created before this connection (while disconnected, or before the client started)
|
||||
// never delivered `session.created`; without their info a running child never joins its root's family.
|
||||
snapshot.forEach((status, id) => {
|
||||
if (status === "running" && !store.session.info[id]) refresh(() => result.session.sync(id))
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
if (activeUpdates === updates) activeUpdates = undefined
|
||||
|
||||
@@ -1186,6 +1186,21 @@ test.each([
|
||||
}
|
||||
})
|
||||
|
||||
test("adds running sessions created while disconnected to their family", async () => {
|
||||
const root = { ...session(0), id: "ses_root" }
|
||||
const child = { ...session(0), id: "ses_child", parentID: "ses_root" }
|
||||
const setup = activityFixture(() => Response.json({ data: { ses_child: { type: "running" } } }), [child])
|
||||
|
||||
try {
|
||||
setup.data.session.remember(root)
|
||||
setup.emit({ type: "server.connected", data: {} })
|
||||
await wait(() => setup.data.session.family("ses_root").includes("ses_child"))
|
||||
expect(setup.data.session.status("ses_child")).toBe("running")
|
||||
} finally {
|
||||
setup.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
test("ignores activity snapshots from an older connection", async () => {
|
||||
const reads: ReturnType<typeof Promise.withResolvers<Response>>[] = []
|
||||
const setup = activityFixture(() => {
|
||||
@@ -1257,7 +1272,7 @@ function modelInfo(name: string): ModelInfo {
|
||||
}
|
||||
}
|
||||
|
||||
function activityFixture(read: () => Response | Promise<Response>) {
|
||||
function activityFixture(read: () => Response | Promise<Response>, sessions: SessionInfo[] = []) {
|
||||
const listeners = new Set<Parameters<CreateDataInput["event"]["listen"]>[0]>()
|
||||
const api = OpenCode.make({
|
||||
baseUrl: "http://opencode.local",
|
||||
@@ -1265,6 +1280,8 @@ function activityFixture(read: () => Response | Promise<Response>) {
|
||||
const request = input instanceof Request ? input : new Request(input, init)
|
||||
const path = new URL(request.url).pathname
|
||||
if (path === "/api/session/active") return read()
|
||||
const known = sessions.find((item) => path === `/api/session/${item.id}`)
|
||||
if (known) return Response.json({ data: known })
|
||||
if (path === "/api/project") return Response.json([])
|
||||
if (path === "/api/location") return Response.json({ directory: "/project" })
|
||||
return Response.json({ location: { directory: "/project" }, data: { branch: "main" } })
|
||||
|
||||
Reference in New Issue
Block a user