Skip to content

The agent that grows with you

fix(desktop): consent RPCs leave a custom HERMES_HOME on its ambient route

Tekniumb79c45bd3e66
diff --git a/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.test.tsx b/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.test.tsx
deleted file mode 100644
index c4782c8e66a..00000000000
--- a/apps/desktop/src/app/contrib/hooks/use-desktop-metrics.test.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import { cleanup, renderHook, waitFor } from '@testing-library/react'
-import { afterEach, describe, expect, it, vi } from 'vitest'
-
-import { requestGatewayForAgent } from '@/store/gateway'
-import { $sharedMetricsConsent, type SharedMetricsConsent } from '@/store/shared-metrics'
-
-import { useDesktopMetrics } from './use-desktop-metrics'
-
-vi.mock('@/store/gateway', async importActual => ({
- ...(await importActual<Record<string, unknown>>()),
- requestGatewayForAgent: vi.fn()
-}))
-
-const CONSENT: SharedMetricsConsent = { enabled: true, send: false, decided: true }
-
-afterEach(() => {
- cleanup()
- vi.mocked(requestGatewayForAgent).mockReset()
- $sharedMetricsConsent.set(null)
-})
-
-describe('useDesktopMetrics', () => {
- it('reads the shared metrics consent from the focused profile', async () => {
- vi.mocked(requestGatewayForAgent).mockResolvedValue(CONSENT as never)
-
- renderHook(() =>
- useDesktopMetrics({
- enabled: true,
- gatewayOpen: true,
- pathname: '/settings',
- profile: 'havoc'
- })
- )
-
- await waitFor(() =>
- expect(requestGatewayForAgent).toHaveBeenCalledWith(null, 'havoc', 'shared_metrics.status', {
- profile: 'havoc'
- })
- )
- })
-})
diff --git a/apps/desktop/src/app/settings/shared-metrics-settings.test.tsx b/apps/desktop/src/app/settings/shared-metrics-settings.test.tsx
deleted file mode 100644
index 0274ded19a4..00000000000
--- a/apps/desktop/src/app/settings/shared-metrics-settings.test.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-
-import { en } from '@/i18n/en'
-import { requestGatewayForAgent } from '@/store/gateway'
-import { $activeGatewayProfile } from '@/store/profile'
-import { $settingsScopeOverride } from '@/store/settings-scope'
-import type { SharedMetricsConsent } from '@/store/shared-metrics'
-
-import { SharedMetricsSettings } from './shared-metrics-settings'
-
-vi.mock('@/store/gateway', async importActual => ({
- ...(await importActual<Record<string, unknown>>()),
- requestGatewayForAgent: vi.fn()
-}))
-
-const initialProfile = $activeGatewayProfile.get()
-const copy = en.sharedMetrics
-
-function installGatewayMock(initial: SharedMetricsConsent) {
- let stored = initial
-
- vi.mocked(requestGatewayForAgent).mockImplementation(async (_connectionId, _profile, method, params) => {
- if (method === 'shared_metrics.set') {
- const enabled = params?.enabled === true
- stored = { enabled, send: enabled && params?.send === true, decided: true }
- }
-
- return stored as never
- })
-}
-
-beforeEach(() => {
- $activeGatewayProfile.set('havoc')
- $settingsScopeOverride.set(null)
-})
-
-afterEach(() => {
- cleanup()
- vi.mocked(requestGatewayForAgent).mockReset()
- $settingsScopeOverride.set(null)
- $activeGatewayProfile.set(initialProfile)
-})
-
-describe('SharedMetricsSettings', () => {
- it('reads and writes shared metrics consent for the settings profile', async () => {
- installGatewayMock({ enabled: false, send: false, decided: false })
-
- render(<SharedMetricsSettings />)
-
- await waitFor(() =>
- expect(requestGatewayForAgent).toHaveBeenCalledWith(
- null,
- 'havoc',
- 'shared_metrics.status',
- { profile: 'havoc' },
- undefined,
- undefined,
- { spawnPriority: 'foreground' }
- )
- )
-
- fireEvent.click(screen.getByRole('switch', { name: copy.collectLabel }))
-
- await waitFor(() =>
- expect(requestGatewayForAgent).toHaveBeenCalledWith(
- null,
- 'havoc',
- 'shared_metrics.set',
- { enabled: true, send: false, first_run: false, profile: 'havoc' },
- undefined,
- undefined,
- { spawnPriority: 'foreground' }
- )
- )
- })
-})
diff --git a/apps/desktop/src/store/shared-metrics.ts b/apps/desktop/src/store/shared-metrics.ts
index 6588d570125..00c23ccf190 100644
--- a/apps/desktop/src/store/shared-metrics.ts
+++ b/apps/desktop/src/store/shared-metrics.ts
@@ -19,11 +19,18 @@ export const SHARED_METRICS_CHOICES: Record<SharedMetricsChoice, { enabled: bool
export type SharedMetricsRequester = <T = unknown>(method: string, params?: Record<string, unknown>) => Promise<T>
+/**
+ * Name the profile on every consent RPC: an unscoped one resolves to the
+ * backend's launch home, so on a shared backend the answer landed in another
+ * profile's config.yaml and the focused profile's offer never retired (#130714).
+ * `custom` is a HERMES_HOME outside profiles/ the backend cannot resolve by
+ * name; there the ambient route already is that home.
+ */
export function sharedMetricsProfileRequester(
request: SharedMetricsRequester,
profile: string
): SharedMetricsRequester {
- return (method, params = {}) => request(method, { ...params, profile })
+ return profile === 'custom' ? request : (method, params = {}) => request(method, { ...params, profile })
}
function isConsent(value: unknown): value is SharedMetricsConsent {