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 <noreply@anthropic.com>
This commit is contained in:
Brennan Benson
2026-09-24 23:54:29 -07:00
co-authored by Claude
parent eab4ef1edf
commit abafbbcc08
4 changed files with 8 additions and 55 deletions
-28
View File
@@ -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<string, string> {
const carried: Record<string, string> = {}
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<string, string> | undefined,
platform: NodeJS.Platform = process.platform
@@ -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)
})
@@ -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<readonly WindowsProcessRow[]> {
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.
-6
View File
@@ -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<T>(
}
}
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',