fix: route new prompt sync to target directory
Keeps optimistic prompt state in the session directory Routes live assistant part updates using upstream event payloads Adds regressions for startup session switch races
This commit is contained in:
@@ -40,6 +40,21 @@ function partUpdatedEvent(): Event {
|
||||
} as Event
|
||||
}
|
||||
|
||||
function topLevelSessionOnlyPartUpdatedEvent(): Event {
|
||||
return {
|
||||
type: "message.part.updated",
|
||||
properties: {
|
||||
sessionID: "ses_1",
|
||||
part: {
|
||||
id: "prt_1",
|
||||
messageID: "msg_1",
|
||||
type: "text",
|
||||
text: "hello",
|
||||
},
|
||||
},
|
||||
} as Event
|
||||
}
|
||||
|
||||
describe("applyDirectoryEvent", () => {
|
||||
test("returns typed materialization when delta arrives before parts", () => {
|
||||
const result = applyDirectoryEvent(state(), deltaEvent())
|
||||
@@ -78,6 +93,40 @@ describe("applyDirectoryEvent", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("uses top-level session id and part message id for part update materialization", () => {
|
||||
const draft = state()
|
||||
const result = applyDirectoryEvent(draft, topLevelSessionOnlyPartUpdatedEvent())
|
||||
|
||||
expect(draft.part.msg_1.map((item) => item.id)).toEqual(["prt_1"])
|
||||
expect(result).toEqual({
|
||||
changed: true,
|
||||
materialization: {
|
||||
type: "incomplete-session-snapshot",
|
||||
sessionID: "ses_1",
|
||||
messageID: "msg_1",
|
||||
partID: "prt_1",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("uses top-level session id for delta materialization", () => {
|
||||
const result = applyDirectoryEvent(state(), {
|
||||
type: "message.part.delta",
|
||||
properties: {
|
||||
sessionID: "ses_1",
|
||||
messageID: "msg_1",
|
||||
partID: "prt_1",
|
||||
field: "text",
|
||||
delta: "hello",
|
||||
},
|
||||
} as Event)
|
||||
|
||||
expect(result).toEqual({
|
||||
changed: false,
|
||||
materialization: { type: "incomplete-session-snapshot", sessionID: "ses_1", messageID: "msg_1", partID: "prt_1" },
|
||||
})
|
||||
})
|
||||
|
||||
test("applies part update without materialization when owning message exists", () => {
|
||||
const draft = state({
|
||||
message: { ses_1: [{ id: "msg_1", sessionID: "ses_1", role: "assistant", time: { created: 1 } } as never] },
|
||||
|
||||
Reference in New Issue
Block a user