Make Terminal a native feature
- Move the Terminal plugin into src/lib/features/terminal/ on the host Svelte runtime, with xterm 6.0.0 and addon-fit 0.11.0. - Buttons, shortcuts, Help rows, and the close guard follow the Terminal switch. The first use loads the module. - Add Settings → Terminal and the terminal settings section. The first start copies the old runestone.terminal key. - The 16 ANSI colors come from the --rs-ansi-* tokens. - Off asks first when a shell runs in any window (pty_running). - Rust: no pty-data or pty-exit events, an owner check for write, resize, and close, output joined up to 64 KiB or 8 ms, and the sessions of a reloaded page close. - Remove api.pty, the terminal contribution, TerminalSlot, and the plugin loader of the smoke harness. - Check only the tested switches in the Background smoke test. - Update the tests, the menu inventory, the docs, and UI-058.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// Feature lifecycle: the built-in Table formulas setting and the Terminal plug-in turn off, persist, reopen across windows, and uninstall without restoration.
|
||||
// An old Table Formulas package stays inactive and shows that the feature is built in.
|
||||
// @requires plugin:terminal
|
||||
// Feature lifecycle: the built-in Table formulas setting and the native Terminal feature turn off, persist, and turn on again across windows.
|
||||
// Terminal off asks first while a shell runs, and then ends the shells of each window.
|
||||
// An old Table Formulas package stays inactive, shows that the feature is built in, and uninstalls without restoration.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
import { mockFeaturePlugins, oldTableFormulasRow } from '../_harness/pluginMocks.mjs';
|
||||
import { mockInstalledPlugins, oldTableFormulasRow } from '../_harness/pluginMocks.mjs';
|
||||
|
||||
await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
@@ -32,24 +32,12 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
test.emit('workspace-event', { root: ws.root, kind: 'modify', paths: [rel] });
|
||||
},
|
||||
settings_open_window: () => null,
|
||||
pty_profiles: () => [{ id: 'powershell', title: 'PowerShell', kind: 'powershell' }],
|
||||
pty_open: async ({ id, channel }) => {
|
||||
const data = new TextEncoder().encode('READY 🪨\r\n\x1b[6n');
|
||||
// A Terminal plugin that uses api.pty passes a channel and gets raw bytes. Released versions listen for events.
|
||||
if (channel) setTimeout(() => { channel.onmessage(data.slice(0, 8).buffer); channel.onmessage(data.slice(8).buffer); }, 0);
|
||||
else {
|
||||
test.emit('pty-data', { id, data: [...data.slice(0, 8)] });
|
||||
test.emit('pty-data', { id, data: [...data.slice(8)] });
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
},
|
||||
pty_write: () => null,
|
||||
pty_resize: () => null,
|
||||
pty_close: () => null,
|
||||
// Terminal off asks first while a shell runs (src/lib/layout/SettingsDialog.svelte).
|
||||
'plugin:dialog|message': args => { test.state.prompts = [...test.state.prompts ?? [], args.message]; return 'Ok'; },
|
||||
};
|
||||
},
|
||||
});
|
||||
await mockFeaturePlugins(context, [oldTableFormulasRow]);
|
||||
await mockInstalledPlugins(context, [oldTableFormulasRow]);
|
||||
const output = await outputDir('plugins/lifecycle');
|
||||
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
@@ -122,29 +110,38 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
await oldPackage.getByText('Included with RuneStone', { exact: true }).waitFor();
|
||||
await oldPackage.getByText(/Table Formulas is now built in\. You can remove this old package\./).waitFor();
|
||||
assert(await oldPackage.getByRole('switch').isDisabled(), 'The old package cannot be enabled');
|
||||
assert.equal(await switchFor('Terminal').count(), 0, 'Terminal is a feature, not a plugin');
|
||||
await dialog.getByRole('button', { name: 'Features', exact: true }).click();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await page.waitForFunction(ptyCalled, 'pty_close');
|
||||
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings.png') });
|
||||
const prompts = await settingsPage.evaluate(() => window.__TEST__.state.prompts);
|
||||
assert.deepEqual(prompts, ['Terminal sessions will end.\nTurn off Terminal?'], 'Terminal off asks first while a shell runs');
|
||||
assert.equal(await settingsPage.evaluate(() => window.__TEST__.settings('features').terminal), false);
|
||||
await settingsPage.screenshot({ path: path.join(output, 'features-terminal-off.png') });
|
||||
await closeSettings();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
const opened = await count('pty_open');
|
||||
await page.keyboard.press('Control+j');
|
||||
await page.keyboard.press('Control+Shift+Backquote');
|
||||
assert.equal(await count('pty_open'), opened);
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
await settings();
|
||||
await settings('Features');
|
||||
assert(!await switchFor('Terminal').isChecked());
|
||||
assert.equal(await dialog.getByRole('button', { name: 'Terminal', exact: true }).count(), 0, 'Settings → Terminal shows only while Terminal is on');
|
||||
|
||||
const standalone = await openPage(context);
|
||||
await standalone.goto(smokeUrl + '?terminalWindow=C%3A%5Csmoke-workspace');
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await standalone.getByText('Terminal is off. Turn it on in Settings → Features.', { exact: true }).waitFor();
|
||||
await switchFor('Terminal').check();
|
||||
await standalone.locator('.xterm').waitFor();
|
||||
await standalone.waitForFunction(ptyCalled, 'pty_open');
|
||||
await dialog.getByRole('button', { name: 'Terminal', exact: true }).waitFor();
|
||||
await switchFor('Terminal').uncheck();
|
||||
await standalone.getByText(/Install and enable the Terminal plugin/).waitFor();
|
||||
await standalone.getByText('Terminal is off. Turn it on in Settings → Features.', { exact: true }).waitFor();
|
||||
await standalone.waitForFunction(ptyCalled, 'pty_close');
|
||||
assert.equal((await settingsPage.evaluate(() => window.__TEST__.state.prompts)).length, 1, 'The shell of the terminal window gives a prompt too');
|
||||
page.errors.push(...standalone.errors);
|
||||
await standalone.close();
|
||||
await switchFor('Terminal').check();
|
||||
@@ -156,17 +153,14 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
await quickOpen('formulas.md');
|
||||
await settings();
|
||||
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
|
||||
for (const name of ['Terminal', 'Table Formulas']) {
|
||||
await idle();
|
||||
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await confirmation.waitFor({ state: 'hidden' });
|
||||
await switchFor(name).waitFor({ state: 'detached' });
|
||||
}
|
||||
await idle();
|
||||
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name: 'Table Formulas', exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
|
||||
const confirmation = settingsPage.getByRole('dialog', { name: 'Uninstall Table Formulas?', exact: true });
|
||||
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
|
||||
await confirmation.waitFor({ state: 'hidden' });
|
||||
await switchFor('Table Formulas').waitFor({ state: 'detached' });
|
||||
await closeSettings();
|
||||
await page.waitForFunction(() => !document.querySelector('.xterm'));
|
||||
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
|
||||
assert.equal(await page.locator('.xterm').count(), 1, 'The package removal does not touch the Terminal feature');
|
||||
assert.equal(await table.locator('.md-table-formula').innerText(), '8', 'Removing the old package keeps the built-in formulas');
|
||||
await page.reload();
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
@@ -181,5 +175,5 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
|
||||
console.log([...page.errors, ...settingsPage.errors]);
|
||||
throw error;
|
||||
}
|
||||
console.log('Plugin smoke passed: formula setting, source preservation, inactive old package, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
|
||||
console.log('Plugin smoke passed: formula setting, source preservation, inactive old package, Terminal off with a prompt, persistence, shortcuts, the terminal window, removal, and no automatic restoration.');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user