mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-02 00:59:32 +01:00
Merge pull request #602: fix(remote): load a remote session's scrollback from the remote tmux
A full-history load of a remote SSH session reads the scrollback from the remote tmux in one bounded ssh round trip and splices it above the local frame. A transport failure (ssh 255, timeout, unparseable output) starts a 30 s per-host back-off; a missing remote session is per-session only. Conflict resolved in session-routes.ts: #602's remote scrollback read runs before #601's capture helper and its alternate-screen fallback. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
f9f00bdb5e
11 files changed
+720
-11
No files matched your search
@@ -77,7 +77,7 @@ OMP's registry entry declares `privilegedParams: []` and a launch spec that only
|
||||
|
||||
Further detail: ⚠️ **Auto-reconnect revives ONLY when the durable remote tmux session is verifiably still alive** (`remoteTmuxSessionAlive()`, a `has-session` probe over ssh, #355): a clean agent exit (Ctrl-C, Ctrl-D, `exit`) tears that session down, and `isPaneDead()` cannot tell it from a transport drop, so the watcher used to relaunch a FRESH agent after every clean exit (claude only looked fine because its `|| --resume` fallback masked it). An unreachable host answers `undefined`, which also means do not revive. ⚠️ `has-session` prints NOTHING on success, so the probe is classified by EXIT STATUS (`classifyRemoteAliveExit`: 0 alive, ssh's 255 or a timeout unknown, anything else gone); reading stdout classified every live session as gone and silently disabled transport-drop reconnects. The answer is cached per session and forgotten whenever the pane is seen alive again, or a stale `true` from one transport drop would revive the next clean exit.
|
||||
|
||||
File reads in a remote case are the second ssh surface (see Remote SSH cases below). The reason writes, office previews and thumbnails are deliberately unsupported over ssh is that no remote file is ever copied onto the server's disk. ssh children are bounded because terminal output in a remote session is written on the remote host, so a prompt-injected agent there can print hundreds of `codeman://attach` links.
|
||||
File reads in a remote case are the second ssh surface (see Remote SSH cases below). The reason writes, office previews and thumbnails are deliberately unsupported over ssh is that no remote file is ever copied onto the server's disk. ssh children are bounded because terminal output in a remote session is written on the remote host, so a prompt-injected agent there can print hundreds of `codeman://attach` links. The third surface is a remote session's full-history load, which reads the scrollback from the remote tmux (`src/remote-pane-history.ts`) through the same limiter, with a bounded slot wait (`maxWaitMs`) since the local capture is its fallback.
|
||||
|
||||
### Remote SSH cases
|
||||
|
||||
|
||||
@@ -251,6 +251,34 @@ unreachable host answers "unknown", which also means do not revive. The answer
|
||||
is cached per session and cleared whenever the pane is next seen alive, so a
|
||||
stale `true` from one transport drop can never revive the NEXT clean exit.
|
||||
|
||||
## Terminal history from the remote tmux
|
||||
|
||||
The local pane runs the ssh attach, so it only sees the remote tmux client's
|
||||
full-screen repaints and keeps a fraction of the scrollback (none after a
|
||||
reattach). A full-history load (`GET /api/sessions/:id/terminal?full=1`) of a
|
||||
remote session therefore reads the scrollback rows from the REMOTE pane in one
|
||||
ssh round trip (`src/remote-pane-history.ts`) and splices them above the local
|
||||
visible frame and caret. Bounded (5 s for the round trip, at most 1.5 s queued
|
||||
for a slot in the shared ssh limiter) and fail-soft: any failure keeps the
|
||||
local capture, and a transport failure (ssh exit 255, a timeout, output that is
|
||||
not the script's) also skips that host for 30 s; a failure of the remote
|
||||
command itself (a remote tmux session that is gone) affects that session only.
|
||||
How much history exists is the remote tmux's own `history-limit`, which the
|
||||
launch command does not set (tmux's default is 2000 lines).
|
||||
|
||||
Two seams can drop rows at the join, silently. Neither loses anything that
|
||||
loaded before this existed:
|
||||
|
||||
- **Rows that scroll during the round trip.** The remote history is read
|
||||
first and the local frame after it, so rows that scrolled off the remote
|
||||
screen in between are in neither (measured: 13 lines lost with a 150 ms
|
||||
round trip and fast output).
|
||||
- **A shared remote session with a taller client.** Under `window-size latest`
|
||||
a remote session attached elsewhere is sized by its latest client; when that
|
||||
client is taller than this pane, the rows between this pane's frame and the
|
||||
remote screen's top are in neither the remote history nor the local frame
|
||||
(measured: 20 rows).
|
||||
|
||||
## File access over SSH
|
||||
|
||||
A remote case's `workingDir` is an absolute path on the **remote** host
|
||||
|
||||
@@ -189,6 +189,13 @@ export interface PaneCaptureOptions {
|
||||
fullHistory?: boolean;
|
||||
/** Bound the full-history capture to this many scrollback lines (`-S -<N>`). */
|
||||
historyLimitLines?: number;
|
||||
/**
|
||||
* Full-history only: scrollback rows read from somewhere other than this pane
|
||||
* (raw `capture-pane -p -e -J` text, oldest first). The pane then contributes
|
||||
* only its visible frame and caret, and its own history is not read. A remote
|
||||
* session's real history lives in the REMOTE tmux (`remote-pane-history.ts`).
|
||||
*/
|
||||
scrollbackOverride?: string;
|
||||
/**
|
||||
* Byte cap the consumer will keep from the capture. Sizes the child-process
|
||||
* stdout buffer (with slack) so multi-MB scrollback dumps aren't killed by
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @fileoverview Scrollback of a remote SSH session, read from the REMOTE tmux.
|
||||
*
|
||||
* A remote session's local pane runs `ssh -t … tmux new-session -A` (or `attach`),
|
||||
* so the local tmux only ever sees what the remote tmux CLIENT draws: full-screen
|
||||
* repaints, not scrolling output. The local pane therefore keeps a fraction of the
|
||||
* history (measured: 48 of 279 lines while output streamed, none after a reattach),
|
||||
* while the remote pane, where the shell really runs, keeps all of it. A full-history
|
||||
* load of a remote session reads the scrollback from there instead, and the caller
|
||||
* splices it above the LOCAL visible frame (`PaneCaptureOptions.scrollbackOverride`):
|
||||
* the local pane is what the live stream keeps drawing into, so its frame and caret
|
||||
* position are the ones the browser must end up with.
|
||||
*
|
||||
* ONE ssh round trip prints the remote pane's `#{history_size}` and its scrollback
|
||||
* rows (`capture-pane -S -<N> -E -1`). The size is load-bearing: with no history at
|
||||
* all, tmux clamps `-E -1` to the first VISIBLE row and would return it as history.
|
||||
*
|
||||
* Bounded and fail-soft. Any failure (unreachable host, auth, missing session, odd
|
||||
* output) returns null and the caller keeps the local capture, so a remote load is
|
||||
* never worse than before. A transport failure also starts a short per-host back-off,
|
||||
* so a host that is asleep costs one timeout, not one per tab switch. The child runs
|
||||
* under the shared remote-ssh limiter (`remote-ssh-limiter.ts`) like every other
|
||||
* short-lived remote ssh, but gives up on a slot it waited too long for (`maxWaitMs`,
|
||||
* enforced in the queue), and the connection options come from
|
||||
* `buildSshConnectionArgs()`.
|
||||
*
|
||||
* How much history exists is the REMOTE tmux's `history-limit` (2000 lines unless
|
||||
* the remote user's tmux.conf raises it); the launch command does not set it.
|
||||
*/
|
||||
|
||||
import { exec } from 'node:child_process';
|
||||
import { promisify } from 'node:util';
|
||||
import type { SessionRemote } from './types/session.js';
|
||||
import { buildSshConnectionArgs, classifyRemoteAliveExit, remoteSshTarget, shellescape } from './remote-hosts.js';
|
||||
import { RemoteSshSlotTimeoutError, runWithRemoteSshLimit } from './remote-ssh-limiter.js';
|
||||
import { remoteTmuxLocation } from './tmux-manager.js';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
/**
|
||||
* Bound on the whole round trip. A full load waits on it, so it is far below the
|
||||
* 10 s `ConnectTimeout` the shared ssh options carry: past this the local capture
|
||||
* is the better answer.
|
||||
*/
|
||||
const REMOTE_HISTORY_TIMEOUT_MS = 5_000;
|
||||
|
||||
/**
|
||||
* Longest a load waits for a slot in the shared ssh pool, which file previews and
|
||||
* attachment probes (20 s each) also hold. Past it the local capture is used.
|
||||
*/
|
||||
const REMOTE_HISTORY_SLOT_WAIT_MS = 1_500;
|
||||
|
||||
/** After a failed read, skip that host for this long and use the local capture. */
|
||||
const REMOTE_HISTORY_BACKOFF_MS = 30_000;
|
||||
|
||||
/** Headroom over the remote `tail -c` bound for the size line and markers. */
|
||||
const REMOTE_HISTORY_SLACK_BYTES = 64 * 1024;
|
||||
|
||||
/** Read ceiling when the configured byte cap is 0 (unbounded) and no `tail -c` runs. */
|
||||
const UNBOUNDED_READ_MAX_BYTES = 64 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* Host id → time the back-off ends. Keyed by HOST, so a sleeping host with five
|
||||
* sessions costs one timeout, and the map is bounded by the configured hosts.
|
||||
*/
|
||||
const backoffUntil = new Map<string, number>();
|
||||
|
||||
/**
|
||||
* The remote shell script. Its first byte is a NUL so a login banner or an rc-file
|
||||
* `echo` printed before it runs is separated without guessing (the same marker
|
||||
* `buildRemoteProbeCommand` uses); a second NUL ends the history size.
|
||||
*/
|
||||
export function buildRemoteScrollbackScript(
|
||||
socket: string,
|
||||
sessionName: string,
|
||||
historyLines: number,
|
||||
maxBytes: number
|
||||
): string {
|
||||
const tmux = `tmux -L ${shellescape(socket)}`;
|
||||
// `=name:` is an EXACT session match, then its active pane. A bare name is
|
||||
// read as a pane index or window name first, so a discovered session named
|
||||
// `0` would capture some other session's pane.
|
||||
const target = shellescape(`=${sessionName}:`);
|
||||
const lines = Math.max(1, Math.trunc(historyLines));
|
||||
// The newest rows are the ones worth keeping, so the byte bound is applied on
|
||||
// the remote side (`tail -c`) rather than by killing the read at maxBuffer.
|
||||
// A cap of 0 means unbounded, as in the route.
|
||||
const bound = maxBytes > 0 ? ` | tail -c ${Math.trunc(maxBytes)}` : '';
|
||||
return (
|
||||
`printf '\\0' && ${tmux} display-message -p -t ${target} '#{history_size}' && printf '\\0' && ` +
|
||||
`${tmux} capture-pane -p -e -J -S -${lines} -E -1 -t ${target}${bound}`
|
||||
);
|
||||
}
|
||||
|
||||
/** The full ssh command line for {@link buildRemoteScrollbackScript}. */
|
||||
export function buildRemoteScrollbackCommand(
|
||||
remote: SessionRemote,
|
||||
sessionId: string,
|
||||
historyLines: number,
|
||||
maxBytes: number
|
||||
): string {
|
||||
const { socket, sessionName } = remoteTmuxLocation(remote, sessionId);
|
||||
const script = buildRemoteScrollbackScript(socket, sessionName, historyLines, maxBytes);
|
||||
// `exec` so a timeout kill reaches ssh itself, not only the local `sh -c`.
|
||||
return ['exec', ...buildSshConnectionArgs(remote), remoteSshTarget(remote), shellescape(script)].join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* A `tail -c` cut lands mid-row (possibly mid-escape) whenever it bit, so the
|
||||
* first, partial row is dropped. Under the bound, the rows are whole.
|
||||
*/
|
||||
export function dropPartialFirstRow(scrollback: string, maxBytes: number): string {
|
||||
if (maxBytes <= 0 || Buffer.byteLength(scrollback, 'utf-8') < maxBytes) return scrollback;
|
||||
const newline = scrollback.indexOf('\n');
|
||||
return newline === -1 ? '' : scrollback.slice(newline + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* The scrollback rows from the script's stdout, '' when the pane has no history,
|
||||
* or null when the output is not the script's.
|
||||
*/
|
||||
export function parseRemoteScrollbackOutput(stdout: string): string | null {
|
||||
const start = stdout.indexOf('\0');
|
||||
if (start === -1) return null;
|
||||
const sizeEnd = stdout.indexOf('\0', start + 1);
|
||||
if (sizeEnd === -1) return null;
|
||||
const sizeText = stdout.slice(start + 1, sizeEnd).trim();
|
||||
if (!/^\d+$/.test(sizeText)) return null;
|
||||
if (Number(sizeText) === 0) return '';
|
||||
return stdout.slice(sizeEnd + 1);
|
||||
}
|
||||
|
||||
/** Runs the ssh command line and resolves its stdout; rejects like `exec` does. */
|
||||
export type RemoteScrollbackRunner = (command: string, opts: { timeout: number; maxBuffer: number }) => Promise<string>;
|
||||
|
||||
const execRunner: RemoteScrollbackRunner = async (command, opts) =>
|
||||
(await execAsync(command, { encoding: 'utf-8', ...opts })).stdout;
|
||||
|
||||
/**
|
||||
* Read a remote session's scrollback from the remote tmux, or null to keep the
|
||||
* local capture. Never throws.
|
||||
*
|
||||
* Only a TRANSPORT failure backs the host off (ssh's own exit 255, a timeout, a
|
||||
* spawn error, output that is not the script's): those say the host is
|
||||
* unreachable for every session on it. A remote command failing (a session
|
||||
* that is gone: tmux exits 1, or answers nothing between the markers when the
|
||||
* `| tail -c` pipe hides its status) is about this session only, so it returns
|
||||
* null and the next session on that host still tries. Same split as
|
||||
* `classifyRemoteAliveExit()`.
|
||||
*
|
||||
* `run` is a test seam: without it nothing runs under vitest, as in
|
||||
* remote-files.ts / remote-hosts.ts.
|
||||
*/
|
||||
export async function fetchRemoteScrollback(
|
||||
remote: SessionRemote,
|
||||
sessionId: string,
|
||||
historyLines: number,
|
||||
maxBytes: number,
|
||||
run?: RemoteScrollbackRunner
|
||||
): Promise<string | null> {
|
||||
if (!run && process.env.VITEST) return null;
|
||||
const runner = run ?? execRunner;
|
||||
const until = backoffUntil.get(remote.hostId);
|
||||
if (until !== undefined) {
|
||||
if (Date.now() < until) return null;
|
||||
backoffUntil.delete(remote.hostId);
|
||||
}
|
||||
const command = buildRemoteScrollbackCommand(remote, sessionId, historyLines, maxBytes);
|
||||
try {
|
||||
const stdout = await runWithRemoteSshLimit(
|
||||
() =>
|
||||
runner(command, {
|
||||
timeout: REMOTE_HISTORY_TIMEOUT_MS,
|
||||
maxBuffer: (maxBytes > 0 ? maxBytes : UNBOUNDED_READ_MAX_BYTES) + REMOTE_HISTORY_SLACK_BYTES,
|
||||
}),
|
||||
// The pool is shared with 20 s file probes; past this the local capture
|
||||
// is the better answer than waiting behind them.
|
||||
{ maxWaitMs: REMOTE_HISTORY_SLOT_WAIT_MS }
|
||||
);
|
||||
const scrollback = parseRemoteScrollbackOutput(stdout);
|
||||
if (scrollback === null) {
|
||||
// Both markers arrived, so the script ran on the host and only tmux had
|
||||
// nothing to say: no such session. The `| tail -c` pipe hides tmux's
|
||||
// exit status, so this comes back as exit 0 rather than exit 1, and it
|
||||
// is about this session alone. Output without the markers is not the
|
||||
// script's at all, which says the host is not answering as expected.
|
||||
const ranOnHost = stdout.split('\0').length >= 3;
|
||||
if (!ranOnHost) backoffUntil.set(remote.hostId, Date.now() + REMOTE_HISTORY_BACKOFF_MS);
|
||||
const what = ranOnHost ? 'no such remote tmux session' : 'unexpected output';
|
||||
console.warn(`[remote-history] ${remote.label}: ${what}; using the local capture`);
|
||||
return null;
|
||||
}
|
||||
return dropPartialFirstRow(scrollback, maxBytes);
|
||||
} catch (err) {
|
||||
// A busy pool says nothing about the host.
|
||||
if (err instanceof RemoteSshSlotTimeoutError) return null;
|
||||
const e = err as { killed?: boolean; code?: unknown };
|
||||
const code = typeof e.code === 'number' ? e.code : null;
|
||||
const transport = classifyRemoteAliveExit(code, e.killed === true) === undefined;
|
||||
if (transport) backoffUntil.set(remote.hostId, Date.now() + REMOTE_HISTORY_BACKOFF_MS);
|
||||
const reason = e.killed ? 'timed out' : code !== null ? `exit ${code}` : 'failed';
|
||||
console.warn(`[remote-history] ${remote.label}: remote scrollback read ${reason}; using the local capture`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Test hook: forget every host back-off. */
|
||||
export function resetRemoteScrollbackBackoff(): void {
|
||||
backoffUntil.clear();
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
/**
|
||||
* @fileoverview Global concurrency limiter for the short-lived `ssh` children that
|
||||
* remote-case file access spawns (`src/remote-files.ts`: the realpath+stat probe and
|
||||
* the buffered text read).
|
||||
* the buffered text read). A remote session's full-history load reads its scrollback
|
||||
* from the remote tmux through the same pool (`src/remote-pane-history.ts`), with a
|
||||
* bounded wait (`maxWaitMs`) because it has the local capture to fall back on.
|
||||
*
|
||||
* Two paths can fan those out without a human behind each one:
|
||||
*
|
||||
@@ -60,12 +62,35 @@ export function getRemoteSshLimit(): number {
|
||||
return MAX_CONCURRENT_REMOTE_SSH;
|
||||
}
|
||||
|
||||
function acquire(): Promise<void> {
|
||||
/** Thrown by {@link runWithRemoteSshLimit} when `maxWaitMs` passed before a slot freed up. */
|
||||
export class RemoteSshSlotTimeoutError extends Error {
|
||||
constructor(maxWaitMs: number) {
|
||||
super(`No remote ssh slot within ${maxWaitMs} ms`);
|
||||
this.name = 'RemoteSshSlotTimeoutError';
|
||||
}
|
||||
}
|
||||
|
||||
function acquire(maxWaitMs?: number): Promise<void> {
|
||||
if (active < MAX_CONCURRENT_REMOTE_SSH) {
|
||||
active++;
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise<void>((resolve) => waiters.push(resolve));
|
||||
if (maxWaitMs === undefined) return new Promise<void>((resolve) => waiters.push(resolve));
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const waiter = () => {
|
||||
clearTimeout(timer);
|
||||
resolve();
|
||||
};
|
||||
// A timed-out waiter leaves the queue and is never handed a slot, so it
|
||||
// owns nothing to give back: `active` is untouched on this path.
|
||||
const timer = setTimeout(() => {
|
||||
const index = waiters.indexOf(waiter);
|
||||
if (index === -1) return; // already handed a slot by release()
|
||||
waiters.splice(index, 1);
|
||||
reject(new RemoteSshSlotTimeoutError(maxWaitMs));
|
||||
}, maxWaitMs);
|
||||
waiters.push(waiter);
|
||||
});
|
||||
}
|
||||
|
||||
function release(): void {
|
||||
@@ -78,9 +103,14 @@ function release(): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** Run `task` once an ssh slot is free, releasing the slot afterward. */
|
||||
export async function runWithRemoteSshLimit<T>(task: () => Promise<T>): Promise<T> {
|
||||
await acquire();
|
||||
/**
|
||||
* Run `task` once an ssh slot is free, releasing the slot afterward. With
|
||||
* `maxWaitMs`, give up instead (rejecting with {@link RemoteSshSlotTimeoutError},
|
||||
* `task` never runs) when no slot frees up in time: for a caller that has a
|
||||
* cheaper answer than waiting behind the queue.
|
||||
*/
|
||||
export async function runWithRemoteSshLimit<T>(task: () => Promise<T>, opts: { maxWaitMs?: number } = {}): Promise<T> {
|
||||
await acquire(opts.maxWaitMs);
|
||||
try {
|
||||
return await task();
|
||||
} finally {
|
||||
|
||||
+35
-2
@@ -694,6 +694,16 @@ export function normalizeScrollbackEol(buffer: string): string {
|
||||
return buffer.replace(/\r?\n/g, '\r\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Put scrollback rows read elsewhere (`PaneCaptureOptions.scrollbackOverride`)
|
||||
* above a visible-frame capture, as one capture in tmux's own shape: rows joined
|
||||
* by a bare `\n`. Undefined or empty scrollback leaves the frame as it is.
|
||||
*/
|
||||
export function joinScrollbackAndFrame(scrollback: string | undefined, frame: string): string {
|
||||
if (!scrollback) return frame;
|
||||
return `${scrollback.replace(/\n$/, '')}\n${frame}`;
|
||||
}
|
||||
|
||||
/** Pane geometry and caret position, as `display-message` reports them. */
|
||||
interface PaneCursorGeometry {
|
||||
cols: number;
|
||||
@@ -978,6 +988,19 @@ export function remoteTmuxSessionName(sessionId: string): string {
|
||||
return `codeman-ssh-${sessionId.slice(0, 8)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The remote tmux socket and session a remote Codeman session's pane is attached
|
||||
* to, matching the command that attached it: an owned session is the one
|
||||
* `buildRemoteLaunchCommand` created on the private socket, a non-owned one is the
|
||||
* discovered session `buildRemoteAttachCommand` joined on `-L codeman`.
|
||||
*/
|
||||
export function remoteTmuxLocation(remote: SessionRemote, sessionId: string): { socket: string; sessionName: string } {
|
||||
if (remote.owned === false) {
|
||||
return { socket: 'codeman', sessionName: remote.remoteSessionName || remoteTmuxSessionName(sessionId) };
|
||||
}
|
||||
return { socket: REMOTE_TMUX_SOCKET, sessionName: remoteTmuxSessionName(sessionId) };
|
||||
}
|
||||
|
||||
/**
|
||||
* COD-104 — build the SSH command that launches (or reattaches) a remote
|
||||
* session INSIDE a tmux server on the remote host, so the remote agent survives
|
||||
@@ -3886,7 +3909,14 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
||||
typeof requestedLines === 'number' && Number.isFinite(requestedLines) && requestedLines > 0
|
||||
? Math.trunc(requestedLines)
|
||||
: DEFAULT_TMUX_HISTORY_LIMIT;
|
||||
const captureFlags = fullHistory ? `capture-pane -p -e -J -S -${historyLines}` : 'capture-pane -p -e';
|
||||
// With a scrollback override this pane's own history is not read at all:
|
||||
// `-S 0` starts at the top of the visible frame.
|
||||
const scrollbackOverride = fullHistory ? opts?.scrollbackOverride : undefined;
|
||||
const captureFlags = !fullHistory
|
||||
? 'capture-pane -p -e'
|
||||
: scrollbackOverride !== undefined
|
||||
? 'capture-pane -p -e -J -S 0'
|
||||
: `capture-pane -p -e -J -S -${historyLines}`;
|
||||
// execSync's default maxBuffer (1MB) kills multi-MB scrollback dumps
|
||||
// (ENOBUFS) and would silently degrade full-history capture to the byte
|
||||
// buffer for exactly the long sessions it exists for — size it from the
|
||||
@@ -3899,7 +3929,10 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer {
|
||||
execOpts.maxBuffer =
|
||||
(opts?.maxCaptureBytes ?? DEFAULT_TERMINAL_BUFFER_MAX_BYTES) + FULL_HISTORY_CAPTURE_SLACK_BYTES;
|
||||
}
|
||||
const rawCapture = execSync(`${this.tmux()} ${captureFlags} -t ${shellescape(target)}`, execOpts);
|
||||
const rawCapture = joinScrollbackAndFrame(
|
||||
scrollbackOverride,
|
||||
execSync(`${this.tmux()} ${captureFlags} -t ${shellescape(target)}`, execOpts)
|
||||
);
|
||||
// Query the cursor BEFORE deciding anything else. On the full-history path
|
||||
// it settles both how the capture is trimmed and whether a cursor move is
|
||||
// appended, and those two have to agree: trailing blank rows are only safe
|
||||
|
||||
@@ -165,6 +165,7 @@ import {
|
||||
toAttachedSessionRemote,
|
||||
toSessionRemote,
|
||||
} from '../../remote-hosts.js';
|
||||
import { fetchRemoteScrollback } from '../../remote-pane-history.js';
|
||||
import {
|
||||
checkDockerAvailable,
|
||||
checkDockerConfigDrift,
|
||||
@@ -3126,6 +3127,19 @@ export function registerSessionRoutes(
|
||||
maxCaptureBytes: terminalBufferMaxBytes,
|
||||
}
|
||||
: {};
|
||||
// A remote session's local pane only sees the remote tmux client's repaints,
|
||||
// so its own scrollback is a fraction of the real one: read that from the
|
||||
// remote tmux and splice it above the local frame. Null (host unreachable,
|
||||
// no remote session, back-off) keeps the local capture as before.
|
||||
if (isFullReload && session.remote && muxName && captureOpts.historyLimitLines !== undefined) {
|
||||
const remoteScrollback = await fetchRemoteScrollback(
|
||||
session.remote,
|
||||
session.id,
|
||||
captureOpts.historyLimitLines,
|
||||
terminalBufferMaxBytes
|
||||
);
|
||||
if (remoteScrollback !== null) captureOpts.scrollbackOverride = remoteScrollback;
|
||||
}
|
||||
const capture = (opts: PaneCaptureOptions): string | null =>
|
||||
muxName && typeof ctx.mux.captureActivePaneBuffer === 'function'
|
||||
? ctx.mux.captureActivePaneBuffer(muxName, opts)
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* @fileoverview Tests for reading a remote session's scrollback from the remote
|
||||
* tmux (`src/remote-pane-history.ts`) and splicing it above the local frame.
|
||||
*
|
||||
* The remote script is also run by a real `/bin/sh`, with a stub `tmux` first on
|
||||
* PATH: the script IS the remote command, so `sh -c <script>` is what sshd runs on
|
||||
* the other end, and quoting mistakes show up there and nowhere else.
|
||||
*
|
||||
* Port: N/A (no HTTP server).
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import {
|
||||
buildRemoteScrollbackCommand,
|
||||
buildRemoteScrollbackScript,
|
||||
dropPartialFirstRow,
|
||||
fetchRemoteScrollback,
|
||||
parseRemoteScrollbackOutput,
|
||||
resetRemoteScrollbackBackoff,
|
||||
} from '../src/remote-pane-history.js';
|
||||
import {
|
||||
getActiveRemoteSshCount,
|
||||
getQueuedRemoteSshCount,
|
||||
getRemoteSshLimit,
|
||||
runWithRemoteSshLimit,
|
||||
} from '../src/remote-ssh-limiter.js';
|
||||
import { joinScrollbackAndFrame, remoteTmuxLocation } from '../src/tmux-manager.js';
|
||||
import type { SessionRemote } from '../src/types/session.js';
|
||||
|
||||
const SESSION_ID = '663e3eae-8da6-4c7f-9231-611eb2840641';
|
||||
const remote: SessionRemote = {
|
||||
hostId: 'h1',
|
||||
label: 'proxx',
|
||||
host: 'proxx.lan',
|
||||
username: 'tim',
|
||||
port: 2222,
|
||||
remotePath: '/home/tim',
|
||||
};
|
||||
|
||||
describe('remoteTmuxLocation', () => {
|
||||
it('an owned session is the launch command’s session on the private socket', () => {
|
||||
expect(remoteTmuxLocation(remote, SESSION_ID)).toEqual({
|
||||
socket: 'codeman-remote',
|
||||
sessionName: 'codeman-ssh-663e3eae',
|
||||
});
|
||||
});
|
||||
|
||||
it('a discovered session is the one the attach command joined on -L codeman', () => {
|
||||
const discovered = { ...remote, owned: false, remoteSessionName: 'codeman-disco1' };
|
||||
expect(remoteTmuxLocation(discovered, SESSION_ID)).toEqual({ socket: 'codeman', sessionName: 'codeman-disco1' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildRemoteScrollbackCommand', () => {
|
||||
it('goes through the shared ssh options and reads history rows only', () => {
|
||||
const command = buildRemoteScrollbackCommand(remote, SESSION_ID, 10000, 2048);
|
||||
expect(command.startsWith('exec ssh -o BatchMode=yes')).toBe(true);
|
||||
expect(command).toContain('-p 2222');
|
||||
expect(command).toContain('tim@proxx.lan');
|
||||
// Socket and target are shellescaped inside the (itself shellescaped) script.
|
||||
expect(command).toContain('codeman-remote');
|
||||
expect(command).toContain('codeman-ssh-663e3eae');
|
||||
expect(command).toContain('capture-pane -p -e -J -S -10000 -E -1');
|
||||
expect(command).toContain('#{history_size}');
|
||||
expect(command).toContain('| tail -c 2048');
|
||||
});
|
||||
|
||||
it('a byte cap of 0 (unbounded) runs no tail', () => {
|
||||
expect(buildRemoteScrollbackCommand(remote, SESSION_ID, 10000, 0)).not.toContain('tail -c');
|
||||
});
|
||||
});
|
||||
|
||||
describe('dropPartialFirstRow', () => {
|
||||
it('drops the row a tail -c cut landed in, and only then', () => {
|
||||
expect(dropPartialFirstRow('ow 1\nrow 2\n', 11)).toBe('row 2\n');
|
||||
expect(dropPartialFirstRow('row 1\nrow 2\n', 100)).toBe('row 1\nrow 2\n');
|
||||
expect(dropPartialFirstRow('no newline at all', 17)).toBe('');
|
||||
expect(dropPartialFirstRow('row 1\nrow 2\n', 0)).toBe('row 1\nrow 2\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseRemoteScrollbackOutput', () => {
|
||||
it('drops anything printed before the script (login banner, rc-file echo)', () => {
|
||||
expect(parseRemoteScrollbackOutput('Welcome to proxx\n\x0042\n\x00line a\nline b\n')).toBe('line a\nline b\n');
|
||||
});
|
||||
|
||||
it('an empty history is empty, not the first visible row tmux clamps -E -1 to', () => {
|
||||
expect(parseRemoteScrollbackOutput('\x000\n\x00$ the prompt row\n')).toBe('');
|
||||
});
|
||||
|
||||
it('rejects output that is not the script’s', () => {
|
||||
expect(parseRemoteScrollbackOutput('')).toBeNull();
|
||||
expect(parseRemoteScrollbackOutput('no markers at all')).toBeNull();
|
||||
expect(parseRemoteScrollbackOutput('\x0042\n')).toBeNull();
|
||||
expect(parseRemoteScrollbackOutput('\x00not a number\n\x00rows')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('the remote script under a real shell', () => {
|
||||
let dir: string;
|
||||
let callsFile: string;
|
||||
|
||||
beforeAll(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), 'remote-scrollback-'));
|
||||
callsFile = join(dir, 'calls');
|
||||
// Stub tmux: logs its argv (one per line), answers display-message with a
|
||||
// history size and capture-pane with two rows.
|
||||
writeFileSync(
|
||||
join(dir, 'tmux'),
|
||||
[
|
||||
'#!/bin/sh',
|
||||
`for a in "$@"; do printf '%s\\n' "$a"; done >> '${callsFile}'`,
|
||||
`printf -- '--\\n' >> '${callsFile}'`,
|
||||
'case " $* " in',
|
||||
' *" display-message "*) echo 2 ;;',
|
||||
' *" capture-pane "*) printf "older row\\nnewer row\\n" ;;',
|
||||
'esac',
|
||||
].join('\n')
|
||||
);
|
||||
chmodSync(join(dir, 'tmux'), 0o755);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('prints the markers and rows the parser expects, with the target as one argument', () => {
|
||||
const script = buildRemoteScrollbackScript('codeman', "codeman-it's", 500, 10);
|
||||
const stdout = execFileSync('/bin/sh', ['-c', script], {
|
||||
encoding: 'utf-8',
|
||||
env: { ...process.env, PATH: `${dir}:${process.env.PATH ?? ''}` },
|
||||
});
|
||||
// `tail -c 10` kept the newest bytes only: "newer row\n".
|
||||
expect(parseRemoteScrollbackOutput(stdout)).toBe('newer row\n');
|
||||
const calls = execFileSync('cat', [callsFile], { encoding: 'utf-8' }).split('--\n').filter(Boolean);
|
||||
expect(calls).toHaveLength(2);
|
||||
// One argv entry per line: the exact-match target with a quote in it arrived whole.
|
||||
expect(calls[0].split('\n').join('|')).toBe("-L|codeman|display-message|-p|-t|=codeman-it's:|#{history_size}|");
|
||||
expect(calls[1].split('\n').join('|')).toBe("-L|codeman|capture-pane|-p|-e|-J|-S|-500|-E|-1|-t|=codeman-it's:|");
|
||||
});
|
||||
});
|
||||
|
||||
describe('joinScrollbackAndFrame', () => {
|
||||
it('puts the scrollback rows above the frame in tmux’s own row shape', () => {
|
||||
expect(joinScrollbackAndFrame('old 1\nold 2\n', 'frame 1\nframe 2\n')).toBe('old 1\nold 2\nframe 1\nframe 2\n');
|
||||
expect(joinScrollbackAndFrame('old 1', 'frame 1')).toBe('old 1\nframe 1');
|
||||
});
|
||||
|
||||
it('no scrollback leaves the frame alone', () => {
|
||||
expect(joinScrollbackAndFrame(undefined, 'frame\n')).toBe('frame\n');
|
||||
expect(joinScrollbackAndFrame('', 'frame\n')).toBe('frame\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchRemoteScrollback', () => {
|
||||
const OK = '\x002\n\x00older row\nnewer row\n';
|
||||
const READ = 'older row\nnewer row\n';
|
||||
/** An exec-shaped rejection: `code` is the exit status, `killed` a timeout kill. */
|
||||
const execError = (fields: { code?: number | string; killed?: boolean }) =>
|
||||
Object.assign(new Error('Command failed'), fields);
|
||||
|
||||
beforeEach(() => {
|
||||
resetRemoteScrollbackBackoff();
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('never opens a connection under test without an injected runner', async () => {
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns the remote rows, running the built command with the round-trip bounds', async () => {
|
||||
const run = vi.fn(async () => OK);
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, run)).toEqual(READ);
|
||||
expect(run).toHaveBeenCalledWith(buildRemoteScrollbackCommand(remote, SESSION_ID, 100, 1024), {
|
||||
timeout: 5000,
|
||||
maxBuffer: 1024 + 64 * 1024,
|
||||
});
|
||||
});
|
||||
|
||||
it('backs the HOST off after a transport failure: ssh exit 255, a timeout, a spawn error, odd output', async () => {
|
||||
const failures: Array<() => Promise<string>> = [
|
||||
async () => Promise.reject(execError({ code: 255 })),
|
||||
async () => Promise.reject(execError({ killed: true, code: null as unknown as number })),
|
||||
async () => Promise.reject(execError({ code: 'ENOENT' })),
|
||||
async () => 'not the script output',
|
||||
];
|
||||
for (const failure of failures) {
|
||||
resetRemoteScrollbackBackoff();
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, vi.fn(failure))).toBeNull();
|
||||
// Another session on the same host is skipped without a round trip.
|
||||
const next = vi.fn(async () => OK);
|
||||
expect(await fetchRemoteScrollback(remote, 'other-session', 100, 1024, next)).toBeNull();
|
||||
expect(next).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
|
||||
it('a remote command failure (tmux exit 1: the session is gone) is that session only, no back-off', async () => {
|
||||
const gone = vi.fn(async () => Promise.reject(execError({ code: 1 })));
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, gone)).toBeNull();
|
||||
const next = vi.fn(async () => OK);
|
||||
expect(await fetchRemoteScrollback(remote, 'other-session', 100, 1024, next)).toEqual(READ);
|
||||
expect(next).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
// Found live against a real host: the `| tail -c` pipe takes tail's exit
|
||||
// status, so a missing session comes back as exit 0 with both markers and
|
||||
// nothing between them. The script ran on the host; only this session is
|
||||
// gone, so the host must not be backed off.
|
||||
it('a missing session hidden behind the tail pipe (exit 0, empty markers) is that session only', async () => {
|
||||
const masked = vi.fn(async () => '\x00\x00');
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, masked)).toBeNull();
|
||||
const next = vi.fn(async () => OK);
|
||||
expect(await fetchRemoteScrollback(remote, 'other-session', 100, 1024, next)).toEqual(READ);
|
||||
expect(next).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('the back-off ends after 30 s', async () => {
|
||||
vi.useFakeTimers();
|
||||
await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, async () => Promise.reject(execError({ code: 255 })));
|
||||
const next = vi.fn(async () => OK);
|
||||
vi.advanceTimersByTime(29_999);
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, next)).toBeNull();
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, next)).toEqual(READ);
|
||||
});
|
||||
|
||||
it('gives up after 1.5 s queued behind a busy ssh pool: never runs, no slot leaked, no back-off', async () => {
|
||||
vi.useFakeTimers();
|
||||
const gates = Array.from({ length: getRemoteSshLimit() }, () => {
|
||||
let release!: () => void;
|
||||
const promise = new Promise<void>((r) => {
|
||||
release = r;
|
||||
});
|
||||
return { promise, release };
|
||||
});
|
||||
const holders = gates.map((gate) => runWithRemoteSshLimit(() => gate.promise));
|
||||
await Promise.resolve();
|
||||
|
||||
const run = vi.fn(async () => OK);
|
||||
const pending = fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, run);
|
||||
await vi.advanceTimersByTimeAsync(1499);
|
||||
expect(getQueuedRemoteSshCount()).toBe(1);
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
expect(await pending).toBeNull();
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
expect(getQueuedRemoteSshCount()).toBe(0);
|
||||
|
||||
for (const gate of gates) gate.release();
|
||||
await Promise.all(holders);
|
||||
expect(getActiveRemoteSshCount()).toBe(0);
|
||||
// A busy pool said nothing about the host.
|
||||
expect(await fetchRemoteScrollback(remote, SESSION_ID, 100, 1024, run)).toEqual(READ);
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,18 @@
|
||||
/**
|
||||
* @fileoverview Tests for the remote-file ssh concurrency limiter
|
||||
* (`src/remote-ssh-limiter.ts`): the cap holds under interleaved async resumption,
|
||||
* waiters are served FIFO, and a task that throws still releases its slot.
|
||||
* waiters are served FIFO, a task that throws still releases its slot, and a
|
||||
* bounded (`maxWaitMs`) waiter that times out neither runs nor leaks a slot.
|
||||
*
|
||||
* Port: N/A (no HTTP server).
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { afterEach, describe, it, expect, vi } from 'vitest';
|
||||
import {
|
||||
getActiveRemoteSshCount,
|
||||
getQueuedRemoteSshCount,
|
||||
getRemoteSshLimit,
|
||||
RemoteSshSlotTimeoutError,
|
||||
runWithRemoteSshLimit,
|
||||
} from '../src/remote-ssh-limiter.js';
|
||||
|
||||
@@ -64,4 +66,75 @@ describe('runWithRemoteSshLimit', () => {
|
||||
expect(getActiveRemoteSshCount()).toBe(0);
|
||||
expect(await runWithRemoteSshLimit(async () => 'after')).toBe('after');
|
||||
});
|
||||
|
||||
describe('maxWaitMs', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('a waiter that times out leaves the queue, never runs, and takes no slot', async () => {
|
||||
vi.useFakeTimers();
|
||||
const cap = getRemoteSshLimit();
|
||||
const gates = Array.from({ length: cap }, () => deferred());
|
||||
const holders = gates.map((gate) => runWithRemoteSshLimit(() => gate.promise));
|
||||
await Promise.resolve();
|
||||
expect(getActiveRemoteSshCount()).toBe(cap);
|
||||
|
||||
let ran = false;
|
||||
const bounded = runWithRemoteSshLimit(
|
||||
async () => {
|
||||
ran = true;
|
||||
},
|
||||
{ maxWaitMs: 1500 }
|
||||
);
|
||||
const outcome = expect(bounded).rejects.toBeInstanceOf(RemoteSshSlotTimeoutError);
|
||||
// An unbounded waiter queued BEHIND it still gets the next slot.
|
||||
let laterRan = false;
|
||||
const later = runWithRemoteSshLimit(async () => {
|
||||
laterRan = true;
|
||||
});
|
||||
expect(getQueuedRemoteSshCount()).toBe(2);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1500);
|
||||
await outcome;
|
||||
expect(ran).toBe(false);
|
||||
expect(getQueuedRemoteSshCount()).toBe(1);
|
||||
expect(getActiveRemoteSshCount()).toBe(cap);
|
||||
|
||||
gates[0].resolve();
|
||||
await later;
|
||||
expect(laterRan).toBe(true);
|
||||
expect(ran).toBe(false);
|
||||
|
||||
for (const gate of gates) gate.resolve();
|
||||
await Promise.all(holders);
|
||||
expect(getActiveRemoteSshCount()).toBe(0);
|
||||
expect(getQueuedRemoteSshCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('a waiter handed a slot in time runs and releases normally', async () => {
|
||||
vi.useFakeTimers();
|
||||
const cap = getRemoteSshLimit();
|
||||
const gates = Array.from({ length: cap }, () => deferred());
|
||||
const holders = gates.map((gate) => runWithRemoteSshLimit(() => gate.promise));
|
||||
await Promise.resolve();
|
||||
|
||||
const bounded = runWithRemoteSshLimit(async () => 'ran', { maxWaitMs: 1500 });
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
gates[0].resolve();
|
||||
expect(await bounded).toBe('ran');
|
||||
// The cancelled timer firing later must not disturb anything.
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
|
||||
for (const gate of gates) gate.resolve();
|
||||
await Promise.all(holders);
|
||||
expect(getActiveRemoteSshCount()).toBe(0);
|
||||
expect(getQueuedRemoteSshCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('takes a free slot at once without starting a timer', async () => {
|
||||
expect(await runWithRemoteSshLimit(async () => 'free', { maxWaitMs: 0 })).toBe('free');
|
||||
expect(getActiveRemoteSshCount()).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -56,6 +56,11 @@ vi.mock('../../src/remote-hosts.js', async (orig) => {
|
||||
};
|
||||
});
|
||||
|
||||
// The remote scrollback read is an ssh round trip; the route only decides when to
|
||||
// ask and what to do with the answer.
|
||||
const remoteScrollback = vi.hoisted(() => vi.fn(async (): Promise<string | null> => null));
|
||||
vi.mock('../../src/remote-pane-history.js', () => ({ fetchRemoteScrollback: remoteScrollback }));
|
||||
|
||||
import { registerSessionRoutes } from '../../src/web/routes/session-routes.js';
|
||||
import { RemoteWakeRegistry, REMOTE_WAKE_REQUEST_READY_TIMEOUT_MS } from '../../src/remote-wake.js';
|
||||
import { resolveTerminalHistoryConfig } from '../../src/config/terminal-history.js';
|
||||
@@ -1190,6 +1195,44 @@ describe('session-routes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("a remote session's full capture takes its scrollback from the remote tmux", async () => {
|
||||
const remote = { hostId: 'h1', label: 'proxx', host: 'proxx.lan', username: 'tim', remotePath: '/home/tim' };
|
||||
(harness.ctx._session as unknown as { remote?: unknown }).remote = remote;
|
||||
harness.ctx._session.mode = 'shell';
|
||||
const captureSpy = vi.fn((_name: string, _opts?: { scrollbackOverride?: string }) => 'captured frame');
|
||||
(harness.ctx.mux as { captureActivePaneBuffer?: unknown }).captureActivePaneBuffer = captureSpy;
|
||||
const load = async (query: string) => {
|
||||
captureSpy.mockClear();
|
||||
remoteScrollback.mockClear();
|
||||
await harness.app.inject({ method: 'GET', url: `/api/sessions/${harness.ctx._sessionId}/terminal?${query}` });
|
||||
return captureSpy.mock.calls[0]?.[1];
|
||||
};
|
||||
|
||||
remoteScrollback.mockResolvedValueOnce('remote line 1\nremote line 2\n');
|
||||
const opts = await load('full=1&lines=500');
|
||||
expect(remoteScrollback).toHaveBeenCalledWith(remote, harness.ctx._sessionId, 500, expect.any(Number));
|
||||
expect(opts).toEqual(
|
||||
expect.objectContaining({
|
||||
fullHistory: true,
|
||||
historyLimitLines: 500,
|
||||
scrollbackOverride: 'remote line 1\nremote line 2\n',
|
||||
})
|
||||
);
|
||||
|
||||
// Unreachable host / back-off: the local capture, unchanged.
|
||||
remoteScrollback.mockResolvedValueOnce(null);
|
||||
expect(await load('full=1&lines=500')).not.toHaveProperty('scrollbackOverride');
|
||||
|
||||
// A visible-frame load reads no history, so it never asks the remote.
|
||||
await load(`tail=${1024 * 1024}`);
|
||||
expect(remoteScrollback).not.toHaveBeenCalled();
|
||||
|
||||
// A local session never asks either.
|
||||
(harness.ctx._session as unknown as { remote?: unknown }).remote = undefined;
|
||||
await load('full=1');
|
||||
expect(remoteScrollback).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('`lines=` leaves a visible-frame capture (no full=1) exactly as it was', async () => {
|
||||
harness.ctx._session.mode = 'shell';
|
||||
const captureSpy = vi.fn(() => 'only the visible frame');
|
||||
|
||||
@@ -36,6 +36,14 @@ describe('tmux full-history pane capture (COD-47)', () => {
|
||||
expect(source).toContain('capture-pane -p -e -J -S -${historyLines}');
|
||||
});
|
||||
|
||||
it('a full capture with a scrollbackOverride (remote history) reads the visible frame only (-J -S 0)', () => {
|
||||
// The remote tmux supplied the history; reading local history too would
|
||||
// splice two histories above one frame.
|
||||
expect(methodBody).toContain('scrollbackOverride !== undefined');
|
||||
expect(methodBody).toContain("'capture-pane -p -e -J -S 0'");
|
||||
expect(methodBody).toContain('joinScrollbackAndFrame(');
|
||||
});
|
||||
|
||||
it('full-history exec sets an explicit maxBuffer (default 1MB would ENOBUFS multi-MB dumps)', () => {
|
||||
expect(methodBody).toContain('maxBuffer');
|
||||
expect(methodBody).toContain('FULL_HISTORY_CAPTURE_SLACK_BYTES');
|
||||
|
||||
Reference in new issue
Block a user