Official
terminal
Built-in integrated terminal (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/terminal@0.2.4
Permissions in 0.2.4
Take care. This plugin asks for permissions that can do anything your account can. The app asks you to hold Enable for two seconds or to type the plugin's name before it turns on.
Files
state.test.ts4.2 KB
// Test workspace isolation, saved session selection, and terminal pane identity.
// Session removal must choose a neighbour in the same workspace, even with interleaved sessions.
import assert from "node:assert/strict";
import test from "node:test";
import type { Terminal, Workspace } from "divergence";
import {
activeTerminal,
arrange,
choiceAfterClose,
forWorkspace,
moveTerminal,
nextTerminal,
pathsByWorkspace,
terminalInPane,
} from "./state.ts";
const terminal = (id: string, workspaceId: string | null = "w1"): Terminal => ({
id,
title: id,
userTitle: null,
cwd: "/",
workspaceId,
running: true,
exitCode: null,
});
test("terminals stay scoped to their workspace", () => {
assert.deepEqual(
forWorkspace([terminal("a"), terminal("b", "w2"), terminal("c")], "w1").map(({ id }) => id),
["a", "c"],
);
});
test("active session uses its saved choice, then the last workspace session", () => {
const terminals = [terminal("a"), terminal("b"), terminal("other", "w2")];
assert.equal(activeTerminal({ terminals, activeByWorkspace: { w1: "a" } }, "w1")?.id, "a");
assert.equal(activeTerminal({ terminals, activeByWorkspace: {} }, "w1")?.id, "b");
assert.equal(activeTerminal({ terminals, activeByWorkspace: {} }, "missing"), null);
assert.equal(activeTerminal({ terminals, activeByWorkspace: { w1: "other" } }, "w1")?.id, "b");
assert.equal(activeTerminal({ terminals, activeByWorkspace: { w1: "deleted" } }, "w1")?.id, "b");
assert.equal(activeTerminal({ terminals, activeByWorkspace: { w1: null } }, "w1")?.id, "b");
});
test("pane session and workspace paths are derived from host state", () => {
assert.equal(terminalInPane({ kind: "terminal", path: "term-1" }), "term-1");
assert.equal(terminalInPane({ kind: "file", path: "a.ts" }), null);
assert.equal(terminalInPane(null), null);
assert.equal(terminalInPane("nope"), null);
const workspaces: Workspace[] = [{ id: "w1", name: "one", path: "/one", position: 0 }];
assert.deepEqual(pathsByWorkspace(workspaces), { w1: "/one" });
});
test("closing chooses the next workspace session, then its previous one", () => {
const first = terminal("first");
const middle = terminal("middle");
const last = terminal("last");
const terminals = [first, terminal("other", "w2"), middle, last];
assert.equal(nextTerminal(terminals, first)?.id, "middle");
assert.equal(nextTerminal(terminals, middle)?.id, "last");
assert.equal(nextTerminal(terminals, last)?.id, "middle");
assert.equal(nextTerminal([first, terminal("other", "w2")], first), null);
});
// With three terminals and the third in use, closing the first used to make the second the one in use.
test("closing a terminal not in use keeps the one in use; closing that one moves to its neighbour", () => {
const terminals = [terminal("a"), terminal("b"), terminal("c")];
const pick = (activeByWorkspace: Record<string, string | null>, closed: Terminal) =>
activeTerminal(
{
terminals: terminals.filter((t) => t !== closed),
activeByWorkspace: { w1: choiceAfterClose({ terminals, activeByWorkspace }, closed) },
},
"w1",
)?.id;
assert.equal(pick({ w1: "c" }, terminals[0]!), "c");
assert.equal(pick({}, terminals[0]!), "c", "the last one is in use when none was picked");
assert.equal(pick({ w1: "b" }, terminals[2]!), "b");
assert.equal(pick({ w1: "b" }, terminals[1]!), "c");
assert.equal(pick({ w1: "c" }, terminals[2]!), "b");
});
test("a dragged terminal keeps its place when the kernel lists the terminals again", () => {
const ids = (list: readonly Terminal[]) => list.map(({ id }) => id);
const listed = [terminal("a"), terminal("b"), terminal("c")];
const moved = moveTerminal(listed, "c", "a", "before");
assert.deepEqual(ids(moved), ["c", "a", "b"]);
// A kernel without `reorder` reports `into`: it takes the other's place.
assert.deepEqual(ids(moveTerminal(listed, "a", "b", "into")), ["b", "a", "c"]);
const order = ids(moved);
// The next list from the kernel, with a new terminal, keeps the user's
// order and puts the new one after it.
assert.deepEqual(ids(arrange([...listed, terminal("d")], order)), ["c", "a", "b", "d"]);
assert.deepEqual(ids(arrange(listed, [])), ["a", "b", "c"]);
});
No comments yet.