From 4d774310ef609bbee646eea4e3cf359077dc3fe7 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 13 Nov 2026 02:15:47 -0800 Subject: [PATCH] fix(lint): split the repo-write check out of use-secret-request-card (max-lines) cloud/integration fails oxlint max-lines on use-secret-request-card.ts (303 counted lines, limit 300) since #637, which fails every premerge that merges integration. Moves canWriteRepo and its cache to secret-request-repo-write.ts; no behaviour change. --- .../agent-pane/secret-request-repo-write.ts | 29 ++++++++++++ .../agent-pane/use-secret-request-card.ts | 45 +++++++------------ 2 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 src/renderer/src/components/agent-pane/secret-request-repo-write.ts diff --git a/src/renderer/src/components/agent-pane/secret-request-repo-write.ts b/src/renderer/src/components/agent-pane/secret-request-repo-write.ts new file mode 100644 index 00000000000..7ea5e0db8bb --- /dev/null +++ b/src/renderer/src/components/agent-pane/secret-request-repo-write.ts @@ -0,0 +1,29 @@ +// Repo-scope write check for the S4-b secret request card (use-secret-request-card.ts), split out to keep that +// hook under the file-length limit. +/** Whether this person can write the workspace repo's scope; asked once per repo per session. */ +const repoWriteCache = new Map>() + +export function canWriteRepo(repoKey: string): Promise { + let pending = repoWriteCache.get(repoKey) + if (!pending) { + const api = window.api.cloudSecrets + pending = api + ? api.effective({ repo: repoKey }).then( + (result) => result.ok && result.value.caller.canWrite.repo, + () => false + ) + : Promise.resolve(false) + // A failed read is retried next time rather than cached as "no". + void pending.then((value) => { + if (!value) { + repoWriteCache.delete(repoKey) + } + }) + repoWriteCache.set(repoKey, pending) + } + return pending +} + +export function resetSecretRequestCardCachesForTests(): void { + repoWriteCache.clear() +} diff --git a/src/renderer/src/components/agent-pane/use-secret-request-card.ts b/src/renderer/src/components/agent-pane/use-secret-request-card.ts index 9c944273351..c5b23277ad7 100644 --- a/src/renderer/src/components/agent-pane/use-secret-request-card.ts +++ b/src/renderer/src/components/agent-pane/use-secret-request-card.ts @@ -29,6 +29,7 @@ import { } from '../../../../shared/secret-request-contract' import { cloudWorkspaceSecretsMode } from '@/lib/orca-cloud/cloud-workspace-secrets-mode' import type { CloudSecretsErrorCode } from '../../../../shared/cloud-secrets/cloud-secrets-wire' +import { canWriteRepo } from './secret-request-repo-write' import type { SecretRequestCardActions, SecretRequestCardModel, @@ -46,33 +47,7 @@ const TRANSPORT_FAILURES: ReadonlySet = new Set([ 'unknown' ]) -/** Whether this person can write the workspace repo's scope; asked once per repo per session. */ -const repoWriteCache = new Map>() - -function canWriteRepo(repoKey: string): Promise { - let pending = repoWriteCache.get(repoKey) - if (!pending) { - const api = window.api.cloudSecrets - pending = api - ? api.effective({ repo: repoKey }).then( - (result) => result.ok && result.value.caller.canWrite.repo, - () => false - ) - : Promise.resolve(false) - // A failed read is retried next time rather than cached as "no". - void pending.then((value) => { - if (!value) { - repoWriteCache.delete(repoKey) - } - }) - repoWriteCache.set(repoKey, pending) - } - return pending -} - -export function resetSecretRequestCardCachesForTests(): void { - repoWriteCache.clear() -} +export { resetSecretRequestCardCachesForTests } from './secret-request-repo-write' function useWorkspaceRepoKey(worktreeId: string | null): string | null { return useAppStore((state) => { @@ -220,7 +195,9 @@ export function useSecretRequestCard(args: { : repoScope ? ['personal', 'repo'] : ['personal'] - const effectiveScope: SecretRequestScope = scopes.includes(scope) ? scope : (scopes[0] ?? 'personal') + const effectiveScope: SecretRequestScope = scopes.includes(scope) + ? scope + : (scopes[0] ?? 'personal') const add = useCallback(async () => { const api = window.api.cloudSecrets @@ -259,7 +236,17 @@ export function useSecretRequestCard(args: { requestId, outcome === 'provided' ? 'saved' : 'savedAfterExpiry' ) - }, [value, local, scopes.length, environmentId, requestId, effectiveScope, repoKey, event.name, t]) + }, [ + value, + local, + scopes.length, + environmentId, + requestId, + effectiveScope, + repoKey, + event.name, + t + ]) const phase: SecretRequestCardPhase = local === 'saving'