fix(cli/run): handle session.status idle event in addition to deprecated session.idle
This commit is contained in:
parent
bb2df9fec6
commit
0565ce839e
73
src/cli/run/event-handlers.test.ts
Normal file
73
src/cli/run/event-handlers.test.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import { describe, it, expect } from "bun:test"
|
||||||
|
import type { RunContext } from "./types"
|
||||||
|
import { createEventState } from "./events"
|
||||||
|
import { handleSessionStatus } from "./event-handlers"
|
||||||
|
|
||||||
|
const createMockContext = (sessionID: string = "test-session"): RunContext => ({
|
||||||
|
sessionID,
|
||||||
|
} as RunContext)
|
||||||
|
|
||||||
|
describe("handleSessionStatus", () => {
|
||||||
|
it("recognizes idle from session.status event (not just deprecated session.idle)", () => {
|
||||||
|
//#given - state with mainSessionIdle=false
|
||||||
|
const ctx = createMockContext("test-session")
|
||||||
|
const state = createEventState()
|
||||||
|
state.mainSessionIdle = false
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
type: "session.status",
|
||||||
|
properties: {
|
||||||
|
sessionID: "test-session",
|
||||||
|
status: { type: "idle" as const },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//#when - handleSessionStatus called with idle status
|
||||||
|
handleSessionStatus(ctx, payload as any, state)
|
||||||
|
|
||||||
|
//#then - state.mainSessionIdle === true
|
||||||
|
expect(state.mainSessionIdle).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("handleSessionStatus sets idle=false on busy", () => {
|
||||||
|
//#given - state with mainSessionIdle=true
|
||||||
|
const ctx = createMockContext("test-session")
|
||||||
|
const state = createEventState()
|
||||||
|
state.mainSessionIdle = true
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
type: "session.status",
|
||||||
|
properties: {
|
||||||
|
sessionID: "test-session",
|
||||||
|
status: { type: "busy" as const },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//#when - handleSessionStatus called with busy status
|
||||||
|
handleSessionStatus(ctx, payload as any, state)
|
||||||
|
|
||||||
|
//#then - state.mainSessionIdle === false
|
||||||
|
expect(state.mainSessionIdle).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does nothing for different session ID", () => {
|
||||||
|
//#given - state with mainSessionIdle=true
|
||||||
|
const ctx = createMockContext("test-session")
|
||||||
|
const state = createEventState()
|
||||||
|
state.mainSessionIdle = true
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
type: "session.status",
|
||||||
|
properties: {
|
||||||
|
sessionID: "other-session",
|
||||||
|
status: { type: "idle" as const },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
//#when - handleSessionStatus called with different session ID
|
||||||
|
handleSessionStatus(ctx, payload as any, state)
|
||||||
|
|
||||||
|
//#then - state.mainSessionIdle remains unchanged
|
||||||
|
expect(state.mainSessionIdle).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -26,8 +26,12 @@ export function handleSessionStatus(ctx: RunContext, payload: EventPayload, stat
|
|||||||
if (payload.type !== "session.status") return
|
if (payload.type !== "session.status") return
|
||||||
|
|
||||||
const props = payload.properties as SessionStatusProps | undefined
|
const props = payload.properties as SessionStatusProps | undefined
|
||||||
if (props?.sessionID === ctx.sessionID && props?.status?.type === "busy") {
|
if (props?.sessionID !== ctx.sessionID) return
|
||||||
|
|
||||||
|
if (props?.status?.type === "busy") {
|
||||||
state.mainSessionIdle = false
|
state.mainSessionIdle = false
|
||||||
|
} else if (props?.status?.type === "idle") {
|
||||||
|
state.mainSessionIdle = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user