fix(chat): stabilize message identities

This commit is contained in:
2026-07-20 18:30:21 +08:00
parent 159e8bfd59
commit 1e13f94b5d
33 changed files with 718 additions and 212 deletions
@@ -22,7 +22,7 @@ describe("chat promotion", () => {
const messages = appendPromotionMessage(
[
{
id: "history-1",
displayId: "history-1",
content: "History",
isFromAI: true,
date: "2026-07-13",
@@ -31,7 +31,7 @@ describe("chat promotion", () => {
state,
);
expect(messages.map((message) => message.id)).toEqual([
expect(messages.map((message) => message.displayId)).toEqual([
"history-1",
"promotion:promotion-1",
]);
@@ -62,7 +62,8 @@ describe("chat promotion", () => {
});
expect(next?.message).toMatchObject({
id: "backend-1",
displayId: "promotion:promotion-1",
remoteId: "backend-1",
imageUrl: "https://example.com/unlocked.jpg",
imagePaywalled: false,
locked: false,
@@ -71,10 +72,19 @@ describe("chat promotion", () => {
it("keeps the promotion last and removes matching history duplicates", () => {
const state = createChatPromotionState(promotion, "backend-1");
const userMessage = {
displayId: "server:backend-1:user",
remoteId: "backend-1",
content: "User message with the shared remote id",
isFromAI: false,
date: "2026-07-13",
};
const messages = appendPromotionMessage(
[
userMessage,
{
id: "backend-1",
displayId: "server:backend-1:assistant",
remoteId: "backend-1",
content: "Stale history copy",
isFromAI: true,
date: "2026-07-13",
@@ -83,6 +93,6 @@ describe("chat promotion", () => {
state,
);
expect(messages).toEqual([state.message]);
expect(messages).toEqual([userMessage, state.message]);
});
});