Skip to content

Commit 4b0e87c

Browse files
committed
test(core): preserve filters across shared project identities
1 parent 7f38866 commit 4b0e87c

1 file changed

Lines changed: 80 additions & 3 deletions

File tree

‎packages/core/test/session-store.test.ts‎

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { describe, expect } from "bun:test"
22
import { asc, eq } from "drizzle-orm"
3-
import { Effect } from "effect"
3+
import { DateTime, Effect } from "effect"
44
import { Bus } from "@opencode/core/bus"
55
import { Database } from "@opencode/core/database/database"
66
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
77
import { ProjectTable } from "@opencode/core/project/sql"
88
import { SessionHistory } from "@opencode/core/session/history"
99
import { SessionProjector } from "@opencode/core/session/projector"
10-
import { SessionMessageTable, SessionPartTable } from "@opencode/core/session/sql"
10+
import { SessionMessageTable, SessionPartTable, SessionTable } from "@opencode/core/session/sql"
1111
import { SessionStore } from "@opencode/core/session/store"
1212
import { Agent } from "@opencode/schema/agent"
1313
import { Event } from "@opencode/schema/event"
1414
import { Model } from "@opencode/schema/model"
1515
import { Project } from "@opencode/schema/project"
1616
import { Provider } from "@opencode/schema/provider"
17-
import { AbsolutePath } from "@opencode/schema/schema"
17+
import { AbsolutePath, RelativePath } from "@opencode/schema/schema"
18+
import { Workspace } from "@opencode/schema/workspace"
1819
import { Session } from "@opencode/schema/session"
1920
import { SessionEvent } from "@opencode/schema/session-event"
2021
import { SessionMessage } from "@opencode/schema/session-message"
@@ -397,6 +398,82 @@ describe("SessionStore", () => {
397398
String(session.id),
398399
)
399400
expect(listed).toEqual(["ses_committed"])
401+
expect((yield* store.list({ project: Project.ID.global })).map((session) => String(session.id))).toEqual([
402+
"ses_commitless",
403+
])
404+
}),
405+
)
406+
it.effect("preserves filters and pagination across shared-worktree identities", () =>
407+
Effect.gen(function* () {
408+
const database = (yield* Database.Service).db
409+
const store = yield* SessionStore.Service
410+
const old = Project.ID.make("proj_filter_old")
411+
const current = Project.ID.make("proj_filter_current")
412+
const worktree = AbsolutePath.make("/shared-filter")
413+
const workspace = Workspace.ID.make("wrk_filter")
414+
yield* database
415+
.insert(ProjectTable)
416+
.values([
417+
{ id: old, worktree, sandboxes: [] },
418+
{ id: current, worktree, sandboxes: [] },
419+
])
420+
.run()
421+
const rows = [
422+
{ id: "ses_filter_old", project_id: old, time_updated: 10 },
423+
{ id: "ses_filter_current", project_id: current, time_updated: 20 },
424+
{ id: "ses_filter_child", project_id: old, time_updated: 30, parent_id: Session.ID.make("ses_filter_old") },
425+
{ id: "ses_filter_archived", project_id: old, time_updated: 40, time_archived: 40 },
426+
{
427+
id: "ses_filter_other_workspace",
428+
project_id: current,
429+
time_updated: 50,
430+
workspace_id: Workspace.ID.make("wrk_other"),
431+
},
432+
{ id: "ses_filter_other_path", project_id: old, time_updated: 60, path: RelativePath.make("other") },
433+
{ id: "ses_filter_other_title", project_id: current, time_updated: 70, title: "excluded" },
434+
]
435+
yield* database
436+
.insert(SessionTable)
437+
.values(
438+
rows.map((row) => ({
439+
directory: worktree,
440+
slug: "filter-test",
441+
version: "test",
442+
workspace_id: workspace,
443+
path: RelativePath.make("sub"),
444+
title: "matching title",
445+
...row,
446+
id: Session.ID.make(row.id),
447+
})),
448+
)
449+
.run()
450+
const input = {
451+
project: current,
452+
workspaceID: workspace,
453+
subpath: RelativePath.make("sub"),
454+
search: "matching",
455+
parentID: null,
456+
archived: false,
457+
}
458+
const first = yield* store.list({ ...input, limit: 1 })
459+
expect(first.map((session) => String(session.id))).toEqual(["ses_filter_current"])
460+
const anchor = first[0]
461+
if (!anchor) throw new Error("Expected a first page")
462+
const second = yield* store.list({
463+
...input,
464+
limit: 1,
465+
anchor: { id: anchor.id, time: DateTime.toEpochMillis(anchor.time.updated), direction: "next" },
466+
})
467+
expect(second.map((session) => String(session.id))).toEqual(["ses_filter_old"])
468+
expect(
469+
(yield* store.list({ ...input, parentID: Session.ID.make("ses_filter_old") })).map((session) =>
470+
String(session.id),
471+
),
472+
).toEqual(["ses_filter_child"])
473+
expect((yield* store.list({ ...input, archived: true })).map((session) => String(session.id))).toEqual([
474+
"ses_filter_archived",
475+
])
476+
expect(yield* store.list({ directory: AbsolutePath.make("/shared-filter/sub"), parentID: null })).toEqual([])
400477
}),
401478
)
402479
})

0 commit comments

Comments
 (0)