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.6
Permissions in 0.2.6
Files
section-order.test.ts7.3 KB
// Moving the sections by their headings: up and down the list, and into
// and out of the dock at its foot, 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 { ARRANGEMENT_KEY, COLLAPSED_KEY, DEFAULT_ARRANGEMENT } from "./sections.ts";
import { fakeHost } from "./testing.ts";
afterEach(() => mock.timers.reset());
const day = (n: number) => `2026-10-0${n}T00:00:00.000Z`;
const SECTION = "divergence/section";
type Target = { onOver: (e: unknown) => void; onDrop: (e: unknown) => void };
// Two open chats and two checked-off ones: Open in the list, Complete docked.
function setup() {
const fake = fakeHost([
{ id: "c1", title: "First", at: day(4) },
{ id: "c2", title: "Second", at: day(3) },
{ id: "c3", title: "Done", at: day(2), done: day(5) },
{ id: "c4", title: "Done too", at: day(1), done: day(6) },
]);
// Complete unfolded, so its rows show.
fake.storage.set(COLLAPSED_KEY, []);
// The ids the scroller holds: its own rows, and the headings and rows docked in its footer.
const parts = () => {
type Node = { id?: string; type?: string; children?: unknown };
const items = (fake.node("chat-list")?.items ?? []) as Node[];
const footer = items.at(-1)?.type === "slot" ? items.at(-1)! : undefined;
const docked = (value: unknown, out: string[] = []): string[] => {
if (Array.isArray(value)) value.forEach((child) => docked(child, out));
else if (value && typeof value === "object") {
const node = value as Node;
if (node.id && /^(heading|row)-/.test(node.id)) out.push(node.id);
else docked(node.children, out);
}
return out;
};
// The selection's fill and the room above a heading are no sections' rows.
const rows = items.filter((item) => item !== footer && !/^(gap-|chat-selection$)/.test(item.id ?? ""));
return { list: rows.map((item) => item.id), dock: docked(footer?.children) };
};
// A heading carried over a target, as the kernel tells it.
const heading = (id: string) => fake.node(`section-${id}`)?.drop as Target;
const carry = (section: string, target: Target, zone: string | null) =>
target.onOver({ type: SECTION, data: { sectionId: section }, zone });
const drop = (section: string, target: Target) => target.onDrop({ type: SECTION, data: { sectionId: section }, zone: "before" });
const end = (section: string) => (fake.node(`section-${section}`)?.drag as { onEnd: () => void }).onEnd();
return { fake, parts, heading, carry, drop, end };
}
test("a heading carried into the dock docks its section, carried out undocks it, and the order is saved", async () => {
const { fake, parts, heading, carry, drop } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
assert.deepEqual(parts(), { list: ["heading-open", "row-c1", "row-c2"], dock: ["heading-settled", "row-c4", "row-c3"] });
// Picked up, Complete is its heading alone; over Open's heading's upper half it goes above Open.
carry("settled", heading("settled"), "before");
await fake.settle();
assert.deepEqual(parts().dock, ["heading-settled"]);
carry("settled", heading("open"), "before");
await fake.settle();
assert.deepEqual(parts().list, ["heading-settled", "heading-open", "row-c1", "row-c2"]);
drop("settled", heading("open"));
await fake.settle();
assert.deepEqual(parts().list, ["heading-settled", "row-c4", "row-c3", "heading-open", "row-c1", "row-c2"]);
assert.equal(fake.node("chat-list")?.items && parts().dock.length, 0, "nothing is docked");
assert.equal(fake.node("more-settled"), undefined, "two chats need no Show more");
assert.deepEqual(fake.storage.get(ARRANGEMENT_KEY), { list: ["drafts", "pinned", "queued", "needs-you", "finished", "settled", "open"], dock: ["running", "snoozed"] });
// Over a row of Open, Complete goes after Open; and over the dock's room it docks again.
carry("settled", heading("settled"), "before");
await fake.settle();
assert.ok(fake.node("dock-area"), "with nothing docked, a carried heading finds room under the list");
(fake.node("row-c2")?.drop as Target).onOver({ type: SECTION, data: { sectionId: "settled" }, zone: "into" });
await fake.settle();
assert.deepEqual(parts().list, ["heading-open", "row-c1", "row-c2", "heading-settled"]);
carry("settled", fake.node("dock-area")?.drop as Target, "after");
await fake.settle();
assert.deepEqual(parts(), { list: ["heading-open", "row-c1", "row-c2"], dock: ["heading-settled"] });
drop("settled", fake.listDrop());
await fake.settle();
assert.deepEqual(parts(), { list: ["heading-open", "row-c1", "row-c2"], dock: ["heading-settled", "row-c4", "row-c3"] });
assert.deepEqual(fake.storage.get(ARRANGEMENT_KEY), { list: ["drafts", "pinned", "queued", "needs-you", "finished", "open"], dock: ["running", "snoozed", "settled"] });
} finally {
await dispose();
}
});
test("a heading let go off the sidebar leaves the sections where they were and saves nothing", async () => {
const { fake, parts, heading, carry, end } = setup();
const dispose = activate(fake.api);
try {
await fake.settle();
carry("open", heading("open"), "after");
carry("open", heading("settled"), "after");
await fake.settle();
assert.deepEqual(parts().dock, ["heading-settled", "row-c4", "row-c3", "heading-open"]);
fake.listDrop().onOver({ type: SECTION, data: { sectionId: "open" }, zone: null });
await fake.settle();
assert.deepEqual(parts().list, ["heading-open"], "the pointer gone, Open is back in its place");
end("open");
await fake.settle();
assert.deepEqual(parts(), { list: ["heading-open", "row-c1", "row-c2"], dock: ["heading-settled", "row-c4", "row-c3"] });
assert.equal(fake.storage.get(ARRANGEMENT_KEY), undefined);
} finally {
await dispose();
}
});
test("the saved order shows from the first draw after a restart", async () => {
const fake = fakeHost([
{ id: "c1", title: "Busy", at: day(9) },
...[1, 2, 3, 4].map((n) => ({ id: `d${n}`, title: `Done ${n}`, at: day(n), done: day(n + 4) })),
]);
fake.storage.set(ARRANGEMENT_KEY, { list: ["settled", "open", "bogus", "open"], dock: ["running"] });
fake.storage.set(COLLAPSED_KEY, []);
// The saved layout answers after the chats, as a slow read would.
const answer = fake.hold("host/storage.get");
const dispose = activate(fake.api);
try {
await fake.settle();
answer();
await fake.settle();
const c1 = { id: "c1", workspaceId: "w1", agentId: "a", title: "Busy", sessionId: "s", createdAt: day(9), updatedAt: day(9), archived: false, options: {}, status: "running" };
fake.emit({ event: "chat_changed", chat: c1 } as never);
await fake.settle();
assert.deepEqual(fake.list(), ["heading-settled", "row-d4", "row-d3", "row-d2", "row-d1", "heading-running", "row-c1"]);
// The first list drawn already has Complete above Open, as it was saved, with nothing to glide into place.
const first = fake.drawn().find((list) => list.length > 0)!;
assert.ok(first.indexOf("heading-settled") < first.indexOf("heading-open"), `first drawn: ${first.join(", ")}`);
assert.deepEqual(DEFAULT_ARRANGEMENT.dock, ["running", "snoozed", "settled"], "the default is untouched");
} finally {
await dispose();
}
});
No comments yet.