-
Notifications
You must be signed in to change notification settings - Fork 91
feat(tui): command-line-only screens for every command without a TUI #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
notgitika
merged 2 commits into
aws:refactor
from
notgitika:feat/cli-only-screens-everywhere
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { test, expect, describe, afterEach } from "bun:test"; | ||
| import type { Command } from "commander"; | ||
| import { | ||
| renderScreen, | ||
| waitForText, | ||
| cleanupScreens, | ||
| createSilentLogger, | ||
| menuEntries, | ||
| TestCoreClient, | ||
| TestGlobalConfigAccessor, | ||
| testIO, | ||
| } from "../testing"; | ||
| import { compile, isTuiCommandSupported, ValueContext } from "../router"; | ||
| import { createRootHandler } from "../handlers"; | ||
|
|
||
| afterEach(cleanupScreens); | ||
|
|
||
| function compiledRoot(): Command { | ||
| return compile( | ||
| createRootHandler(new TestCoreClient(), { | ||
| io: testIO().io, | ||
| logger: createSilentLogger(), | ||
| globalConfigAccessor: new TestGlobalConfigAccessor(), | ||
| }), | ||
| ValueContext.EmptyContext(), | ||
| ); | ||
| } | ||
|
|
||
| // cliOnlyCommands walks the compiled Commander tree for every command without | ||
| // a screen, so a command added later is covered without a new test. `help` is | ||
| // Commander's own, not one of ours. | ||
| function cliOnlyCommands(command = compiledRoot(), path: string[] = []): [string[], Command][] { | ||
| const here = [...path, command.name()]; | ||
| const own: [string[], Command][] = isTuiCommandSupported(command) ? [] : [[here, command]]; | ||
| return [ | ||
| ...own, | ||
| ...command.commands | ||
| .filter((child) => child.name() !== "help") | ||
| .flatMap((child) => cliOnlyCommands(child, here)), | ||
| ]; | ||
| } | ||
|
|
||
| const CLI_ONLY = cliOnlyCommands(); | ||
|
|
||
| describe("menus list command-line-only subcommands below a divider", () => { | ||
| test("the root menu", async () => { | ||
| const r = renderScreen("/agentcore"); | ||
|
|
||
| await waitForText(r.lastFrame, "command line only"); | ||
| expect(menuEntries(r.lastFrame()!)).toEqual({ | ||
| screens: ["harness", "identity", "runtime", "memory", "gateway", "eval", "project"], | ||
| cliOnly: ["feedback", "config", "update"], | ||
| }); | ||
| r.unmount(); | ||
| }); | ||
|
|
||
| test("the eval menu", async () => { | ||
| const r = renderScreen("/agentcore/eval"); | ||
|
|
||
| await waitForText(r.lastFrame, "command line only"); | ||
| expect(menuEntries(r.lastFrame()!).cliOnly).toEqual(["ondemand", "recommendation"]); | ||
| r.unmount(); | ||
| }); | ||
|
|
||
| test("a menu whose every subcommand is command line only", async () => { | ||
| const r = renderScreen("/agentcore/eval/recommendation"); | ||
|
|
||
| await waitForText(r.lastFrame, "command line only"); | ||
| expect(menuEntries(r.lastFrame()!)).toEqual({ | ||
| screens: [], | ||
| cliOnly: ["start", "get", "list", "delete"], | ||
| }); | ||
| r.unmount(); | ||
| }); | ||
|
|
||
| test("the divider is omitted when nothing is command line only", async () => { | ||
| const r = renderScreen("/agentcore/harness"); | ||
|
|
||
| await waitForText(r.lastFrame, "manage agentcore harnesses"); | ||
| expect(r.lastFrame()).not.toContain("command line only"); | ||
| r.unmount(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("every command-line-only command opens on screen", () => { | ||
| test("there are command-line-only commands to cover", () => { | ||
| expect(CLI_ONLY.length).toBeGreaterThan(50); | ||
| }); | ||
|
|
||
| test.each(CLI_ONLY.map(([path, command]) => [path.join(" "), path, command] as const))( | ||
| "%s opens its menu or help, and esc returns to the parent", | ||
| async (_label, path, command) => { | ||
| const r = renderScreen("/" + path.join("/")); | ||
| // Wide and tall enough that no option term wraps and nothing is below the | ||
| // fold; scrolling and wrapping have their own tests. | ||
| await r.resize(220, 200); | ||
| const parent = command.parent!; | ||
|
|
||
| if (command.commands.length > 0) { | ||
| // A group opens its own menu, with every child under the divider. | ||
| await waitForText(r.lastFrame, path.join(" → ")); | ||
| await waitForText(r.lastFrame, "command line only"); | ||
| expect(menuEntries(r.lastFrame()!).screens).toEqual([]); | ||
| } else { | ||
| await waitForText(r.lastFrame, "this command runs from the command line"); | ||
| const help = command.createHelp(); | ||
| const frame = r.lastFrame()!.replace(/\s+/g, " "); | ||
| expect(frame).toContain(help.commandUsage(command)); | ||
| // Every option but --help, which means nothing on the help itself. | ||
| for (const option of help.visibleOptions(command)) { | ||
| if (option.long === "--help") expect(frame).not.toContain("--help"); | ||
| else expect(frame).toContain(help.optionTerm(option)); | ||
| } | ||
| for (const argument of help.visibleArguments(command)) { | ||
| expect(frame).toContain(help.argumentTerm(argument)); | ||
| } | ||
| } | ||
|
|
||
| await r.press("escape"); | ||
| await waitForText(r.lastFrame, parent.description()); | ||
| r.unmount(); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| describe("paths without a screen of their own", () => { | ||
| test("an unknown path retains the standard help fallback", async () => { | ||
| const r = renderScreen("/agentcore/gateway/no-such-command"); | ||
|
|
||
| await waitForText(() => r.frames.join("\n"), "Usage:"); | ||
| const output = r.frames.join("\n"); | ||
| expect(output).toContain("harness"); | ||
| expect(output).not.toContain("command line only"); | ||
| r.unmount(); | ||
| }); | ||
|
|
||
| test("a group drills down to a leaf's help and back", async () => { | ||
| const r = renderScreen("/agentcore/gateway"); | ||
|
|
||
| await waitForText(r.lastFrame, "command line only"); | ||
| await r.write("create"); | ||
| await waitForText(r.lastFrame, "❯ create"); | ||
| await r.press("return"); | ||
|
|
||
| await waitForText(r.lastFrame, "agentcore → gateway → create"); | ||
| const frame = r.lastFrame()!.replace(/\s+/g, " "); | ||
| expect(frame).toContain("this command runs from the command line"); | ||
| expect(frame).toContain("agentcore gateway create [options]"); | ||
| expect(frame).toContain("--authorizer-type"); | ||
|
|
||
| await r.press("escape"); | ||
| await waitForText(r.lastFrame, "inspect AgentCore Gateways"); | ||
| r.unmount(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to remove the HelpScreen fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm good question. I think we should preserve it because if an unknown or a new route is introduced, we should have that as a fallback. Let me revert it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added help screen back