mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-14 02:29:33 +01:00
fix(terminal): capture remote history and preserve isolated wheel travel (#7)
This commit is contained in:
1 parent
131ee1a31e
commit
242bbfcd31
9 files changed
+173
-16
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { chromium, type Browser } from 'playwright';
|
||||
import { WebServer } from '../src/web/server.js';
|
||||
|
||||
// Adversarial browser layout fixture, not evidence of native Codex history:
|
||||
// authentic CLI behavior is measured separately in an isolated live pane.
|
||||
describe('tracked remote Codex wheel routing (#13)', () => {
|
||||
let server: WebServer;
|
||||
let browser: Browser;
|
||||
beforeAll(async () => {
|
||||
server = new WebServer(0, false, true);
|
||||
await server.start();
|
||||
browser = await chromium.launch({ headless: true });
|
||||
}, 60000);
|
||||
afterAll(async () => {
|
||||
await browser?.close();
|
||||
await server?.stop();
|
||||
});
|
||||
|
||||
it('sends plain wheel to the CLI rather than scrolling stale repaint frames', async () => {
|
||||
const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
|
||||
try {
|
||||
await page.goto(`http://127.0.0.1:${server.boundPort}`, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForFunction(() => (window as any).app?.terminal);
|
||||
await page.waitForTimeout(3500);
|
||||
await page.evaluate(async () => {
|
||||
const app = (window as any).app;
|
||||
app.activeSessionId = 'codex-wheel-probe';
|
||||
app.sessions.set(app.activeSessionId, { id: app.activeSessionId, mode: 'codex', cliMouseTracking: true });
|
||||
(window as any).scrollInputs = [];
|
||||
// Cell hit testing is irrelevant to routing; the empty dashboard covers the test terminal.
|
||||
app._clientPointToCell = () => ({ col: 1, row: 1 });
|
||||
app._sendInputEphemeral = (id: string, data: string) => (window as any).scrollInputs.push({ id, data });
|
||||
app.loadAppSettingsFromStorage = () => ({ terminalWheelLocalScrollback: false });
|
||||
await new Promise<void>((resolve) => app.terminal.write('\r\nold repaint row'.repeat(100), resolve));
|
||||
app.terminal.scrollToTop();
|
||||
});
|
||||
const fire = (shiftKey = false) =>
|
||||
page.evaluate((shiftKey) => {
|
||||
const t = (window as any).app.terminal;
|
||||
t.element.dispatchEvent(new WheelEvent('wheel', { deltaY: -100, shiftKey, bubbles: true, cancelable: true }));
|
||||
}, shiftKey);
|
||||
await fire();
|
||||
await page.waitForTimeout(150);
|
||||
const forwarded = await page.evaluate(() => {
|
||||
const app = (window as any).app;
|
||||
return {
|
||||
inputs: (window as any).scrollInputs,
|
||||
baseY: app.terminal.buffer.active.baseY,
|
||||
viewportY: app.terminal.buffer.active.viewportY,
|
||||
};
|
||||
});
|
||||
expect(forwarded.inputs.length).toBeGreaterThan(0);
|
||||
expect(forwarded.inputs.every((i: { id: string }) => i.id === 'codex-wheel-probe')).toBe(true);
|
||||
expect(
|
||||
forwarded.inputs
|
||||
.map((i: { data: string }) => i.data)
|
||||
.join('')
|
||||
.match(/\x1b\[<64;/g)
|
||||
).toHaveLength(4);
|
||||
expect(forwarded.viewportY).toBe(forwarded.baseY);
|
||||
for (const shift of [false, true]) {
|
||||
await page.evaluate((tracked) => {
|
||||
const app = (window as any).app;
|
||||
app.sessions.get(app.activeSessionId).cliMouseTracking = tracked;
|
||||
app.terminal.scrollToBottom();
|
||||
(window as any).scrollInputs = [];
|
||||
}, shift);
|
||||
await fire(shift);
|
||||
await page.waitForTimeout(150);
|
||||
const local = await page.evaluate(() => {
|
||||
const b = (window as any).app.terminal.buffer.active;
|
||||
return { inputs: (window as any).scrollInputs, baseY: b.baseY, viewportY: b.viewportY };
|
||||
});
|
||||
expect(local.inputs).toEqual([]);
|
||||
expect(local.viewportY).toBeLessThan(local.baseY);
|
||||
}
|
||||
} finally {
|
||||
await page.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
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 { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import {
|
||||
@@ -79,6 +79,40 @@ describe('buildRemoteScrollbackCommand', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('remote history PATH bootstrap', () => {
|
||||
it('finds tmux installed under the remote home when the login shell omits it', () => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'remote-history-path-'));
|
||||
const home = join(root, 'remote home');
|
||||
const sshBin = join(root, 'local-bin');
|
||||
const remoteBin = join(home, '.local', 'bin');
|
||||
mkdirSync(sshBin, { recursive: true });
|
||||
mkdirSync(remoteBin, { recursive: true });
|
||||
writeFileSync(join(sshBin, 'ssh'), '#!/bin/sh\nfor arg do command="$arg"; done\nexec /bin/sh -c "$command"\n', {
|
||||
mode: 0o755,
|
||||
});
|
||||
writeFileSync(
|
||||
join(remoteBin, 'tmux'),
|
||||
`#!/bin/sh
|
||||
printf 'older row\\n${MARKER}\\n1\\ncurrent screen\\n'
|
||||
`,
|
||||
{ mode: 0o755 }
|
||||
);
|
||||
try {
|
||||
const command = buildRemoteScrollbackCommand(remote, SESSION_ID, 100, 0, MARKER);
|
||||
const stdout = execFileSync('/bin/sh', ['-c', command], {
|
||||
encoding: 'utf-8',
|
||||
env: { ...process.env, HOME: home, PATH: `${sshBin}:/usr/bin:/bin` },
|
||||
});
|
||||
expect(parseRemoteScrollbackOutput(stdout, MARKER, 0)).toEqual({
|
||||
scrollback: 'older row\n',
|
||||
screen: 'current screen\n',
|
||||
});
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('remoteTailBytes', () => {
|
||||
it('adds room for the marker, size and screen to the cap, so a cut lands in the history', () => {
|
||||
expect(remoteTailBytes(2048)).toBe(2048 + 1024 * 1024);
|
||||
|
||||
@@ -909,6 +909,25 @@ describe('consistent scroll gesture adapters', () => {
|
||||
expect(loadTerminalUiHarness().windowRef.CodemanTerminalInput.PAGE_KEY_IMMEDIATE_MAX_ROWS).toBe(2);
|
||||
});
|
||||
|
||||
it('preserves rounded travel for isolated coarse clicks without accumulating a capped backlog', () => {
|
||||
const { wheelTicksForGesture } = loadTerminalUiHarness().windowRef.CodemanTerminalInput;
|
||||
for (const direction of [-1, 1]) {
|
||||
expect(wheelTicksForGesture(null, direction * 4.8, 0).ticks).toBe(direction * 5); // 120px
|
||||
expect(wheelTicksForGesture(null, direction * 1.6, 0).ticks).toBe(direction * 2); // 40px
|
||||
let state = null;
|
||||
let ticks = 0;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const step = wheelTicksForGesture(state, direction * 4.8, i * 300);
|
||||
state = step.state;
|
||||
ticks += step.ticks;
|
||||
}
|
||||
expect(ticks).toBe(direction * 25);
|
||||
const capped = wheelTicksForGesture(null, direction * 40, 0);
|
||||
expect(capped.ticks).toBe(direction * 5);
|
||||
expect(capped.state.pending).toBe(0); // don't retain travel discarded by the event cap
|
||||
}
|
||||
});
|
||||
|
||||
it('pre-pays an isolated deliberate opening tick and repays its signed debt', () => {
|
||||
const { wheelTicksForGesture } = loadTerminalUiHarness().windowRef.CodemanTerminalInput;
|
||||
const opening = wheelTicksForGesture(null, -0.16, 0); // a 4px mouse click
|
||||
|
||||
Reference in new issue
Block a user