From abafbbcc08ea78724991572196fe01a1ac279a65 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 24 Sep 2026 23:54:29 -0700 Subject: [PATCH] refactor(native-chat): drop helpers only the terminal handoff called `claudeAuthEnvCarriedForward`, `isPathWithinDirectory` and `queryWindowsProcessRowsFresh` lost their last caller with the handoff. The fresh-scan tests now go through `queryWindowsProcessDescendants({ fresh: true })`, the teardown path that still depends on that contract. Co-Authored-By: Claude --- src/main/claude-accounts/environment.ts | 28 ------------------- .../windows-foreground-process-rows.test.ts | 13 +++++---- .../windows-foreground-process-rows.ts | 16 +---------- src/main/runtime/orca-runtime-core.ts | 6 ---- 4 files changed, 8 insertions(+), 55 deletions(-) diff --git a/src/main/claude-accounts/environment.ts b/src/main/claude-accounts/environment.ts index b85dd60a854..3f7e1893462 100644 --- a/src/main/claude-accounts/environment.ts +++ b/src/main/claude-accounts/environment.ts @@ -84,34 +84,6 @@ export function shouldStripClaudeAuthEnvForAccount( * authenticate nor beat the pinned account, while the strip removes the name regardless. * Refusing it would break a terminal launch that works today for no security gain. */ -/** - * The inherited Anthropic auth a non-stripping launch has to carry forward explicitly. - * - * applyClaudeEnvPatch always strips the inherited half of a child env, and the - * configured half is what overrides it — so a system-auth user's own key only survives - * if the caller puts it back deliberately. Returns the exact keys present, so a - * win32 `anthropic_api_key` is carried under the name the OS actually has. - */ -export function claudeAuthEnvCarriedForward( - inherited: NodeJS.ProcessEnv, - platform: NodeJS.Platform = process.platform -): Record { - const carried: Record = {} - for (const [key, value] of Object.entries(inherited)) { - if (value === undefined) { - continue - } - const normalized = platform === 'win32' ? key.toUpperCase() : key - if ( - CLAUDE_AUTH_ENV_VARS.some((authKey) => authKey === normalized) || - (normalized === 'ANTHROPIC_CUSTOM_HEADERS' && isAuthLikeCustomHeaders(value)) - ) { - carried[key] = value - } - } - return carried -} - export function hasClaudeAuthEnvConflict( env: Record | undefined, platform: NodeJS.Platform = process.platform diff --git a/src/main/providers/windows-foreground-process-rows.test.ts b/src/main/providers/windows-foreground-process-rows.test.ts index 42330dd6fe8..106d1baccc4 100644 --- a/src/main/providers/windows-foreground-process-rows.test.ts +++ b/src/main/providers/windows-foreground-process-rows.test.ts @@ -19,7 +19,6 @@ import { import { queryWindowsProcessDescendants, queryWindowsProcessLinksFresh, - queryWindowsProcessRowsFresh, resetWindowsProcessRowsSnapshotForTests } from './windows-foreground-process-rows' // A real snapshot always contains the process doing the querying; the reader @@ -85,7 +84,7 @@ describe('windows process rows', () => { }) resetWindowsProcessRowsSnapshotForTests() - await expect(queryWindowsProcessRowsFresh()).rejects.toThrow(/unreadable/) + expect(await queryWindowsProcessDescendants(100, { fresh: true })).toBeNull() }) it('reports an unreadable table as unavailable, not as an empty machine', async () => { @@ -96,7 +95,7 @@ describe('windows process rows', () => { }) resetWindowsProcessRowsSnapshotForTests() - await expect(queryWindowsProcessRowsFresh()).rejects.toThrow() + expect(await queryWindowsProcessDescendants(100, { fresh: true })).toBeNull() expect(await queryWindowsProcessDescendants(100)).toBeNull() }) @@ -107,17 +106,19 @@ describe('windows process rows', () => { it('collapses a burst of concurrent identity probes into one scan', async () => { // A worktree delete tears down PTYs 32-wide. - const rows = await Promise.all(Array.from({ length: 32 }, () => queryWindowsProcessRowsFresh())) + const rows = await Promise.all( + Array.from({ length: 32 }, () => queryWindowsProcessDescendants(100, { fresh: true })) + ) expect(scanCount()).toBe(1) - expect(rows[31]?.map((row) => row.pid)).toEqual([process.pid, 100, 200]) + expect(rows[31]?.map((row) => row.pid)).toEqual([200]) }) it('never answers from the TTL cache, which can predate the recycle it detects', async () => { await queryWindowsProcessDescendants(100) expect(scanCount()).toBe(1) - await queryWindowsProcessRowsFresh() + await queryWindowsProcessDescendants(100, { fresh: true }) expect(scanCount()).toBe(2) }) diff --git a/src/main/providers/windows-foreground-process-rows.ts b/src/main/providers/windows-foreground-process-rows.ts index 16f01d5fbe7..de24a271712 100644 --- a/src/main/providers/windows-foreground-process-rows.ts +++ b/src/main/providers/windows-foreground-process-rows.ts @@ -51,21 +51,7 @@ function projectProcessRows(native: readonly NativeWindowsProcessRow[]): Windows } /** - * Rows from a scan that starts after this call. - * - * PID-identity checks in teardown must not reuse a cached row — it can predate - * the very recycle it is meant to detect. Rejects when the table is unreadable, - * so "unavailable" stays distinguishable from "nothing is running". - * - * `readonly` because the projection is shared with every other reader of the - * same snapshot. - */ -export async function queryWindowsProcessRowsFresh(): Promise { - return projectProcessRows(await readWindowsProcessTableFresh()) -} - -/** - * The same fresh scan for an ancestry walk, which reads only pid/ppid. + * A fresh scan for an ancestry walk, which reads only pid/ppid. * * Returns identity rows so the command line is not merely unused but absent: * asking for it costs an `OpenProcess` per process on the box. diff --git a/src/main/runtime/orca-runtime-core.ts b/src/main/runtime/orca-runtime-core.ts index f2c7cf4405d..bf5821215e8 100644 --- a/src/main/runtime/orca-runtime-core.ts +++ b/src/main/runtime/orca-runtime-core.ts @@ -4,7 +4,6 @@ import type { TerminalWorkspaceLaunchScope } from './runtime-legacy-worker-termi import type { ResolvedWorktree } from './runtime-worktree-path-identity' import type { RuntimeLeafRecord } from './runtime-terminal-state-records' import { isCursorAgentTitle } from '../../shared/agent-detection' -import { isAbsolute, relative, resolve } from 'node:path' import { IMMEDIATE_KILL_REPLY_BUDGET_MS } from '../daemon/immediate-kill-reply-budget' import type { RuntimeTerminalDriverState, @@ -274,11 +273,6 @@ export function addListenerToMap( } } -export function isPathWithinDirectory(directory: string, candidate: string): boolean { - const relativePath = relative(resolve(directory), resolve(candidate)) - return relativePath === '' || (!relativePath.startsWith('..') && !isAbsolute(relativePath)) -} - export const AGENT_HOOK_RUNTIME_ENV_KEYS = [ 'ORCA_AGENT_HOOK_PORT', 'ORCA_AGENT_HOOK_TOKEN',