fix(terminal): keep running-command tooltips concise (#6991)

Co-authored-by: Bill Leoutsakos <billleoutsakos@Bills-MacBook-Pro.local>
This commit is contained in:
Bill Leoutsakos
2026-08-22 17:01:22 -07:00
committed by GitHub
co-authored by Bill Leoutsakos
parent cbf3aad569
commit 6f919ef192
2 changed files with 42 additions and 5 deletions
@@ -9,8 +9,45 @@ import {
terminalFontSizeForZoom,
terminalSelectionLabel,
terminalSelectionSnapshot,
terminalTooltip,
} from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-session'
describe('terminal tab tooltips', () => {
it('summarizes a long compound heredoc command by its foreground program', () => {
const running = `mkdir -p ~/.doordash-bot/bin && cat > ~/.doordash-bot/bin/dd-cli-mock <<'EOF'
#!/usr/bin/env node
const carts = new Map()
process.stdout.write(JSON.stringify([...carts]))
EOF
chmod +x ~/.doordash-bot/bin/dd-cli-mock && echo '--- smoke test ---' && ~/.doordash-bot/bin/dd-cli-mock submit mock_123`
const tooltip = terminalTooltip({
terminalId: 'terminal-1',
title: 'mkdir',
cwd: '/Users/emirkarabeg',
running,
interactive: false,
active: false,
})
expect(tooltip).toBe('/Users/emirkarabeg — dd-cli-mock')
expect(tooltip).not.toContain('const carts')
})
it('preserves the working-directory tooltip for idle terminals', () => {
const idleTab = {
terminalId: 'terminal-1',
title: 'sim',
cwd: '/Users/emirkarabeg/sim',
running: null,
interactive: false,
active: true,
}
expect(terminalTooltip(idleTab)).toBe('/Users/emirkarabeg/sim')
expect(terminalTooltip({ ...idleTab, cwd: null })).toBe('Terminal')
})
})
describe('suspended terminal resource lifecycle', () => {
it('does not remove a resource when administrative suspension clears its PTYs', () => {
expect(shouldRemoveTerminalResource(0, true, true)).toBe(false)
@@ -114,10 +114,10 @@ function hideMountedMenuSurfaces(): void {
*/
const COMMAND_SETTLE_MS = 1_000
/** Full working directory, plus whatever the shell is running in it. */
function terminalTooltip(tab: TerminalTabState): string {
/** Full working directory, plus a concise name for whatever the shell is running. */
export function terminalTooltip(tab: TerminalTabState): string {
const where = tab.cwd ?? 'Terminal'
return tab.running ? `${where} — ${tab.running}` : where
return tab.running ? `${where} — ${describeRunningCommand(tab.running)}` : where
}
function sameIds(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
@@ -902,8 +902,8 @@ export function TerminalSession({ visible, scopeId }: TerminalSessionProps) {
id: tab.terminalId,
title: counts.get(label) === 1 ? label : `${label} ${occurrence}`,
// The label is a basename, and the tab may be running something it
// is not naming yet, so hovering gives the whole picture: where the
// shell is, and what it is doing there.
// is not naming yet, so hovering identifies the working directory and
// foreground program without exposing the literal command.
tooltip: terminalTooltip(tab),
icon: (
<TerminalTabIcon