@robota-sdk/agent-ui-terminal 3.0.0-beta.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +27 -0
- package/dist/node/index.cjs +32 -0
- package/dist/node/index.d.cts +1066 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.ts +1066 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +33 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +93 -0
- package/src/App.tsx +146 -0
- package/src/AppPresentation.tsx +190 -0
- package/src/AppView.tsx +26 -0
- package/src/BackgroundTaskPanel.tsx +73 -0
- package/src/CjkTextInput.tsx +336 -0
- package/src/ConfirmPrompt.tsx +140 -0
- package/src/ContextWarningBanner.tsx +45 -0
- package/src/ExecutionWorkspaceDetailPane.tsx +85 -0
- package/src/ExecutionWorkspaceSwitcher.tsx +213 -0
- package/src/HistorySearchOverlay.tsx +150 -0
- package/src/InputArea.tsx +338 -0
- package/src/ListPicker.tsx +158 -0
- package/src/MenuSelect.tsx +159 -0
- package/src/MessageList.tsx +308 -0
- package/src/MultiSelectList.tsx +294 -0
- package/src/PendingActionPrompt.tsx +121 -0
- package/src/PermissionPrompt.tsx +186 -0
- package/src/PluginTUI.tsx +258 -0
- package/src/RoleLabel.tsx +72 -0
- package/src/SafeText.tsx +66 -0
- package/src/SessionEventNotices.tsx +27 -0
- package/src/SessionPicker.tsx +72 -0
- package/src/SessionStatusBar.tsx +76 -0
- package/src/SlashAutocomplete.tsx +154 -0
- package/src/StatusBar.tsx +284 -0
- package/src/StreamingIndicator.tsx +145 -0
- package/src/SupervisedSessionView.tsx +455 -0
- package/src/TextPrompt.tsx +112 -0
- package/src/ThemePicker.tsx +366 -0
- package/src/ToolCommandOutput.tsx +48 -0
- package/src/ToolDiffBlock.tsx +44 -0
- package/src/TransportTUI.tsx +166 -0
- package/src/TuiInteractionChannel.ts +567 -0
- package/src/UpdateNotice.tsx +18 -0
- package/src/UsageSummaryEntry.tsx +49 -0
- package/src/WaveText.tsx +70 -0
- package/src/__tests__/ListPicker.test.tsx +188 -0
- package/src/__tests__/MenuSelect.test.tsx +127 -0
- package/src/__tests__/PendingActionPrompt.test.tsx +193 -0
- package/src/__tests__/PluginTUI.test.tsx +167 -0
- package/src/__tests__/SlashAutocomplete.test.tsx +162 -0
- package/src/__tests__/SupervisedSessionView-render.test.tsx +24 -0
- package/src/__tests__/SupervisedSessionView.test.tsx +629 -0
- package/src/__tests__/TextPrompt.test.tsx +112 -0
- package/src/__tests__/TransportTUI.test.tsx +124 -0
- package/src/__tests__/TuiInteractionChannel.askUser.test.ts +124 -0
- package/src/__tests__/TuiInteractionChannel.display-contract.test.ts +284 -0
- package/src/__tests__/TuiInteractionChannel.lifecycle.test.ts +642 -0
- package/src/__tests__/UpdateNotice.test.tsx +15 -0
- package/src/__tests__/abort-after-permission.test.tsx +160 -0
- package/src/__tests__/abort-streaming-e2e.test.tsx +183 -0
- package/src/__tests__/attention-bell-and-marks.test.ts +144 -0
- package/src/__tests__/autocomplete-editing-keys.test.tsx +127 -0
- package/src/__tests__/background-task-panel-countdown.test.tsx +75 -0
- package/src/__tests__/background-task-panel.test.tsx +98 -0
- package/src/__tests__/background-task-row-format.test.ts +152 -0
- package/src/__tests__/channel-factory-integration.test.ts +150 -0
- package/src/__tests__/cjk-defer-submit.test.tsx +67 -0
- package/src/__tests__/cjk-fallback-render.test.tsx +78 -0
- package/src/__tests__/cjk-text-input-flow.test.ts +186 -0
- package/src/__tests__/cjk-text-input.test.ts +191 -0
- package/src/__tests__/command-handoff-pty-e2e.test.ts +107 -0
- package/src/__tests__/command-output-summary.test.ts +95 -0
- package/src/__tests__/command-result-handler.test.ts +171 -0
- package/src/__tests__/compact-event-bridge.test.ts +20 -0
- package/src/__tests__/confirm-permission-flow.test.ts +149 -0
- package/src/__tests__/confirm-prompt.test.tsx +103 -0
- package/src/__tests__/contextual-keybindings-input.test.tsx +158 -0
- package/src/__tests__/default-tui-cli-adapter-host-settings.test.ts +45 -0
- package/src/__tests__/effort-reaches-the-session.test.ts +41 -0
- package/src/__tests__/execution-workspace-switcher.test.tsx +147 -0
- package/src/__tests__/execution-workspace-view-model.test.ts +94 -0
- package/src/__tests__/external-prompt-notice.test.tsx +100 -0
- package/src/__tests__/fixtures/command-handoff-driver.tsx +111 -0
- package/src/__tests__/fixtures/fake-editor.sh +7 -0
- package/src/__tests__/fixtures/terminal-handoff-driver.tsx +90 -0
- package/src/__tests__/fork-attach.test.tsx +235 -0
- package/src/__tests__/helpers/terminal-profiles.ts +152 -0
- package/src/__tests__/helpers/vt-cursor-interpreter.ts +175 -0
- package/src/__tests__/history-clear-broadcast.test.ts +66 -0
- package/src/__tests__/history-search-overlay.test.tsx +329 -0
- package/src/__tests__/humanize-tool-name.test.ts +30 -0
- package/src/__tests__/input-area-bottom-border.test.tsx +45 -0
- package/src/__tests__/input-area-flow.test.ts +199 -0
- package/src/__tests__/input-area-focus-handoff.test.tsx +77 -0
- package/src/__tests__/interaction-channel-charter.test.ts +13 -0
- package/src/__tests__/key-hint-consistency.test.tsx +249 -0
- package/src/__tests__/key-hint-footer.test.tsx +69 -0
- package/src/__tests__/live-trace-reaches-session.test.ts +14 -0
- package/src/__tests__/message-list-rendering.test.tsx +473 -0
- package/src/__tests__/org-policy-reaches-the-channel.test.ts +77 -0
- package/src/__tests__/output-style-reaches-session.test.ts +35 -0
- package/src/__tests__/palette-consistency.test.ts +330 -0
- package/src/__tests__/permission-prompt-availability.test.tsx +23 -0
- package/src/__tests__/permission-prompt-peer.test.tsx +34 -0
- package/src/__tests__/product-display-name.test.tsx +79 -0
- package/src/__tests__/prompt-queue.test.tsx +260 -0
- package/src/__tests__/provider-definitions-reach-the-session.test.ts +75 -0
- package/src/__tests__/pty/ask-user-question.ptytest.ts +72 -0
- package/src/__tests__/pty/background-work-switcher.ptytest.ts +53 -0
- package/src/__tests__/pty/behavior-2437-git.ptytest.ts +342 -0
- package/src/__tests__/pty/fixtures/ask-user-question.jsonl +3 -0
- package/src/__tests__/pty/fixtures/replay-conversation.jsonl +4 -0
- package/src/__tests__/pty/fixtures/screen-005-ask-shapes.jsonl +5 -0
- package/src/__tests__/pty/fixtures/screen-005-permission.jsonl +3 -0
- package/src/__tests__/pty/fixtures/screen-006-colors.jsonl +3 -0
- package/src/__tests__/pty/fixtures/screen-2002-themes.jsonl +5 -0
- package/src/__tests__/pty/flag-tui.ptytest.ts +56 -0
- package/src/__tests__/pty/flow-2006-deep-link.ptytest.ts +291 -0
- package/src/__tests__/pty/ime-cursor-tmux.ptytest.ts +165 -0
- package/src/__tests__/pty/ime-cursor.ptytest.ts +186 -0
- package/src/__tests__/pty/isolated-home.ts +64 -0
- package/src/__tests__/pty/org-policy.ptytest.ts +71 -0
- package/src/__tests__/pty/provider-setup.ptytest.ts +61 -0
- package/src/__tests__/pty/pty-driver.ts +153 -0
- package/src/__tests__/pty/replay-conversation.ptytest.ts +68 -0
- package/src/__tests__/pty/screen-005-prompt-footers.ptytest.ts +134 -0
- package/src/__tests__/pty/screen-006-no-color.ptytest.ts +138 -0
- package/src/__tests__/pty/screen-010-scrollback.ptytest.ts +123 -0
- package/src/__tests__/pty/screen-1993-scrollback.ptytest.ts +124 -0
- package/src/__tests__/pty/screen-2002-themes.ptytest.ts +292 -0
- package/src/__tests__/pty/screen-2670-prepark.ptytest.ts +228 -0
- package/src/__tests__/pty/screen-reader-mode.ptytest.ts +228 -0
- package/src/__tests__/pty/settings-screen.ptytest.ts +49 -0
- package/src/__tests__/pty/spawn-pty.test.ts +120 -0
- package/src/__tests__/pty/spawn-pty.ts +229 -0
- package/src/__tests__/pty/terminal-handoff.ptytest.ts +79 -0
- package/src/__tests__/pty/tui-pty.ptytest.ts +65 -0
- package/src/__tests__/pty-driver-dispose.test.ts +43 -0
- package/src/__tests__/real-cursor-positioning.test.tsx +263 -0
- package/src/__tests__/rename-broadcast-persistence.test.tsx +140 -0
- package/src/__tests__/render-channel-options.test.ts +201 -0
- package/src/__tests__/render-lifecycle.test.ts +36 -0
- package/src/__tests__/render-markdown.test.ts +164 -0
- package/src/__tests__/rendered-markdown-styling.test.tsx +98 -0
- package/src/__tests__/safe-text-boundary.test.tsx +75 -0
- package/src/__tests__/screen-reader-input.test.tsx +106 -0
- package/src/__tests__/screen-reader-labels.test.ts +91 -0
- package/src/__tests__/screen-reader-menus.test.tsx +200 -0
- package/src/__tests__/screen-reader-pacing.test.ts +230 -0
- package/src/__tests__/screen-reader-prepark-echo.test.tsx +200 -0
- package/src/__tests__/screen-reader-render-options.test.ts +262 -0
- package/src/__tests__/screen-reader-stdout.test.ts +322 -0
- package/src/__tests__/screen-reader-turn-marks-port.test.tsx +85 -0
- package/src/__tests__/screen-reader-turn-signals.test.tsx +125 -0
- package/src/__tests__/sec-019-terminal-sanitizer.test.ts +276 -0
- package/src/__tests__/sec-019-tool-label-render.test.tsx +207 -0
- package/src/__tests__/selection-flow.test.ts +61 -0
- package/src/__tests__/session-event-notices.test.tsx +31 -0
- package/src/__tests__/session-init-poller.test.ts +102 -0
- package/src/__tests__/session-switch-channel.test.tsx +470 -0
- package/src/__tests__/shutdown-signal.test.ts +34 -0
- package/src/__tests__/status-activity.test.ts +71 -0
- package/src/__tests__/status-bar.test.tsx +282 -0
- package/src/__tests__/status-glyph.test.ts +30 -0
- package/src/__tests__/streaming-indicator.test.tsx +177 -0
- package/src/__tests__/terminal-capabilities.test.ts +153 -0
- package/src/__tests__/terminal-handoff-controller.test.ts +173 -0
- package/src/__tests__/terminal-handoff-pty-e2e.test.ts +77 -0
- package/src/__tests__/text-prompt-flow.test.ts +77 -0
- package/src/__tests__/theme-picker.test.tsx +345 -0
- package/src/__tests__/transport-boundary.test.ts +11 -0
- package/src/__tests__/tui-app-channel-port.test.ts +31 -0
- package/src/__tests__/tui-channel-init-failure.test.ts +62 -0
- package/src/__tests__/tui-channel-lifecycle-coordinator.test.ts +258 -0
- package/src/__tests__/tui-interaction-queues.test.ts +139 -0
- package/src/__tests__/tui-preset-capabilities.test.ts +33 -0
- package/src/__tests__/tui-state-manager.error-stall.test.ts +169 -0
- package/src/__tests__/tui-state-manager.test.ts +451 -0
- package/src/__tests__/ui-intent-rendering.test.tsx +291 -0
- package/src/__tests__/wave-text.test.tsx +133 -0
- package/src/app-banner.tsx +42 -0
- package/src/app-static-items.ts +35 -0
- package/src/app-view-model.ts +136 -0
- package/src/attention/__tests__/attention-coordinator.test.ts +166 -0
- package/src/attention/__tests__/attention-tracker.test.ts +103 -0
- package/src/attention/__tests__/countdown.test.ts +15 -0
- package/src/attention/__tests__/focus-input-filter.test.ts +92 -0
- package/src/attention/__tests__/interval-recap.test.ts +49 -0
- package/src/attention/attention-coordinator.ts +71 -0
- package/src/attention/attention-tracker.ts +124 -0
- package/src/attention/countdown.ts +24 -0
- package/src/attention/focus-input-filter.ts +131 -0
- package/src/attention/interval-recap.ts +148 -0
- package/src/attention/time-units.ts +6 -0
- package/src/attention-bell.ts +79 -0
- package/src/attributed-user-echo.ts +30 -0
- package/src/background-task-row-format.ts +99 -0
- package/src/command-interaction.ts +8 -0
- package/src/command-output-summary.ts +129 -0
- package/src/create-default-tui-cli-adapter.ts +45 -0
- package/src/execution-workspace-switcher-selection.ts +118 -0
- package/src/execution-workspace-view-model.ts +139 -0
- package/src/external-prompt-notice.tsx +38 -0
- package/src/flows/__tests__/background-focus-flow.test.ts +48 -0
- package/src/flows/__tests__/defer-submit.test.ts +87 -0
- package/src/flows/__tests__/real-cursor-flow.test.ts +124 -0
- package/src/flows/background-focus-flow.ts +44 -0
- package/src/flows/cjk-cursor-motion.ts +75 -0
- package/src/flows/cjk-text-deletion.ts +53 -0
- package/src/flows/cjk-text-input-flow.ts +248 -0
- package/src/flows/cjk-text-input-types.ts +24 -0
- package/src/flows/confirm-prompt-flow.ts +90 -0
- package/src/flows/defer-submit.ts +67 -0
- package/src/flows/fork-attach-flow.ts +62 -0
- package/src/flows/input-area-flow.ts +188 -0
- package/src/flows/permission-prompt-flow.ts +108 -0
- package/src/flows/real-cursor-flow.ts +83 -0
- package/src/flows/selection-flow.ts +205 -0
- package/src/flows/session-init-poller.ts +76 -0
- package/src/flows/text-prompt-flow.ts +93 -0
- package/src/history-search/__tests__/history-search-flow.test.ts +86 -0
- package/src/history-search/history-search-flow.ts +94 -0
- package/src/history-search/useHistorySearch.ts +336 -0
- package/src/hooks/__tests__/use-app-loop-escape.test.tsx +74 -0
- package/src/hooks/__tests__/use-plugin-callbacks.test.ts +18 -0
- package/src/hooks/__tests__/use-tui-channel-stability.test.tsx +100 -0
- package/src/hooks/__tests__/useAppThemeState.test.tsx +130 -0
- package/src/hooks/command-result-handler.ts +44 -0
- package/src/hooks/side-effects-types.ts +45 -0
- package/src/hooks/useAppController.ts +267 -0
- package/src/hooks/useAppInputBindings.ts +145 -0
- package/src/hooks/useAppInteractionState.ts +81 -0
- package/src/hooks/useAppLifecycleState.ts +81 -0
- package/src/hooks/useAppOverlays.ts +74 -0
- package/src/hooks/useAppScreenState.ts +81 -0
- package/src/hooks/useAppSubmissionState.ts +45 -0
- package/src/hooks/useAppThemeState.ts +157 -0
- package/src/hooks/useAppWorkspaceState.ts +149 -0
- package/src/hooks/useAppearanceSettings.ts +30 -0
- package/src/hooks/useAutocomplete.ts +101 -0
- package/src/hooks/useBackgroundPanel.ts +58 -0
- package/src/hooks/useCountdownTick.ts +24 -0
- package/src/hooks/useExecutionDetailPage.ts +69 -0
- package/src/hooks/useForkAttach.ts +60 -0
- package/src/hooks/useInputAreaHistorySearch.ts +72 -0
- package/src/hooks/useInputAreaKeys.ts +114 -0
- package/src/hooks/useNumberedSelection.ts +76 -0
- package/src/hooks/usePluginCallbacks.ts +38 -0
- package/src/hooks/usePluginScreenData.ts +85 -0
- package/src/hooks/useRealCursorPosition.ts +125 -0
- package/src/hooks/useRenderMarkdown.ts +38 -0
- package/src/hooks/useScreenReaderTurnSignals.ts +113 -0
- package/src/hooks/useSideEffects.ts +144 -0
- package/src/hooks/useStatusLineSettings.ts +50 -0
- package/src/hooks/useTerminalHandoffSuspension.ts +30 -0
- package/src/hooks/useTuiChannel.ts +129 -0
- package/src/humanize-tool-name.ts +51 -0
- package/src/index.ts +56 -0
- package/src/input-area-rules.tsx +71 -0
- package/src/json-value.ts +18 -0
- package/src/key-hint-footer.tsx +54 -0
- package/src/keybindings/__tests__/keybinding-registry.test.ts +228 -0
- package/src/keybindings/__tests__/node-keybindings-source.test.ts +111 -0
- package/src/keybindings/keybinding-catalogue.ts +171 -0
- package/src/keybindings/keybinding-registry.ts +303 -0
- package/src/keybindings/keybinding-syntax.ts +155 -0
- package/src/keybindings/keybindings-context.tsx +124 -0
- package/src/keybindings/node-keybindings-source.ts +189 -0
- package/src/numbered-list.tsx +113 -0
- package/src/plugin-tui-handlers.ts +163 -0
- package/src/product-display-name-context.tsx +30 -0
- package/src/render-markdown.ts +209 -0
- package/src/render.tsx +544 -0
- package/src/sanitize-terminal-text.ts +171 -0
- package/src/screen-reader-announcement.ts +52 -0
- package/src/screen-reader-context.tsx +32 -0
- package/src/screen-reader-labels.ts +64 -0
- package/src/screen-reader-pacing-context.tsx +47 -0
- package/src/screen-reader-pacing.ts +178 -0
- package/src/screen-reader-stdout.ts +328 -0
- package/src/shutdown-signal.ts +34 -0
- package/src/status-activity.ts +70 -0
- package/src/status-glyph.ts +78 -0
- package/src/terminal-capabilities-context.tsx +27 -0
- package/src/terminal-capabilities.ts +77 -0
- package/src/terminal-focus-reporting.ts +50 -0
- package/src/terminal-handoff-controller.ts +98 -0
- package/src/terminal-marks.ts +63 -0
- package/src/theme/__tests__/built-in-themes.test.ts +117 -0
- package/src/theme/__tests__/color-vision.test.ts +82 -0
- package/src/theme/__tests__/theme-context.test.tsx +146 -0
- package/src/theme/__tests__/theme-document.test.ts +222 -0
- package/src/theme/__tests__/theme-registry.test.ts +138 -0
- package/src/theme/__tests__/theme-styles.test.ts +233 -0
- package/src/theme/built-in-themes.ts +342 -0
- package/src/theme/color-vision.ts +171 -0
- package/src/theme/index.ts +45 -0
- package/src/theme/theme-context.tsx +81 -0
- package/src/theme/theme-contracts.ts +139 -0
- package/src/theme/theme-document.ts +278 -0
- package/src/theme/theme-registry.ts +127 -0
- package/src/theme/theme-styles.ts +177 -0
- package/src/tool-summary-status.ts +59 -0
- package/src/tui-app-channel-port.ts +83 -0
- package/src/tui-channel-lifecycle-coordinator.ts +149 -0
- package/src/tui-channel-options.ts +172 -0
- package/src/tui-cli-adapter-context.tsx +13 -0
- package/src/tui-cli-adapter.ts +24 -0
- package/src/tui-interaction-queues.ts +163 -0
- package/src/tui-session-binding.ts +52 -0
- package/src/tui-session-event-projector.ts +140 -0
- package/src/tui-session-events.ts +82 -0
- package/src/tui-session-notice-store.ts +43 -0
- package/src/tui-session-options.ts +118 -0
- package/src/tui-state-manager.ts +327 -0
- package/src/types.ts +19 -0
- package/src/use-terminal-title.ts +29 -0
- package/src/utils/__tests__/edit-diff.test.ts +426 -0
- package/src/utils/__tests__/paste-detection.test.ts +116 -0
- package/src/utils/__tests__/paste-labels.test.ts +46 -0
- package/src/utils/__tests__/tool-call-extractor.test.ts +227 -0
- package/src/utils/__tests__/tool-diff-summary.test.ts +104 -0
- package/src/utils/edit-diff.ts +151 -0
- package/src/utils/input-top-border.ts +19 -0
- package/src/utils/paste-labels.ts +9 -0
- package/src/utils/tool-call-extractor.ts +92 -0
- package/src/utils/tool-diff-summary.ts +75 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
applyCjkTextInput,
|
|
4
|
+
applyCjkTextPaste,
|
|
5
|
+
createCjkTextInputFlowState,
|
|
6
|
+
syncCjkTextInputFlowState,
|
|
7
|
+
} from '../flows/cjk-text-input-flow.js';
|
|
8
|
+
|
|
9
|
+
describe('cjk text input flow', () => {
|
|
10
|
+
it('Given printable input When applied Then value changes at cursor', () => {
|
|
11
|
+
const result = applyCjkTextInput(
|
|
12
|
+
createCjkTextInputFlowState('ab'),
|
|
13
|
+
'c',
|
|
14
|
+
{},
|
|
15
|
+
{ canPaste: true },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(result.state).toMatchObject({ value: 'abc', cursor: 3 });
|
|
19
|
+
expect(result.effect).toEqual({ type: 'change', value: 'abc' });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Given cursor in middle When backspace is applied Then previous char is removed', () => {
|
|
23
|
+
const state = { ...createCjkTextInputFlowState('abc'), cursor: 2 };
|
|
24
|
+
|
|
25
|
+
const result = applyCjkTextInput(state, '', { backspace: true }, { canPaste: true });
|
|
26
|
+
|
|
27
|
+
expect(result.state).toMatchObject({ value: 'ac', cursor: 1 });
|
|
28
|
+
expect(result.effect).toEqual({ type: 'change', value: 'ac' });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('Given return key When applied Then submit effect contains current value', () => {
|
|
32
|
+
const result = applyCjkTextInput(
|
|
33
|
+
createCjkTextInputFlowState('hello'),
|
|
34
|
+
'',
|
|
35
|
+
{ return: true },
|
|
36
|
+
{ canPaste: true },
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(result.effect).toEqual({ type: 'submit', value: 'hello' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Given multiline fallback paste When applied Then paste effect is emitted', () => {
|
|
43
|
+
const result = applyCjkTextInput(
|
|
44
|
+
createCjkTextInputFlowState(''),
|
|
45
|
+
'a\nb',
|
|
46
|
+
{},
|
|
47
|
+
{ canPaste: true },
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(result.effect).toEqual({ type: 'paste', text: 'a\nb', cursor: 0 });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('Given Ink usePaste single-line text When applied Then text is inserted at cursor', () => {
|
|
54
|
+
const state = { ...createCjkTextInputFlowState('ab'), cursor: 1 };
|
|
55
|
+
|
|
56
|
+
const result = applyCjkTextPaste(state, '한글', { canPaste: true });
|
|
57
|
+
|
|
58
|
+
expect(result.state).toMatchObject({ value: 'a한글b', cursor: 3 });
|
|
59
|
+
expect(result.effect).toEqual({ type: 'change', value: 'a한글b' });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('Given Ink usePaste multiline text When applied Then normalized paste effect is emitted', () => {
|
|
63
|
+
const state = { ...createCjkTextInputFlowState('ab'), cursor: 1 };
|
|
64
|
+
|
|
65
|
+
const result = applyCjkTextPaste(state, 'x\r\ny\rz', { canPaste: true });
|
|
66
|
+
|
|
67
|
+
expect(result.state).toBe(state);
|
|
68
|
+
expect(result.effect).toEqual({ type: 'paste', text: 'x\ny\nz', cursor: 1 });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('Given bracketed multiline paste When end marker arrives Then buffered paste is emitted', () => {
|
|
72
|
+
const started = applyCjkTextInput(
|
|
73
|
+
createCjkTextInputFlowState('x'),
|
|
74
|
+
'[200~hello',
|
|
75
|
+
{},
|
|
76
|
+
{ canPaste: true },
|
|
77
|
+
).state;
|
|
78
|
+
const result = applyCjkTextInput(started, '\nworld[201~', {}, { canPaste: true });
|
|
79
|
+
|
|
80
|
+
expect(result.effect).toEqual({ type: 'paste', text: 'hello\nworld', cursor: 1 });
|
|
81
|
+
expect(result.state.isPasting).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('Given external value update When synced Then cursor hint is honored', () => {
|
|
85
|
+
const state = createCjkTextInputFlowState('abc');
|
|
86
|
+
|
|
87
|
+
const result = syncCjkTextInputFlowState(state, 'a[Pasted]bc', 9);
|
|
88
|
+
|
|
89
|
+
expect(result).toMatchObject({ value: 'a[Pasted]bc', cursor: 9 });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('Given vertical navigation disabled When up arrow is applied Then cursor is unchanged', () => {
|
|
93
|
+
const state = { ...createCjkTextInputFlowState('abcdef'), cursor: 5 };
|
|
94
|
+
|
|
95
|
+
const result = applyCjkTextInput(
|
|
96
|
+
state,
|
|
97
|
+
'',
|
|
98
|
+
{ upArrow: true },
|
|
99
|
+
{
|
|
100
|
+
canPaste: true,
|
|
101
|
+
enableVerticalNavigation: false,
|
|
102
|
+
availableWidth: 2,
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(result.state).toBe(state);
|
|
107
|
+
expect(result.effect).toEqual({ type: 'none' });
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* CLI-2004 — `Ctrl+W` and `Ctrl+U` are NEW BINDINGS, and they are unconditional.
|
|
113
|
+
*
|
|
114
|
+
* Ink reports `Ctrl+W` as `input: 'w'` with `ctrl: true`, so before this change the keystroke fell
|
|
115
|
+
* through to the printable path and typed a literal `w` into the buffer. That is a defect on the
|
|
116
|
+
* default path, not only in screen-reader mode, so the fix is not gated on the mode — which makes it
|
|
117
|
+
* a change to today's behaviour, and these cases are where that change is pinned. What the mode adds
|
|
118
|
+
* is only the announcement, which is `InputArea`'s to render from `deleted` / `deletedScope`.
|
|
119
|
+
*/
|
|
120
|
+
describe('CLI-2004 — word and line deletion are default bindings, not mode-gated ones', () => {
|
|
121
|
+
it('Given Ctrl+W When applied Then the word before the cursor is deleted, not a "w" typed', () => {
|
|
122
|
+
const result = applyCjkTextInput(
|
|
123
|
+
createCjkTextInputFlowState('hello world'),
|
|
124
|
+
'w',
|
|
125
|
+
{ ctrl: true },
|
|
126
|
+
{ canPaste: true },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result.state).toMatchObject({ value: 'hello ', cursor: 6 });
|
|
130
|
+
expect(result.effect).toEqual({
|
|
131
|
+
type: 'change',
|
|
132
|
+
value: 'hello ',
|
|
133
|
+
deleted: 'world',
|
|
134
|
+
deletedScope: 'word',
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('Given Ctrl+W with trailing spaces Then the spaces go with the word, as every shell does', () => {
|
|
139
|
+
const result = applyCjkTextInput(
|
|
140
|
+
createCjkTextInputFlowState('one two '),
|
|
141
|
+
'w',
|
|
142
|
+
{ ctrl: true },
|
|
143
|
+
{ canPaste: true },
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(result.state.value).toBe('one ');
|
|
147
|
+
expect(result.effect).toMatchObject({ deleted: 'two ', deletedScope: 'word' });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('Given Ctrl+U When applied Then everything before the cursor is deleted', () => {
|
|
151
|
+
const state = { ...createCjkTextInputFlowState('abc def'), cursor: 4 };
|
|
152
|
+
|
|
153
|
+
const result = applyCjkTextInput(state, 'u', { ctrl: true }, { canPaste: true });
|
|
154
|
+
|
|
155
|
+
expect(result.state).toMatchObject({ value: 'def', cursor: 0 });
|
|
156
|
+
expect(result.effect).toEqual({
|
|
157
|
+
type: 'change',
|
|
158
|
+
value: 'def',
|
|
159
|
+
deleted: 'abc ',
|
|
160
|
+
deletedScope: 'line',
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('Given a plain "w" with no ctrl Then it is still typed', () => {
|
|
165
|
+
const result = applyCjkTextInput(
|
|
166
|
+
createCjkTextInputFlowState('ne'),
|
|
167
|
+
'w',
|
|
168
|
+
{},
|
|
169
|
+
{ canPaste: true },
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(result.state.value).toBe('new');
|
|
173
|
+
expect(result.effect).toEqual({ type: 'change', value: 'new' });
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('Given the cursor at the start Then either deletion is a no-op rather than an empty change', () => {
|
|
177
|
+
const state = createCjkTextInputFlowState('');
|
|
178
|
+
|
|
179
|
+
expect(applyCjkTextInput(state, 'w', { ctrl: true }, { canPaste: true }).effect).toEqual({
|
|
180
|
+
type: 'none',
|
|
181
|
+
});
|
|
182
|
+
expect(applyCjkTextInput(state, 'u', { ctrl: true }, { canPaste: true }).effect).toEqual({
|
|
183
|
+
type: 'none',
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for CjkTextInput pure utility functions.
|
|
3
|
+
*
|
|
4
|
+
* These test the input filtering and insertion logic extracted from
|
|
5
|
+
* the React component, without requiring Ink/React rendering.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect } from 'vitest';
|
|
9
|
+
import {
|
|
10
|
+
filterPrintable,
|
|
11
|
+
insertAtCursor,
|
|
12
|
+
displayOffset,
|
|
13
|
+
charIndexAtDisplayOffset,
|
|
14
|
+
} from '../flows/cjk-text-input-flow.js';
|
|
15
|
+
|
|
16
|
+
describe('filterPrintable', () => {
|
|
17
|
+
it('returns empty string for null input', () => {
|
|
18
|
+
expect(filterPrintable(null)).toBe('');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('returns empty string for undefined input', () => {
|
|
22
|
+
expect(filterPrintable(undefined)).toBe('');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('returns empty string for empty string', () => {
|
|
26
|
+
expect(filterPrintable('')).toBe('');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('passes through normal ASCII text', () => {
|
|
30
|
+
expect(filterPrintable('hello')).toBe('hello');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('passes through Korean characters', () => {
|
|
34
|
+
expect(filterPrintable('안녕하세요')).toBe('안녕하세요');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('passes through emoji', () => {
|
|
38
|
+
expect(filterPrintable('🎉')).toBe('🎉');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('filters out null byte', () => {
|
|
42
|
+
expect(filterPrintable('\x00')).toBe('');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('filters out escape character', () => {
|
|
46
|
+
expect(filterPrintable('\x1b')).toBe('');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('filters out DEL character', () => {
|
|
50
|
+
expect(filterPrintable('\x7f')).toBe('');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('filters out mixed control characters, keeps printable', () => {
|
|
54
|
+
expect(filterPrintable('\x01hello\x02world\x7f')).toBe('helloworld');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns empty when input is only control characters', () => {
|
|
58
|
+
expect(filterPrintable('\x00\x01\x02\x03\x1f\x7f')).toBe('');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('handles tab character (0x09) — filtered as control', () => {
|
|
62
|
+
expect(filterPrintable('\t')).toBe('');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('handles newline (0x0a) — filtered as control', () => {
|
|
66
|
+
expect(filterPrintable('\n')).toBe('');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('insertAtCursor', () => {
|
|
71
|
+
it('inserts at the beginning', () => {
|
|
72
|
+
const result = insertAtCursor('world', 0, 'hello ');
|
|
73
|
+
expect(result.value).toBe('hello world');
|
|
74
|
+
expect(result.cursor).toBe(6);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('inserts at the end', () => {
|
|
78
|
+
const result = insertAtCursor('hello', 5, ' world');
|
|
79
|
+
expect(result.value).toBe('hello world');
|
|
80
|
+
expect(result.cursor).toBe(11);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('inserts in the middle', () => {
|
|
84
|
+
const result = insertAtCursor('helo', 3, 'l');
|
|
85
|
+
expect(result.value).toBe('hello');
|
|
86
|
+
expect(result.cursor).toBe(4);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('inserts into empty string', () => {
|
|
90
|
+
const result = insertAtCursor('', 0, 'abc');
|
|
91
|
+
expect(result.value).toBe('abc');
|
|
92
|
+
expect(result.cursor).toBe(3);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('handles multi-character paste', () => {
|
|
96
|
+
const result = insertAtCursor('ac', 1, 'bb');
|
|
97
|
+
expect(result.value).toBe('abbc');
|
|
98
|
+
expect(result.cursor).toBe(3);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('handles Korean character insertion', () => {
|
|
102
|
+
const result = insertAtCursor('안세요', 1, '녕하');
|
|
103
|
+
expect(result.value).toBe('안녕하세요');
|
|
104
|
+
expect(result.cursor).toBe(3);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('handles emoji insertion', () => {
|
|
108
|
+
const result = insertAtCursor('hello world', 6, '🎉 ');
|
|
109
|
+
expect(result.value).toBe('hello 🎉 world');
|
|
110
|
+
expect(result.cursor).toBe(9);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('displayOffset', () => {
|
|
115
|
+
it('returns 0 for charIndex 0', () => {
|
|
116
|
+
expect(displayOffset([...'hello'], 0, 10)).toBe(0);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns char count for ASCII within one line', () => {
|
|
120
|
+
expect(displayOffset([...'hello'], 3, 10)).toBe(3);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('accumulates across wrap boundary', () => {
|
|
124
|
+
// "abcde" width 3: offset at index 4 = 4 (abc on line 0, de on line 1)
|
|
125
|
+
expect(displayOffset([...'abcde'], 4, 3)).toBe(4);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('cursor before CJK char is at end of previous content', () => {
|
|
129
|
+
// "abcd한" width 5: cursor before "한" is at col 4 on line 0
|
|
130
|
+
// gap happens when "한" renders, not at cursor position
|
|
131
|
+
expect(displayOffset([...'abcd한'], 4, 5)).toBe(4);
|
|
132
|
+
// cursor after "한": 4(gap included) + 2 = 7 → but via offset: gap is at render
|
|
133
|
+
expect(displayOffset([...'abcd한'], 5, 5)).toBe(7);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('handles pure CJK', () => {
|
|
137
|
+
// "한글" width 5: "한"=2, "글"=2 → total 4, fits on one line
|
|
138
|
+
expect(displayOffset([...'한글'], 2, 5)).toBe(4);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('handles CJK wrapping', () => {
|
|
142
|
+
// "한글테" width 5: cursor before "테" is after "글" (offset 4)
|
|
143
|
+
// "테" doesn't fit at col 4, but cursor is BEFORE the wrap
|
|
144
|
+
expect(displayOffset([...'한글테'], 2, 5)).toBe(4);
|
|
145
|
+
// cursor after "테": gap(1) + 2 = offset 7
|
|
146
|
+
expect(displayOffset([...'한글테'], 3, 5)).toBe(7);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('charIndexAtDisplayOffset', () => {
|
|
151
|
+
it('returns 0 for offset 0', () => {
|
|
152
|
+
expect(charIndexAtDisplayOffset([...'hello'], 0, 10)).toBe(0);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('finds correct index for ASCII', () => {
|
|
156
|
+
expect(charIndexAtDisplayOffset([...'hello'], 3, 10)).toBe(3);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('returns text length when offset exceeds text', () => {
|
|
160
|
+
expect(charIndexAtDisplayOffset([...'hi'], 100, 10)).toBe(2);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('round-trips with displayOffset for ASCII', () => {
|
|
164
|
+
const text = 'abcdefghij';
|
|
165
|
+
const chars = [...text];
|
|
166
|
+
const width = 4;
|
|
167
|
+
for (let i = 0; i <= chars.length; i++) {
|
|
168
|
+
const off = displayOffset(chars, i, width);
|
|
169
|
+
expect(charIndexAtDisplayOffset(chars, off, width)).toBe(i);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('round-trips with displayOffset for CJK', () => {
|
|
174
|
+
const text = '한글테스트';
|
|
175
|
+
const chars = [...text];
|
|
176
|
+
const width = 5;
|
|
177
|
+
for (let i = 0; i <= chars.length; i++) {
|
|
178
|
+
const off = displayOffset(chars, i, width);
|
|
179
|
+
expect(charIndexAtDisplayOffset(chars, off, width)).toBe(i);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('up arrow simulation: offset - width gives previous line position', () => {
|
|
184
|
+
// "abcdef" width 3: line 0 = "abc", line 1 = "def"
|
|
185
|
+
// cursor at index 4 (line 1, col 1) → offset = 4
|
|
186
|
+
// offset - 3 = 1 → charIndex 1 (line 0, col 1)
|
|
187
|
+
const chars = [...'abcdef'];
|
|
188
|
+
const off = displayOffset(chars, 4, 3);
|
|
189
|
+
expect(charIndexAtDisplayOffset(chars, off - 3, 3)).toBe(1);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEST-007 / TERM-003 + TERM-004: `/shell` and `/editor` through a real terminal handoff, end-to-end
|
|
3
|
+
* in a PTY. Drives `fixtures/command-handoff-driver.tsx` (real executors + real
|
|
4
|
+
* `TerminalHandoffController`). Proves on a real TTY that the child (subshell / `$EDITOR`) receives
|
|
5
|
+
* the driver's keystrokes and the command returns cleanly — the behavior only a PTY can validate
|
|
6
|
+
* (the session command-pipeline path is covered by the framework functional tests with a fake
|
|
7
|
+
* handoff).
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, readFileSync, rmSync, realpathSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
15
|
+
|
|
16
|
+
import { createPtyEnv } from './pty/isolated-home.js';
|
|
17
|
+
import { spawnPtyFixture } from './pty/spawn-pty.js';
|
|
18
|
+
|
|
19
|
+
import type { IPtyRunSession } from './pty/spawn-pty.js';
|
|
20
|
+
|
|
21
|
+
const FIXTURE = fileURLToPath(new URL('./fixtures/command-handoff-driver.tsx', import.meta.url));
|
|
22
|
+
const FAKE_EDITOR = fileURLToPath(new URL('./fixtures/fake-editor.sh', import.meta.url));
|
|
23
|
+
const PACKAGE_DIR = fileURLToPath(new URL('../..', import.meta.url));
|
|
24
|
+
const TEST_TIMEOUT_MS = 30_000;
|
|
25
|
+
|
|
26
|
+
const tempDirs: string[] = [];
|
|
27
|
+
const sessions: IPtyRunSession[] = [];
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
for (const session of sessions.splice(0)) session.dispose();
|
|
31
|
+
for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
interface IResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
message: string;
|
|
37
|
+
exitCode?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readResult(outputPath: string): IResult {
|
|
41
|
+
return JSON.parse(readFileSync(outputPath, 'utf8')) as IResult;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('command handoff PTY E2E', () => {
|
|
45
|
+
it(
|
|
46
|
+
'/shell runs a one-shot command on the real terminal and returns its exit code',
|
|
47
|
+
async () => {
|
|
48
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'robota-shell-pty-')));
|
|
49
|
+
tempDirs.push(dir);
|
|
50
|
+
const outputPath = join(dir, 'result.json');
|
|
51
|
+
const session = spawnPtyFixture(FIXTURE, {
|
|
52
|
+
argv: ['shell', outputPath, 'IFS= read -r line; printf "SHELL_GOT:[%s]\\n" "$line"'],
|
|
53
|
+
cwd: PACKAGE_DIR,
|
|
54
|
+
// HARNESS-025: isolated HOME — the subshell must not read the developer's `~` (a real
|
|
55
|
+
// shell rc there would otherwise change what the handoff child does).
|
|
56
|
+
env: createPtyEnv(),
|
|
57
|
+
});
|
|
58
|
+
sessions.push(session);
|
|
59
|
+
|
|
60
|
+
await session.waitFor('READY canHandoff=true', 10_000);
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
62
|
+
await session.sendKeys('shell-input', 10);
|
|
63
|
+
session.write('\r');
|
|
64
|
+
await session.waitFor('CMD_DONE', 10_000);
|
|
65
|
+
session.write('r');
|
|
66
|
+
await session.waitFor('INPUT_AFTER_HANDOFF r', 10_000);
|
|
67
|
+
expect(await session.expectExit(5_000)).toBe(0);
|
|
68
|
+
|
|
69
|
+
expect(session.snapshot()).toContain('SHELL_GOT:[shell-input]');
|
|
70
|
+
const result = readResult(outputPath);
|
|
71
|
+
expect(result.success).toBe(true);
|
|
72
|
+
expect(result.exitCode).toBe(0);
|
|
73
|
+
},
|
|
74
|
+
TEST_TIMEOUT_MS,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
it(
|
|
78
|
+
'/editor opens $EDITOR on the real terminal and round-trips the composed text',
|
|
79
|
+
async () => {
|
|
80
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'robota-editor-pty-')));
|
|
81
|
+
tempDirs.push(dir);
|
|
82
|
+
const outputPath = join(dir, 'result.json');
|
|
83
|
+
const session = spawnPtyFixture(FIXTURE, {
|
|
84
|
+
argv: ['editor', outputPath, ''],
|
|
85
|
+
cwd: PACKAGE_DIR,
|
|
86
|
+
// HARNESS-025: isolated HOME — only the EDITOR override comes from the test, so a real
|
|
87
|
+
// `~/.selected_editor` (or similar) on the host cannot influence the assertion.
|
|
88
|
+
env: createPtyEnv({ EDITOR: `sh ${FAKE_EDITOR}` }),
|
|
89
|
+
});
|
|
90
|
+
sessions.push(session);
|
|
91
|
+
|
|
92
|
+
await session.waitFor('READY canHandoff=true', 10_000);
|
|
93
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
94
|
+
await session.sendKeys('composed-in-editor', 10);
|
|
95
|
+
session.write('\r');
|
|
96
|
+
await session.waitFor('CMD_DONE', 10_000);
|
|
97
|
+
session.write('r');
|
|
98
|
+
await session.waitFor('INPUT_AFTER_HANDOFF r', 10_000);
|
|
99
|
+
expect(await session.expectExit(5_000)).toBe(0);
|
|
100
|
+
|
|
101
|
+
const result = readResult(outputPath);
|
|
102
|
+
expect(result.success).toBe(true);
|
|
103
|
+
expect(result.message).toBe('composed-in-editor');
|
|
104
|
+
},
|
|
105
|
+
TEST_TIMEOUT_MS,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { formatCommandOutputSummary } from '../command-output-summary.js';
|
|
3
|
+
|
|
4
|
+
describe('formatCommandOutputSummary', () => {
|
|
5
|
+
it('renders short command output inline without transcript decoration', () => {
|
|
6
|
+
const summary = formatCommandOutputSummary({
|
|
7
|
+
toolName: 'Bash',
|
|
8
|
+
firstArg: 'echo hello',
|
|
9
|
+
isRunning: false,
|
|
10
|
+
result: 'success',
|
|
11
|
+
toolResultData: JSON.stringify({ success: true, output: 'hello\n', exitCode: 0 }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(summary).toMatchObject({
|
|
15
|
+
status: 'success',
|
|
16
|
+
statusLabel: 'ok',
|
|
17
|
+
previewLines: ['hello'],
|
|
18
|
+
omittedLineCount: 0,
|
|
19
|
+
transcriptHint: undefined,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('renders long command output with a bounded preview and transcript hint', () => {
|
|
24
|
+
const output = Array.from({ length: 8 }, (_, index) => `line-${index + 1}`).join('\n');
|
|
25
|
+
const summary = formatCommandOutputSummary({
|
|
26
|
+
toolName: 'Bash',
|
|
27
|
+
firstArg: 'pnpm test',
|
|
28
|
+
isRunning: false,
|
|
29
|
+
result: 'success',
|
|
30
|
+
toolResultData: JSON.stringify({ success: true, output, exitCode: 0 }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(summary?.previewLines).toEqual(['line-1', 'line-2', 'line-3', 'line-4']);
|
|
34
|
+
expect(summary?.omittedLineCount).toBe(4);
|
|
35
|
+
expect(summary?.transcriptHint).toBe('... +4 lines (full output in session transcript)');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('keeps stderr distinct when stdout and stderr are structured separately', () => {
|
|
39
|
+
const summary = formatCommandOutputSummary({
|
|
40
|
+
toolName: 'Bash',
|
|
41
|
+
firstArg: 'node script.js',
|
|
42
|
+
isRunning: false,
|
|
43
|
+
result: 'success',
|
|
44
|
+
toolResultData: JSON.stringify({
|
|
45
|
+
success: true,
|
|
46
|
+
stdout: 'ok',
|
|
47
|
+
stderr: 'warn',
|
|
48
|
+
exitCode: 0,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(summary?.previewLines).toEqual(['ok', '[stderr] warn']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('marks non-zero exit codes as failed even when the tool transport succeeded', () => {
|
|
56
|
+
const summary = formatCommandOutputSummary({
|
|
57
|
+
toolName: 'Bash',
|
|
58
|
+
firstArg: 'exit 42',
|
|
59
|
+
isRunning: false,
|
|
60
|
+
result: 'success',
|
|
61
|
+
toolResultData: JSON.stringify({ success: true, output: '', exitCode: 42 }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(summary?.status).toBe('error');
|
|
65
|
+
expect(summary?.statusLabel).toBe('exit 42');
|
|
66
|
+
expect(summary?.previewLines).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('renders no-output commands without dangling transcript hints', () => {
|
|
70
|
+
const summary = formatCommandOutputSummary({
|
|
71
|
+
toolName: 'Bash',
|
|
72
|
+
firstArg: 'true',
|
|
73
|
+
isRunning: false,
|
|
74
|
+
result: 'success',
|
|
75
|
+
toolResultData: JSON.stringify({ success: true, output: '', exitCode: 0 }),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(summary?.status).toBe('success');
|
|
79
|
+
expect(summary?.previewLines).toEqual([]);
|
|
80
|
+
expect(summary?.omittedLineCount).toBe(0);
|
|
81
|
+
expect(summary?.transcriptHint).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('ignores non-command tools', () => {
|
|
85
|
+
const summary = formatCommandOutputSummary({
|
|
86
|
+
toolName: 'Read',
|
|
87
|
+
firstArg: 'file.ts',
|
|
88
|
+
isRunning: false,
|
|
89
|
+
result: 'success',
|
|
90
|
+
toolResultData: 'large file content',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(summary).toBeUndefined();
|
|
94
|
+
});
|
|
95
|
+
});
|