Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ vi.mock('../../i18n', () => ({
'terminal.notice.error': `Error: ${values?.['message'] ?? ''}`,
'terminal.notice.unknownError': 'Unknown error',
'terminal.notice.reconnecting': 'Connection lost — reconnecting…',
'terminal.notice.protocolMismatch':
'Terminal protocol changed; restart the daemon and reload this page.',
})[key] ?? key,
}),
}));
Expand Down Expand Up @@ -316,9 +318,17 @@ describe('TerminalPanel', () => {
ws.close.mock.invocationCallOrder[0]!,
);
expect(ws.close).toHaveBeenCalledWith(4002, 'Terminal protocol mismatch');
// The localized restart notice is a named deliverable; without pinning it
// the mock's `?? key` fallback would silently render the raw key instead.
expect(terminal.writeln).toHaveBeenCalledWith(
expect.stringContaining('Terminal protocol changed'),
);
const sent = ws.send.mock.calls.length;
act(() => releaseWebTerminal('terminal:one'));
expect(ws.send).toHaveBeenCalledTimes(sent);
// The mismatch branch already released this PTY: the releaseRequested flag
// must keep release() from opening a second, release-only socket.
expect(FakeWebSocket.instances).toHaveLength(1);
expect(terminal.write).not.toHaveBeenCalled();
});

Expand Down
8 changes: 7 additions & 1 deletion packages/web-shell/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export const BRAND_ROUTE_PROXY = '^/brand/?$';
// bridge hangs in `connecting`.
export const QUALIFIED_ACP_WS_PROXY = '^/workspaces/[^/]+/acp/?$';

// Shared with vite.lib.config.ts so the app and lib builds can never drift
// onto different syntax floors: esbuild miscompiles xterm's logical
// assignments below ES2021 (#11643), and the lib build bundles the same
// xterm for npm hosts.
export const WEB_SHELL_BUILD_TARGET = 'es2021';

export default defineConfig(({ command }) => ({
root: 'client',
plugins: [react(), tailwindcss()],
Expand Down Expand Up @@ -89,7 +95,7 @@ export default defineConfig(({ command }) => ({
},
build: {
// Avoid esbuild lowering xterm's logical assignments into invalid code.
target: 'es2021',
target: WEB_SHELL_BUILD_TARGET,
outDir: '../dist',
emptyOutDir: true,
},
Expand Down
6 changes: 6 additions & 0 deletions packages/web-shell/vite.lib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import tailwindcss from '@tailwindcss/vite';
import postcss from 'postcss';
import selectorParser from 'postcss-selector-parser';
import pkg from './package.json' with { type: 'json' };
import { WEB_SHELL_BUILD_TARGET } from './vite.config';

const COMPONENT_SCOPE =
':where([data-web-shell-root][data-web-shell-shadcn], [data-web-shell-portal-root][data-web-shell-shadcn], [data-web-shell-root][data-web-shell-shadcn] *, [data-web-shell-portal-root][data-web-shell-shadcn] *)';
Expand Down Expand Up @@ -169,6 +170,11 @@ export default defineConfig(({ mode }) => ({
},
build: {
emptyOutDir: false,
// Same floor as the app build: the lib bundle minifies the same xterm
// (it is not external), and Vite 5's default target lowers its logical
// assignments into code that throws on the first mode query. Also covers
// the transcript entry inlined into /export html documents.
target: WEB_SHELL_BUILD_TARGET,
lib: {
entry:
mode === 'transcript'
Expand Down
5 changes: 4 additions & 1 deletion scripts/tests/package-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,10 @@ describe('package asset scripts', () => {
.filter(([name]) => name.startsWith('@lydell/node-pty'))
.map(([name]) => [name, '1.2.0-test-pin']),
);
expect(Object.keys(pins)).toHaveLength(6);
// The pin *count* is owned by conpty-host.test.ts as a deliberate human
// re-check tripwire; here a non-empty guard keeps `toEqual(pins)` honest
// without duplicating a number that fails before the code under test runs.
expect(Object.keys(pins).length).toBeGreaterThan(0);
core.optionalDependencies = pins;
writeFileSync(corePath, JSON.stringify(core));
createBundleArtifacts(rootDir);
Expand Down
65 changes: 44 additions & 21 deletions scripts/tests/web-terminal-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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.
Expand All @@ -18,6 +17,18 @@ import { transform } from 'esbuild';
const require = createRequire(import.meta.url);
const webShellRoot = resolve(import.meta.dirname, '../../packages/web-shell');

// Resolve the config through web-shell's own Vite: the bare `vite` import
// here lands on the root-hoisted Vite 7, whose default `build.target`
// (chrome107/…) never lowers logical assignments, so a dropped
// `target: 'es2021'` would keep this probe green while the real Vite 5
// build ships a broken bundle. Vite 5 exposes `resolveConfig` on `.default`
// under some interops, so normalize that.
const webShellVite = createRequire(resolve(webShellRoot, 'package.json'))(
'vite',
) as typeof import('vite') & { default?: typeof import('vite') };
const resolveViteConfig = (webShellVite.resolveConfig ??
webShellVite.default?.resolveConfig)!;

interface TestTerminal {
onData(listener: (data: string) => void): void;
_core: { _inputHandler: { parse(data: string): void } };
Expand Down Expand Up @@ -75,23 +86,35 @@ function queryAndPrint(terminal: TestTerminal) {
};
}

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');
try {
expect(queryAndPrint(terminal)).toEqual({
replies: ['\x1b[?2004;2$y'],
output: 'after-query',
});
} finally {
terminal.dispose();
}
});
});
// The package runs three builds: the app (`vite.config.ts`) and the two lib
// invocations (`vite.lib.config.ts`, default and transcript modes). Both
// configs must carry the ES2021 floor or the shipped bundle throws on the
// first DECRQM query.
describe.each(['vite.config.ts', 'vite.lib.config.ts'])(
'Web Shell production terminal (%s)',
(configFile) => {
it('answers DECRQM and keeps processing output after minification', async () => {
const config = await resolveViteConfig(
{
root: webShellRoot,
configFile: resolve(webShellRoot, configFile),
},
'build',
);
// Pin the floor itself: the probe cannot discriminate it (both esbuild
// copies miscompile identically only at the Vite 5 default), and
// resolveConfig always fills a default so a dropped `target` would be
// masked without this assertion.
expect(config.build.target).toBe('es2021');
const terminal = await builtTerminal(config.build.target);
try {
expect(queryAndPrint(terminal)).toEqual({
replies: ['\x1b[?2004;2$y'],
output: 'after-query',
});
} finally {
terminal.dispose();
}
});
},
);
Loading