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:
@@ -5,6 +5,7 @@ import { FEATURES, featureEntry, featureOfOwner } from "../../../src/lib/feature
|
||||
import { storedSwitches, switchesFrom } from "../../../src/lib/features/state.ts";
|
||||
import { legacySwitch, migrateFeatures, type LegacyPlugin } from "../../../src/lib/features/migration.ts";
|
||||
import type { BackgroundMigrationHost, BackgroundSettings } from "../../../src/lib/features/backgroundSettings.ts";
|
||||
import type { TerminalMigrationHost } from "../../../src/lib/features/terminalSettings.ts";
|
||||
import { featureErrors, featureRequested, loadFeature } from "../../../src/lib/features/loader.ts";
|
||||
import { FeatureSession } from "../../../src/lib/features/session.ts";
|
||||
import type { FeatureContext, FeatureInstance, FeatureModule } from "../../../src/lib/features/types.ts";
|
||||
@@ -29,12 +30,12 @@ test("each feature keeps the ID of its old plugin package as its owner ID", () =
|
||||
});
|
||||
|
||||
test("switches keep known booleans only, and missing keys take the default", () => {
|
||||
assert.deepEqual(storedSwitches({ git: false, terminal: true, other: "yes" }), { git: false });
|
||||
assert.deepEqual(storedSwitches({ git: false, terminal: "no", csv: true, other: "yes" }), { git: false });
|
||||
assert.deepEqual(storedSwitches(null), {});
|
||||
assert.deepEqual(storedSwitches(["git"]), {});
|
||||
assert.deepEqual(switchesFrom(undefined), { git: true, background: true });
|
||||
assert.deepEqual(switchesFrom({ git: false, background: false }), { git: false, background: false });
|
||||
assert.deepEqual(switchesFrom({ git: "false" }), { git: true, background: true });
|
||||
assert.deepEqual(switchesFrom(undefined), { git: true, background: true, terminal: true });
|
||||
assert.deepEqual(switchesFrom({ git: false, background: false, terminal: false }), { git: false, background: false, terminal: false });
|
||||
assert.deepEqual(switchesFrom({ git: "false" }), { git: true, background: true, terminal: true });
|
||||
});
|
||||
|
||||
test("an installed package gives its state, and without a package the default applies", () => {
|
||||
@@ -57,6 +58,11 @@ function presentBackground(): BackgroundMigrationHost {
|
||||
return { missing: () => false, hasImage: () => false, migrateFolder: async () => { throw new Error("not asked"); }, write: async () => { throw new Error("not asked"); } };
|
||||
}
|
||||
|
||||
/** A terminal host with a section already present. */
|
||||
function presentTerminal(): TerminalMigrationHost {
|
||||
return { missing: () => false, legacy: () => { throw new Error("not asked"); }, write: async () => { throw new Error("not asked"); } };
|
||||
}
|
||||
|
||||
test("the migration asks only for features without a switch, and keeps other keys", async () => {
|
||||
const writes: unknown[] = [];
|
||||
const asked: string[][] = [];
|
||||
@@ -65,10 +71,10 @@ test("the migration asks only for features without a switch, and keeps other key
|
||||
write: async (value: unknown) => { writes.push(value); },
|
||||
legacy: async (ids: string[]) => { asked.push(ids); return packages; },
|
||||
});
|
||||
assert.deepEqual(await migrateFeatures(host({ future: 1, background: false }, [{ id: "runestone.git", installed: true, enabled: false, settings: null }]), presentBackground()), ["git"]);
|
||||
assert.deepEqual(await migrateFeatures(host({ future: 1, background: false, terminal: true }, [{ id: "runestone.git", installed: true, enabled: false, settings: null }]), presentBackground(), presentTerminal()), ["git"]);
|
||||
assert.deepEqual(asked, [["runestone.git"]]);
|
||||
assert.deepEqual(writes, [{ future: 1, background: false, git: false }]);
|
||||
assert.deepEqual(await migrateFeatures(host({ git: true, background: true }, []), presentBackground()), []);
|
||||
assert.deepEqual(writes, [{ future: 1, background: false, terminal: true, git: false }]);
|
||||
assert.deepEqual(await migrateFeatures(host({ git: true, background: true, terminal: true }, []), presentBackground(), presentTerminal()), []);
|
||||
assert.equal(asked.length, 1, "A stored switch needs no package read.");
|
||||
assert.equal(writes.length, 1);
|
||||
});
|
||||
@@ -78,17 +84,17 @@ test("a missing background section asks for the slideshow package and makes the
|
||||
const switches: unknown[] = [];
|
||||
const sections: BackgroundSettings[] = [];
|
||||
const background: BackgroundMigrationHost = { missing: () => true, hasImage: () => true, migrateFolder: async () => true, write: async value => { sections.push(value); } };
|
||||
const host = { read: () => ({ git: true, background: false }), write: async (value: unknown) => { switches.push(value); }, legacy: async (ids: string[]) => { asked.push(ids); return []; } };
|
||||
assert.deepEqual(await migrateFeatures(host, background), []);
|
||||
const host = { read: () => ({ git: true, background: false, terminal: true }), write: async (value: unknown) => { switches.push(value); }, legacy: async (ids: string[]) => { asked.push(ids); return []; } };
|
||||
assert.deepEqual(await migrateFeatures(host, background, presentTerminal()), []);
|
||||
assert.deepEqual(asked, [["runestone.bg-slideshow"]]);
|
||||
assert.deepEqual(switches, [], "Stored switches stay.");
|
||||
assert.equal(sections.length, 1);
|
||||
assert.equal(sections[0].source, "image");
|
||||
// Both migrations together ask once for both packages.
|
||||
asked.length = 0;
|
||||
await migrateFeatures({ ...host, read: () => undefined }, background);
|
||||
assert.deepEqual(asked, [["runestone.git", "runestone.bg-slideshow"]]);
|
||||
assert.deepEqual(switches, [{ git: true, background: true }]);
|
||||
await migrateFeatures({ ...host, read: () => undefined }, background, presentTerminal());
|
||||
assert.deepEqual(asked, [["runestone.git", "runestone.bg-slideshow", "runestone.terminal"]]);
|
||||
assert.deepEqual(switches, [{ git: true, background: true, terminal: true }]);
|
||||
});
|
||||
|
||||
test("a failed package read writes nothing, so the next start tries again", async () => {
|
||||
@@ -97,7 +103,7 @@ test("a failed package read writes nothing, so the next start tries again", asyn
|
||||
console.error = () => {};
|
||||
try {
|
||||
const background: BackgroundMigrationHost = { missing: () => true, hasImage: () => true, migrateFolder: async () => true, write: async value => { writes.push(value); } };
|
||||
const result = await migrateFeatures({ read: () => undefined, write: async value => { writes.push(value); }, legacy: async () => { throw new Error("no host"); } }, background);
|
||||
const result = await migrateFeatures({ read: () => undefined, write: async value => { writes.push(value); }, legacy: async () => { throw new Error("no host"); } }, background, presentTerminal());
|
||||
assert.deepEqual(result, []);
|
||||
assert.deepEqual(writes, []);
|
||||
} finally { console.error = error; }
|
||||
|
||||
Reference in New Issue
Block a user