forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-list.test.ts
More file actions
110 lines (92 loc) · 3.19 KB
/
session-list.test.ts
File metadata and controls
110 lines (92 loc) · 3.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { afterEach, describe, expect, test } from "bun:test"
import { Effect } from "effect"
import { Instance } from "../../src/project/instance"
import { Session as SessionNs } from "../../src/session"
import { Log } from "../../src/util"
import { tmpdir } from "../fixture/fixture"
void Log.init({ print: false })
function run<A, E>(fx: Effect.Effect<A, E, SessionNs.Service>) {
return Effect.runPromise(fx.pipe(Effect.provide(SessionNs.defaultLayer)))
}
const svc = {
...SessionNs,
create(input?: SessionNs.CreateInput) {
return run(SessionNs.Service.use((svc) => svc.create(input)))
},
}
afterEach(async () => {
await Instance.disposeAll()
})
describe("session.list", () => {
test("filters by directory", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({
directory: tmp.path,
fn: async () => {
const first = await svc.create({})
await using other = await tmpdir({ git: true })
const second = await Instance.provide({
directory: other.path,
fn: async () => svc.create({}),
})
const sessions = [...svc.list({ directory: tmp.path })]
const ids = sessions.map((s) => s.id)
expect(ids).toContain(first.id)
expect(ids).not.toContain(second.id)
},
})
})
test("filters root sessions", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({
directory: tmp.path,
fn: async () => {
const root = await svc.create({ title: "root-session" })
const child = await svc.create({ title: "child-session", parentID: root.id })
const sessions = [...svc.list({ roots: true })]
const ids = sessions.map((s) => s.id)
expect(ids).toContain(root.id)
expect(ids).not.toContain(child.id)
},
})
})
test("filters by start time", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({
directory: tmp.path,
fn: async () => {
await svc.create({ title: "new-session" })
const futureStart = Date.now() + 86400000
const sessions = [...svc.list({ start: futureStart })]
expect(sessions.length).toBe(0)
},
})
})
test("filters by search term", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({
directory: tmp.path,
fn: async () => {
await svc.create({ title: "unique-search-term-abc" })
await svc.create({ title: "other-session-xyz" })
const sessions = [...svc.list({ search: "unique-search" })]
const titles = sessions.map((s) => s.title)
expect(titles).toContain("unique-search-term-abc")
expect(titles).not.toContain("other-session-xyz")
},
})
})
test("respects limit parameter", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({
directory: tmp.path,
fn: async () => {
await svc.create({ title: "session-1" })
await svc.create({ title: "session-2" })
await svc.create({ title: "session-3" })
const sessions = [...svc.list({ limit: 2 })]
expect(sessions.length).toBe(2)
},
})
})
})