Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): address PR #292 round-3 review — plugin permissions
Andy Pavia56f8af3e2e15
diff --git a/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts b/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.tsindex acb506ff6..5190208b9 100644--- a/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts+++ b/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts@@ -286,14 +286,6 @@ describe('applySandboxUiNavigationPolicies (dispatch wiring)', () => {expect(openExternal).not.toHaveBeenCalled()})- it('still supports the legacy positional oauth callback', () => {- const legacyOauth = vi.fn()- const fake = makeWebContents()- applySandboxUiNavigationPolicies(fake.wc, allowed, legacyOauth)- fake.navigate('clerum://oauth?clientId=google-gmail')- expect(legacyOauth).toHaveBeenCalledWith('google-gmail', false)- })-it('dispatches window.open(gfs://…) and denies the popup', () => {const onGfsOpen = vi.fn()const fake = makeWebContents()diff --git a/desktop-app/src/sandboxUiPartitionPolicies.ts b/desktop-app/src/sandboxUiPartitionPolicies.tsindex 74bda6236..ae40f7285 100644--- a/desktop-app/src/sandboxUiPartitionPolicies.ts+++ b/desktop-app/src/sandboxUiPartitionPolicies.ts@@ -156,12 +156,9 @@ export type SandboxUiNavigationHandlers = {export function applySandboxUiNavigationPolicies(webContents: WebContents,allowedPrefix: string,- handlers?: SandboxUiNavigationHandlers | ((oauthClientId: string, background: boolean) => void)+ handlers?: SandboxUiNavigationHandlers): void {- // Accepts the legacy positional oauth callback so existing call sites and- // tests keep working.- const resolved: SandboxUiNavigationHandlers =- typeof handlers === 'function' ? { onOauthAuthorize: handlers } : (handlers ?? {})+ const resolved: SandboxUiNavigationHandlers = handlers ?? {}const dispatch = (outcome: EmbedNavigationOutcome): void => {if (outcome.kind === 'external') {diff --git a/desktop-app/ui/src/components/PluginPermissions/index.tsx b/desktop-app/ui/src/components/PluginPermissions/index.tsxindex 4853bb075..332ab8028 100644--- a/desktop-app/ui/src/components/PluginPermissions/index.tsx+++ b/desktop-app/ui/src/components/PluginPermissions/index.tsx@@ -124,7 +124,7 @@ export function PluginPermissions() {<span className="da-grid__cell da-grid__cell--right"><Buttoncolor="danger"- disabled={controller.revoking}+ disabled={controller.revoking || controller.clearingActivity}onClick={() => controller.revoke(group.pluginId).catch(() => undefined)}size="sm"variant="ghost"@@ -150,7 +150,7 @@ export function PluginPermissions() {<span className="da-grid__cell da-grid__cell--right"><Buttoncolor="danger"- disabled={controller.revoking}+ disabled={controller.revoking || controller.clearingActivity}onClick={() =>controller.revoke(grant.pluginId, grant.capability)diff --git a/desktop-app/ui/src/hooks/domain/__tests__/usePluginPermissionsController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/usePluginPermissionsController.test.tsxindex dd5c73037..9f069eb84 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/usePluginPermissionsController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/usePluginPermissionsController.test.tsx@@ -40,7 +40,7 @@ describe('usePluginPermissionsController', () => {delete (window as { clerum?: unknown }).clerum})- it('surfaces a failed revoke in the error banner (R1-M4)', async () => {+ it('surfaces a failed revoke in the error banner, labeled (R1-M4)', async () => {installPluginSdk({revoke: vi.fn(async () => {throw new Error('revoke failed')@@ -54,11 +54,13 @@ describe('usePluginPermissionsController', () => {await act(async () => {await result.current.revoke('ns/plugin').catch(() => undefined)})- // The security action used to fail silently; the banner must now show it.- await waitFor(() => expect(result.current.error).toBe('revoke failed'))+ // The security action used to fail silently; the banner must show it, labeled.+ await waitFor(() => expect(result.current.error).toBe('Failed to revoke access: revoke failed'))})- it('clears a stale clear-activity error after a later successful revoke (R2-M1)', async () => {+ // Both masking directions: one action's success must never wipe the OTHER+ // action's genuine failure, and the label keeps them unambiguous.+ it('a successful revoke does not mask a prior clear-activity failure (R2-M1)', async () => {installPluginSdk({clearActivity: vi.fn(async () => {throw new Error('clear failed')@@ -72,13 +74,40 @@ describe('usePluginPermissionsController', () => {await act(async () => {await result.current.clearActivity().catch(() => undefined)})- await waitFor(() => expect(result.current.error).toBe('clear failed'))+ await waitFor(() =>+ expect(result.current.error).toBe('Failed to clear the activity log: clear failed')+ )- // A subsequent SUCCESSFUL revoke must not leave the stale clear-activity- // error in the banner (reads as "your revoke failed" when it didn't).+ // A later SUCCESSFUL revoke must not wipe (or be misread as) the clear failure.await act(async () => {await result.current.revoke('ns/plugin')})- await waitFor(() => expect(result.current.error).toBeNull())+ await waitFor(() =>+ expect(result.current.error).toBe('Failed to clear the activity log: clear failed')+ )+ expect(result.current.error).not.toContain('revoke')+ })++ it('a successful clear-activity does not mask a prior revoke failure (R3-M1)', async () => {+ installPluginSdk({+ revoke: vi.fn(async () => {+ throw new Error('revoke failed')+ }),+ })+ const { result } = renderHook(() => usePluginPermissionsController(), {+ wrapper: makeWrapper(),+ })+ await waitFor(() => expect(result.current.loading).toBe(false))++ await act(async () => {+ await result.current.revoke('ns/plugin').catch(() => undefined)+ })+ await waitFor(() => expect(result.current.error).toBe('Failed to revoke access: revoke failed'))++ // A later SUCCESSFUL clear-activity must not wipe the revoke failure.+ await act(async () => {+ await result.current.clearActivity()+ })+ await waitFor(() => expect(result.current.error).toBe('Failed to revoke access: revoke failed'))})})diff --git a/desktop-app/ui/src/hooks/domain/usePluginPermissionsController.ts b/desktop-app/ui/src/hooks/domain/usePluginPermissionsController.tsindex f8ac3a60b..9e3cd3223 100644--- a/desktop-app/ui/src/hooks/domain/usePluginPermissionsController.ts+++ b/desktop-app/ui/src/hooks/domain/usePluginPermissionsController.ts@@ -83,25 +83,32 @@ export function usePluginPermissionsController() {[activityQuery.data])- // Show the error of the most-recently-submitted action, so a newer success- // supersedes an older failure and no stale error lingers. Derived from- // submittedAt rather than .reset()-ing the sibling — resetting an in-flight- // mutation would drop a real failure and desync isPending. submittedAt is 0- // for a mutation that has never run.- const latestAction =- clearActivityMutation.submittedAt > revokeMutation.submittedAt- ? clearActivityMutation- : revokeMutation- const actionError = latestAction.error ? toErrorMessage(latestAction.error) : null+ // Surface EACH action's error independently and labeled by action, so one+ // action's success (or a newer action) never masks another's genuine failure:+ // a security-relevant revoke that failed must not be silently wiped by an+ // unrelated clear-activity, and vice versa. React Query holds a mutation's+ // error until that SAME mutation re-runs, so a lingering error always reflects+ // a real, still-unaddressed failure of that specific action — and the label+ // stops it from being misread as the other action's failure.+ const actionErrors: string[] = []+ if (revokeMutation.isError) {+ actionErrors.push(`Failed to revoke access: ${toErrorMessage(revokeMutation.error)}`)+ }+ if (clearActivityMutation.isError) {+ actionErrors.push(+ `Failed to clear the activity log: ${toErrorMessage(clearActivityMutation.error)}`+ )+ }+ const actionError = actionErrors.length > 0 ? actionErrors.join(' · ') : nullreturn {groups,activity,loading: grantsQuery.isPending || activityQuery.isPending,- // Query errors take precedence; otherwise the most-recent action's error- // (null when it succeeded). Without surfacing mutation failures a failed- // revoke/clear silently left the UI unchanged, so the user believed a- // permission was revoked when it was not.+ // Query errors take precedence; otherwise every action still in an error+ // state is surfaced (labeled). Without this a failed revoke/clear silently+ // left the UI unchanged, so the user believed a permission was revoked when+ // it was not.error: grantsQuery.error? toErrorMessage(grantsQuery.error): activityQuery.error