Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(desktop): realign eight renderer contract tests with the remote-session gates

vastsa7b037ef9f719
diff --git a/apps/desktop/test/native-pi-sessions.test.mjs b/apps/desktop/test/native-pi-sessions.test.mjs
index fa8c11c06..899b597c4 100644
--- a/apps/desktop/test/native-pi-sessions.test.mjs
+++ b/apps/desktop/test/native-pi-sessions.test.mjs
@@ -10,7 +10,7 @@ const events = await read("../src/stores/slices/events-slice.ts");
const sidecarDispatch = await read("../../../packages/agent-runtime/src/sidecar.ts");
test("native model readiness uses capability instead of Desktop secrets", () => {
- assert.match(composer, /const modelReady\s*=\s*nativeSession\s*\?\s*activeSessionSummary\??\.capabilities\?\.canPrompt === true\s*:/);
+ assert.match(composer, /const modelReady\s*=\s*remoteSession\s*\?\s*promptAllowed\s*:\s*nativeSession\s*\?\s*activeSessionSummary\.capabilities\?\.canPrompt === true\s*:/);
});
test("native abort bypasses smart-stop rewrite and refreshes source detail", () => {
@@ -157,9 +157,9 @@ test("native prompt only dispatches sidecar and cannot create a host queue entry
test("native model readiness never depends on a Desktop provider but read-only fails closed", () => {
const expression = composer.match(/const modelReady = ([\s\S]*?);/)[1];
- const evaluateReady = new Function("isImageGenerationModel", "imageGenerationCandidates", "settings", "nativeSession", "activeSessionSummary", "provider", "modelId", `return ${expression}`);
- const ready = (nativeSession, activeSessionSummary, provider, modelId, settings) =>
- evaluateReady(isImageGenerationModel, imageGenerationBindings(settings?.imageGenerationModels, settings?.imageGeneration), settings, nativeSession, activeSessionSummary, provider, modelId);
+ const evaluateReady = new Function("isImageGenerationModel", "imageGenerationCandidates", "settings", "nativeSession", "activeSessionSummary", "provider", "modelId", "remoteSession", "promptAllowed", `return ${expression}`);
+ const ready = (nativeSession, activeSessionSummary, provider, modelId, settings, remoteSession = false, promptAllowed = false) =>
+ evaluateReady(isImageGenerationModel, imageGenerationBindings(settings?.imageGenerationModels, settings?.imageGeneration), settings, nativeSession, activeSessionSummary, provider, modelId, remoteSession, promptAllowed);
assert.equal(ready(true, { capabilities: { canPrompt: true } }, undefined, undefined), true);
assert.equal(ready(true, { capabilities: { canPrompt: false } }, { enabled: true, hasSecret: true }, "model"), false);
assert.equal(ready(true, {}, undefined, undefined), false);
@@ -173,6 +173,11 @@ test("native model readiness never depends on a Desktop provider but read-only f
assert.equal(ready(false, {}, imageProvider, "other-model", settings), true);
assert.equal(ready(true, { capabilities: { canPrompt: true } }, imageProvider, "model", settings), true);
assert.equal(ready(true, { capabilities: { canPrompt: false } }, imageProvider, "model", settings), false);
+
+ // A remote session reads its own prompt capability and never a local provider.
+ assert.equal(ready(false, {}, { enabled: true, hasSecret: true }, "model", undefined, true, true), true);
+ assert.equal(ready(false, {}, { enabled: true, hasSecret: true }, "model", undefined, true, false), false);
+ assert.equal(ready(true, { capabilities: { canPrompt: true } }, undefined, undefined, undefined, true, false), false);
});
diff --git a/apps/desktop/test/plan-mode-source-contract.test.mjs b/apps/desktop/test/plan-mode-source-contract.test.mjs
index 40113e860..985872561 100644
--- a/apps/desktop/test/plan-mode-source-contract.test.mjs
+++ b/apps/desktop/test/plan-mode-source-contract.test.mjs
@@ -244,7 +244,10 @@ test("pending approval keeps the draft while gating every composer control", ()
assert.match(composerSource, /aria-readonly=\{inputBlocked\}/);
assert.match(composerSource, /enabled: !inputBlocked/);
assert.match(composerSource, /disabled=\{controlsBlocked\}/);
- assert.match(composerSource, /const controlsBlocked = approvalPending \|\| nativeSession;/);
+ assert.match(
+ composerSource,
+ /const controlsBlocked = approvalPending \|\| nativeSession \|\| !sessionAllows\(capabilitySession, "canConfigureModel"\);/,
+ );
assert.match(composerSource, /const sendBlocked = approvalPending \|\| pasting \|\| nativeInputBlocked;/);
assert.match(storeSource, /if \(get\(\)\.pendingPlans\[sessionId\]\?\.status === "pending"\) return/);
});
diff --git a/apps/desktop/test/plan-renderer-flow.test.mjs b/apps/desktop/test/plan-renderer-flow.test.mjs
index c87fa5f74..cb036947f 100644
--- a/apps/desktop/test/plan-renderer-flow.test.mjs
+++ b/apps/desktop/test/plan-renderer-flow.test.mjs
@@ -56,7 +56,10 @@ test("pending input is retained but every composer/model mutation control is gat
assert.match(composer, /aria-readonly=\{inputBlocked\}/);
assert.match(composer, /enabled: !inputBlocked/);
assert.match(composer, /disabled=\{controlsBlocked\}/);
- assert.match(composer, /const controlsBlocked = approvalPending \|\| nativeSession;/);
+ assert.match(
+ composer,
+ /const controlsBlocked = approvalPending \|\| nativeSession \|\| !sessionAllows\(capabilitySession, "canConfigureModel"\);/,
+ );
assert.match(composer, /const sendBlocked = approvalPending \|\| pasting \|\| nativeInputBlocked;/);
assert.match(store, /pendingPlans\[sessionId\]\?\.status === "pending"/);
assert.match(store, /pendingPlans\[resolution\.sessionId\]/);
diff --git a/apps/desktop/test/session-message-presentation.test.mjs b/apps/desktop/test/session-message-presentation.test.mjs
index 0d20e6c71..878de6198 100644
--- a/apps/desktop/test/session-message-presentation.test.mjs
+++ b/apps/desktop/test/session-message-presentation.test.mjs
@@ -7,9 +7,11 @@ import { renderToStaticMarkup } from "react-dom/server";
import { splitInlineContent } from "@pi-desktop/shared";
import ts from "typescript";
import { getExtraMessageAttachments } from "../src/features/chat/transcript/extra-attachments.ts";
+import { isRemoteSession, safeSessionSummary, sessionAllows } from "../src/lib/remote-session-safety.ts";
const t = (key, values) => values?.name ? `${key}: ${values.name}` : key;
const store = {
+ sessions: [],
editUserMessage: async () => true,
activateMessageRevision: async () => {},
deleteMessage: async () => {},
@@ -41,6 +43,8 @@ function loadComponent(name, extras = {}) {
"react/jsx-runtime": jsxRuntime,
"react-i18next": { useTranslation: () => ({ t }) },
"../../../stores/app-store": { useAppStore },
+ "../../../lib/remote-session-safety": { isRemoteSession, safeSessionSummary, sessionAllows },
+ "../../../plugins/renderer-slots/use-slots": { useSlotSessionId: () => "local-session" },
"../../../hooks/use-preview-target": { useOpenChatFileRef: () => () => {} },
"../../../lib/chat-links": { splitChatText: () => [] },
"../../../components/Markdown": { Markdown: ({ source: text }) => text },
diff --git a/apps/desktop/test/session-reference-ui.test.mjs b/apps/desktop/test/session-reference-ui.test.mjs
index 7e2db8989..7100d7974 100644
--- a/apps/desktop/test/session-reference-ui.test.mjs
+++ b/apps/desktop/test/session-reference-ui.test.mjs
@@ -17,6 +17,7 @@ import { catalogs } from "@pi-desktop/i18n";
import { formatSessionLink, isRenderableAttachment } from "@pi-desktop/shared";
import { splitChatText } from "../src/lib/chat-links.ts";
import { getExtraMessageAttachments } from "../src/features/chat/transcript/extra-attachments.ts";
+import { isRemoteSession, safeSessionSummary, sessionAllows } from "../src/lib/remote-session-safety.ts";
const here = dirname(fileURLToPath(import.meta.url));
register(pathToFileURL(join(here, "helpers/ts-import-hooks.mjs")));
@@ -116,6 +117,12 @@ const { MessageRow } = load(new URL("../src/features/chat/transcript/MessageRow.
React.createElement("button", { ...props, "aria-label": ariaLabel ?? tooltip }),
},
"../../../stores/app-store": { useAppStore },
+ "../../../lib/remote-session-safety": {
+ isRemoteSession,
+ safeSessionSummary,
+ sessionAllows,
+ },
+ "../../../plugins/renderer-slots/use-slots": { useSlotSessionId: () => "local-session" },
"../../../plugins/renderer-slots/slot-message": { slotMessage: () => undefined },
"./menu-items": { userMessageMenuItems: () => [] },
"./ActionBarSlots": { ActionSlotSide: () => null },
diff --git a/apps/desktop/test/subagent-transcript.test.mjs b/apps/desktop/test/subagent-transcript.test.mjs
index 64544bff2..94ca1995d 100644
--- a/apps/desktop/test/subagent-transcript.test.mjs
+++ b/apps/desktop/test/subagent-transcript.test.mjs
@@ -259,7 +259,7 @@ test("every Task row renders as one accessible delegation topology", () => {
assert.doesNotMatch(topologyNode, /tool-row-caret/);
assert.match(
topologyNode,
- /onClick=\{\(\) => \{\s*if \(!hasDetails\) return;\s*onUserInteraction\?\.\(\);\s*openSubagentTab\(panelSelectionId, agentName \|\| undefined\);\s*\}\}/,
+ /onClick=\{\s*\(\) => \{\s*if \(!hasDetails\) return;\s*onUserInteraction\?\.\(\);\s*localToolsAllowed && openSubagentTab\(panelSelectionId, agentName \|\| undefined\);\s*\}\}/,
);
assert.match(
transcriptSource,
diff --git a/apps/desktop/test/tool-row-file-refs.test.mjs b/apps/desktop/test/tool-row-file-refs.test.mjs
index 728fe28ca..a300fa4f8 100644
--- a/apps/desktop/test/tool-row-file-refs.test.mjs
+++ b/apps/desktop/test/tool-row-file-refs.test.mjs
@@ -4,6 +4,7 @@ import test from "node:test";
import * as React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import ts from "typescript";
+import { isRemoteSession, safeSessionSummary, sessionAllows } from "../src/lib/remote-session-safety.ts";
/*
* The opener a tool row's summary and a tool result's file/match list call.
@@ -48,6 +49,7 @@ const state = {
workspace: { path: "C:/project" },
activeSessionId: "session-1",
pluginViews: [],
+ sessions: [],
openFileInWorkPanel: (...args) => calls.files.push(args),
openUrlInWorkPanel: (...args) => calls.urls.push(args),
openWorkPanelTab: (tab) => calls.tabs.push(tab),
@@ -114,6 +116,9 @@ const { useOpenPreviewTarget } = loadModule("../src/hooks/use-preview-target.ts"
}),
"../lib/open-http-url": { openHttpUrl: (...args) => calls.urls.push(args) },
"../lib/work-panel-tabs": workPanelTabs,
+ "./use-chat-session-capability": { useChatSessionCapability: () => true },
+ "../lib/remote-session-safety": { isRemoteSession, safeSessionSummary, sessionAllows },
+ "../plugins/renderer-slots/use-slots": { useSlotSessionId: () => "" },
});
const flush = () => new Promise((resolve) => setImmediate(resolve));
diff --git a/apps/desktop/test/transcript-style.test.mjs b/apps/desktop/test/transcript-style.test.mjs
index 0c97e1482..a93665903 100644
--- a/apps/desktop/test/transcript-style.test.mjs
+++ b/apps/desktop/test/transcript-style.test.mjs
@@ -362,7 +362,10 @@ test("delete remains on user turns and is removed from assistant toolbar", async
assert.match(storeSource, /replaceSessionMessages\(sessionId,\s*next\)/);
assert.match(transcriptSource, /deleteMessage\(message\.id\)/);
assert.match(transcriptSource, /chat\.deleteMessage/);
- assert.match(transcriptSource, /const editableUserMessage = isUser && !isSessionMessage;/);
+ assert.match(
+ transcriptSource,
+ /const editableUserMessage = isUser && !isSessionMessage && canEditMessages;/,
+ );
assert.match(transcriptSource, /\{editableUserMessage \? \(/);
assert.match(stylesSource, /\.copy-btn\.danger:hover/);
});