| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375 |
- /** @jsxImportSource @opentui/solid */
- import { expect, test } from "bun:test"
- import { BoxRenderable, RGBA, type RootRenderable } from "@opentui/core"
- import { testRender, useRenderer } from "@opentui/solid"
- import { createSignal } from "solid-js"
- import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"
- import type { QuestionRequest } from "@kirincode-ai/sdk/v2"
- import { OpencodeKeymapProvider, registerOpencodeKeymap } from "@kirincode-ai/tui/keymap"
- import {
- RUN_COMMAND_PANEL_ROWS,
- RUN_SUBAGENT_PANEL_ROWS,
- RunCommandMenuBody,
- RunModelSelectBody,
- RunQueuedPromptSelectBody,
- RunSkillSelectBody,
- RunSubagentSelectBody,
- RunVariantSelectBody,
- } from "@/cli/cmd/run/footer.command"
- import { RunFooterView } from "@/cli/cmd/run/footer.view"
- import { RunEntryContent } from "@/cli/cmd/run/scrollback.writer"
- import { RUN_THEME_FALLBACK, type RunTheme } from "@/cli/cmd/run/theme"
- import type {
- FooterState,
- FooterSubagentState,
- FooterSubagentTab,
- FooterView,
- RunCommand,
- RunInput,
- RunPrompt,
- RunProvider,
- RunTuiConfig,
- StreamCommit,
- } from "@/cli/cmd/run/types"
- import { RunQuestionBody } from "@/cli/cmd/run/footer.question"
- import { RejectField } from "@/cli/cmd/run/footer.permission"
- import { createTuiResolvedConfig } from "../../fixture/tui-runtime"
- const tuiConfig = createTuiResolvedConfig()
- function command(input: { name: string; description: string; source?: "command" | "mcp" | "skill" }) {
- return {
- name: input.name,
- description: input.description,
- source: input.source,
- template: "",
- hints: [],
- } satisfies RunCommand
- }
- function model(input: {
- id: string
- name: string
- status?: "active" | "deprecated"
- cost?: number
- variants?: Record<string, Record<string, never>>
- }) {
- return {
- id: input.id,
- providerID: "kirincode",
- api: {
- id: "kirincode",
- url: "https://kirincode.ai",
- npm: "@ai-sdk/openai-compatible",
- },
- name: input.name,
- capabilities: {
- temperature: true,
- reasoning: true,
- attachment: true,
- toolcall: true,
- input: {
- text: true,
- audio: false,
- image: true,
- video: false,
- pdf: true,
- },
- output: {
- text: true,
- audio: false,
- image: false,
- video: false,
- pdf: false,
- },
- interleaved: false,
- },
- cost: {
- input: input.cost ?? 1,
- output: 1,
- cache: {
- read: 0,
- write: 0,
- },
- },
- limit: {
- context: 128000,
- output: 8192,
- },
- status: input.status ?? "active",
- options: {},
- headers: {},
- release_date: "2026-01-01",
- variants: input.variants,
- } satisfies RunProvider["models"][string]
- }
- function provider() {
- return {
- id: "kirincode",
- name: "kirincode",
- source: "api",
- env: [],
- options: {},
- models: {
- "gpt-5": model({ id: "gpt-5", name: "GPT-5", variants: { high: {}, minimal: {} } }),
- "gpt-free": model({ id: "gpt-free", name: "GPT Free", cost: 0 }),
- old: model({ id: "old", name: "Old Model", status: "deprecated" }),
- },
- } satisfies RunProvider
- }
- function subagent(input: {
- sessionID: string
- label: string
- description: string
- status?: FooterSubagentTab["status"]
- }) {
- return {
- sessionID: input.sessionID,
- partID: `part-${input.sessionID}`,
- callID: `call-${input.sessionID}`,
- label: input.label,
- description: input.description,
- status: input.status ?? "running",
- lastUpdatedAt: 1,
- } satisfies FooterSubagentTab
- }
- function footerState(input: Partial<FooterState> = {}) {
- return createSignal<FooterState>({
- phase: "idle",
- status: "",
- queue: 0,
- model: "gpt-5",
- duration: "",
- usage: "",
- first: false,
- interrupt: 0,
- exit: 0,
- ...input,
- })[0]
- }
- async function renderFooter(
- input: {
- tuiConfig?: RunTuiConfig
- commands?: RunCommand[]
- theme?: () => RunTheme
- providers?: RunProvider[]
- currentModel?: RunInput["model"]
- currentVariant?: string
- subagents?: FooterSubagentState
- backgroundSubagents?: boolean
- width?: number
- height?: number
- state?: Partial<FooterState>
- onCycle?: () => void
- onSubmit?: (prompt: RunPrompt) => boolean
- } = {},
- ) {
- const [view] = createSignal<FooterView>({ type: "prompt" })
- const [subagents] = createSignal<FooterSubagentState>(
- input.subagents ?? { tabs: [], details: {}, permissions: [], questions: [] },
- )
- const state = footerState(input.state)
- const config = input.tuiConfig ?? tuiConfig
- let offKeymap: (() => void) | undefined
- function Harness() {
- const renderer = useRenderer()
- const keymap = createDefaultOpenTuiKeymap(renderer)
- offKeymap = registerOpencodeKeymap(keymap, renderer, config)
- return (
- <OpencodeKeymapProvider keymap={keymap}>
- <RunFooterView
- directory="/tmp"
- findFiles={async () => []}
- agents={() => []}
- resources={() => []}
- commands={() => input.commands ?? []}
- providers={() => input.providers}
- currentModel={() => input.currentModel}
- variants={() => []}
- currentVariant={() => input.currentVariant}
- state={state}
- view={view}
- subagent={subagents}
- theme={input.theme ?? (() => RUN_THEME_FALLBACK)}
- tuiConfig={config}
- backgroundSubagents={input.backgroundSubagents ?? true}
- agent="kirincode"
- onSubmit={input.onSubmit ?? (() => true)}
- onPermissionReply={() => {}}
- onQuestionReply={() => {}}
- onQuestionReject={() => {}}
- onCycle={input.onCycle ?? (() => {})}
- onInterrupt={() => false}
- onEditorOpen={async () => undefined}
- onInputClear={() => {}}
- onExit={() => {}}
- onModelSelect={() => {}}
- onVariantSelect={() => {}}
- onRows={() => {}}
- onLayout={() => {}}
- onStatus={() => {}}
- onQueuedRemove={async () => true}
- />
- </OpencodeKeymapProvider>
- )
- }
- const app = await testRender(
- () => (
- <box width={input.width ?? 100} height={input.height ?? 8}>
- <Harness />
- </box>
- ),
- { width: input.width ?? 100, height: input.height ?? 8, kittyKeyboard: true },
- )
- return {
- ...app,
- cleanup() {
- app.renderer.currentFocusedRenderable?.blur()
- app.renderer.currentFocusedEditor?.blur()
- offKeymap?.()
- offKeymap = undefined
- app.renderer.destroy()
- },
- }
- }
- function expectPaletteList(list: BoxRenderable, selectedIndex: number) {
- expect(list.backgroundColor.toInts()).toEqual((RUN_THEME_FALLBACK.footer.shade as RGBA).toInts())
- expect((list.getChildren()[selectedIndex] as BoxRenderable).backgroundColor.toInts()).toEqual(
- (RUN_THEME_FALLBACK.footer.selected as RGBA).toInts(),
- )
- }
- function child(root: BoxRenderable | RootRenderable, index: number) {
- return root.getChildren()[index] as BoxRenderable
- }
- function boxPath(root: BoxRenderable | RootRenderable, name: string): BoxRenderable[] | undefined {
- for (const item of root.getChildren()) {
- if (item.constructor.name === name) return root instanceof BoxRenderable ? [root] : []
- if (!(item instanceof BoxRenderable)) continue
- const path = boxPath(item, name)
- if (path) return root instanceof BoxRenderable ? [root, ...path] : path
- }
- }
- function footerComposerFrame(root: BoxRenderable | RootRenderable) {
- return boxPath(root, "TextareaRenderable")!.at(-5)!
- }
- function footerStatusline(root: BoxRenderable | RootRenderable) {
- const status = (RUN_THEME_FALLBACK.footer.status as RGBA).toInts()
- const accent = (RUN_THEME_FALLBACK.footer.statusAccent as RGBA).toInts()
- const boxes = root.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable)
- for (const box of boxes) {
- const first = box.getChildren().find((item): item is BoxRenderable => item instanceof BoxRenderable)
- if (
- box.backgroundColor?.toInts().every((value, index) => value === status[index]) &&
- first?.backgroundColor?.toInts().every((value, index) => value === accent[index])
- )
- return box
- boxes.push(...box.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable))
- }
- throw new Error("Footer statusline not found")
- }
- function panelMenu(root: BoxRenderable | RootRenderable) {
- const panel = child(child(root, 0), 0)
- const content = child(panel, 0)
- return child(content.getChildren().at(-1) as BoxRenderable, 0)
- }
- test("direct footer composer area does not adopt footer surface", async () => {
- const surface = RGBA.fromHex("#123456")
- const [theme, setTheme] = createSignal(RUN_THEME_FALLBACK)
- const app = await renderFooter({ theme })
- try {
- await app.renderOnce()
- const area = child(footerComposerFrame(app.renderer.root), 0)
- expect(area.backgroundColor.toInts()).not.toEqual(surface.toInts())
- setTheme({
- ...RUN_THEME_FALLBACK,
- footer: {
- ...RUN_THEME_FALLBACK.footer,
- surface,
- },
- })
- await app.renderOnce()
- expect(area.backgroundColor.toInts()).not.toEqual(surface.toInts())
- } finally {
- app.cleanup()
- }
- })
- test("run entry content updates when live commit text changes", async () => {
- const [commit, setCommit] = createSignal<StreamCommit>({
- kind: "tool",
- text: "I",
- phase: "progress",
- source: "tool",
- messageID: "msg-1",
- partID: "part-1",
- tool: "bash",
- })
- const app = await testRender(
- () => (
- <box width={80} height={4}>
- <RunEntryContent commit={commit()} theme={RUN_THEME_FALLBACK} width={80} />
- </box>
- ),
- {
- width: 80,
- height: 4,
- },
- )
- try {
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("I")
- setCommit({
- kind: "tool",
- text: "I need to inspect the codebase",
- phase: "progress",
- source: "tool",
- messageID: "msg-1",
- partID: "part-1",
- tool: "bash",
- })
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("I need to inspect the codebase")
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct command panel renders grouped command palette", async () => {
- const [commands] = createSignal<RunCommand[] | undefined>([
- command({ name: "review", description: "Review code" }),
- command({ name: "deploy", description: "Deploy prompt", source: "mcp" }),
- command({ name: "internal", description: "Skill command", source: "skill" }),
- ])
- const [subagents] = createSignal([])
- const [variants] = createSignal(["high", "minimal"])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunCommandMenuBody
- theme={() => RUN_THEME_FALLBACK.footer}
- commands={commands}
- subagents={subagents}
- queued={() => []}
- variants={variants}
- variantCycle="ctrl+t"
- onClose={() => {}}
- onModel={() => {}}
- onEditor={() => {}}
- onSkill={() => {}}
- onSubagent={() => {}}
- onQueued={() => {}}
- onVariant={() => {}}
- onVariantCycle={() => {}}
- onCommand={() => {}}
- onNew={() => {}}
- onExit={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("Commands")
- expect(frame).toContain("Search")
- expect(frame).toContain("Session")
- expect(frame).toContain("Agent")
- expect(frame).toContain("Prompt")
- expect(frame).toContain("Open editor")
- expect(frame).toContain("/editor")
- expect(frame).toContain("Switch model")
- expect(frame).toContain("Skills")
- expect(frame).toContain("/skills")
- expect(frame.match(/\bAgent\b/g)?.length).toBe(1)
- expect(frame).not.toContain("┌")
- expect(frame).not.toContain("┃")
- expect(frame).not.toContain("/internal")
- expect(frame).not.toContain("Choose model for future turns")
- expect(frame).not.toContain("Cycle reasoning effort for future turns")
- expect(frame).not.toContain("Review code")
- expect(frame).not.toContain("Commands 8")
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct skill panel renders searchable skill list", async () => {
- const [commands] = createSignal<RunCommand[] | undefined>([
- command({ name: "review", description: "Review code" }),
- command({ name: "internal", description: "Skill command", source: "skill" }),
- command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
- ])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunSkillSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- commands={commands}
- onClose={() => {}}
- onSelect={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("Skills")
- expect(frame).toContain("Search")
- expect(frame).toContain("internal")
- expect(frame).not.toContain("/internal")
- expect(frame).toContain("formatter")
- expect(frame).toContain("Apply formatter fixes")
- expect(frame).not.toContain("review")
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct skill panel truncates long descriptions from the end", async () => {
- const [commands] = createSignal<RunCommand[] | undefined>([
- command({
- name: "terminal-control",
- description:
- "Control and test terminal applications, REPLs, interactive CLIs, shell processes, OpenTUI applications, or other terminal-backed workflows.",
- source: "skill",
- }),
- ])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunSkillSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- commands={commands}
- onClose={() => {}}
- onSelect={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("terminal-control")
- expect(frame).toContain("Control and test terminal applications")
- expect(frame).not.toMatch(/application(?:…|\.\.\.)ocess/)
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct command panel shows subagent entry when available", async () => {
- const [commands] = createSignal<RunCommand[] | undefined>([])
- const [subagents] = createSignal([subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })])
- const [variants] = createSignal<string[]>([])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunCommandMenuBody
- theme={() => RUN_THEME_FALLBACK.footer}
- commands={commands}
- subagents={subagents}
- queued={() => []}
- variants={variants}
- variantCycle="ctrl+t"
- onClose={() => {}}
- onModel={() => {}}
- onEditor={() => {}}
- onSkill={() => {}}
- onSubagent={() => {}}
- onQueued={() => {}}
- onVariant={() => {}}
- onVariantCycle={() => {}}
- onCommand={() => {}}
- onNew={() => {}}
- onExit={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("View subagents")
- expect(frame).toContain("1 active")
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct command panel keeps completed subagents available", async () => {
- const [commands] = createSignal<RunCommand[] | undefined>([])
- const [subagents] = createSignal([
- subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" }),
- ])
- const [variants] = createSignal<string[]>([])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunCommandMenuBody
- theme={() => RUN_THEME_FALLBACK.footer}
- commands={commands}
- subagents={subagents}
- queued={() => []}
- variants={variants}
- variantCycle="ctrl+t"
- onClose={() => {}}
- onModel={() => {}}
- onEditor={() => {}}
- onSkill={() => {}}
- onSubagent={() => {}}
- onQueued={() => {}}
- onVariant={() => {}}
- onVariantCycle={() => {}}
- onCommand={() => {}}
- onNew={() => {}}
- onExit={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("View subagents")
- expect(frame).toContain("1 recent")
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct subagent panel renders active subagents", async () => {
- const [tabs] = createSignal([
- subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" }),
- subagent({ sessionID: "s-2", label: "General", description: "Write migration plan", status: "completed" }),
- ])
- const [current] = createSignal<string | undefined>("s-1")
- let rows = 0
- const app = await testRender(
- () => (
- <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
- <RunSubagentSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- tabs={tabs}
- current={current}
- onClose={() => {}}
- onSelect={() => {}}
- onRows={(value) => {
- rows = value
- }}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_SUBAGENT_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- const list = panelMenu(app.renderer.root)
- expect(frame).toContain("Select subagent")
- expect(frame).toContain("Inspect auth flow")
- expect(frame).toContain("Write migration plan")
- expect(frame).toContain("done")
- expect(frame).not.toContain("┌")
- expect(frame).not.toContain("┃")
- expectPaletteList(list, 0)
- expect(rows).toBe(8)
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct queued prompt panel renders pending prompt actions", async () => {
- const [prompts] = createSignal([
- { messageID: "m-1", partID: "p-1", prompt: { text: "fix the auth test", parts: [] } },
- ])
- const app = await testRender(
- () => (
- <box width={100} height={RUN_SUBAGENT_PANEL_ROWS}>
- <RunQueuedPromptSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- prompts={prompts}
- onClose={() => {}}
- onEdit={() => {}}
- onDelete={() => {}}
- />
- </box>
- ),
- { width: 100, height: RUN_SUBAGENT_PANEL_ROWS },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- const list = panelMenu(app.renderer.root)
- expect(frame).toContain("Queued prompts")
- expect(frame).toContain("fix the auth test")
- expect(frame).toContain("queued")
- expect(frame).not.toContain("┌")
- expect(frame).not.toContain("┃")
- expectPaletteList(list, 0)
- } finally {
- app.renderer.destroy()
- }
- })
- // OpenTUI currently crashes Bun in the full `test/cli/run` directory run here.
- // Re-enable after the upstream OpenTUI fix lands in this repo.
- test.skip("direct footer recreates the frame across command panel transitions", async () => {
- const app = await renderFooter()
- try {
- await app.renderOnce()
- for (let index = 0; index < 3; index++) {
- const composerFrame = footerComposerFrame(app.renderer.root)
- app.mockInput.pressKey("p", { ctrl: true })
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("Commands")
- expect(footerComposerFrame(app.renderer.root)).not.toBe(composerFrame)
- app.mockInput.pressKey("c", { ctrl: true })
- await app.renderOnce()
- expect(app.captureCharFrame()).not.toContain("Commands")
- expect(app.captureCharFrame()).not.toContain("┃")
- expect(app.captureCharFrame()).not.toContain("█")
- }
- } finally {
- app.cleanup()
- }
- })
- test.skip("direct footer dispatches leader variant binding only when leader is registered", async () => {
- const calls: string[] = []
- const app = await renderFooter({
- tuiConfig: createTuiResolvedConfig({ keybinds: { leader: "ctrl+x", variant_cycle: "<leader>t" } }),
- onCycle: () => calls.push("cycle"),
- })
- try {
- await app.renderOnce()
- app.mockInput.pressKey("t")
- expect(calls).toEqual([])
- app.mockInput.pressKey("x", { ctrl: true })
- app.mockInput.pressKey("t")
- expect(calls).toEqual(["cycle"])
- } finally {
- app.cleanup()
- }
- })
- test("direct footer keeps leader variant binding inactive when leader is disabled", async () => {
- const calls: string[] = []
- const app = await renderFooter({
- tuiConfig: createTuiResolvedConfig({ keybinds: { leader: "none", variant_cycle: "<leader>t" } }),
- onCycle: () => calls.push("cycle"),
- })
- try {
- await app.renderOnce()
- app.mockInput.pressKey("t")
- app.mockInput.pressKey("x", { ctrl: true })
- app.mockInput.pressKey("t")
- expect(calls).toEqual([])
- } finally {
- app.cleanup()
- }
- })
- test("direct footer submits slash autocomplete selections without dispatching shell completions", async () => {
- const submits: RunPrompt[] = []
- const app = await renderFooter({
- commands: [command({ name: "review", description: "Review code" })],
- onSubmit(prompt) {
- submits.push(prompt)
- return true
- },
- })
- try {
- await app.renderOnce()
- "/rev".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- "/rev".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressKey("TAB")
- await app.renderOnce()
- "/re branch".split("").forEach((key) => app.mockInput.pressKey(key))
- Array.from({ length: 7 }).forEach(() => app.mockInput.pressKey("ARROW_LEFT"))
- app.mockInput.pressKey("v")
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- "/nx".split("").forEach((key) => app.mockInput.pressKey(key))
- app.mockInput.pressKey("ARROW_LEFT")
- app.mockInput.pressKey("e")
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- "/n scratch".split("").forEach((key) => app.mockInput.pressKey(key))
- Array.from({ length: 8 }).forEach(() => app.mockInput.pressKey("ARROW_LEFT"))
- app.mockInput.pressKey("e")
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- app.mockInput.pressKey("!")
- "/rev".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual([
- { text: "/review ", parts: [], command: { name: "review", arguments: "" } },
- { text: "/review ", parts: [], command: { name: "review", arguments: "" } },
- { text: "/review branch", parts: [], command: { name: "review", arguments: "branch" } },
- { text: "/new ", parts: [] },
- { text: "/new ", parts: [] },
- ])
- expect(app.captureCharFrame()).toContain("/review")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer slash autocomplete keeps a real skills command", async () => {
- const submits: RunPrompt[] = []
- const app = await renderFooter({
- commands: [
- command({ name: "skills", description: "Run the real skills command" }),
- command({ name: "formatter", description: "Apply formatter fixes", source: "skill" }),
- ],
- onSubmit(prompt) {
- submits.push(prompt)
- return true
- },
- })
- try {
- await app.renderOnce()
- "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual([{ text: "/skills ", parts: [], command: { name: "skills", arguments: "" } }])
- expect(app.captureCharFrame()).not.toContain("Apply formatter fixes")
- } finally {
- app.cleanup()
- }
- })
- // OpenTUI currently segfaults Bun while tearing down this composer-to-skill-panel transition.
- // Re-enable after the upstream renderer teardown fix lands.
- test.skip("direct footer skill picker inserts an editable bound skill command", async () => {
- const submits: RunPrompt[] = []
- const app = await renderFooter({
- commands: [command({ name: "new", description: "Skill named new", source: "skill" })],
- onSubmit(prompt) {
- submits.push(prompt)
- return true
- },
- })
- try {
- await app.renderOnce()
- "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("Skill named new")
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual([])
- expect(app.captureCharFrame()).toContain("/new")
- "task".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual([{ text: "/new task", parts: [], command: { name: "new", arguments: "task" } }])
- } finally {
- app.cleanup()
- }
- })
- // OpenTUI currently segfaults Bun while tearing down this skill-panel close transition.
- // Re-enable after the upstream renderer teardown fix lands.
- test.skip("direct footer clears the synthetic skills draft when the panel closes", async () => {
- const submits: RunPrompt[] = []
- const app = await renderFooter({
- commands: [command({ name: "formatter", description: "Apply formatter fixes", source: "skill" })],
- onSubmit(prompt) {
- submits.push(prompt)
- return true
- },
- })
- try {
- await app.renderOnce()
- "/skills".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("Apply formatter fixes")
- app.mockInput.pressKey("c", { ctrl: true })
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual([])
- expect(app.captureCharFrame()).not.toContain("/skills")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer shows editable prompts and additional queued work while running", async () => {
- const [state] = createSignal<FooterState>({
- phase: "running",
- status: "",
- queue: 3,
- model: "gpt-5",
- duration: "",
- usage: "",
- first: false,
- interrupt: 0,
- exit: 0,
- })
- const [view] = createSignal<FooterView>({ type: "prompt" })
- const [subagents] = createSignal<FooterSubagentState>({
- tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
- details: {},
- permissions: [],
- questions: [],
- })
- let offKeymap: (() => void) | undefined
- function Harness() {
- const renderer = useRenderer()
- const keymap = createDefaultOpenTuiKeymap(renderer)
- offKeymap = registerOpencodeKeymap(keymap, renderer, tuiConfig)
- return (
- <OpencodeKeymapProvider keymap={keymap}>
- <RunFooterView
- directory="/tmp"
- findFiles={async () => []}
- agents={() => []}
- resources={() => []}
- commands={() => []}
- providers={() => undefined}
- currentModel={() => ({
- providerID: "kirincode",
- modelID: "a-model-name-long-enough-to-force-responsive-truncation",
- })}
- variants={() => []}
- currentVariant={() => undefined}
- state={state}
- view={view}
- subagent={subagents}
- queuedPrompts={() => [
- { messageID: "m-queued", partID: "p-queued", prompt: { text: "follow up", parts: [] } },
- ]}
- theme={() => RUN_THEME_FALLBACK}
- tuiConfig={tuiConfig}
- backgroundSubagents={true}
- agent="kirincode"
- onSubmit={() => true}
- onPermissionReply={() => {}}
- onQuestionReply={() => {}}
- onQuestionReject={() => {}}
- onCycle={() => {}}
- onInterrupt={() => false}
- onEditorOpen={async () => undefined}
- onInputClear={() => {}}
- onExit={() => {}}
- onModelSelect={() => {}}
- onVariantSelect={() => {}}
- onRows={() => {}}
- onLayout={() => {}}
- onStatus={() => {}}
- onQueuedRemove={async () => true}
- />
- </OpencodeKeymapProvider>
- )
- }
- const app = await testRender(
- () => (
- <box width={160} height={8}>
- <Harness />
- </box>
- ),
- {
- width: 160,
- height: 8,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- const transparent = RGBA.fromValues(0, 0, 0, 0).toInts()
- const tinted = (RUN_THEME_FALLBACK.footer.status as RGBA).toInts()
- const accent = (RUN_THEME_FALLBACK.footer.statusAccent as RGBA).toInts()
- const statusline = footerStatusline(app.renderer.root)
- const statusItems = statusline.getChildren().filter((item): item is BoxRenderable => item instanceof BoxRenderable)
- const mode = statusItems[0]
- const main = statusItems[1]
- const spinner = main.getChildren()[0]
- const model = statusItems[2]
- const queued = statusItems[3]
- const hint = statusItems.at(-1)!
- expect(spinner).toBeDefined()
- expect(frame).toContain("a-model-name-long-enough-to-force-responsive-truncation")
- expect(frame).toContain("3 queued")
- expect(frame).toContain("ctrl+b background")
- expect(frame).toContain("ctrl+x q 3 queued")
- expect(frame).toContain("ctrl+x down subagents")
- expect(frame).toContain("ctrl+p cmd")
- expect(frame).toContain("a-model-name-long-enough-to-force-responsive-truncation")
- expect(frame).toContain("subagents · ctrl+p cmd")
- expect(frame).not.toContain("1 agent")
- expect(statusline.backgroundColor.toInts()).toEqual(tinted)
- expect(mode.backgroundColor.toInts()).toEqual(accent)
- expect(main.backgroundColor.toInts()).toEqual(transparent)
- expect(model.backgroundColor.toInts()).toEqual(transparent)
- expect(queued.backgroundColor.toInts()).toEqual(transparent)
- expect(hint.backgroundColor.toInts()).toEqual(transparent)
- } finally {
- app.renderer.currentFocusedRenderable?.blur()
- app.renderer.currentFocusedEditor?.blur()
- offKeymap?.()
- app.renderer.destroy()
- }
- })
- test("direct footer separates a lone context hint from model and command hint", async () => {
- const app = await renderFooter({
- providers: [provider()],
- currentModel: { providerID: "kirincode", modelID: "gpt-5" },
- currentVariant: "xhigh",
- subagents: {
- tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow" })],
- details: {},
- permissions: [],
- questions: [],
- },
- backgroundSubagents: false,
- width: 160,
- })
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("GPT-5")
- expect(frame).toContain("xhigh · ctrl+x down subagents · ctrl+p cmd")
- expect(frame).not.toContain("ctrl+b background")
- expect(frame).not.toContain("queued")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer hides the subagent hint when only completed subagents remain", async () => {
- const app = await renderFooter({
- providers: [provider()],
- currentModel: { providerID: "kirincode", modelID: "gpt-5" },
- currentVariant: "xhigh",
- subagents: {
- tabs: [subagent({ sessionID: "s-1", label: "Explore", description: "Inspect auth flow", status: "completed" })],
- details: {},
- permissions: [],
- questions: [],
- },
- backgroundSubagents: false,
- width: 160,
- })
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("GPT-5")
- expect(frame).toContain("xhigh · ctrl+p cmd")
- expect(frame).not.toContain("ctrl+x down subagents")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer omits interrupt key hint when interrupt is unbound", async () => {
- const app = await renderFooter({
- tuiConfig: createTuiResolvedConfig({ keybinds: { session_interrupt: "none", input_clear: "ctrl+l" } }),
- state: { phase: "running" },
- })
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("interrupt")
- expect(frame).not.toContain("ctrl+l")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer shows full usage metadata when room is available", async () => {
- const app = await renderFooter({
- state: { usage: "159.6K (16%) · $4.23" },
- })
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- expect(frame).toContain("159.6K (16%) · $4.23")
- } finally {
- app.cleanup()
- }
- })
- test("direct footer mode label keeps left padding without a status pill", async () => {
- const app = await renderFooter()
- try {
- await app.renderOnce()
- const statusline = app
- .captureCharFrame()
- .split("\n")
- .find((line) => line.includes("BUILD") && line.includes("cmd"))
- expect(statusline).toBeDefined()
- expect(statusline?.startsWith(" BUILD ")).toBe(true)
- } finally {
- app.cleanup()
- }
- })
- test("direct question body separates single-select checkmark from label", async () => {
- const request = {
- id: "question-1",
- sessionID: "session-1",
- questions: [
- {
- question: "Which categorical concept is often described as a universal way to combine two objects?",
- header: "Universal Product",
- options: [
- { label: "Product", description: "A product comes with projections." },
- { label: "Equalizer", description: "An equalizer selects morphisms where arrows agree." },
- ],
- },
- ],
- } satisfies QuestionRequest
- const replies: unknown[] = []
- const app = await testRender(
- () => (
- <box width={100} height={12}>
- <RunQuestionBody
- request={request}
- theme={RUN_THEME_FALLBACK.footer}
- onReply={(input) => {
- replies.push(input)
- }}
- onReject={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: 12,
- },
- )
- try {
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(replies).toHaveLength(1)
- expect(app.captureCharFrame()).toContain("Product ✓")
- } finally {
- app.renderer.destroy()
- }
- })
- // OpenTUI currently segfaults while tearing down this textarea-backed keymap renderer.
- // Re-enable after the runtime fix.
- test.skip("direct custom answer submits through keymap return binding", async () => {
- const question = {
- id: "question-1",
- sessionID: "session-1",
- questions: [
- {
- question: "Which answer should I use?",
- header: "Answer",
- options: [{ label: "Provided", description: "Use the listed answer." }],
- custom: true,
- },
- ],
- } satisfies QuestionRequest
- const questions: unknown[] = []
- let off: (() => void) | undefined
- function Harness() {
- const renderer = useRenderer()
- const keymap = createDefaultOpenTuiKeymap(renderer)
- off = registerOpencodeKeymap(keymap, renderer, tuiConfig)
- return (
- <OpencodeKeymapProvider keymap={keymap}>
- <RunQuestionBody
- request={question}
- theme={RUN_THEME_FALLBACK.footer}
- onReply={(input) => {
- questions.push(input)
- }}
- onReject={() => {}}
- />
- </OpencodeKeymapProvider>
- )
- }
- const app = await testRender(
- () => (
- <box width={100} height={18}>
- <Harness />
- </box>
- ),
- { width: 100, height: 18, kittyKeyboard: true },
- )
- try {
- await app.renderOnce()
- app.mockInput.pressKey("2")
- await app.renderOnce()
- "typed".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(questions).toEqual([{ requestID: "question-1", answers: [["typed"]] }])
- } finally {
- app.renderer.currentFocusedRenderable?.blur()
- app.renderer.currentFocusedEditor?.blur()
- off?.()
- app.renderer.destroy()
- }
- })
- test("direct permission rejection submits through keymap return binding", async () => {
- let text = ""
- const submits: string[] = []
- let off: (() => void) | undefined
- function Harness() {
- const renderer = useRenderer()
- const keymap = createDefaultOpenTuiKeymap(renderer)
- off = registerOpencodeKeymap(keymap, renderer, tuiConfig)
- return (
- <OpencodeKeymapProvider keymap={keymap}>
- <RejectField
- theme={RUN_THEME_FALLBACK.footer}
- text=""
- disabled={false}
- onChange={(input) => {
- text = input
- }}
- onConfirm={() => {
- submits.push(text)
- }}
- onCancel={() => {}}
- />
- </OpencodeKeymapProvider>
- )
- }
- const app = await testRender(
- () => (
- <box width={100} height={18}>
- <Harness />
- </box>
- ),
- { width: 100, height: 18, kittyKeyboard: true },
- )
- try {
- await app.renderOnce()
- "retry".split("").forEach((key) => app.mockInput.pressKey(key))
- await app.renderOnce()
- expect(app.captureCharFrame()).toContain("retry")
- app.mockInput.pressEnter()
- await app.renderOnce()
- expect(submits).toEqual(["retry"])
- } finally {
- app.renderer.currentFocusedRenderable?.blur()
- app.renderer.currentFocusedEditor?.blur()
- off?.()
- app.renderer.destroy()
- }
- })
- test("direct model panel renders current model selector", async () => {
- const [providers] = createSignal<RunProvider[] | undefined>([provider()])
- const [current] = createSignal<RunInput["model"]>({ providerID: "kirincode", modelID: "gpt-5" })
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunModelSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- providers={providers}
- current={current}
- onClose={() => {}}
- onSelect={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- const list = panelMenu(app.renderer.root)
- expect(frame).toContain("Select model")
- expect(frame).toContain("Search")
- expect(frame).toContain("kirincode")
- expect(frame).toContain("GPT-5")
- expect(frame).toContain("current")
- expect(frame).toContain("GPT Free")
- expect(frame).toContain("Free")
- expect(frame).not.toContain("┌")
- expect(frame).not.toContain("┃")
- expect(frame).not.toContain("Old Model")
- expectPaletteList(list, 2)
- } finally {
- app.renderer.destroy()
- }
- })
- test("direct variant panel renders current variant selector", async () => {
- const [variants] = createSignal(["high", "minimal"])
- const [current] = createSignal<string | undefined>("high")
- const app = await testRender(
- () => (
- <box width={100} height={RUN_COMMAND_PANEL_ROWS}>
- <RunVariantSelectBody
- theme={() => RUN_THEME_FALLBACK.footer}
- variants={variants}
- current={current}
- onClose={() => {}}
- onSelect={() => {}}
- />
- </box>
- ),
- {
- width: 100,
- height: RUN_COMMAND_PANEL_ROWS,
- },
- )
- try {
- await app.renderOnce()
- const frame = app.captureCharFrame()
- const list = panelMenu(app.renderer.root)
- expect(frame).toContain("Select variant")
- expect(frame).toContain("Default")
- expect(frame).toContain("high")
- expect(frame).toContain("minimal")
- expect(frame).toContain("current")
- expect(frame).not.toContain("┌")
- expect(frame).not.toContain("┃")
- expectPaletteList(list, 1)
- } finally {
- app.renderer.destroy()
- }
- })
|