@@ -1131,6 +1131,55 @@ describe("connectGateway", () => {
|
1131 | 1131 | expect(loadChatHistoryMock).not.toHaveBeenCalled(); |
1132 | 1132 | }); |
1133 | 1133 | |
| 1134 | +it("keeps source-reply finals live even when message tool events were seen", () => { |
| 1135 | +const { host, client } = connectHostGateway(); |
| 1136 | +host.chatRunId = "main-run-with-message-tool"; |
| 1137 | +host.chatMessages = [ |
| 1138 | +{ |
| 1139 | +role: "user", |
| 1140 | +content: [{ type: "text", text: "Hey there" }], |
| 1141 | +timestamp: 100, |
| 1142 | +}, |
| 1143 | +]; |
| 1144 | +emitToolResultEvent(client); |
| 1145 | +expect(host.toolStreamOrder).toHaveLength(1); |
| 1146 | +loadChatHistoryMock.mockClear(); |
| 1147 | + |
| 1148 | +client.emitEvent({ |
| 1149 | +event: "session.message", |
| 1150 | +payload: { |
| 1151 | +sessionKey: "main", |
| 1152 | +}, |
| 1153 | +}); |
| 1154 | +client.emitEvent({ |
| 1155 | +event: "chat", |
| 1156 | +payload: { |
| 1157 | +runId: "main-run-with-message-tool", |
| 1158 | +sessionKey: "main", |
| 1159 | +state: "final", |
| 1160 | +message: { |
| 1161 | +role: "assistant", |
| 1162 | +content: [{ type: "text", text: "Final answer" }], |
| 1163 | +}, |
| 1164 | +}, |
| 1165 | +}); |
| 1166 | + |
| 1167 | +expect(host.chatRunId).toBeNull(); |
| 1168 | +expect(host.chatMessages).toEqual([ |
| 1169 | +{ |
| 1170 | +role: "user", |
| 1171 | +content: [{ type: "text", text: "Hey there" }], |
| 1172 | +timestamp: 100, |
| 1173 | +}, |
| 1174 | +{ |
| 1175 | +role: "assistant", |
| 1176 | +content: [{ type: "text", text: "Final answer" }], |
| 1177 | +}, |
| 1178 | +]); |
| 1179 | +expect(host.toolStreamOrder).toHaveLength(1); |
| 1180 | +expect(loadChatHistoryMock).not.toHaveBeenCalled(); |
| 1181 | +}); |
| 1182 | + |
1134 | 1183 | it("replays deferred session.message reloads after legacy silent final payload", () => { |
1135 | 1184 | const { host, client } = connectHostGateway(); |
1136 | 1185 | host.chatRunId = "main-run-silent"; |
|