/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/utils/worktree.test.ts
58 строк
2 KB
Luke Parker
feat(app): improve desktop multi-server support (#30678)
05 июн 2026, 09:30
Не верифицирован
05 июн 2026, 09:30
7f33576
Код
Авторство
О чём код?
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(scope, `${key}/`) expect(Worktree.get(scope, key)).toEqual({ status: "ready" }) }) test("pending does not overwrite a terminal state", () => { const key = dir("pending") Worktree.failed(scope, key, "boom") Worktree.pending(scope, key) 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(scope, key) const a = Worktree.wait(scope, key) const b = Worktree.wait(scope, `${key}/`) expect(a).toBe(b) Worktree.ready(scope, key) expect(await a).toEqual({ status: "ready" }) expect(await b).toEqual({ status: "ready" }) }) test("wait resolves with failure message", async () => { const key = dir("wait-failed") const waiting = Worktree.wait(scope, key) Worktree.failed(scope, key, "permission denied") expect(await waiting).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" }) }) })