Skip to content

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

fix(ci): avoid repeated Electron client certificate handshake (#1927)

Lanc9e6f055a867
diff --git a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
index fd5bd6113..c901a5290 100644
--- a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
+++ b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
@@ -266,15 +266,25 @@ function TranscriptBody({
}
};
- const canCopyConversation = hasConversationToCopy({
+ /*
+ Both copy predicates are read only where a menu is built: the background
+ menu on right-click and the ring when it opens. Computing them on every
+ transcript update would read every historical body for a disabled or
+ unopened menu.
+ */
+ const canCopyConversation = () => hasConversationToCopy({
sessionId,
hasMoreBefore,
hasMoreAfter,
messages,
});
- /* The newest settled answer, for the ring's optional copy slot. */
- const lastAnswer = useMemo(() => {
+ /*
+ The newest settled answer, for the ring's optional copy slot. Read lazily:
+ the ring builds its items only when it opens, so an unopened or disabled
+ ring must not scan historical message bodies on every transcript update.
+ */
+ const findLastAnswer = (): string => {
for (let index = messages.length - 1; index >= 0; index -= 1) {
const message = messages[index];
if (message?.role === "assistant" && message.content.trim()) {
@@ -282,15 +292,16 @@ function TranscriptBody({
}
}
return "";
- }, [messages]);
+ };
/*
One slot per direction, in ring order. An action the conversation cannot
fill (no answer yet, or the `none` placeholder) keeps its sector disabled
so the geometry does not depend on message state.
*/
- const buildRadialMenuItems = (): RadialMenuSlot[] =>
- RADIAL_MENU_DIRECTIONS.map((direction) => {
+ const buildRadialMenuItems = (): RadialMenuSlot[] => {
+ const copyable = canCopyConversation();
+ return RADIAL_MENU_DIRECTIONS.map((direction) => {
const action: RadialMenuAction = radialMenu.slots[direction];
const id = `${direction}:${action}`;
const label = t(RADIAL_MENU_ACTION_LABEL_KEYS[action]);
@@ -300,7 +311,7 @@ function TranscriptBody({
id,
label,
icon: <IconCopy size={18} />,
- disabled: !canCopyConversation,
+ disabled: !copyable,
onSelect: () => void copyConversation(),
};
case "select-conversation":
@@ -310,7 +321,8 @@ function TranscriptBody({
icon: <IconTextSelect size={18} />,
onSelect: () => selectText(contentRef.current),
};
- case "copy-last-answer":
+ case "copy-last-answer": {
+ const lastAnswer = findLastAnswer();
return {
id,
label,
@@ -318,6 +330,7 @@ function TranscriptBody({
disabled: !lastAnswer,
onSelect: () => void copyText(lastAnswer),
};
+ }
case "scroll-top":
return {
id,
@@ -377,6 +390,7 @@ function TranscriptBody({
return { id, label, icon: <IconChat size={18} />, disabled: true, onSelect: () => {} };
}
});
+ };
const onContextMenu = (event: ReactMouseEvent<HTMLDivElement>) => {
if (radialMenu.enabled) {
@@ -389,7 +403,7 @@ function TranscriptBody({
label: t("chat.conversationMenu"),
items: conversationMenuItems({
t,
- canCopy: canCopyConversation,
+ canCopy: canCopyConversation(),
onCopyConversation: () => void copyConversation(),
scrollRef,
contentRef,
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 71eba6898..552e91f02 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -18770,11 +18770,12 @@ host-created files. The full app's file-preview viewer is covered separately.
- **Preconditions:** The locked Electron 43 runtime, built workspace packages,
and an isolated profile. Only a local HTTPS fixture and local proxy are used;
trust is confined to the test process/session and fixture certificate.
-- **Steps:** Run `node scripts/e2e-provider-client-certificate.mjs`. Confirm the
- original `net.fetch` aborts before HTTP. Probe the model list and connection
- through the real metadata service; repeat with an invalid fixture key and an
- authenticated custom HTTP proxy. Return a cross-origin redirect, then cancel
- a pending response.
+- **Steps:** Run `node scripts/e2e-provider-client-certificate.mjs`. Confirm one
+ real `net.fetch` fails or stalls before HTTP. Replay that isolated fixture
+ failure for subsequent probes to avoid a second Chromium TLS handshake, then
+ exercise model discovery and connection through the real metadata fallback;
+ repeat with an invalid fixture key and an authenticated custom HTTP proxy.
+ Return a cross-origin redirect, then cancel a pending response.
- **Expected:** Valid credentials return the fixture model; invalid credentials
reach HTTP 401. The retry follows the proxy route, sends no client identity,
refuses cross-origin redirects and aborts with the original signal.
diff --git a/scripts/e2e/provider-client-certificate.ts b/scripts/e2e/provider-client-certificate.ts
index 9ae3eb0d6..ecb4ec4df 100644
--- a/scripts/e2e/provider-client-certificate.ts
+++ b/scripts/e2e/provider-client-certificate.ts
@@ -99,6 +99,19 @@ void app.whenReady().then(async () => {
}
assert.equal(requests, 0, "the original Electron 43 failure precedes HTTP");
console.log(`baseline: Electron 43 net.fetch ${baselineOutcome.kind === "timeout" ? "stalled" : "failed"} before HTTP`);
+ // Linux Electron may leave a second client-certificate handshake pending.
+ // Reuse the observed failure so subsequent calls exercise the real metadata
+ // fallback without issuing another Chromium request to the fixture.
+ const primaryFailure = baselineOutcome.kind === "error"
+ ? baselineOutcome.error
+ : new Error("net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED");
+ const fixtureOrigin = new URL(baseUrl).origin;
+ const electronFetch = globalThis.fetch;
+ globalThis.fetch = async (input, init) => {
+ const requestUrl = input instanceof Request ? input.url : String(input);
+ if (new URL(requestUrl).origin === fixtureOrigin) throw primaryFailure;
+ return electronFetch(input, init);
+ };
const options = { baseUrl, apiKey: "fixture", signal: AbortSignal.timeout(8_000) };
assert.deepEqual((await probeModelList(options)).models, [{ modelId: "fixture-model", displayName: "fixture-model" }]);
assert.equal((await probeProviderEndpoint(options)).status, 200);