fix(plugin): normalize event session ids
Handle OpenCode session events that carry the session ID under properties.info.id or properties.info.sessionID so background tasks and continuation hooks do not miss idle/error/delete events. Add regression coverage for nested session.idle events completing background tasks and waking continuation hooks.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import { resolveMessageEventSessionID, resolveSessionEventID } from "./event-session-id"
|
||||
|
||||
describe("event session id resolvers", () => {
|
||||
test("#given legacy message.part.updated properties #when resolving message session id #then part.sessionID is used", () => {
|
||||
const sessionID = resolveMessageEventSessionID({
|
||||
part: {
|
||||
id: "part-1",
|
||||
messageID: "msg-1",
|
||||
sessionID: "ses-part-only",
|
||||
type: "text",
|
||||
text: "working",
|
||||
},
|
||||
})
|
||||
|
||||
expect(sessionID).toBe("ses-part-only")
|
||||
})
|
||||
|
||||
test("#given message.updated info id #when resolving message session id #then message id is not mistaken for session id", () => {
|
||||
const sessionID = resolveMessageEventSessionID({
|
||||
info: {
|
||||
id: "msg-not-session",
|
||||
role: "assistant",
|
||||
},
|
||||
})
|
||||
|
||||
expect(sessionID).toBeUndefined()
|
||||
})
|
||||
|
||||
test("#given legacy session lifecycle properties #when resolving session id #then info.id is used", () => {
|
||||
const sessionID = resolveSessionEventID({
|
||||
info: {
|
||||
id: "ses-legacy-info-id",
|
||||
},
|
||||
})
|
||||
|
||||
expect(sessionID).toBe("ses-legacy-info-id")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user