|
1 | 1 | import { describe, expect } from "bun:test" |
2 | 2 | import { asc, eq } from "drizzle-orm" |
3 | | -import { Effect } from "effect" |
| 3 | +import { DateTime, Effect } from "effect" |
4 | 4 | import { Bus } from "@opencode/core/bus" |
5 | 5 | import { Database } from "@opencode/core/database/database" |
6 | 6 | import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder" |
7 | 7 | import { ProjectTable } from "@opencode/core/project/sql" |
8 | 8 | import { SessionHistory } from "@opencode/core/session/history" |
9 | 9 | 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" |
11 | 11 | import { SessionStore } from "@opencode/core/session/store" |
12 | 12 | import { Agent } from "@opencode/schema/agent" |
13 | 13 | import { Event } from "@opencode/schema/event" |
14 | 14 | import { Model } from "@opencode/schema/model" |
15 | 15 | import { Project } from "@opencode/schema/project" |
16 | 16 | 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" |
18 | 19 | import { Session } from "@opencode/schema/session" |
19 | 20 | import { SessionEvent } from "@opencode/schema/session-event" |
20 | 21 | import { SessionMessage } from "@opencode/schema/session-message" |
@@ -397,6 +398,82 @@ describe("SessionStore", () => { |
397 | 398 | String(session.id), |
398 | 399 | ) |
399 | 400 | 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([]) |
400 | 477 | }), |
401 | 478 | ) |
402 | 479 | }) |
0 commit comments