Repository navigation
fix(web-shell): prevent terminal query freezes and clean up protocol rejection #11748
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
+168
−5
Merged
Changes from all commits
Commits
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
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,97 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { readFile } from 'node:fs/promises'; | ||
| import { createRequire } from 'node:module'; | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { runInNewContext } from 'node:vm'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { resolveConfig } from 'vite'; | ||
| import { JSDOM } from 'jsdom'; | ||
| // Use the repository's compiler; a locally overridden Vite dependency may | ||
| // already fix the logical-assignment lowering bug and mask this regression. | ||
| import { transform } from 'esbuild'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| const webShellRoot = resolve(import.meta.dirname, '../../packages/web-shell'); | ||
|
|
||
| interface TestTerminal { | ||
| onData(listener: (data: string) => void): void; | ||
| _core: { _inputHandler: { parse(data: string): void } }; | ||
| buffer: { | ||
| active: { getLine(index: number): { translateToString(): string } }; | ||
| }; | ||
| dispose(): void; | ||
| } | ||
|
|
||
| async function builtTerminal(target: string | string[]) { | ||
| const source = await readFile( | ||
| resolve(dirname(require.resolve('@xterm/xterm')), 'xterm.mjs'), | ||
| 'utf8', | ||
| ); | ||
| const { code } = await transform(source, { | ||
| target, | ||
| minify: true, | ||
| format: 'cjs', | ||
| }); | ||
| const module = { | ||
| exports: {} as { | ||
| Terminal: new (options: { allowProposedApi: boolean }) => TestTerminal; | ||
| }, | ||
| }; | ||
| const { window } = new JSDOM(); | ||
| Object.defineProperty(window.HTMLCanvasElement.prototype, 'getContext', { | ||
| value: () => null, | ||
| }); | ||
| runInNewContext(code, { | ||
| window, | ||
| document: window.document, | ||
| navigator: window.navigator, | ||
| module, | ||
| exports: module.exports, | ||
| setTimeout, | ||
| clearTimeout, | ||
| setInterval, | ||
| clearInterval, | ||
| queueMicrotask, | ||
| console, | ||
| performance, | ||
| }); | ||
| return new module.exports.Terminal({ allowProposedApi: true }); | ||
| } | ||
|
|
||
| function queryAndPrint(terminal: TestTerminal) { | ||
| const replies: string[] = []; | ||
| terminal.onData((data) => replies.push(data)); | ||
| // Parsing synchronously exposes failures that xterm's asynchronous write queue | ||
| // otherwise reports outside the test, without requiring a browser renderer. | ||
| terminal._core._inputHandler.parse('\x1b[?2004$pafter-query'); | ||
| return { | ||
| replies, | ||
| output: terminal.buffer.active.getLine(0).translateToString().trimEnd(), | ||
| }; | ||
| } | ||
|
|
||
| describe('Web Shell production terminal', () => { | ||
| it('answers DECRQM and keeps processing output after minification', async () => { | ||
| const config = await resolveConfig( | ||
| { | ||
| root: webShellRoot, | ||
| configFile: resolve(webShellRoot, 'vite.config.ts'), | ||
| }, | ||
| 'build', | ||
| ); | ||
| const terminal = await builtTerminal(config.build.target || 'esnext'); | ||
|
yiliang114 marked this conversation as resolved.
Resolved
|
||
| try { | ||
| expect(queryAndPrint(terminal)).toEqual({ | ||
| replies: ['\x1b[?2004;2$y'], | ||
| output: 'after-query', | ||
| }); | ||
| } finally { | ||
| terminal.dispose(); | ||
| } | ||
| }); | ||
| }); | ||
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.