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(plugins): pin session filter and reload IPC wiring
vastsa19aaedf46e9d
diff --git a/apps/desktop/test/main-wiring-contract.test.mjs b/apps/desktop/test/main-wiring-contract.test.mjsindex 32991d669..0b04a7544 100644--- a/apps/desktop/test/main-wiring-contract.test.mjs+++ b/apps/desktop/test/main-wiring-contract.test.mjs@@ -204,9 +204,9 @@ test("a finished turn is announced to every plugin surface", () => {services,services.indexOf("{", services.indexOf("const broadcastSessionEvent")),);- assert.match(fanOut, /plugins\.broadcastEvent\(event, \[payload\](?:, scopeFilter)?\)/);+ assert.match(fanOut, /plugins\.broadcastEvent\(event, \[payload\], scopeFilter\)/);assert.match(fanOut, /pluginPanels\.broadcast\(event, payload\)/);- assert.match(fanOut, /pluginViews\.broadcast\(event, payload(?:, scopeFilter)?\)/);+ assert.match(fanOut, /pluginViews\.broadcast\(event, payload, scopeFilter\)/);// Each surface owns its failure: one unreachable plugin process, panel or// view must not suppress the other two.assert.equal(@@ -228,9 +228,9 @@ test("the selected session is announced to every plugin surface", () => {// The snapshot is announced from the one module that owns it, and reaches the// same three surfaces as a finished turn.assert.match(context, /announce\("session:activated", next\)/);- assert.match(services, /plugins\.broadcastEvent\(event, \[payload\](?:, scopeFilter)?\)/);+ assert.match(services, /plugins\.broadcastEvent\(event, \[payload\], scopeFilter\)/);assert.match(services, /pluginPanels\.broadcast\(event, payload\)/);- assert.match(services, /pluginViews\.broadcast\(event, payload(?:, scopeFilter)?\)/);+ assert.match(services, /pluginViews\.broadcast\(event, payload, scopeFilter\)/);// Turn identity and start time come from the host, never from the renderer.assert.match(services,@@ -242,6 +242,25 @@ test("the selected session is announced to every plugin surface", () => {assert.match(root, /pluginServices\.pluginSession\.noteTurnStarted\(sessionId, turnId\)/);});+test("session activation derives one project filter for process and docked-view delivery", () => {+ const services = read("services/plugin-services.ts");+ const fanOut = braceBody(+ services,+ services.indexOf("{", services.indexOf("const broadcastSessionEvent")),+ );+ assert.match(+ fanOut,+ /sessionEventScopeFilter\(\s*event,\s*sessionId,\s*sessionProjects,\s*pluginActiveInProject,\s*\)/,+ );+ assert.match(fanOut, /plugins\.broadcastEvent\(event, \[payload\], scopeFilter\)/);+ assert.match(fanOut, /pluginViews\.broadcast\(event, payload, scopeFilter\)/);+ assert.match(+ fanOut,+ /if \(!SESSION_SCOPED_EVENTS\.has\(event\)\) \{[\s\S]*?pluginPanels\.broadcast\(event, payload\)/,+ "selection events stay out of detached app-scoped panels",+ );+});+test("the shell publishes its selection and opens a revealed view", () => {const shell = readFileSync(join(here, "..", "src", "features", "app", "useAppShellRuntime.tsx"),diff --git a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjsindex df8a2363e..b61f6d5ff 100644--- a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs+++ b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs@@ -4,9 +4,10 @@ import test from "node:test";import ts from "typescript";import { IPC } from "../../../packages/shared/src/protocol.ts";import { pluginProviderCatalogEntries } from "../electron/main/plugin-provider-catalog.ts";+import { createSessionPushGate } from "../electron/main/plugin-session-push-gate.ts";/** Load the real main-process registration function with unrelated hosts stubbed. */-function loadPluginUiIpc() {+function loadPluginUiIpc({ gateFactory = () => () => ({ ignored: false }) } = {}) {const file = new URL("../electron/main/ipc/plugin-ui-ipc.ts", import.meta.url);const { outputText } = ts.transpileModule(fs.readFileSync(file, "utf8"), {compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS },@@ -28,7 +29,7 @@ function loadPluginUiIpc() {"../plugin-view-host": { pluginViewKey: (...parts) => parts.join("/") },"../plugin-panel-host": {},"../plugin-provider-catalog": { pluginProviderCatalogEntries },- "../plugin-session-push-gate": { createSessionPushGate: () => () => ({ ignored: false }) },+ "../plugin-session-push-gate": { createSessionPushGate: gateFactory },};new Function("require", "exports", "module", outputText)((id) => {@@ -91,3 +92,44 @@ test("the plugin Add Service IPC returns declared categories through the Host hadescription: "一句话中文简介。",}]);});++test("the plugin session IPC resets ordering on renderer reload and rejects stale pushes", async () => {+ const handlers = new Map();+ const activeSessions = [];+ loadPluginUiIpc({ gateFactory: createSessionPushGate })({+ registrar: { handle: (channel, handler) => handlers.set(channel, handler) },+ plugins: { listLoaded: () => [] },+ browserHost: {},+ pluginViews: {},+ pluginPanels: {},+ pluginActiveInProject: () => true,+ currentWorkspacePath: () => null,+ getUpdaterLocale: () => "en",+ getPluginPanelTheme: () => ({}),+ setActivePluginSession: (session) => activeSessions.push(session),+ });++ const handler = handlers.get(IPC.invoke.pluginSessionActive);+ assert.equal(typeof handler, "function", "session-active IPC handler is registered");+ assert.deepEqual(+ await handler({ sessionId: "before-reload", projectPath: "/work/a", seq: 8, bootId: "boot-a" }),+ { ok: true },+ );+ assert.deepEqual(+ await handler({ sessionId: "after-reload", projectPath: "/work/b", seq: 1, bootId: "boot-b" }),+ { ok: true },+ );+ assert.deepEqual(+ await handler({ sessionId: "after-newer-push", projectPath: "/work/b", seq: 3, bootId: "boot-b" }),+ { ok: true },+ );+ assert.deepEqual(+ await handler({ sessionId: "stale", projectPath: "/work/a", seq: 2, bootId: "boot-b" }),+ { ok: true, ignored: true },+ );+ assert.deepEqual(activeSessions, [+ { sessionId: "before-reload", projectPath: "/work/a" },+ { sessionId: "after-reload", projectPath: "/work/b" },+ { sessionId: "after-newer-push", projectPath: "/work/b" },+ ]);+});diff --git a/apps/desktop/test/plugin-work-panel-views.test.mjs b/apps/desktop/test/plugin-work-panel-views.test.mjsindex f659e1558..c7ed51eaa 100644--- a/apps/desktop/test/plugin-work-panel-views.test.mjs+++ b/apps/desktop/test/plugin-work-panel-views.test.mjs@@ -283,6 +283,7 @@ test("opening a different project refreshes the scope-filtered view list", () =>test("host panel events reach docked views as well as detached windows", () => {assert.match(viewHostSource, /broadcast\(event: string, payload: unknown(?:, filter\?:[^)]*)?\)/);+ assert.match(viewHostSource, /if \(filter && !filter\(entry\.pluginId\)\) continue/);assert.match(viewHostSource, /pi-plugin-panel-event:\$\{event\}/);assert.match(mainSource, /function broadcastPluginPanelEvent/);assert.match(mainSource, /broadcastPluginPanelEvent\("appearance:changed"/);