mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 22:01:11 +00:00
* fix(process): report actual UTF-8 byte count in send-keys message Replace string.length (UTF-16 code units) with Buffer.byteLength(data, 'utf8') so the reported byte count matches the actual bytes sent to process stdin. For ASCII key sequences the values are identical. For non-ASCII text sent via literal key data, string.length underreports the actual UTF-8 byte count. * test(process): cover UTF-8 send-keys byte count Co-authored-by: 陈志强0668000989 <chen.zhiqiang1@xydigit.com> * ci: prune stale max-lines baseline --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
/**
|
|
* Regression coverage for process send-keys cursor-mode handling.
|
|
* Cursor-sensitive keys must wait until PTY startup output establishes mode.
|
|
*/
|
|
import { expect, test } from "vitest";
|
|
import { createProcessSessionFixture } from "./bash-process-registry.test-helpers.js";
|
|
import { handleProcessSendKeys, type WritableStdin } from "./bash-tools.process-send-keys.js";
|
|
|
|
function createWritableStdinStub(): WritableStdin {
|
|
return {
|
|
write(dataValue: string, cb?: (err?: Error | null) => void) {
|
|
cb?.();
|
|
},
|
|
end() {},
|
|
destroyed: false,
|
|
};
|
|
}
|
|
|
|
function expectTextContent(content: unknown, text: string) {
|
|
const part = content as { type?: string; text?: string } | undefined;
|
|
expect(part?.type).toBe("text");
|
|
expect(part?.text).toContain(text);
|
|
}
|
|
|
|
test("process send-keys fails loud for unknown cursor mode when arrows depend on it", async () => {
|
|
const result = await handleProcessSendKeys({
|
|
sessionId: "sess-unknown-mode",
|
|
session: createProcessSessionFixture({
|
|
id: "sess-unknown-mode",
|
|
command: "vim",
|
|
backgrounded: true,
|
|
cursorKeyMode: "unknown",
|
|
}),
|
|
stdin: createWritableStdinStub(),
|
|
keys: ["up"],
|
|
});
|
|
|
|
expect((result.details as { status?: string }).status).toBe("failed");
|
|
expectTextContent(result.content[0], "cursor key mode is not known yet");
|
|
});
|
|
|
|
test("process send-keys still sends non-cursor keys while mode is unknown", async () => {
|
|
const result = await handleProcessSendKeys({
|
|
sessionId: "sess-unknown-enter",
|
|
session: createProcessSessionFixture({
|
|
id: "sess-unknown-enter",
|
|
command: "vim",
|
|
backgrounded: true,
|
|
cursorKeyMode: "unknown",
|
|
}),
|
|
stdin: createWritableStdinStub(),
|
|
keys: ["Enter"],
|
|
});
|
|
|
|
expect((result.details as { status?: string }).status).toBe("running");
|
|
});
|
|
|
|
test("process send-keys reports the UTF-8 byte count", async () => {
|
|
const result = await handleProcessSendKeys({
|
|
sessionId: "sess-literal-bytes",
|
|
session: createProcessSessionFixture({ id: "sess-literal-bytes", command: "cat" }),
|
|
stdin: createWritableStdinStub(),
|
|
literal: "你好😀",
|
|
});
|
|
|
|
expectTextContent(result.content[0], "Sent 10 bytes to session sess-literal-bytes");
|
|
});
|