xonecas.io
64875
Mc

mini-coder / commit 5807e5e

test: add tests for input control action detection

- Add comprehensive tests for getTurnControlAction
- Add comprehensive tests for getSubagentControlAction
- Verify ESC, CTRL+C, and CTRL+D detection behavior

xonecas2026-03-14 5807e5ec7d25e3944eaa68c6a85c339020aa7f4f parent fbc02c0

2 files changed

TODO.md+0−2
@@ -1,6 +1,4 @@
11 # TODO
2-
3-- CTRL+d hangs instead of exiting cleanly.
42 - Strange output mid session:
53
64 ```
src/cli/input-control.test.ts+57−0
@@ -0,0 +1,57 @@
1+import { describe, expect, test } from "bun:test";
2+import {
3+ getSubagentControlAction,
4+ getTurnControlAction,
5+} from "./input-control.ts";
6+
7+describe("getTurnControlAction", () => {
8+ test("returns cancel for ESC key", () => {
9+ expect(getTurnControlAction(new Uint8Array([0x1b]))).toBe("cancel");
10+ });
11+
12+ test("returns quit for CTRL+C", () => {
13+ expect(getTurnControlAction(new Uint8Array([0x03]))).toBe("quit");
14+ });
15+
16+ test("returns quit for CTRL+D", () => {
17+ expect(getTurnControlAction(new Uint8Array([0x04]))).toBe("quit");
18+ });
19+
20+ test("returns null for other input", () => {
21+ expect(getTurnControlAction(new Uint8Array([0x61]))).toBeNull();
22+ });
23+
24+ test("detects CTRL+C in multi-byte input", () => {
25+ expect(getTurnControlAction(new Uint8Array([0x61, 0x03, 0x62]))).toBe(
26+ "quit",
27+ );
28+ });
29+
30+ test("does not trigger cancel for ESC in multi-byte input", () => {
31+ expect(getTurnControlAction(new Uint8Array([0x61, 0x1b, 0x62]))).toBeNull();
32+ });
33+});
34+
35+describe("getSubagentControlAction", () => {
36+ test("returns quit for CTRL+C", () => {
37+ expect(getSubagentControlAction(new Uint8Array([0x03]))).toBe("quit");
38+ });
39+
40+ test("returns quit for CTRL+D", () => {
41+ expect(getSubagentControlAction(new Uint8Array([0x04]))).toBe("quit");
42+ });
43+
44+ test("returns cancel for ESC key", () => {
45+ expect(getSubagentControlAction(new Uint8Array([0x1b]))).toBe("cancel");
46+ });
47+
48+ test("returns cancel for ESC in multi-byte input", () => {
49+ expect(getSubagentControlAction(new Uint8Array([0x61, 0x1b, 0x62]))).toBe(
50+ "cancel",
51+ );
52+ });
53+
54+ test("prioritizes quit over cancel", () => {
55+ expect(getSubagentControlAction(new Uint8Array([0x1b, 0x03]))).toBe("quit");
56+ });
57+});