Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
test(plugin-launcher): cover unified tiles, the pin cap, and content height
v_wyxgwang2170b8afc784
diff --git a/apps/desktop/test/launcher-search.test.mjs b/apps/desktop/test/launcher-search.test.mjsindex 951107741..684aeed51 100644--- a/apps/desktop/test/launcher-search.test.mjs+++ b/apps/desktop/test/launcher-search.test.mjs@@ -6,6 +6,7 @@ import {LAUNCHER_MATCH_TILES,LAUNCHER_PINNED_TILES,LAUNCHER_RECENT_TILES,+ buildLauncherAllPluginsSection,buildLauncherPinnedSection,buildLauncherRecentSection,indexLauncherCatalog,@@ -16,7 +17,6 @@ import {const EMPTY_STORE = {recents: [],pins: [],- aliases: {},disabledPlugins: [],disabledTriggers: [],};@@ -61,6 +61,18 @@ test("the grid is 8 columns wide with the documented row budget", () => {assert.equal(LAUNCHER_MATCH_TILES, 24);});+test("a tile carries the name, the monogram, and nothing that explains the match", () => {+ const items = catalog([], [app("chrome", "Google Chrome")]);++ const tile = search(items, "chrome").tiles[0];++ assert.equal(tile.kind, "app");+ assert.equal(tile.name, "Google Chrome");+ assert.equal(tile.monogram, "G");+ assert.equal("detail" in tile, false);+ assert.equal("reason" in tile, false);+});+test("a declared trigger outranks a plugin whose name merely contains the input", () => {const items = catalog([plugin("calc.name-only", "1+1 helper"),@@ -72,7 +84,22 @@ test("a declared trigger outranks a plugin whose name merely contains the input"const result = search(items, "1+1");assert.equal(result.tiles[0].id, "plugin:calculator");- assert.equal(result.tiles[0].reason, "pattern");+ assert.deepEqual(result.tiles[0].trigger, { id: "expr", payload: "1+1" });+});++test("a trigger hit appears once: it is not scored against the name as well", () => {+ // The plugin's name would also match the input, which used to be able to+ // surface the same plugin twice: once for the pattern, once for the name.+ const items = catalog([+ plugin("calculator", "== 1+1 ==", {+ triggers: [{ id: "expr", pattern: "^[0-9+\\-*/(). ]+$" }],+ }),+ ]);++ const result = search(items, "1+1");++ assert.equal(result.total, 1);+ assert.equal(result.tiles.length, 1);assert.deepEqual(result.tiles[0].trigger, { id: "expr", payload: "1+1" });});@@ -112,21 +139,25 @@ test("Chinese names match by full pinyin and by initials", () => {const items = catalog([], [app("wechat", "微信")]);assert.equal(search(items, "weixin").tiles[0].id, "app:wechat");- assert.equal(search(items, "weixin").tiles[0].reason, "pinyin");assert.equal(search(items, "wx").tiles[0].id, "app:wechat");- assert.equal(search(items, "wx").tiles[0].reason, "initials");assert.equal(search(items, "微信").tiles[0].id, "app:wechat");});-test("a user alias matches and reports that it was the alias", () => {- const store = { ...EMPTY_STORE, aliases: { "app:wechat": ["聊天"] } };- const items = catalog([], [app("wechat", "WeChat")]);+test("an application's icon data URL reaches the tile", () => {+ const items = catalog([], [+ app("chrome", "Chrome", { iconDataUrl: "data:image/png;base64,AAAA" }),+ ]);++ assert.equal(+ search(items, "chrome").tiles[0].iconDataUrl,+ "data:image/png;base64,AAAA",+ );+});- const result = search(items, "liaotian", store);+test("plugins never carry an application icon", () => {+ const items = catalog([plugin("notes", "Notes")]);- assert.equal(result.tiles[0].id, "app:wechat");- assert.equal(result.tiles[0].reason, "alias");- assert.equal(result.tiles[0].detail, "聊天");+ assert.equal(search(items, "notes").tiles[0].iconDataUrl, undefined);});test("same-named plugin and application both appear, plugins first", () => {@@ -165,7 +196,6 @@ test("a description-only match ranks last", () => {assert.equal(result.tiles[0].id, "plugin:markdown");assert.equal(result.tiles[1].id, "plugin:notes");- assert.equal(result.tiles[1].reason, "description");});test("recents report their real total while the grid shows two rows", () => {@@ -184,7 +214,6 @@ test("recents report their real total while the grid shows two rows", () => {assert.equal(section.tiles.length, 16);assert.equal(section.total, 20);- assert.equal(section.tiles[0].reason, "recent");});test("pins show one row and keep the pin order", () => {@@ -200,7 +229,29 @@ test("pins show one row and keep the pin order", () => {section.tiles.map((tile) => tile.id),["app:c", "app:a", "app:b"],);- assert.equal(section.tiles[0].reason, "pinned");+});++test("the all-plugins view lists plugins only, recently used first", () => {+ const items = catalog(+ [plugin("alpha", "Alpha"), plugin("beta", "Beta"), plugin("gamma", "Gamma")],+ [app("chrome", "Chrome")],+ );+ const store = { ...EMPTY_STORE, recents: ["plugin:gamma"] };++ const section = buildLauncherAllPluginsSection(+ indexLauncherCatalog(items, store),+ store,+ );++ assert.deepEqual(+ section.tiles.map((tile) => tile.id),+ ["plugin:gamma", "plugin:alpha", "plugin:beta"],+ );+ assert.equal(section.total, 3);+ assert.deepEqual(+ section.tiles.filter((tile) => tile.kind !== "plugin"),+ [],+ );});test("a plugin the user hid from the launcher is not searchable", () => {@@ -226,10 +277,7 @@ test("a disabled trigger no longer claims the input", () => {const result = search(items, "1+1", store);- assert.equal(- result.tiles.every((tile) => tile.reason !== "pattern"),- true,- );+ assert.equal(result.tiles.length, 0);});test("recency breaks a tie between equal matches", () => {diff --git a/apps/desktop/test/launcher-store.test.mjs b/apps/desktop/test/launcher-store.test.mjsindex 79dd5418a..b78b7889f 100644--- a/apps/desktop/test/launcher-store.test.mjs+++ b/apps/desktop/test/launcher-store.test.mjs@@ -3,13 +3,12 @@ import test from "node:test";import {EMPTY_LAUNCHER_STATE,- LAUNCHER_ALIAS_LIMIT,+ LAUNCHER_PIN_LIMIT,LAUNCHER_RECENT_LIMIT,launcherTriggerKey,pruneLauncherState,readLauncherState,rememberLauncherUse,- setLauncherAliases,setLauncherPinned,setLauncherPluginDisabled,setLauncherTriggerDisabled,@@ -62,10 +61,7 @@ test("plugin history written by the previous panel survives the upgrade", () =>test("an empty store reports nothing pinned or disabled", () => {const state = withStorage(fakeStorage(), () => readLauncherState());- assert.deepEqual(state.pins, []);- assert.deepEqual(state.aliases, {});- assert.deepEqual(state.disabledPlugins, []);- assert.deepEqual(state.disabledTriggers, []);+ assert.deepEqual(state, EMPTY_LAUNCHER_STATE);});test("opening an item moves it to the front exactly once", () => {@@ -94,42 +90,51 @@ test("recents stay capped", () => {});});-test("pinning is idempotent and unpinning removes the entry", () => {+test("pinning appends once and unpinning removes the entry", () => {const storage = fakeStorage();withStorage(storage, () => {setLauncherPinned("app:a", true);setLauncherPinned("app:b", true);- assert.deepEqual(setLauncherPinned("app:a", true).pins, ["app:b", "app:a"]);+ // Re-pinning an item that is already pinned keeps its place.+ assert.deepEqual(setLauncherPinned("app:a", true).pins, ["app:a", "app:b"]);assert.deepEqual(setLauncherPinned("app:b", false).pins, ["app:a"]);});});-test("aliases are trimmed, deduplicated and capped", () => {+test("the pin budget is eight and a full row refuses a ninth pin", () => {const storage = fakeStorage();- const aliases = Array.from(- { length: LAUNCHER_ALIAS_LIMIT + 4 },- (_, index) => ` alias ${index} `,- );- withStorage(storage, () => {- const state = setLauncherAliases("app:wechat", ["微信", "微信", ...aliases]);-- assert.deepEqual(state.aliases["app:wechat"], [- "微信",- ...aliases.slice(0, LAUNCHER_ALIAS_LIMIT - 1).map((alias) => alias.trim()),- ]);- });-});--test("clearing every alias drops the item key", () => {- const storage = fakeStorage();+ assert.equal(LAUNCHER_PIN_LIMIT, 8);withStorage(storage, () => {- setLauncherAliases("app:wechat", ["微信"]);- const state = setLauncherAliases("app:wechat", [" "]);+ for (let index = 0; index < 10; index += 1) {+ setLauncherPinned(`app:${index}`, true);+ }+ const state = readLauncherState();++ assert.equal(state.pins.length, LAUNCHER_PIN_LIMIT);+ assert.deepEqual(+ state.pins,+ Array.from({ length: LAUNCHER_PIN_LIMIT }, (_, index) => `app:${index}`),+ );- assert.equal("app:wechat" in state.aliases, false);+ // A full row keeps the pins it has and does not evict the oldest one.+ const afterRefusal = setLauncherPinned("app:extra", true);+ assert.deepEqual(afterRefusal.pins, state.pins);++ // Unpinning frees a slot for the next pin.+ setLauncherPinned("app:0", false);+ assert.deepEqual(setLauncherPinned("app:extra", true).pins, [+ "app:1",+ "app:2",+ "app:3",+ "app:4",+ "app:5",+ "app:6",+ "app:7",+ "app:extra",+ ]);});});@@ -158,20 +163,18 @@ test("a plugin hidden from the launcher keeps that preference through pruning",});});-test("pruning forgets recents, pins and aliases of items that are gone", () => {+test("pruning forgets recents and pins of items that are gone", () => {const storage = fakeStorage();withStorage(storage, () => {rememberLauncherUse("plugin:gone");rememberLauncherUse("app:kept");setLauncherPinned("plugin:gone", true);- setLauncherAliases("plugin:gone", ["x"]);const state = pruneLauncherState(["app:kept"]);assert.deepEqual(state.recents, ["app:kept"]);assert.deepEqual(state.pins, []);- assert.deepEqual(state.aliases, {});assert.deepEqual(readLauncherState().recents, ["app:kept"]);});});@@ -184,12 +187,36 @@ test("unreadable persisted state degrades to an empty store", () => {assert.deepEqual(state, EMPTY_LAUNCHER_STATE);});+test("a legacy payload with aliases is read without them and left untouched", () => {+ const aliases = { "app:wechat": ["聊天"] };+ const storage = fakeStorage({+ [STATE_KEY]: JSON.stringify({+ recents: ["app:wechat"],+ pins: ["app:wechat"],+ aliases,+ disabledPlugins: [],+ disabledTriggers: [],+ }),+ });++ const state = withStorage(storage, () => readLauncherState());++ assert.deepEqual(state, {+ recents: ["app:wechat"],+ pins: ["app:wechat"],+ disabledPlugins: [],+ disabledTriggers: [],+ });+ // Reading is not a migration: the stored payload is not rewritten behind the+ // user's back, so a downgrade still finds its aliases.+ assert.deepEqual(JSON.parse(storage.map.get(STATE_KEY)).aliases, aliases);+});+test("a wrong-shaped payload is sanitized instead of trusted", () => {const storage = fakeStorage({[STATE_KEY]: JSON.stringify({recents: ["app:a", 7, "app:a", ""],pins: "nope",- aliases: { "app:a": ["ok", 5], " ": ["bad"] },disabledPlugins: null,disabledTriggers: ["calculator::expr", 1],}),@@ -199,7 +226,6 @@ test("a wrong-shaped payload is sanitized instead of trusted", () => {assert.deepEqual(state.recents, ["app:a"]);assert.deepEqual(state.pins, []);- assert.deepEqual(state.aliases, { "app:a": ["ok"] });assert.deepEqual(state.disabledPlugins, []);assert.deepEqual(state.disabledTriggers, ["calculator::expr"]);});diff --git a/apps/desktop/test/local-apps.test.mjs b/apps/desktop/test/local-apps.test.mjsindex 518cba428..957b08214 100644--- a/apps/desktop/test/local-apps.test.mjs+++ b/apps/desktop/test/local-apps.test.mjs@@ -2,6 +2,7 @@ import assert from "node:assert/strict";import test from "node:test";import {+ LOCAL_APP_MAX_ICON_BYTES,createLocalAppCatalog,linuxApplicationDirectories,localAppId,@@ -9,6 +10,7 @@ import {parseDesktopEntry,windowsStartMenuDirs,} from "../electron/main/local-apps.ts";+import { readMainModuleSync } from "./helpers/source-contracts.mjs";import {desktopExecutable,isLaunchableDesktopEntry,@@ -369,7 +371,7 @@ test("icon failures and oversized icons never fail the scan", async () => {icons: [[CHROME_TARGET, new Error("icon extraction failed")],[second, "data:image/png;base64,AAAA"],- [third, `data:image/png;base64,${"A".repeat(5_000)}`],+ [third, `data:image/png;base64,${"A".repeat(LOCAL_APP_MAX_ICON_BYTES + 1)}`],],});@@ -382,6 +384,53 @@ test("icon failures and oversized icons never fail the scan", async () => {assert.equal(state.iconRequests, 3);});+test("the icon budget is 32 KiB so a large native icon still fits", () => {+ assert.equal(LOCAL_APP_MAX_ICON_BYTES, 32_768);+ // The small variant reads as a blurry square on the launcher's tiles.+ assert.match(+ readMainModuleSync("local-apps.ts"),+ /app\.getFileIcon\(target, \{ size: "large" \}\)/,+ );+});++test("a rescan reuses the icon it already fetched", async () => {+ const { deps, state } = createFakeHost({+ shortcuts: { [`${START_MENU}\\Chrome.lnk`]: { target: CHROME_TARGET } },+ existing: [CHROME_TARGET],+ icons: [[CHROME_TARGET, "data:image/png;base64,AAAA"]],+ });+ const catalog = createLocalAppCatalog(deps);++ const first = await catalog.list();+ assert.equal(state.iconRequests, 1);+ assert.equal(first[0].iconDataUrl, "data:image/png;base64,AAAA");++ const rescanned = await catalog.refresh();++ assert.equal(state.iconRequests, 1);+ assert.equal(rescanned[0].iconDataUrl, "data:image/png;base64,AAAA");+});++test("an icon is dropped from the cache when its application disappears", async () => {+ const shortcut = `${START_MENU}\\Chrome.lnk`;+ const { deps, state } = createFakeHost({+ shortcuts: { [shortcut]: { target: CHROME_TARGET } },+ existing: [CHROME_TARGET],+ icons: [[CHROME_TARGET, "data:image/png;base64,AAAA"]],+ });+ const catalog = createLocalAppCatalog(deps);++ await catalog.list();+ assert.equal(state.iconRequests, 1);++ state.shortcuts.delete(shortcut);+ assert.deepEqual(await catalog.refresh(), []);++ // Reinstalling must not be served the stale image of the previous install.+ state.shortcuts.set(shortcut, { target: CHROME_TARGET });+ await catalog.refresh();+ assert.equal(state.iconRequests, 2);+});test("icons are requested for at most 200 entries", async () => {const shortcuts = {};const existing = [];diff --git a/apps/desktop/test/plugin-launcher-height.test.mjs b/apps/desktop/test/plugin-launcher-height.test.mjsnew file mode 100644index 000000000..93dace464--- /dev/null+++ b/apps/desktop/test/plugin-launcher-height.test.mjs@@ -0,0 +1,93 @@+import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";+import test from "node:test";++import { readMainModuleSync } from "./helpers/source-contracts.mjs";+import { resolveLauncherContentHeight } from "../src/lib/launcher-height.ts";+import {+ PLUGIN_LAUNCHER_MAX_HEIGHT,+ PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT,+ clampLauncherContentHeight,+} from "../electron/main/plugin-launcher-state.ts";++test("the window height is the sum of the parts the panel renders", () => {+ const height = resolveLauncherContentHeight({+ searchRowHeight: 58,+ resultsHeight: 200,+ footerHeight: 38,+ chromeHeight: 22,+ });++ assert.equal(height, 318);+});++test("a fractional measurement rounds up so no scrollbar is left behind", () => {+ const height = resolveLauncherContentHeight({+ searchRowHeight: 57.5,+ resultsHeight: 120.25,+ footerHeight: 38,+ chromeHeight: 22,+ });++ assert.equal(height, 238);+});++test("a collapsed layout asks for no window at all", () => {+ const empty = {+ searchRowHeight: 0,+ resultsHeight: 0,+ footerHeight: 0,+ chromeHeight: 0,+ };++ assert.equal(resolveLauncherContentHeight(empty), 0);+ assert.equal(+ resolveLauncherContentHeight({ ...empty, resultsHeight: -40 }),+ 0,+ );+ assert.equal(+ resolveLauncherContentHeight({ ...empty, resultsHeight: Number.NaN }),+ 0,+ );+});++test("the height floor is small enough for a one-row panel", () => {+ assert.equal(PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT, 120);+ assert.ok(PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT < 380);+});++test("a measured height is clamped into the supported range", () => {+ assert.equal(clampLauncherContentHeight(320), 320);+ assert.equal(clampLauncherContentHeight(58), PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT);+ assert.equal(clampLauncherContentHeight(4_000), PLUGIN_LAUNCHER_MAX_HEIGHT);+ assert.equal(clampLauncherContentHeight(320.4), 320);+});++test("anything that is not a finite positive number is refused", () => {+ for (const value of [undefined, null, "320", Number.NaN, Infinity, -20, 0]) {+ assert.equal(clampLauncherContentHeight(value), null, String(value));+ }+});++test("the launcher window only sets the height, never the width", () => {+ const ipc = readMainModuleSync("ipc/plugin-launcher-ipc.ts");++ assert.match(ipc, /IPC\.invoke\.pluginLauncherContentHeight/);+ assert.match(ipc, /assertLauncherSender\(getPluginLauncherWindow, event\.sender\.id\)/);+ // The width keeps whatever the user dragged it to.+ assert.match(ipc, /const \[width\] = window\.getContentSize\(\);/);+ assert.match(ipc, /window\.setContentSize\(width, height, false\)/);+});++test("the panel reports its measured height instead of a remembered one", async () => {+ const launcher = await readFile(+ new URL("../src/components/PluginLauncher.tsx", import.meta.url),+ "utf8",+ );++ assert.match(launcher, /api\.launcherSetContentHeight\(/);+ assert.match(launcher, /resolveLauncherContentHeight\(/);+ assert.match(launcher, /new ResizeObserver\(/);+ // Typing narrows matches, so the window may only ever grow to the cap.+ assert.match(launcher, /plugin-launcher-results-content/);+});diff --git a/apps/desktop/test/plugin-launcher-state.test.mjs b/apps/desktop/test/plugin-launcher-state.test.mjsindex e185dc9a8..73b66b200 100644--- a/apps/desktop/test/plugin-launcher-state.test.mjs+++ b/apps/desktop/test/plugin-launcher-state.test.mjs@@ -8,7 +8,7 @@ import {PLUGIN_LAUNCHER_DEFAULT_HEIGHT,PLUGIN_LAUNCHER_DEFAULT_WIDTH,PLUGIN_LAUNCHER_MAX_WIDTH,- PLUGIN_LAUNCHER_MIN_HEIGHT,+ PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT,PLUGIN_LAUNCHER_MIN_WIDTH,PLUGIN_LAUNCHER_STATE_FILE,parseLauncherWindowState,@@ -38,10 +38,11 @@ test("a missing state file means the panel opens at its default size", () => {});test("the window cannot be persisted narrower than the eight-column floor", () => {- const state = parseLauncherWindowState({ width: 120, height: 100 });+ const state = parseLauncherWindowState({ width: 120, height: 20 });assert.equal(state.width, PLUGIN_LAUNCHER_MIN_WIDTH);- assert.equal(state.height, PLUGIN_LAUNCHER_MIN_HEIGHT);+ // Height is content-driven now, so only a very small floor is enforced.+ assert.equal(state.height, PLUGIN_LAUNCHER_MIN_CONTENT_HEIGHT);});test("an oversized remembered width is clamped", () => {