Official
settings
Built-in settings 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 convergence/settings@0.2.2
Permissions in 0.2.2
Files
service.test.ts29.4 KB
// The convergence/settings service: showShortcuts routes to settings and
// opens Keyboard Shortcuts searched for the command. Real activation
// against a fake host and kernel; calls go through the provided method.
import assert from "node:assert/strict";
import { test } from "node:test";
import type {
Api,
AppState,
AppStatePatch,
HostEvent,
PluginSummary,
RenderResult,
SettingValue,
SlotOptions,
ViewContext,
Workspace,
} from "convergence";
import { ui } from "convergence";
import { testLayer } from "convergence/effect/testing";
import { activate } from "./main.ts";
import { nodes } from "../sdk/ui-testing.ts";
import type { AgentEntry } from "./controller.ts";
const tick = () => new Promise<void>((resolve) => setImmediate(resolve));
const stable = (value: unknown) =>
JSON.stringify(value, (_key, item: unknown) => (typeof item === "function" ? "@handler" : item));
type ServiceImpl = Record<string, (params: never, ctx: unknown) => Promise<unknown>>;
function fakeApi(options: { progress?: unknown; agents?: AgentEntry[]; workspaces?: Workspace[]; plugins?: PluginSummary[]; autoImport?: boolean; sessions?: Record<string, string[]>; hasChats?: boolean; route?: string } = {}) {
let state: AppState = { route: options.route };
let progress: unknown = "progress" in options ? options.progress : { done: true, step: 0, workspaceId: null };
let agents = options.agents ?? [];
const workspaces = options.workspaces ?? [];
let plugins = options.plugins ?? [];
const ownSettings: Record<string, SettingValue> = { autoImportChats: options.autoImport ?? false };
const settingsListeners = new Set<(values: Record<string, SettingValue>) => unknown>();
const importedChats: { id: string; sessionId: string; agentId: string; workspaceId: string }[] = [];
let appearance = "system";
let pickedPath: string | null = null;
let failure: string | null = null;
let waitFor: { method: string; promise: Promise<void> } | null = null;
const appListeners = new Set<(state: AppState) => void>();
const views: { render: (ctx: ViewContext<object>) => RenderResult; active: boolean }[] = [];
const listeners = new Map<string, Set<(event: HostEvent) => unknown>>();
const hostCalls: { method: string; params: unknown }[] = [];
const kernelCalls: { method: string; params: unknown }[] = [];
const notices: string[] = [];
let dirty = true;
const provided = new Map<string, ServiceImpl>();
const emitted: { event: string; payload: unknown }[] = [];
const registered = new Map<string, () => void>();
const commands = {
commands: [
{
id: "a.open",
title: "Open",
category: "A",
plugin: "a",
pluginTitle: "A",
official: true,
key: "cmd+x",
defaultKey: "cmd+x",
keys: ["cmd+x"],
labels: ["⌘X"],
source: "default",
conflict: null,
problem: null,
kernel: false,
enabled: true,
registered: true,
},
],
errors: [],
};
const update = (patch: AppStatePatch) => {
state = {
...state,
...patch,
workspaceId: patch.workspaceId === null ? undefined : (patch.workspaceId ?? state.workspaceId),
chatId: patch.chatId === null ? undefined : (patch.chatId ?? state.chatId),
route: patch.route ?? state.route,
shared: { ...state.shared, ...patch.shared },
};
dirty = true;
for (const listener of appListeners) listener(state);
};
const hostCall = async (method: string, params: unknown) => {
hostCalls.push({ method, params });
if (waitFor?.method === method) await waitFor.promise;
if (failure === method) throw new Error("Test service is unavailable");
switch (method) {
case "host/storage.get":
return { value: progress };
case "host/storage.set":
progress = (params as { value: unknown }).value;
return {};
case "host/settings.get":
return { appearance, tools: { mode: "code", disabled: [], disabledRules: [] } };
case "host/settings.update":
appearance = (params as { appearance: string }).appearance;
return { appearance };
case "host/agents.all":
return { agents };
case "host/agents.set_enabled": {
const patch = params as { agentId: string; enabled: boolean };
agents = agents.map((a) => a.id === patch.agentId ? { ...a, enabled: patch.enabled } : a);
return {};
}
case "host/agents.authenticate":
agents = agents.map((a) => a.id === (params as { agentId: string }).agentId ? { ...a, status: { state: "ready" } } : a);
return {};
case "host/agents.update":
return {};
case "host/plugins.list":
return { plugins };
case "host/plugins.set_enabled": {
const patch = params as { name: string; enabled: boolean };
plugins = plugins.map((p) => p.name === patch.name ? { ...p, enabled: patch.enabled } : p);
return {};
}
case "host/plugins.request_enable":
return { requestId: "native-approval" };
case "host/workspaces.list":
return { workspaces };
case "host/workspaces.add": {
const workspace = { id: "project", name: "Project", path: (params as { path: string }).path, position: workspaces.length };
workspaces.push(workspace);
return workspace;
}
case "host/chats.list":
return { chats: [...(options.hasChats ? [{ id: "existing" }] : []), ...importedChats] };
case "host/chats.import": {
const { workspaceId, agentId } = params as { workspaceId: string; agentId: string };
let imported = 0;
for (const sessionId of options.sessions?.[`${workspaceId}/${agentId}`] ?? []) {
if (importedChats.some((c) => c.sessionId === sessionId && c.agentId === agentId)) continue;
importedChats.push({ id: `chat-${sessionId}`, sessionId, agentId, workspaceId });
imported++;
}
return { imported };
}
case "host/chats.create":
return { id: "first", ...(params as object) };
case "host/updates.status":
return {};
case "host/tools.list":
return null;
case "host/plugins.settings":
return { name: "x", error: null, properties: [], notices: [] };
default:
throw new Error(`Unexpected host method ${method}`);
}
};
const kernelCall = async (method: string, params: unknown) => {
kernelCalls.push({ method, params });
if (method === "commands") return commands;
if (method === "themes") return { themes: [] };
if (method === "settings_view") return { view: null };
if (method === "theme") return {};
throw new Error(`Unexpected kernel method ${method}`);
};
const broker = testLayer();
// This assertion describes a local fake; unused API methods fail rather than impersonating external replies.
const api = new Proxy(
{
...broker.api,
plugin: "settings",
id: "convergence/settings",
ui,
services: {
provide: async (def: { name: string }, impl: ServiceImpl) => {
provided.set(def.name, impl);
return {
emit: (event: string, payload: unknown) => {
emitted.push({ event, payload });
},
remove: () => {
provided.delete(def.name);
},
};
},
get: (name: string) => {
throw new Error(`no provider for ${name}`);
},
available: () => false,
when: () => () => {},
},
host: { ...broker.api.host, call: hostCall, kernel: kernelCall },
settings: {
...broker.api.settings,
get: ((key?: string) => key === undefined ? ownSettings : ownSettings[key] ?? null) as Api["settings"]["get"],
set: async (key: string, value: SettingValue) => {
ownSettings[key] = value;
for (const listener of settingsListeners) listener(ownSettings);
return value;
},
onChange: (fn: (values: Record<string, SettingValue>) => unknown) => {
settingsListeners.add(fn);
return () => { settingsListeners.delete(fn); };
},
},
app: {
state: () => state,
update,
select: (chatId: string, workspaceId: string) => update({ chatId, workspaceId, route: "chat" }),
route: (route: string) => update({ route }),
onChange: (fn: (state: AppState) => void) => {
appListeners.add(fn);
return () => {
appListeners.delete(fn);
};
},
},
slot: (slot: string, render: (ctx: ViewContext<object>) => RenderResult, _options?: SlotOptions) => {
const view = { render, active: true };
views.push(view);
dirty = true;
return {
id: views.length,
update: () => {
dirty = true;
},
remove: () => {
view.active = false;
},
};
},
on: (name: string, fn: (event: HostEvent) => unknown) => {
const subscribers = listeners.get(name) ?? new Set();
listeners.set(name, subscribers);
subscribers.add(fn);
return () => {
subscribers.delete(fn);
};
},
command: (definition: { id: string; run: () => void }) => {
registered.set(definition.id, definition.run);
return { remove() { registered.delete(definition.id); } };
},
pickFolder: async () => ({ path: pickedPath }),
notify: (message: string) => {
notices.push(message);
},
focus: () => {},
},
{
get(target, key, receiver) {
if (Reflect.has(target, key)) return Reflect.get(target, key, receiver);
throw new Error(`Unexpected API ${String(key)}`);
},
},
) as unknown as Api;
const render = () =>
views
.filter((view) => view.active)
.map((view) =>
view.render({
state: {},
app: state,
plugin: "settings",
update: () => {
dirty = true;
},
}),
);
let trees: RenderResult[] = [];
const settle = async () => {
for (let round = 0; round < 50; round++) {
await tick();
if (!dirty) {
await tick();
if (!dirty) return;
}
dirty = false;
trees = render();
}
throw new Error("settings did not settle");
};
const ctx = { caller: { plugin: "test/client", id: "test/client" }, signal: AbortSignal.timeout(5000) };
return {
api,
hostCalls,
kernelCalls,
notices,
provided,
settle,
trees: () => stable(trees),
state: () => state,
progress: () => progress,
settings: () => ({ ...ownSettings }),
chats: () => importedChats,
plugins: (next: PluginSummary[]) => { plugins = next; },
route: (route: string) => update({ route }),
node: (id: string) => {
const node = nodes(trees).find((node) => node.id === id);
assert.ok(node, `Missing control ${id}`);
return node;
},
click: async (id: string) => {
const node = nodes(trees).find((node) => node.id === id);
assert.ok(node && typeof node.onClick === "function", `Missing action ${id}`);
assert.ok(!node.disabled, `${id} is disabled`);
node.onClick();
await settle();
},
change: async (id: string, value: unknown) => {
const node = nodes(trees).find((node) => node.id === id);
assert.ok(node && typeof node.onChange === "function", `Missing input ${id}`);
assert.ok(!node.disabled, `${id} is disabled`);
node.onChange({ value });
await settle();
},
pick: (path: string | null) => { pickedPath = path; },
fail: (method: string | null) => { failure = method; },
block: (method: string) => {
const { promise, resolve } = Promise.withResolvers<void>();
waitFor = { method, promise };
return () => { waitFor = null; resolve(); };
},
emit: async (event: HostEvent) => {
for (const fn of listeners.get(event.event) ?? []) fn(event);
await settle();
},
agents: (next: AgentEntry[]) => { agents = next; },
command: async (id: string) => { registered.get(id)?.(); await settle(); },
callService: (method: string, params: unknown) =>
provided.get("convergence/settings")?.[method]?.(params as never, ctx),
};
}
test("showShortcuts routes to settings and searches Keyboard Shortcuts", async () => {
const fake = fakeApi();
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.provided.has("convergence/settings"));
// Before the page ever loads there are no keys to reload; the route still moves.
assert.deepEqual(await fake.callService("showShortcuts", { query: "assign-me" }), null);
assert.equal(fake.state().route, "settings");
assert.ok(!fake.kernelCalls.some((call) => call.method === "commands"));
assert.equal(fake.state().shared?.showShortcuts, undefined);
// Opening the page loads it; the next request reloads the keys too.
await fake.settle();
assert.ok(fake.trees().includes("Keyboard Shortcuts") || fake.trees().includes("Loading settings"));
await fake.settle();
assert.deepEqual(await fake.callService("showShortcuts", { query: "assign-me" }), null);
await fake.settle();
assert.ok(fake.kernelCalls.some((call) => call.method === "commands"));
assert.ok(fake.trees().includes("assign-me"));
assert.equal(fake.notices.length, 0);
} finally {
await dispose();
}
});
const pluginsWorkspace: Workspace = { id: "plugins", name: "Plugins", path: "/plugins", mark: "puzzle", position: 0 };
const available: AgentEntry = { id: "test-agent", name: "Test Agent", enabled: true, status: { state: "ready" }, capabilities: { sessionList: true } };
test("first-run guide explains plugins, saves progress, and opens a real workspace chat", async () => {
const fake = fakeApi({ progress: null, agents: [available], workspaces: [pluginsWorkspace] });
const dispose = activate(fake.api);
try {
await fake.settle();
assert.equal(fake.state().route, "onboarding");
for (const topic of ["Everything is a plugin", "Plugins workspace", "Marketplace", "checkpoints", "Type @ to add files", "Git and Terminal"])
assert.ok(fake.trees().includes(topic), topic);
assert.deepEqual(fake.progress(), { done: false, step: 0, workspaceId: null, returning: false });
assert.equal(fake.node("onboarding-step-2").onClick, undefined, "later steps cannot be skipped to");
await fake.click("onboarding-next");
assert.ok(fake.trees().includes("Test Agent"));
assert.ok(fake.trees().includes("Ready"));
await fake.change("agent-test-agent", false);
assert.equal(fake.node("agent-test-agent").checked, false);
await fake.change("agent-test-agent", true);
await fake.click("onboarding-next");
await fake.change("onboarding-appearance", "dark");
assert.ok(fake.kernelCalls.some((c) => c.method === "theme" && stable(c.params) === stable({ mode: "dark" })));
fake.pick(null);
await fake.click("onboarding-folder");
assert.ok(!fake.hostCalls.some((c) => c.method === "host/workspaces.add"));
fake.pick("/project");
await fake.click("onboarding-folder");
assert.equal(fake.node("onboarding-workspace").value, "project");
assert.equal(fake.node("onboarding-next").label, "Choose plugins");
await fake.click("onboarding-next");
assert.ok(fake.trees().includes("Optional plugins"));
assert.equal(fake.node("onboarding-next").label, "Start your first chat");
await fake.click("onboarding-next");
assert.equal(fake.state().route, "chat");
assert.equal(fake.state().workspaceId, "project");
assert.equal(fake.state().chatId, "first");
assert.deepEqual(fake.progress(), { done: true, step: 3, workspaceId: "project", returning: false });
assert.deepEqual(fake.hostCalls.find((c) => c.method === "host/chats.create")?.params, { workspaceId: "project", agentId: "test-agent" });
assert.equal(fake.notices.length, 0);
} finally { await dispose(); }
});
test("existing users and completed setup retain their route; the command reopens the guide", async () => {
for (const options of [
{ progress: null, hasChats: true },
{ progress: null, workspaces: [{ id: "project", name: "Project", path: "/project", position: 0 }] },
{},
{ progress: null, route: "market" },
]) {
const fake = fakeApi(options);
const dispose = activate(fake.api);
try {
await fake.settle();
assert.notEqual(fake.state().route, "onboarding");
await fake.command("settings.onboarding");
assert.equal(fake.state().route, "onboarding");
assert.ok(fake.trees().includes("Everything is a plugin"));
} finally { await dispose(); }
}
});
test("interrupted setup resumes its step and selected workspace, with back navigation", async () => {
const fake = fakeApi({ progress: { done: false, step: 2, workspaceId: "plugins" }, agents: [available], workspaces: [pluginsWorkspace] });
const dispose = activate(fake.api);
try {
await fake.settle();
assert.equal(fake.state().route, "onboarding");
assert.equal(fake.node("onboarding-workspace").value, "plugins");
await fake.click("onboarding-back");
assert.ok(fake.trees().includes("Bring your favorite agents"));
await fake.click("onboarding-step-0");
assert.ok(fake.trees().includes("Everything is a plugin"));
await fake.click("onboarding-skip");
assert.equal(fake.state().route, "chat");
assert.equal((fake.progress() as { done: boolean }).done, true);
assert.ok(!fake.hostCalls.some((c) => c.method === "host/chats.create"));
} finally { await dispose(); }
});
test("agent setup shows starting, unavailable and sign-in states, guards duplicate requests, and recovers", async () => {
const auth: AgentEntry = { ...available, status: { state: "auth_required", message: "Sign in to continue" }, authMethods: [{ id: "login", name: "Sign in" }] };
const fake = fakeApi({ progress: { done: false, step: 1, workspaceId: null }, agents: [auth] });
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.trees().includes("Sign in needed"));
fake.fail("host/agents.authenticate");
await fake.click("auth-test-agent-login");
assert.ok(fake.trees().includes("Test service is unavailable"));
assert.equal(fake.node("onboarding-next").disabled, false);
fake.fail(null);
const release = fake.block("host/agents.authenticate");
await fake.click("auth-test-agent-login");
assert.equal(fake.node("auth-test-agent-login").loading, true);
assert.equal(fake.node("onboarding-next").disabled, true);
const handler = fake.node("auth-test-agent-login").onClick;
assert.equal(typeof handler, "function");
if (typeof handler === "function") handler();
await fake.settle();
assert.equal(fake.hostCalls.filter((c) => c.method === "host/agents.authenticate").length, 2);
release();
await fake.settle();
assert.ok(fake.trees().includes("Ready"));
assert.ok(!fake.trees().includes("Test service is unavailable"));
fake.agents([{ ...available, status: { state: "starting" } }]);
await fake.emit({ event: "agents_changed" });
assert.ok(fake.trees().includes("Checking…"));
assert.ok(!fake.trees().includes("Unavailable"));
fake.agents([{ ...available, status: { state: "unavailable", message: "Install the agent first" } }]);
await fake.emit({ event: "agents_changed" });
assert.ok(fake.trees().includes("Install the agent first"));
await fake.click("onboarding-next");
assert.equal(fake.node("onboarding-next").label, "Choose plugins");
await fake.click("onboarding-next");
assert.equal(fake.node("onboarding-next").label, "Open Divergence");
await fake.click("onboarding-next");
assert.equal(fake.state().route, "chat");
assert.ok(!fake.hostCalls.some((c) => c.method === "host/chats.create"));
} finally { await dispose(); }
});
test("loading and completion failures remain on setup and can be retried without a false completion", async () => {
const fake = fakeApi({ progress: { done: false, step: 3, workspaceId: "plugins" }, agents: [available], workspaces: [pluginsWorkspace] });
fake.fail("host/settings.get");
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.trees().includes("Test service is unavailable"));
assert.equal(fake.node("onboarding-next").disabled, true);
fake.fail(null);
await fake.click("onboarding-retry");
assert.equal(fake.node("onboarding-next").disabled, false);
fake.fail("host/chats.create");
await fake.click("onboarding-next");
assert.equal(fake.state().route, "onboarding");
assert.equal((fake.progress() as { done: boolean }).done, false);
fake.fail("host/storage.set");
await fake.click("onboarding-next");
assert.equal(fake.state().route, "onboarding");
assert.equal((fake.progress() as { done: boolean }).done, false);
fake.fail(null);
await fake.click("onboarding-next");
assert.equal(fake.state().route, "chat");
} finally { await dispose(); }
});
const projectWorkspace: Workspace = { id: "project", name: "Project", path: "/project", position: 1 };
const optionalPlugin: PluginSummary = {
name: "extra", id: "convergence/extra", version: "1.0.0", description: "Optional official tools",
official: true, claimsOfficial: false, source: "official-bundle", enabled: false, state: "disabled",
ui: true, sandboxed: null, permissions: [], pending: [], commands: 0,
};
const marketPlugin: PluginSummary = { ...optionalPlugin, name: "market", id: "convergence/market", enabled: true, state: "loaded" };
test("onboarding enables official extras, requests native approval, and returns from install chats across restarts", async () => {
const visuals = { ...optionalPlugin, name: "visuals", id: "convergence/visuals", enabled: true, disabledByDefault: true };
const downloaded: PluginSummary = { ...optionalPlugin, name: "downloaded", id: "someone/downloaded", official: false, source: "marketplace", state: "not_enabled" };
const fake = fakeApi({ progress: { done: false, step: 3, workspaceId: "project" }, agents: [available], workspaces: [projectWorkspace], plugins: [optionalPlugin, marketPlugin, downloaded, visuals] });
let dispose = activate(fake.api);
try {
await fake.settle();
assert.equal(fake.node("onboarding-plugin-visuals").checked, true, "enabled optional plugins remain choices");
assert.ok(!fake.trees().includes("onboarding-plugin-market"), "enabled core plugins are not optional choices");
await fake.change("onboarding-plugin-extra", true);
assert.equal(fake.node("onboarding-plugin-extra").checked, true);
await fake.click("onboarding-review-downloaded");
assert.equal(fake.node("onboarding-review-downloaded").label, "Review and enable…");
assert.ok(fake.hostCalls.some((c) => c.method === "host/plugins.request_enable" && stable(c.params) === stable({ name: "downloaded" })));
assert.ok(!fake.hostCalls.some((c) => c.method === "host/plugins.set_enabled" && stable(c.params).includes("downloaded")));
fake.plugins([{ ...optionalPlugin, enabled: true }, marketPlugin, { ...downloaded, enabled: true, state: "loaded" }, visuals]);
await fake.emit({ event: "access_changed", plugin: "downloaded" });
assert.equal(fake.node("onboarding-plugin-downloaded").checked, true);
await fake.click("onboarding-market");
assert.equal(fake.state().route, "market");
assert.equal(fake.node("onboarding-return").label, "Back to onboarding");
fake.route("chat");
await fake.settle();
assert.equal(fake.node("onboarding-return").label, "Back to onboarding");
await dispose();
dispose = activate(fake.api);
await fake.settle();
assert.equal(fake.state().route, "chat", "reloading must not interrupt the installation chat");
await fake.click("onboarding-return");
assert.equal(fake.state().route, "onboarding");
assert.ok(fake.trees().includes("Step 4 of 4"));
assert.equal(fake.node("onboarding-plugin-visuals").checked, true, "optional choices survive an activation restart");
assert.equal(fake.node("onboarding-next").label, "Start your first chat");
assert.equal((fake.progress() as { returning: boolean }).returning, false);
await fake.command("settings.onboarding");
assert.ok(fake.trees().includes("Step 1 of 4"));
} finally { await dispose(); }
});
test("auto-import is opt-in during agent setup, imports after a project is added, and can be disabled in General", async () => {
const fake = fakeApi({ progress: { done: false, step: 1, workspaceId: null }, agents: [available], workspaces: [pluginsWorkspace], sessions: { "project/test-agent": ["outside-1", "outside-2"], "plugins/test-agent": ["plugin-session"] } });
const dispose = activate(fake.api);
try {
await fake.settle();
assert.equal(fake.node("auto-import-chats").checked, false);
await fake.change("auto-import-chats", true);
assert.equal(fake.settings().autoImportChats, true);
assert.deepEqual(fake.chats(), []);
await fake.click("onboarding-next");
fake.pick("/project");
await fake.click("onboarding-folder");
assert.deepEqual(fake.chats().map((c) => [c.workspaceId, c.agentId, c.sessionId]), [
["project", "test-agent", "outside-1"], ["project", "test-agent", "outside-2"],
]);
assert.ok(fake.trees().includes("Imported 2 chats."));
await fake.emit({ event: "workspaces_changed" });
assert.equal(fake.hostCalls.filter((c) => c.method === "host/chats.import").length, 1);
fake.route("settings");
await fake.settle();
assert.equal(fake.node("auto-import-chats").checked, true);
await fake.change("auto-import-chats", false);
assert.equal(fake.settings().autoImportChats, false);
fake.agents([available, { ...available, id: "another" }]);
await fake.emit({ event: "agents_changed" });
assert.equal(fake.hostCalls.filter((c) => c.method === "host/chats.import").length, 1);
} finally { await dispose(); }
});
test("startup imports only ready history-listing agents, and later readiness/enabling imports each project once", async () => {
const later: AgentEntry = { ...available, id: "later", name: "Later", status: { state: "starting" } };
const disabled: AgentEntry = { ...available, id: "disabled", enabled: false };
const noHistory: AgentEntry = { ...available, id: "no-history", capabilities: { sessionHistory: true, sessionList: false } };
const workspaces = [pluginsWorkspace, projectWorkspace];
const sessions = { "project/test-agent": ["first"], "project/later": ["second", "third"], "project/disabled": ["fourth"], "other/test-agent": ["fifth"] };
const fake = fakeApi({ autoImport: true, agents: [available, later, disabled, noHistory], workspaces, sessions });
const dispose = activate(fake.api);
try {
await fake.settle();
assert.deepEqual(fake.chats().map((c) => c.sessionId), ["first"]);
fake.agents([available, { ...later, status: { state: "ready" } }, { ...disabled, enabled: true }, noHistory]);
await fake.emit({ event: "agents_changed" });
assert.deepEqual(fake.chats().map((c) => c.sessionId), ["first", "second", "third", "fourth"]);
workspaces.push({ id: "other", name: "Other", path: "/other", position: 2 });
await fake.emit({ event: "workspaces_changed" });
assert.deepEqual(fake.chats().map((c) => c.sessionId), ["first", "second", "third", "fourth", "fifth"]);
const imports = fake.hostCalls.filter((c) => c.method === "host/chats.import");
await fake.emit({ event: "agents_changed" });
await fake.emit({ event: "workspaces_changed" });
assert.equal(fake.hostCalls.filter((c) => c.method === "host/chats.import").length, imports.length);
assert.ok(!imports.some((c) => stable(c.params).includes("no-history") || stable(c.params).includes("plugins")));
} finally { await dispose(); }
});
test("a slow import coalesces change events and disabling it prevents more work without deleting imported chats", async () => {
const fake = fakeApi({ autoImport: true, route: "settings", agents: [available, { ...available, id: "other" }], workspaces: [projectWorkspace], sessions: { "project/test-agent": ["first"], "project/other": ["must-not-import"] } });
const release = fake.block("host/chats.import");
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.trees().includes("Importing existing chats"));
await fake.emit({ event: "agents_changed" });
await fake.emit({ event: "workspaces_changed" });
await fake.change("auto-import-chats", false);
release();
await fake.settle();
assert.deepEqual(fake.chats().map((c) => c.sessionId), ["first"]);
assert.equal(fake.node("auto-import-chats").checked, false);
assert.equal(fake.hostCalls.filter((c) => c.method === "host/chats.import").length, 1);
} finally { release(); await dispose(); }
});
test("automatic import errors stay visible, can be retried, and survive leaving onboarding", async () => {
const fake = fakeApi({ autoImport: true, route: "settings", agents: [available], workspaces: [projectWorkspace], sessions: { "project/test-agent": ["recoverable"] } });
fake.fail("host/chats.import");
const dispose = activate(fake.api);
try {
await fake.settle();
assert.ok(fake.trees().includes("Could not import Test Agent chats into Project"));
assert.ok(fake.notices.some((n) => n.includes("Test service is unavailable")));
assert.deepEqual(fake.chats(), []);
fake.fail(null);
await fake.click("auto-import-retry");
assert.deepEqual(fake.chats().map((c) => c.sessionId), ["recoverable"]);
assert.ok(!fake.trees().includes("Some chats could not be imported"));
assert.ok(fake.trees().includes("Imported 1 chat."));
} finally { await dispose(); }
});
No comments yet.