fix: isolate assistant conversation state
This commit is contained in:
1 parent
3faac7a96d
commit
33695753dd
3 files changed
+144
-18
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { initialAssistantNotificationState, updateAssistantNotificationState } from "./assistant-notifications";
|
||||
|
||||
describe("updateAssistantNotificationState", () => {
|
||||
test("baselines the current response when notifications initialize", () => {
|
||||
const update = updateAssistantNotificationState(initialAssistantNotificationState, {
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
});
|
||||
|
||||
expect(update.shouldNotify).toBe(false);
|
||||
expect(update.state).toEqual({
|
||||
initialized: true,
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
});
|
||||
});
|
||||
|
||||
test("notifies when a response completes in the active conversation", () => {
|
||||
const update = updateAssistantNotificationState(
|
||||
{
|
||||
initialized: true,
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: null,
|
||||
},
|
||||
{
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
},
|
||||
);
|
||||
|
||||
expect(update.shouldNotify).toBe(true);
|
||||
});
|
||||
|
||||
test("does not count existing history when the selected conversation changes", () => {
|
||||
const update = updateAssistantNotificationState(
|
||||
{
|
||||
initialized: true,
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
},
|
||||
{
|
||||
conversationId: "conversation-b",
|
||||
notificationKey: "response-b:complete",
|
||||
},
|
||||
);
|
||||
|
||||
expect(update.shouldNotify).toBe(false);
|
||||
expect(update.state.notificationKey).toBe("response-b:complete");
|
||||
});
|
||||
|
||||
test("notifies for the next completion after switching conversations", () => {
|
||||
const switched = updateAssistantNotificationState(
|
||||
{
|
||||
initialized: true,
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
},
|
||||
{
|
||||
conversationId: "conversation-b",
|
||||
notificationKey: "response-b:complete",
|
||||
},
|
||||
);
|
||||
const completed = updateAssistantNotificationState(switched.state, {
|
||||
conversationId: "conversation-b",
|
||||
notificationKey: "response-c:complete",
|
||||
});
|
||||
|
||||
expect(completed.shouldNotify).toBe(true);
|
||||
});
|
||||
|
||||
test("ignores running and repeated response states", () => {
|
||||
const previous = {
|
||||
initialized: true,
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
};
|
||||
|
||||
expect(
|
||||
updateAssistantNotificationState(previous, {
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: null,
|
||||
}).shouldNotify,
|
||||
).toBe(false);
|
||||
expect(
|
||||
updateAssistantNotificationState(previous, {
|
||||
conversationId: "conversation-a",
|
||||
notificationKey: "response-a:complete",
|
||||
}).shouldNotify,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user