cloudaxe-opencode/packages/opencode/test/cli/tui/prompt-key.test.ts
2026-03-16 20:49:08 -04:00

26 lines
1.1 KiB
TypeScript

import { describe, expect, test } from "bun:test"
import { shellPassthrough } from "../../../src/cli/cmd/tui/component/prompt/key"
const key = (name: string, extra: { readonly shift?: boolean } = {}) => ({
name,
shift: false,
...extra,
})
describe("shellPassthrough", () => {
test("allows tab agent-cycle bindings to pass through in shell mode", () => {
const match = (target: string, evt: { readonly name?: string }) => target === "agent_cycle" && evt.name === "tab"
expect(shellPassthrough({ match }, key("tab"), "shell")).toBe(true)
})
test("allows reverse agent-cycle bindings to pass through in shell mode", () => {
const match = (target: string, evt: { readonly name?: string; readonly shift?: boolean }) =>
target === "agent_cycle_reverse" && evt.name === "tab" && evt.shift
expect(shellPassthrough({ match }, key("tab", { shift: true }), "shell")).toBe(true)
})
test("does not bypass agent-cycle outside shell mode", () => {
const match = (target: string, evt: { readonly name?: string }) => target === "agent_cycle" && evt.name === "tab"
expect(shellPassthrough({ match }, key("tab"), "normal")).toBe(false)
})
})