fix: count qmd output caps by code point · openclaw/openclaw@9e1faf8
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
packages/memory-host-sdk/src/host
| Original file line number | Diff line number | Diff line change |
|---|
@@ -283,4 +283,25 @@ describe("runCliCommand", () => {
|
283 | 283 | }), |
284 | 284 | ).rejects.toThrow(/produced too much output/); |
285 | 285 | }); |
| 286 | + |
| 287 | +it("counts surrogate pairs as one character when capping failed command output", async () => { |
| 288 | +const child = createMockChild(); |
| 289 | +spawnMock.mockImplementationOnce(() => { |
| 290 | +queueMicrotask(() => { |
| 291 | +child.stderr.emit("data", "a🙂"); |
| 292 | +child.closeWith(1); |
| 293 | +}); |
| 294 | +return child; |
| 295 | +}); |
| 296 | + |
| 297 | +await expect( |
| 298 | +runCliCommand({ |
| 299 | +commandSummary: "qmd query test", |
| 300 | +spawnInvocation: { command: "qmd", argv: ["query", "test", "--json"] }, |
| 301 | +env: process.env, |
| 302 | +cwd: tempDir, |
| 303 | +maxOutputChars: 2, |
| 304 | +}), |
| 305 | +).rejects.toThrow(/🙂/); |
| 306 | +}); |
286 | 307 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -259,10 +259,11 @@ function appendOutputWithCap(
|
259 | 259 | maxChars: number, |
260 | 260 | ): { text: string; truncated: boolean } { |
261 | 261 | const appended = current + chunk; |
262 | | -if (appended.length <= maxChars) { |
| 262 | +const chars = Array.from(appended); |
| 263 | +if (chars.length <= maxChars) { |
263 | 264 | return { text: appended, truncated: false }; |
264 | 265 | } |
265 | | -return { text: appended.slice(-maxChars), truncated: true }; |
| 266 | +return { text: chars.slice(-maxChars).join(""), truncated: true }; |
266 | 267 | } |
267 | 268 | |
268 | 269 | function formatQmdAvailabilityError(err: unknown): string { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。