Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/client/src/solid/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,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
Expand Down
19 changes: 18 additions & 1 deletion packages/client/test/solid-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,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(() => {
Expand Down Expand Up @@ -1087,14 +1102,16 @@ 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",
fetch: async (input, init) => {
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" } })
Expand Down
Loading