Files
paseo/packages/protocol/src/terminal-key-input.test.ts
Mohamed Boudra 53c14d9855 Extract client SDK package (#1052)
* Extract client SDK package

* Polish SDK client identity defaults

* Build client before dependent CI jobs

* Restore daemon client server export

* Extract protocol and client SDK packages

* Fix provider override schema validation

* Fix app test daemon client imports

* Simplify workspace build targets

* Fix CLI test server build bootstrap

* Run SDK package tests in CI

* Fix rebase package split drift

* Restore lockfile registry metadata

* Update SDK config test for prompt default

* Move terminal stream router test to client package

* Fix rebase drift for protocol imports

* Fix SDK agent capability fixture

* Restore legacy server client exports

* Fix server export compatibility test

* Advertise custom mode icon client capability

* Remove server daemon-client exports

* Format rebased mode control import

* Fix rebase drift for protocol imports

Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split
shared/ paths that this branch moves into @getpaseo/protocol. Redirect
those imports to the protocol package so typecheck stays green after the
rebase.
2026-05-28 01:58:18 +08:00

58 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { encodeTerminalKeyInput } from "./terminal-key-input.js";
describe("encodeTerminalKeyInput", () => {
it("encodes ctrl+b for tmux prefix", () => {
expect(encodeTerminalKeyInput({ key: "b", ctrl: true })).toBe("\x02");
});
it("encodes shifted arrow key modifiers", () => {
expect(encodeTerminalKeyInput({ key: "ArrowLeft", shift: true })).toBe("\x1b[1;2D");
});
it("encodes alt-modified printable keys", () => {
expect(encodeTerminalKeyInput({ key: "x", alt: true })).toBe("\x1bx");
});
it("encodes enter and backspace", () => {
expect(encodeTerminalKeyInput({ key: "Enter" })).toBe("\r");
expect(encodeTerminalKeyInput({ key: "Backspace" })).toBe("\x7f");
});
it("keeps modified Enter as carriage return before enhanced input mode is active", () => {
expect(encodeTerminalKeyInput({ key: "Enter", shift: true })).toBe("\r");
});
it("encodes Enter with modifiers using CSI u after Kitty keyboard mode is active", () => {
const options = { inputMode: { kittyKeyboardFlags: 7, win32InputMode: false } };
expect(encodeTerminalKeyInput({ key: "Enter", shift: true }, options)).toBe("\x1b[13;2u");
expect(encodeTerminalKeyInput({ key: "Enter", ctrl: true }, options)).toBe("\x1b[13;5u");
expect(encodeTerminalKeyInput({ key: "Enter", alt: true }, options)).toBe("\x1b[13;3u");
expect(encodeTerminalKeyInput({ key: "Enter", meta: true }, options)).toBe("\x1b[13;9u");
expect(encodeTerminalKeyInput({ key: "Enter", shift: true, ctrl: true }, options)).toBe(
"\x1b[13;6u",
);
});
it("encodes Shift+Enter using Win32 input mode when ConPTY requests it", () => {
const options = { inputMode: { kittyKeyboardFlags: 0, win32InputMode: true } };
expect(encodeTerminalKeyInput({ key: "Enter", shift: true }, options)).toBe(
"\x1b[13;28;13;1;16;1_",
);
});
it("prefers Win32 input mode over CSI u when both modes are active", () => {
const options = { inputMode: { kittyKeyboardFlags: 7, win32InputMode: true } };
expect(encodeTerminalKeyInput({ key: "Enter", shift: true }, options)).toBe(
"\x1b[13;28;13;1;16;1_",
);
});
it("returns empty string for unsupported keys", () => {
expect(encodeTerminalKeyInput({ key: "UnidentifiedKey" })).toBe("");
});
});