Repository navigation
fix: accept RPC responses up to 64 MiB and refuse a larger success with PROTOCOL_ERROR #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
814ef21
test: cap the RPC request id and keep surrogate pairs whole in a shor…
ThomasK33 cf826bf
fix: cap the RPC request id and keep surrogate pairs whole in a short…
ThomasK33 78ac00b
docs: describe the RPC request id cap and the surrogate-safe message cut
ThomasK33 0a7ca28
test: return an RPC success response over 1 MiB and refuse one over 6…
ThomasK33 d93a8d5
fix: accept RPC responses up to 64 MiB and refuse a larger success wi…
ThomasK33 9db4a64
docs: describe the 64 MiB RPC response cap and its PROTOCOL_ERROR
ThomasK33 f81d785
docs: name MAX_RPC_RESPONSE_CHARS in the protocol README
ThomasK33 b9b502f
test: give a snapshot with cells 60 s and scan each RPC response chun…
ThomasK33 51cbc09
fix: give a snapshot with cells 60 s and scan each RPC response chunk…
ThomasK33 041476d
docs: describe the snapshot cells timeout and the per-chunk newline scan
ThomasK33 17e4ffe
Merge remote-tracking branch 'origin/main' into fix/rpc-response-cap
ThomasK33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import type { SnapshotResult } from '../../src/protocol/messages.js'; | ||
| import { | ||
| cleanupHome, | ||
| createIsolatedHome, | ||
| DEFAULT_CLI_TIMEOUT_MS, | ||
| fixtureCommand, | ||
| runCli, | ||
| runCliJson, | ||
| type SuccessEnvelope, | ||
| type WaitResult, | ||
| } from './helpers.js'; | ||
|
|
||
| interface CreateResult { | ||
| sessionId: string; | ||
| } | ||
|
|
||
| const COLS = 300; | ||
| const ROWS = 100; | ||
|
|
||
| function testEnv(home: string): Record<string, string> { | ||
| return { AGENT_TTY_HOME: home }; | ||
| } | ||
|
|
||
| describe('large snapshot e2e', { timeout: 90_000 }, () => { | ||
| let testHome = ''; | ||
| let createdSessionIds: string[] = []; | ||
|
|
||
| beforeEach(async () => { | ||
| testHome = await createIsolatedHome(); | ||
| createdSessionIds = []; | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| const env = testEnv(testHome); | ||
|
|
||
| for (const sessionId of createdSessionIds) { | ||
| runCli(['destroy', sessionId, '--force', '--json'], env); | ||
| } | ||
|
|
||
| await cleanupHome(testHome); | ||
| }); | ||
|
|
||
| it('returns a styled 300x100 snapshot with cells, larger than 1 MiB', () => { | ||
| const env = testEnv(testHome); | ||
| const createEnvelope = runCliJson<SuccessEnvelope<CreateResult>>( | ||
| [ | ||
| 'create', | ||
| '--cols', | ||
| String(COLS), | ||
| '--rows', | ||
| String(ROWS), | ||
| '--', | ||
| ...fixtureCommand('styled-fill'), | ||
| ], | ||
| env, | ||
| ); | ||
| const { sessionId } = createEnvelope.result; | ||
| createdSessionIds.push(sessionId); | ||
|
|
||
| const waitEnvelope = runCliJson<SuccessEnvelope<WaitResult>>( | ||
| ['wait', sessionId, '--text', 'FILL-DONE', '--timeout', '30000'], | ||
| env, | ||
| ); | ||
| expect(waitEnvelope.ok).toBe(true); | ||
|
|
||
| // spawnSync keeps at most 1 MiB of stdout unless maxBuffer is raised. | ||
| const snapshot = spawnSync( | ||
| process.execPath, | ||
| [ | ||
| '--import', | ||
| 'tsx', | ||
| './src/cli/main.ts', | ||
| 'snapshot', | ||
| sessionId, | ||
| '--include-cells', | ||
| '--json', | ||
| ], | ||
| { | ||
| cwd: process.cwd(), | ||
| encoding: 'utf8', | ||
| env: { ...process.env, ...env }, | ||
| maxBuffer: 64 * 1_048_576, | ||
| timeout: DEFAULT_CLI_TIMEOUT_MS, | ||
| }, | ||
| ); | ||
|
|
||
| const envelope = JSON.parse( | ||
| snapshot.stdout, | ||
| ) as SuccessEnvelope<SnapshotResult> & { | ||
| error?: unknown; | ||
| }; | ||
| expect(envelope.error).toBeUndefined(); | ||
| expect(envelope.ok).toBe(true); | ||
| expect(snapshot.status).toBe(0); | ||
| expect(snapshot.stdout.length).toBeGreaterThan(1_048_576); | ||
| const { result } = envelope; | ||
| if (result.format !== 'structured') { | ||
| throw new Error('expected a structured snapshot'); | ||
| } | ||
| expect(result.cells).toHaveLength(ROWS); | ||
| expect(result.cells?.[0]?.cells).toHaveLength(COLS); | ||
| expect(result.cells?.[0]?.cells[0]).toMatchObject({ | ||
| char: 'a', | ||
| bold: true, | ||
| }); | ||
| expect(result.cells?.[0]?.cells[0]?.fg).toBeDefined(); | ||
| expect(result.cells?.[0]?.cells[0]?.bg).toBeDefined(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import process from 'node:process'; | ||
|
|
||
| // Fills the whole screen with cells that each have their own truecolor | ||
| // foreground, background and bold, the largest per-cell snapshot data. | ||
| const MARKER = 'FILL-DONE'; | ||
| const HOLD_OPEN_MS = 60_000; | ||
|
|
||
| const cols = process.stdout.columns; | ||
| const rows = process.stdout.rows; | ||
| assert( | ||
| Number.isInteger(cols) && Number.isInteger(rows) && cols > MARKER.length, | ||
| 'styled-fill needs a TTY wider than its marker', | ||
| ); | ||
|
|
||
| let output = '\u001b[2J'; | ||
| for (let row = 0; row < rows; row += 1) { | ||
| output += `\u001b[${String(row + 1)};1H`; | ||
| const isLastRow = row === rows - 1; | ||
| // Leave the last cell of the screen empty so the screen does not scroll. | ||
| const width = isLastRow ? cols - 1 - MARKER.length : cols; | ||
| for (let col = 0; col < width; col += 1) { | ||
| const fg = `${String(col % 256)};${String(row % 256)};${String((col * 7) % 256)}`; | ||
| const bg = `${String((row * 3) % 256)};${String((col * 5) % 256)};${String(255 - (col % 256))}`; | ||
| const char = String.fromCharCode(97 + ((row * cols + col) % 26)); | ||
| output += `\u001b[1;38;2;${fg}m\u001b[48;2;${bg}m${char}`; | ||
| } | ||
| if (isLastRow) { | ||
| output += `\u001b[0m${MARKER}`; | ||
| } | ||
| } | ||
| process.stdout.write(output); | ||
|
|
||
| setTimeout(() => { | ||
| process.exit(0); | ||
| }, HOLD_OPEN_MS); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.