Files
Netcatty/components/terminal/useTerminalContextActions.test.ts
T
cb06857480 feat(terminal): confirm before pasting multiple lines (#3398) (#3400)
* fix(#3398): automated AI fix

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix: address Codex review on PR #3400

* fix(terminal): protect popup and sanitized multiline pastes

* fix(terminal): preserve input state across paste confirmation

* fix(terminal): retain serial character-mode paste echo

* test(terminal): cover paced input write options

* fix(terminal): retain telnet echo for paced pastes

* test(terminal): scope serial buffer assertion to serial sessions

* fix(terminal): align runtime write options with bridge contract

* fix(terminal): preserve bookkeeping for all paced pastes

* fix(terminal): record confirmed paste lines in order

* fix: record paced paste commands after transport writes

* fix: omit paste receipts for filtered input

* fix: cancel superseded paste batches across input paths

* fix: classify each acknowledged paste line before recording

* fix: stop paced paste when editing buffered serial input

* fix: preserve recording pause boundaries and serial edit cancellation

* fix: treat paced terminal pastes as user input

* fix: preserve paste drafts until write and snippet broadcast origin

* fix: retain filtered paste drafts and invalidate urgent input ownership

* fix: broadcast paced user paste only on guarded line receipts

---------

Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
2026-09-18 15:19:34 +08:00

93 lines
3.8 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { broadcastTerminalPasteData } from "./hooks/useTerminalContextActions";
test("terminal context paste reports whether it broadcast to peers", () => {
const broadcasted: Array<{ data: string; sessionId: string }> = [];
const didBroadcast = broadcastTerminalPasteData("line one", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "backend-session-1" },
isBroadcastEnabledRef: { current: true },
onBroadcastInputRef: {
current: (data, sourceSessionId) => {
broadcasted.push({ data, sessionId: sourceSessionId });
},
},
});
assert.equal(didBroadcast, true);
assert.deepEqual(broadcasted, [{ data: "line one", sessionId: "workspace-session-1" }]);
});
test("terminal context paste forwards paste options to the broadcast handler", () => {
const broadcasted: Array<{ data: string; sessionId: string; options?: { lineDelayMs?: number } }> = [];
const didBroadcast = broadcastTerminalPasteData("line one", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "backend-session-1" },
isBroadcastEnabledRef: { current: true },
onBroadcastInputRef: {
current: (data, sourceSessionId, options) => {
broadcasted.push({ data, sessionId: sourceSessionId, options });
},
},
}, { lineDelayMs: 250 });
assert.equal(didBroadcast, true);
assert.deepEqual(broadcasted, [
{ data: "line one", sessionId: "workspace-session-1", options: { lineDelayMs: 250 } },
]);
});
test("terminal context paste reports false when broadcast is disabled", () => {
const didBroadcast = broadcastTerminalPasteData("line one", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "session-1" },
isBroadcastEnabledRef: { current: false },
onBroadcastInputRef: {
current: () => {
throw new Error("broadcast should not run");
},
},
});
assert.equal(didBroadcast, false);
});
test("paste selection dismisses the history preview before sending text", async () => {
const { readFileSync } = await import("node:fs");
const source = readFileSync(new URL("./hooks/useTerminalContextActions.ts", import.meta.url), "utf8");
assert.match(source, /requestHistoryPreviewHide\(term\.element\?\.parentElement\)/);
assert.equal(source.split("requestHistoryPreviewHide(term.element?.parentElement)").length - 1, 2);
});
test("paste selection routes through the multi-line paste confirmation gate", async () => {
const { readFileSync } = await import("node:fs");
const source = readFileSync(new URL("./hooks/useTerminalContextActions.ts", import.meta.url), "utf8");
const runtimeSource = readFileSync(new URL("./runtime/createXTermRuntime.ts", import.meta.url), "utf8");
// Context-menu Paste Selection goes through the shared #3398 gate.
assert.match(source, /const onPasteSelection = useCallback\(async \(\) => \{[\s\S]*?pasteTextWithMultilineConfirm\(selection, \{[\s\S]*?requestMultilinePasteConfirm/u);
// The pasteSelection shortcut applies the same gate instead of pasting
// the selected text directly into the session.
assert.match(runtimeSource, /case "pasteSelection": \{[\s\S]*?pasteTextWithMultilineConfirm\(selection, \{/u);
assert.doesNotMatch(runtimeSource, /case "pasteSelection":[\s\S]*?pasteTextIntoTerminal/u);
});
test("terminal context paste never broadcasts password-prompt input", () => {
const didBroadcast = broadcastTerminalPasteData("secret", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "session-1" },
isBroadcastEnabledRef: { current: true },
passwordPromptActiveRef: { current: true },
onBroadcastInputRef: {
current: () => {
throw new Error("sensitive paste must not broadcast");
},
},
});
assert.equal(didBroadcast, false);
});