Skip to content

Commit c65fe8a

Browse files
committed
tests: refactor message pagination tests to use withSession helper
1 parent 6a67795 commit c65fe8a

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

packages/opencode/test/session/messages-pagination.test.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -289,50 +289,44 @@ describe("MessageV2.page", () => {
289289
}),
290290
)
291291

292-
test("pages forward with after cursor", async () => {
293-
await WithInstance.provide({
294-
directory: root,
295-
fn: async () => {
296-
const session = await svc.create({})
297-
const ids = await fill(session.id, 6)
292+
it.instance("pages forward with after cursor", () =>
293+
withSession(({ sessionID }) =>
294+
Effect.gen(function* () {
295+
const ids = yield* fill(sessionID, 6)
298296

299297
// Anchor at "before everything": all messages are newer than time 0
300298
const anchor = MessageV2.cursor.encode({ id: MessageID.ascending(), time: 0 })
301299

302-
const a = MessageV2.page({ sessionID: session.id, limit: 2, after: anchor })
300+
const a = MessageV2.page({ sessionID, limit: 2, after: anchor })
303301
expect(a.items.map((item) => item.info.id)).toEqual(ids.slice(0, 2))
304302
expect(a.more).toBe(true)
305303
expect(a.cursor).toBeTruthy()
306304

307-
const b = MessageV2.page({ sessionID: session.id, limit: 2, after: a.cursor! })
305+
const b = MessageV2.page({ sessionID, limit: 2, after: a.cursor! })
308306
expect(b.items.map((item) => item.info.id)).toEqual(ids.slice(2, 4))
309307
expect(b.more).toBe(true)
310308
expect(b.cursor).toBeTruthy()
311309

312-
const c = MessageV2.page({ sessionID: session.id, limit: 2, after: b.cursor! })
310+
const c = MessageV2.page({ sessionID, limit: 2, after: b.cursor! })
313311
expect(c.items.map((item) => item.info.id)).toEqual(ids.slice(4, 6))
314312
expect(c.more).toBe(false)
315313
expect(c.cursor).toBeUndefined()
314+
}),
315+
),
316+
)
316317

317-
await svc.remove(session.id)
318-
},
319-
})
320-
})
321-
322-
test("rejects requests with both before and after", async () => {
323-
await WithInstance.provide({
324-
directory: root,
325-
fn: async () => {
326-
const session = await svc.create({})
327-
await fill(session.id, 2)
318+
it.instance("rejects requests with both before and after", () =>
319+
withSession(({ sessionID }) =>
320+
Effect.gen(function* () {
321+
yield* fill(sessionID, 2)
328322
const dummyCursor = MessageV2.cursor.encode({ id: MessageID.ascending(), time: 0 })
323+
329324
expect(() =>
330-
MessageV2.page({ sessionID: session.id, limit: 2, before: dummyCursor, after: dummyCursor }),
325+
MessageV2.page({ sessionID, limit: 2, before: dummyCursor, after: dummyCursor }),
331326
).toThrow()
332-
await svc.remove(session.id)
333-
},
334-
})
335-
})
327+
}),
328+
),
329+
)
336330

337331
it.instance("large limit returns all messages without cursor", () =>
338332
withSession(({ sessionID }) =>

0 commit comments

Comments
 (0)