feat(app): improve desktop multi-server support (#30678)

Co-authored-by: Brendan Allan <git@brendonovich.dev>
This commit is contained in:
Luke Parker 2026-06-05 16:30:02 +10:00 committed by GitHub
commit 7f33576f46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
62 changed files with 1523 additions and 841 deletions

View file

@ -1,34 +1,36 @@
import { describe, expect, test } from "bun:test"
import { Worktree } from "./worktree"
import { ServerScope } from "./server-scope"
const dir = (name: string) => `/tmp/opencode-worktree-${name}-${crypto.randomUUID()}`
describe("Worktree", () => {
const scope = ServerScope.local
test("normalizes trailing slashes", () => {
const key = dir("normalize")
Worktree.ready(`${key}/`)
Worktree.ready(scope, `${key}/`)
expect(Worktree.get(key)).toEqual({ status: "ready" })
expect(Worktree.get(scope, key)).toEqual({ status: "ready" })
})
test("pending does not overwrite a terminal state", () => {
const key = dir("pending")
Worktree.failed(key, "boom")
Worktree.pending(key)
Worktree.failed(scope, key, "boom")
Worktree.pending(scope, key)
expect(Worktree.get(key)).toEqual({ status: "failed", message: "boom" })
expect(Worktree.get(scope, key)).toEqual({ status: "failed", message: "boom" })
})
test("wait resolves shared pending waiter when ready", async () => {
const key = dir("wait-ready")
Worktree.pending(key)
Worktree.pending(scope, key)
const a = Worktree.wait(key)
const b = Worktree.wait(`${key}/`)
const a = Worktree.wait(scope, key)
const b = Worktree.wait(scope, `${key}/`)
expect(a).toBe(b)
Worktree.ready(key)
Worktree.ready(scope, key)
expect(await a).toEqual({ status: "ready" })
expect(await b).toEqual({ status: "ready" })
@ -36,11 +38,21 @@ describe("Worktree", () => {
test("wait resolves with failure message", async () => {
const key = dir("wait-failed")
const waiting = Worktree.wait(key)
const waiting = Worktree.wait(scope, key)
Worktree.failed(key, "permission denied")
Worktree.failed(scope, key, "permission denied")
expect(await waiting).toEqual({ status: "failed", message: "permission denied" })
expect(await Worktree.wait(key)).toEqual({ status: "failed", message: "permission denied" })
expect(await Worktree.wait(scope, key)).toEqual({ status: "failed", message: "permission denied" })
})
test("isolates identical directories by server scope", () => {
const key = dir("scope")
const remote = "https://debian.example" as ServerScope
Worktree.ready(scope, key)
Worktree.failed(remote, key, "remote failed")
expect(Worktree.get(scope, key)).toEqual({ status: "ready" })
expect(Worktree.get(remote, key)).toEqual({ status: "failed", message: "remote failed" })
})
})