mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
Five items, two of which he could only see by running it, plus six smaller ones. Taking the two blockers first, because both were wrong in ways the existing tests could not catch. **Adopting the PTY's rows put the CLI's input line off-screen.** A phone that took a desktop's 43 rows into a viewport with room for 18 painted an `.xterm-screen` far taller than its container; xterm's own viewport then had nothing to scroll, so the bottom of the frame sat below the container with no gesture able to reach it. Output visible, typing invisible, for as long as the desktop kept the claim hot. `reconcilePtyGeometry` adopts COLUMNS ONLY now: width is the axis Ink's wrap and `eraseLines` arithmetic depend on, and keeping the local row count keeps the composer at the bottom of a viewport that scrolls. Measured at his geometry — a 360x300 container against a 198x43 pane now keeps 13 rows, takes 198 columns, paints 202px into a 210px container, and the input line is inside the box. **`capture-geometry-retry.browser.test.ts` failed, and CI could not see it** because the file is in `BROWSER_TEST_GLOBS`. Its premise WAS the clamp — `getTerminalDimensions()` floored while `fitAddon.fit()` did not — which this work removes at the source, so it can never hold again at any viewport. The case survives on its own terms: a pane already drawing at the requested size must not be replayed. Its premise is now the #464 invariant itself, that the floored report and the terminal agree, which is a stronger guard because the clamp coming back fails it here rather than silently restoring the replay loop. The helper docblock that repeated the old premise is corrected too. **A session with no pane reported 120x40 and the client adopted it.** `resize()` writes `_ptyCols`/`_ptyRows` only when `ptyProcess` is set and nothing seeds them from the spawn geometry, so a dead-pane session still held the constructor defaults — clicking that tab resized the browser terminal to 120x40 and, on anything narrower, claimed another device owned the pane when none existed. `Session.ptyGeometry` returns null without a pane, the HTTP route answers `{}` and the socket sends no frame at all. The raw `ptyCols`/`ptyRows` getters are deleted rather than left available to be misused again. **The 40-column floor clipped the pane with nothing able to reach it.** The affordance keyed on a PTY mismatch, and the floor produces no mismatch — xterm and the PTY agree throughout, the terminal is simply wider than the box. It keys on what does not FIT now, MEASURED (`.xterm-screen` against the container, on the next frame, because the screen takes its width with the render) rather than derived from cell arithmetic. Measured at 360px: font 24 applies 40 columns and paints 560px, and all 200px of the overhang is reachable. `.pty-oversized` is renamed `.term-overflows-x`, because after this the old name describes only one of the two causes. **"Scroll sideways" did not work on touch for the sessions it targets.** `touch-action: pan-x` is cancelled before it starts by the `preventDefault()` `touchstart` calls on every 'content' tap. The terminal's own touchmove handler pans the container now, with the axis locked once per gesture so a diagonal cannot pan and scroll at once, and the CSS grants no `touch-action` at all — handing the browser a pan AS WELL would move the pane twice for one finger on the taps where that preventDefault does not run. Measured under real touch dispatch: a 140px swipe reaches `scrollLeft` 140 where it reached 0 before, the buffer does not move with it, and a vertical swipe still scrolls the scrollback. Three defects in the above, found while checking it rather than by being told: - `canPanHorizontally` first tested `scrollWidth > clientWidth` alone, which is true of a container that is not a scroller — a sideways swipe would have locked the axis, done nothing, AND suppressed the vertical scroll it should have been. Gated on the class as well. - The notice advised scrolling sideways whenever the PTY was wider, including when it still fitted and nothing scrolled. It is gated on measured overflow, and on a comparison against the width this container WOULD request rather than the one it currently holds — once adopted those are equal, so the second question answers itself false while the condition is still true. - `_syncTerminalOverflowAffordance` could throw out of `document.getElementById` before reaching its try block. It runs off every geometry change, so a cosmetic affordance could have taken the resize down with it. The smaller items: - `docs/architecture-invariants.md` no longer explains the equality guard as a clamp signature; it records what the clamp used to do and why it cannot any more. Edited by hand — that file is outside the Prettier glob, and letting Prettier near it rewrote eleven unrelated emphasis markers. - `throttledResize`'s HTTP fallback reads the reply. It is the path where a declined resize is least likely to be noticed, because no socket means no `{"t":"zc"}` frame either. - The changeset covers the whole release: the geometry work, the queued replay clear, the renderer watchdog, the body-covering fetch deadline, the WebSocket output-gap reconcile, the build-generated service-worker precache and per-build cache key, and the crash-trail hygiene. - `@xterm/headless` is declared in the root devDependencies instead of being reached through workspace hoisting. - The output-gap marker is cleared after any response arrives, not only when the capture was non-empty: a server that answers with an empty capture HAS reconciled us, and leaving the marker set refetched on every reconnect. - `e587d845`'s message claimed a test asserted the failed-load copy against the built asset. It did not — that assertion lived in a probe deleted with the other scratch scripts, so the claim was false when it was written. There is a real test now, and it reads the source rather than `dist/`, because `dist/` is not committed and a test that skips when it is absent would pass for the wrong reason in CI. `Session.ptyGeometry` gets behavioural coverage against the real class in `session-resize-arbitration.test.ts` rather than a source guard, including the contrast — a pane that does exist still reports, and still follows a resize — so "always null" would fail it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
216 lines
8.2 KiB
TypeScript
216 lines
8.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { Session } from '../src/session.js';
|
|
|
|
/** Must exceed Session.DESKTOP_CLAIM_IDLE_MS (90s) */
|
|
const PAST_IDLE_MS = 91_000;
|
|
|
|
type ResizeableSessionInternals = {
|
|
ptyProcess: { resize: (cols: number, rows: number) => void };
|
|
_ptyCols: number;
|
|
_ptyRows: number;
|
|
};
|
|
|
|
function attachFakePty(session: Session, cols = 160, rows = 48) {
|
|
const resize = vi.fn();
|
|
const internals = session as unknown as ResizeableSessionInternals;
|
|
internals.ptyProcess = { resize };
|
|
internals._ptyCols = cols;
|
|
internals._ptyRows = rows;
|
|
return resize;
|
|
}
|
|
|
|
describe('Session.ptyGeometry', () => {
|
|
// ⚠️ `resize()` writes `_ptyCols`/`_ptyRows` only when `ptyProcess` is set,
|
|
// and nothing seeds them from the spawn geometry — so the fields hold the
|
|
// constructor defaults of 120x40 for any session whose pane is not running.
|
|
// Reporting those to a client made it adopt a width no process had ever been
|
|
// told, and on anything narrower than 120 columns claim another device owned
|
|
// the pane when none existed (issue #464).
|
|
it('reports nothing for a session that has no pane', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
expect(session.ptyGeometry).toBeNull();
|
|
});
|
|
|
|
it('still reports nothing after a resize it could not apply', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
session.resize(45, 20, { viewportType: 'mobile' });
|
|
// The resize was swallowed (no pty to resize), so there is no geometry to
|
|
// report — NOT the 120x40 the fields still hold.
|
|
expect(session.ptyGeometry).toBeNull();
|
|
});
|
|
|
|
it('reports the pane geometry once a pane exists, and follows a resize', () => {
|
|
// The contrast, so "always null" would fail this.
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
attachFakePty(session, 160, 48);
|
|
expect(session.ptyGeometry).toEqual({ cols: 160, rows: 48 });
|
|
|
|
session.resize(62, 40, { viewportType: 'mobile' });
|
|
expect(session.ptyGeometry).toEqual({ cols: 62, rows: 40 });
|
|
});
|
|
});
|
|
|
|
describe('Session resize arbitration', () => {
|
|
it('lets a mobile-only session shrink below the spawn default (no desktop connected)', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
|
|
expect(resize).toHaveBeenCalledWith(48, 28);
|
|
});
|
|
|
|
it('lets a mobile-only session shrink rows only', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.resize(160, 28, { viewportType: 'mobile' });
|
|
|
|
expect(resize).toHaveBeenCalledWith(160, 28);
|
|
});
|
|
|
|
it('lets a mobile-only session re-grow after shrinking', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
session.resize(80, 36, { viewportType: 'tablet' });
|
|
|
|
expect(resize).toHaveBeenNthCalledWith(1, 48, 28);
|
|
expect(resize).toHaveBeenNthCalledWith(2, 80, 36);
|
|
});
|
|
|
|
it('ignores mobile resizes while a desktop connection holds a sizing claim', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
const desktop = Symbol('desktop-conn');
|
|
|
|
session.claimDesktopSizing(desktop);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
// Grow is ignored too — it would reflow the desktop view just the same.
|
|
session.resize(200, 60, { viewportType: 'tablet' });
|
|
|
|
expect(resize).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('always applies desktop resizes, claim or not', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.claimDesktopSizing(Symbol('desktop-conn'));
|
|
session.resize(120, 40, { viewportType: 'desktop' });
|
|
|
|
expect(resize).toHaveBeenCalledWith(120, 40);
|
|
});
|
|
|
|
it('restores mobile control once the desktop claim is released', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
const desktop = Symbol('desktop-conn');
|
|
|
|
session.claimDesktopSizing(desktop);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).not.toHaveBeenCalled();
|
|
|
|
session.releaseDesktopSizing(desktop);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).toHaveBeenCalledWith(48, 28);
|
|
});
|
|
|
|
it('keeps ignoring mobile resizes until every desktop claim is released', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
const desktopA = Symbol('desktop-a');
|
|
const desktopB = Symbol('desktop-b');
|
|
|
|
session.claimDesktopSizing(desktopA);
|
|
session.claimDesktopSizing(desktopB);
|
|
session.releaseDesktopSizing(desktopA);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).not.toHaveBeenCalled();
|
|
|
|
session.releaseDesktopSizing(desktopB);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).toHaveBeenCalledWith(48, 28);
|
|
});
|
|
|
|
it('applies untyped (legacy/API) resizes regardless of claims', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.claimDesktopSizing(Symbol('desktop-conn'));
|
|
session.resize(100, 30);
|
|
|
|
expect(resize).toHaveBeenCalledWith(100, 30);
|
|
});
|
|
|
|
it('applies forced resizes even when the dimensions did not change', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 120, 40);
|
|
|
|
session.resize(120, 40, { force: true });
|
|
|
|
expect(resize).toHaveBeenCalledWith(120, 40);
|
|
});
|
|
|
|
describe('idle-desktop override (whoever is active wins)', () => {
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('lets a mobile client take the pane once the desktop claim goes idle', () => {
|
|
vi.useFakeTimers();
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.claimDesktopSizing(Symbol('desktop-conn'));
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).not.toHaveBeenCalled(); // fresh claim → ignored
|
|
|
|
vi.advanceTimersByTime(PAST_IDLE_MS);
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).toHaveBeenCalledWith(48, 28); // idle desktop → applied
|
|
});
|
|
|
|
it('keeps blocking mobile while the desktop stays active via typed input', () => {
|
|
vi.useFakeTimers();
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.claimDesktopSizing(Symbol('desktop-conn'));
|
|
vi.advanceTimersByTime(PAST_IDLE_MS - 10_000);
|
|
session.noteDesktopActivity(); // user typed on desktop
|
|
vi.advanceTimersByTime(20_000); // idle since claim, but not since input
|
|
|
|
session.resize(48, 28, { viewportType: 'mobile' });
|
|
expect(resize).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('re-asserts the desktop layout on desktop input after a mobile override', () => {
|
|
vi.useFakeTimers();
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.resize(208, 45, { viewportType: 'desktop' }); // desktop sizes the pane
|
|
session.claimDesktopSizing(Symbol('desktop-conn'));
|
|
vi.advanceTimersByTime(PAST_IDLE_MS);
|
|
|
|
session.resize(48, 28, { viewportType: 'mobile' }); // phone takes over
|
|
expect(resize).toHaveBeenLastCalledWith(48, 28);
|
|
|
|
session.noteDesktopActivity(); // desktop user types again
|
|
expect(resize).toHaveBeenLastCalledWith(208, 45); // layout restored
|
|
});
|
|
|
|
it('does not re-assert when no mobile override happened', () => {
|
|
const session = new Session({ workingDir: '/tmp', mode: 'shell' });
|
|
const resize = attachFakePty(session, 160, 48);
|
|
|
|
session.resize(208, 45, { viewportType: 'desktop' });
|
|
resize.mockClear();
|
|
session.noteDesktopActivity();
|
|
expect(resize).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|