Skip to content

Commit 700188f

Browse files
Mark Hendersonfwang
authored andcommitted
fix: use Session.Event.Deleted instead of manually constructed event
Address Copilot review comments - import Session and use the proper Session.Event.Deleted event definition instead of bypassing type checking with manually constructed objects.
1 parent e8ae922 commit 700188f

1 file changed

Lines changed: 34 additions & 42 deletions

File tree

packages/opencode/test/permission/cleanup.test.ts

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { test, expect } from "bun:test"
22
import { PermissionNext } from "../../src/permission/next"
33
import { Bus } from "../../src/bus"
44
import { Instance } from "../../src/project/instance"
5+
import { Session } from "../../src/session"
56
import { tmpdir } from "../fixture/fixture"
67

78
test("clearSession - rejects pending permissions for session", async () => {
@@ -129,22 +130,19 @@ test("init - subscribes to session.deleted and clears session", async () => {
129130

130131
// Simulate session deletion by publishing the event
131132
// Bus.publish returns a Promise that resolves when all handlers complete
132-
await Bus.publish(
133-
{ type: "session.deleted", properties: {} as any },
134-
{
135-
info: {
136-
id: "session_deleted",
137-
projectID: "project_1",
138-
directory: tmp.path,
139-
title: "Test Session",
140-
version: "1.0.0",
141-
time: {
142-
created: Date.now(),
143-
updated: Date.now(),
144-
},
133+
await Bus.publish(Session.Event.Deleted, {
134+
info: {
135+
id: "session_deleted",
136+
projectID: "project_1",
137+
directory: tmp.path,
138+
title: "Test Session",
139+
version: "1.0.0",
140+
time: {
141+
created: Date.now(),
142+
updated: Date.now(),
145143
},
146144
},
147-
)
145+
})
148146

149147
// Verify pending was cleared
150148
expect((await PermissionNext.list()).length).toBe(0)
@@ -181,22 +179,19 @@ test("dispose - unsubscribes from events", async () => {
181179
expect((await PermissionNext.list()).length).toBe(1)
182180

183181
// Publish session deleted event - should NOT clear because we disposed
184-
await Bus.publish(
185-
{ type: "session.deleted", properties: {} as any },
186-
{
187-
info: {
188-
id: "session_after_dispose",
189-
projectID: "project_1",
190-
directory: tmp.path,
191-
title: "Test Session",
192-
version: "1.0.0",
193-
time: {
194-
created: Date.now(),
195-
updated: Date.now(),
196-
},
182+
await Bus.publish(Session.Event.Deleted, {
183+
info: {
184+
id: "session_after_dispose",
185+
projectID: "project_1",
186+
directory: tmp.path,
187+
title: "Test Session",
188+
version: "1.0.0",
189+
time: {
190+
created: Date.now(),
191+
updated: Date.now(),
197192
},
198193
},
199-
)
194+
})
200195

201196
// Pending should still exist because we disposed
202197
expect((await PermissionNext.list()).length).toBe(1)
@@ -233,22 +228,19 @@ test("init - calling init twice does not duplicate subscriptions", async () => {
233228
const result = askPromise.catch((e) => e)
234229

235230
// Publish session deleted event
236-
await Bus.publish(
237-
{ type: "session.deleted", properties: {} as any },
238-
{
239-
info: {
240-
id: "session_multi_init",
241-
projectID: "project_1",
242-
directory: tmp.path,
243-
title: "Test Session",
244-
version: "1.0.0",
245-
time: {
246-
created: Date.now(),
247-
updated: Date.now(),
248-
},
231+
await Bus.publish(Session.Event.Deleted, {
232+
info: {
233+
id: "session_multi_init",
234+
projectID: "project_1",
235+
directory: tmp.path,
236+
title: "Test Session",
237+
version: "1.0.0",
238+
time: {
239+
created: Date.now(),
240+
updated: Date.now(),
249241
},
250242
},
251-
)
243+
})
252244

253245
// Should be cleared exactly once (no duplicate handlers)
254246
expect((await PermissionNext.list()).length).toBe(0)

0 commit comments

Comments
 (0)