Repository navigation
Expand file tree
/
Copy pathworktree.test.ts
More file actions
58 lines (43 loc) · 1.86 KB
/
Copy pathworktree.test.ts
File metadata and controls
58 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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" })
})
})