Skip to content

Commit 015e79f

Browse files
authored
fix(session): respect directory filter with workspaces (anomalyco#30804)
1 parent d5b2056 commit 015e79f

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎packages/opencode/src/session/session.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ function listByProject(
10131013
: or(...conds)!,
10141014
)
10151015
}
1016-
} else if (input.scope !== "project" && !input.experimentalWorkspaces) {
1016+
} else if (input.scope !== "project") {
10171017
if (input.directory) {
10181018
conditions.push(eq(SessionTable.directory, input.directory))
10191019
}

‎packages/opencode/test/server/session-list.test.ts‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { RuntimeFlags } from "@/effect/runtime-flags"
1616
import { BackgroundJob } from "@/background/job"
1717

1818
void Log.init({ print: false })
19-
const it = testEffect(
19+
const layer = (experimentalWorkspaces: boolean) =>
2020
Layer.mergeAll(
2121
Database.defaultLayer,
2222
SessionNs.layer.pipe(
@@ -25,11 +25,12 @@ const it = testEffect(
2525
Layer.provide(Database.defaultLayer),
2626
Layer.provide(EventV2Bridge.defaultLayer),
2727
Layer.provide(SessionProjector.defaultLayer),
28-
Layer.provide(RuntimeFlags.layer({ experimentalWorkspaces: false })),
28+
Layer.provide(RuntimeFlags.layer({ experimentalWorkspaces })),
2929
Layer.provide(BackgroundJob.defaultLayer),
3030
),
31-
),
32-
)
31+
)
32+
const it = testEffect(layer(false))
33+
const itWorkspaces = testEffect(layer(true))
3334

3435
const withSession = (input?: Parameters<SessionNs.Interface["create"]>[0]) =>
3536
Effect.acquireRelease(SessionNs.use.create(input), (created) =>
@@ -99,6 +100,30 @@ describe("session.list", () => {
99100
{ git: true },
100101
)
101102

103+
itWorkspaces.instance(
104+
"filters by directory when experimental workspaces are enabled",
105+
() =>
106+
Effect.gen(function* () {
107+
const test = yield* TestInstance
108+
yield* Effect.promise(() => mkdir(path.join(test.directory, "packages", "opencode"), { recursive: true }))
109+
yield* Effect.promise(() => mkdir(path.join(test.directory, "packages", "app"), { recursive: true }))
110+
111+
const current = yield* withSession({ title: "current" }).pipe(
112+
provideInstance(path.join(test.directory, "packages", "opencode")),
113+
)
114+
const sibling = yield* withSession({ title: "sibling" }).pipe(
115+
provideInstance(path.join(test.directory, "packages", "app")),
116+
)
117+
118+
const ids = (yield* SessionNs.Service.use((session) =>
119+
session.list({ directory: path.join(test.directory, "packages", "opencode") }),
120+
)).map((session) => session.id)
121+
expect(ids).toContain(current.id)
122+
expect(ids).not.toContain(sibling.id)
123+
}),
124+
{ git: true },
125+
)
126+
102127
it.instance(
103128
"matches a session regardless of directory separator on Windows",
104129
() =>

0 commit comments

Comments
 (0)