Official
sidebar
Built-in sidebar UI (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/sidebar@0.2.5
Permissions in 0.2.5
Files
rows.test.ts9.6 KB
// What a row does when it is renamed, checked off, given a menu or a
// preview, against the fake host in testing.ts.
import assert from "node:assert/strict";
import { afterEach, mock, test } from "node:test";
import activate from "./main.ts";
import { fakeHost } from "./testing.ts";
afterEach(() => mock.timers.reset());
const day = (n: number) => `2026-10-0${n}T00:00:00.000Z`;
const type = (fake: ReturnType<typeof fakeHost>, id: string, value: string) =>
(fake.node(id)?.onChange as (event: { value: string }) => void)({ value });
test("rename takes the keyboard, Escape keeps the title, and Enter on an untouched field writes nothing", async () => {
const fake = fakeHost([{ id: "c1", title: "First", at: day(1) }]);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.action("row-c1", "Rename");
await fake.settle();
assert.deepEqual(fake.focused.slice(-1), ["rename-c1"], "the field has the keyboard");
type(fake, "rename-c1", "Changed");
(fake.node("rename-c1")?.onKey as (event: { key: string }) => void)({ key: "escape" });
await fake.settle();
assert.equal(fake.node("rename-c1"), undefined, "Escape closes the field");
fake.action("row-c1", "Rename");
await fake.settle();
fake.click("rename-c1", "onSubmit");
await fake.settle();
assert.deepEqual(
fake.calls.filter((call) => call.method === "host/chats.update"),
[],
"neither Escape nor an untouched Enter writes the title",
);
} finally {
await dispose();
}
});
test("leaving the rename field saves what was typed, and a field that leaves after Escape or after another row opened saves nothing", async () => {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(2) },
{ id: "c2", title: "Second", at: day(1) },
]);
const dispose = activate(fake.api);
const blur = (id: string) => (fake.node(id)?.onBlur as (event: { value: string }) => void)({ value: "" });
const writes = () => fake.calls.filter((call) => call.method === "host/chats.update");
try {
await fake.settle();
fake.action("row-c1", "Rename");
await fake.settle();
type(fake, "rename-c1", "Renamed");
blur("rename-c1");
await fake.settle();
assert.deepEqual(writes(), [{ method: "host/chats.update", params: { chatId: "c1", title: "Renamed" } }]);
assert.equal(fake.node("rename-c1"), undefined, "leaving the field closes it");
fake.action("row-c2", "Rename");
await fake.settle();
const leaving = fake.node("rename-c2")?.onBlur as (event: { value: string }) => void;
type(fake, "rename-c2", "Kept out");
(fake.node("rename-c2")?.onKey as (event: { key: string }) => void)({ key: "escape" });
await fake.settle();
leaving({ value: "Kept out" });
await fake.settle();
assert.equal(writes().length, 1, "a blur after Escape writes nothing");
fake.action("row-c2", "Rename");
await fake.settle();
const first = fake.node("rename-c2")?.onBlur as (event: { value: string }) => void;
fake.action("row-c1", "Rename");
await fake.settle();
first({ value: "Second" });
await fake.settle();
assert.ok(fake.node("rename-c1"), "the old field's late blur leaves the new field open");
} finally {
await dispose();
}
});
test("another row's pencil saves what was typed in the open field", async () => {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(2) },
{ id: "c2", title: "Second", at: day(1) },
]);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.action("row-c1", "Rename");
await fake.settle();
type(fake, "rename-c1", "Renamed");
fake.action("row-c2", "Rename");
await fake.settle();
assert.deepEqual(fake.calls.filter((call) => call.method === "host/chats.update"), [
{ method: "host/chats.update", params: { chatId: "c1", title: "Renamed" } },
]);
assert.ok(fake.node("rename-c2"), "the field moved to the other row");
} finally {
await dispose();
}
});
test("archiving the chat on screen from its row moves the screen to the next open chat", async () => {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(3) },
{ id: "c2", title: "Second", at: day(2) },
{ id: "c3", title: "Third", at: day(1) },
]);
const dispose = activate(fake.api);
try {
fake.update({ chatId: "c2" });
await fake.settle();
fake.action("row-c2", "Archive");
await fake.settle();
assert.equal(fake.api.app.state().chatId, "c3");
fake.action("row-c1", "Archive");
await fake.settle();
assert.equal(fake.api.app.state().chatId, "c3", "archiving a chat that is not on screen leaves the screen");
} finally {
await dispose();
}
});
test("a check-off the host refuses puts the row back where it was", async () => {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(2) },
{ id: "c2", title: "Second", at: day(1) },
]);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.fail("host/chats.update", "the store is read-only");
fake.click("glyph-c2");
await fake.settle();
assert.deepEqual(fake.list(), ["heading-open", "row-c1", "row-c2"]);
assert.deepEqual(fake.notices, ["Could not update the chat: the store is read-only"]);
} finally {
await dispose();
}
});
test("a new chat the host refuses says so", async () => {
const fake = fakeHost([{ id: "c1", title: "First", at: day(1) }]);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.fail("host/chats.create", "the workspace is gone");
await fake.run("sidebar.newChat");
await fake.settle();
assert.deepEqual(fake.notices, ["Could not create a chat: the workspace is gone"]);
} finally {
await dispose();
}
});
test("a task row's popover comes back after its menu was opened", async () => {
const fake = fakeHost(
[
{ id: "c1", title: "First", at: day(2) },
{ id: "c2", title: "Second", at: day(1) },
],
[{ id: "t", chats: ["c1", "c2"], title: "Both" }],
);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.click("row-c1", "onSecondaryClick");
await fake.settle();
assert.ok(fake.node("row-menu"), "the menu opened");
// Escape or a click away closes the kernel's list without telling the plugin.
fake.click("row-c1", "onPointerLeave");
fake.click("row-c1", "onPointerEnter");
mock.timers.tick(1000);
await fake.settle();
assert.equal(fake.node("task-popover-t")?.open, true);
} finally {
await dispose();
}
});
test("the row menu shows the keys its commands are bound to now", async () => {
const fake = fakeHost([{ id: "c1", title: "First", at: day(1) }]);
const dispose = activate(fake.api);
try {
await fake.settle();
fake.click("row-c1", "onSecondaryClick");
await fake.settle();
const options = fake.node("row-menu")?.options as { value: string; detail?: string }[];
assert.deepEqual(
options.map((option) => [option.value, option.detail]),
[
["row-menu-pin", undefined],
["row-menu-rename", undefined],
["row-menu-done", "⇧⌘M"],
["row-menu-archive", undefined],
],
);
} finally {
await dispose();
}
});
test("previews that cannot be read say so once, and a chat that changes is read again", async () => {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(2) },
{ id: "c2", title: "Second", at: day(1) },
]);
fake.fail("host/chats.peek", "the transcript is locked");
const dispose = activate(fake.api);
try {
await fake.settle();
await fake.settle();
assert.equal(fake.peeks(), 2, "each row asked once");
assert.deepEqual(fake.notices, ["Chat preview unavailable: the transcript is locked"]);
await fake.settle();
assert.equal(fake.peeks(), 2, "a failed read is not asked again at every draw");
fake.pass("host/chats.peek");
fake.touch("c1");
await fake.settle();
assert.equal(fake.peeks(), 3, "the chat that changed is read again");
} finally {
await dispose();
}
});
// A read that failed after the agent had streamed a line used to show the
// notice and mark the streamed preview failed, so the next change of the
// chat threw that line away and read it again.
test("a preview read that fails after the agent streamed a line changes nothing", async () => {
const fake = fakeHost([{ id: "c1", title: "First", at: day(2) }]);
fake.fail("host/chats.peek", "the transcript is locked");
const release = fake.hold("host/chats.peek");
const dispose = activate(fake.api);
try {
await fake.settle();
assert.equal(fake.peeks(), 1);
fake.emit({ event: "agent", chatId: "c1", kind: { event: "text_delta", itemId: "a", text: "Reading the parser.\n", mode: "append" } });
await fake.settle();
release();
await fake.settle();
assert.deepEqual(fake.notices, [], "the streamed line already answers the read");
fake.touch("c1");
await fake.settle();
assert.equal(fake.peeks(), 1, "the streamed preview is kept, not read again");
assert.ok(fake.text().includes("Reading the parser."));
} finally {
await dispose();
}
});
test("a first read that fails says so in place of the list, and the next event reads again", async () => {
const fake = fakeHost([{ id: "c1", title: "First", at: day(1) }]);
fake.fail("host/chats.list", "the store is locked");
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.text().includes("The chats could not be read: the store is locked"));
fake.pass("host/chats.list");
fake.emit({ event: "workspaces_changed" } as never);
await fake.settle();
assert.deepEqual(fake.list(), ["heading-open", "row-c1"]);
} finally {
await dispose();
}
});
No comments yet.