fix: validate embedded chat history limits · openclaw/openclaw@7bf100b
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -132,4 +132,51 @@ describe("embedded gateway stub", () => {
|
132 | 132 | }, |
133 | 133 | ); |
134 | 134 | }); |
| 135 | + |
| 136 | +it("normalizes string chat history limits before projection", async () => { |
| 137 | +const rawMessages = [ |
| 138 | +{ role: "user", content: "older" }, |
| 139 | +{ role: "assistant", content: "newer" }, |
| 140 | +]; |
| 141 | +runtime.readSessionMessagesAsync.mockResolvedValueOnce(rawMessages); |
| 142 | + |
| 143 | +const callGateway = createEmbeddedCallGateway(); |
| 144 | +await callGateway<{ messages: unknown[] }>({ |
| 145 | +method: "chat.history", |
| 146 | +params: { sessionKey: "agent:main:main", limit: "2" }, |
| 147 | +}); |
| 148 | + |
| 149 | +expect(runtime.projectRecentChatDisplayMessages).toHaveBeenCalledWith(rawMessages, { |
| 150 | +maxChars: 100_000, |
| 151 | +maxMessages: 2, |
| 152 | +}); |
| 153 | +expect(runtime.readSessionMessagesAsync).toHaveBeenCalledWith( |
| 154 | +"sess-main", |
| 155 | +"/tmp/openclaw-sessions.json", |
| 156 | +undefined, |
| 157 | +{ |
| 158 | +mode: "recent", |
| 159 | +maxMessages: 2, |
| 160 | +maxBytes: 1024 * 1024, |
| 161 | +}, |
| 162 | +); |
| 163 | +}); |
| 164 | + |
| 165 | +it("rejects malformed chat history limits before reading session files", async () => { |
| 166 | +const callGateway = createEmbeddedCallGateway(); |
| 167 | + |
| 168 | +await expect( |
| 169 | +callGateway({ |
| 170 | +method: "chat.history", |
| 171 | +params: { sessionKey: "agent:main:main", limit: "2.5" }, |
| 172 | +}), |
| 173 | +).rejects.toThrow("limit must be a positive integer"); |
| 174 | +await expect( |
| 175 | +callGateway({ |
| 176 | +method: "chat.history", |
| 177 | +params: { sessionKey: "agent:main:main", limit: -1 }, |
| 178 | +}), |
| 179 | +).rejects.toThrow("limit must be a positive integer"); |
| 180 | +expect(runtime.readSessionMessagesAsync).not.toHaveBeenCalled(); |
| 181 | +}); |
135 | 182 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。