-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(terminal): serialize only the visible width after a column shrink #22586
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
Open
Jinwoo-H
wants to merge
14
commits into
main
Choose a base branch
from
fix/terminal-serialize-alt-screen-width
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc9111a
fix(terminal): serialize only the visible width after a column shrink
Jinwoo-H a3ba483
test(terminal): read shrink-snapshot fixtures through public APIs
Jinwoo-H ecfdea0
fix(terminal): blank a wide glyph clipped by a column shrink when ser…
Jinwoo-H 0624e75
test(mobile): move the session closure pin past the main agent status…
Jinwoo-H b249561
test(terminal): differential serialize round-trip fuzz and transcript…
Jinwoo-H f532fda
test(terminal): build the differential serialize baseline from any gi…
Jinwoo-H b06b751
fix(terminal): serialize a clipped wide glyph as a width-1 blank
Jinwoo-H c63dad1
test(terminal): neutral paths in the serialize fixtures and usage com…
Jinwoo-H 15feb5c
fix(terminal): keep trailing background-only rows when serializing
Jinwoo-H ada3892
test(terminal): narrow the I1 carve-out to where the serializer keeps…
Jinwoo-H c5ba3a2
test(native-chat): pin that screen scrapers ignore kept background rows
Jinwoo-H 4eff4a5
Merge origin/main into fix/terminal-serialize-alt-screen-width
Jinwoo-H ccfc5ad
test(terminal): read xterm core internals through a checked parser, n…
Jinwoo-H b70c8dd
test(terminal): keep captured serialize transcripts byte-exact on Win…
Jinwoo-H 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
169 changes: 144 additions & 25 deletions
169
config/patches/@xterm__addon-serialize@0.15.0-beta.300.patch
Large diffs are not rendered by default.
Oops, something went wrong.
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,123 @@ | ||
| #!/usr/bin/env node | ||
| // Materializes the patched @xterm/addon-serialize dist of any git ref, for the | ||
| // differential serialize fuzz (src/main/daemon/serialize-grid.differential.fuzz.test.ts): | ||
| // | ||
| // node config/scripts/build-serialize-addon-at-ref.mjs --ref origin/main --out-dir /tmp/serialize-old | ||
| // ORCA_OLD_SERIALIZE_ADDON=<printed path> pnpm exec vitest run --config config/vitest.config.ts src/main/daemon/serialize-grid.differential.fuzz.test.ts | ||
| // | ||
| // It recovers the pristine dist by reverse-applying whichever patch produced the | ||
| // installed node_modules copy, applies the ref's patch, and checks every step | ||
| // against the blob hashes in the patches' index lines. | ||
|
|
||
| import { execFileSync } from 'node:child_process' | ||
| import { createHash } from 'node:crypto' | ||
| import { | ||
| cpSync, | ||
| existsSync, | ||
| mkdirSync, | ||
| readFileSync, | ||
| readdirSync, | ||
| rmSync, | ||
| writeFileSync | ||
| } from 'node:fs' | ||
| import path from 'node:path' | ||
|
|
||
| const REPO_ROOT = path.resolve(import.meta.dirname, '..', '..') | ||
| const PACKAGE = '@xterm/addon-serialize' | ||
| const DIST_FILE = 'lib/addon-serialize.js' | ||
|
|
||
| function parseArgs(argv) { | ||
| const args = {} | ||
| for (let i = 0; i < argv.length; i += 2) { | ||
| args[argv[i].replace(/^--/, '')] = argv[i + 1] | ||
| } | ||
| if (!args.ref || !args['out-dir']) { | ||
| throw new Error('usage: build-serialize-addon-at-ref.mjs --ref <git-ref> --out-dir <dir>') | ||
| } | ||
| return args | ||
| } | ||
|
|
||
| function git(args, options = {}) { | ||
| return execFileSync('git', args, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, ...options }) | ||
| } | ||
|
|
||
| function blobHash(content) { | ||
| return createHash('sha1').update(`blob ${content.length}\0`).update(content).digest('hex') | ||
| } | ||
|
|
||
| function patchFileName() { | ||
| const name = readdirSync(path.join(REPO_ROOT, 'config', 'patches')).find( | ||
| (file) => file.startsWith('@xterm__addon-serialize@') && file.endsWith('.patch') | ||
| ) | ||
| if (!name) { | ||
| throw new Error('no @xterm/addon-serialize dist patch under config/patches') | ||
| } | ||
| return name | ||
| } | ||
|
|
||
| /** Pre- and post-image blob hashes the patch records for the dist file. */ | ||
| function distHashes(patchText) { | ||
| const match = patchText.match( | ||
| new RegExp(`diff --git a/${DIST_FILE} b/${DIST_FILE}\\nindex ([0-9a-f]+)\\.\\.([0-9a-f]+)`) | ||
| ) | ||
| if (!match) { | ||
| throw new Error(`patch does not touch ${DIST_FILE}`) | ||
| } | ||
| return { pristine: match[1], patched: match[2] } | ||
| } | ||
|
|
||
| function applyPatch(packageDir, patchPath, reverse) { | ||
| // Ceiling stops git from discovering an enclosing repository, so paths stay package-relative. | ||
| git(['apply', ...(reverse ? ['-R'] : []), `--include=${DIST_FILE}`, patchPath], { | ||
| cwd: packageDir, | ||
| env: { ...process.env, GIT_CEILING_DIRECTORIES: path.dirname(packageDir) } | ||
| }) | ||
| } | ||
|
|
||
| function main() { | ||
| const args = parseArgs(process.argv.slice(2)) | ||
| const outDir = path.resolve(args['out-dir']) | ||
| const name = patchFileName() | ||
| const relativePatch = path.posix.join('config', 'patches', name) | ||
| const refPatch = git(['show', `${args.ref}:${relativePatch}`], { cwd: REPO_ROOT }) | ||
| const target = distHashes(refPatch) | ||
|
|
||
| const packageDir = path.join(outDir, 'package') | ||
| rmSync(outDir, { recursive: true, force: true }) | ||
| mkdirSync(path.join(packageDir, 'lib'), { recursive: true }) | ||
| const installed = path.join(REPO_ROOT, 'node_modules', PACKAGE, DIST_FILE) | ||
| cpSync(installed, path.join(packageDir, DIST_FILE)) | ||
| const distPath = path.join(packageDir, DIST_FILE) | ||
| const installedHash = blobHash(readFileSync(distPath)) | ||
|
|
||
| if (installedHash !== target.patched) { | ||
| const candidates = [ | ||
| readFileSync(path.join(REPO_ROOT, relativePatch), 'utf8'), | ||
| git(['show', `HEAD:${relativePatch}`], { cwd: REPO_ROOT }) | ||
| ] | ||
| const source = candidates.find((text) => distHashes(text).patched === installedHash) | ||
| if (!source) { | ||
| throw new Error( | ||
| `installed ${DIST_FILE} (${installedHash}) matches neither the working-tree nor the HEAD patch; run pnpm install` | ||
| ) | ||
| } | ||
| const sourcePath = path.join(outDir, 'installed.patch') | ||
| writeFileSync(sourcePath, source) | ||
| applyPatch(packageDir, sourcePath, true) | ||
| if (blobHash(readFileSync(distPath)) !== target.pristine) { | ||
| throw new Error(`reverse-applied dist is not the pristine ${target.pristine} the ref patches`) | ||
| } | ||
| const refPatchPath = path.join(outDir, 'ref.patch') | ||
| writeFileSync(refPatchPath, refPatch) | ||
| applyPatch(packageDir, refPatchPath, false) | ||
| } | ||
| const finalHash = blobHash(readFileSync(distPath)) | ||
| if (finalHash !== target.patched || !existsSync(distPath)) { | ||
| throw new Error( | ||
| `built ${DIST_FILE} hashes to ${finalHash}, the ref patch expects ${target.patched}` | ||
| ) | ||
| } | ||
| process.stdout.write(`${distPath}\n`) | ||
| } | ||
|
|
||
| main() |
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.