Skip to content

The agent that grows with you

test(desktop): trim config route-binding tests to the two invariants

kshitijk4poor5485d17e9e45
diff --git a/apps/desktop/src/api/config-route-binding.test.ts b/apps/desktop/src/api/config-route-binding.test.ts
index 96aa44ec72d..211ec8447f4 100644
--- a/apps/desktop/src/api/config-route-binding.test.ts
+++ b/apps/desktop/src/api/config-route-binding.test.ts
@@ -1,12 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
- getHermesConfigDefaults,
getHermesConfigRecord,
peekConfigReadOrigin,
- resolveConfigWriteScope,
saveHermesConfig,
- saveHermesConfigRecord,
setApiRequestConnection,
setApiRequestProfile
} from '@/hermes'
@@ -60,54 +57,4 @@ describe('config read/write route binding', () => {
)
expect(puts.filter(call => call[0].connectionId === 'connection-b')).toHaveLength(0)
})
-
- it('explicit connection/profile pins still win over a captured origin', async () => {
- setApiRequestConnection('connection-a')
- const record = await getHermesConfigRecord()
- setApiRequestConnection('connection-b')
-
- await saveHermesConfigRecord(record, { connectionId: 'explicit-pin', profile: 'worker' })
-
- const put = api.mock.calls.find(call => call[0].method === 'PUT')?.[0]
-
- expect(put).toEqual(
- expect.objectContaining({
- connectionId: 'explicit-pin',
- profile: 'worker'
- })
- )
- })
-
- it('unbound local writes keep the live ambient path', () => {
- setApiRequestConnection('connection-b')
- setApiRequestProfile('coder')
-
- expect(resolveConfigWriteScope({ model: 'fresh' })).toEqual({
- connectionId: 'connection-b',
- profile: 'coder'
- })
- })
-
- it('treats a null read scope as absent and preserves the active profile', async () => {
- setApiRequestConnection('connection-a')
- setApiRequestProfile('worker')
-
- const record = await getHermesConfigRecord(null)
-
- expect(peekConfigReadOrigin(record)).toEqual({ connectionId: 'connection-a', profile: 'worker' })
- })
-
- it('writes reset defaults back through the route that fetched them', async () => {
- setApiRequestConnection('connection-a')
- setApiRequestProfile('default')
-
- const defaults = await getHermesConfigDefaults()
- setApiRequestConnection('connection-b')
-
- await saveHermesConfig(defaults)
-
- expect(api.mock.calls.find(call => call[0].method === 'PUT')?.[0]).toEqual(
- expect.objectContaining({ connectionId: 'connection-a', profile: 'default' })
- )
- })
})
diff --git a/apps/desktop/src/app/hooks/use-config-record.test.tsx b/apps/desktop/src/app/hooks/use-config-record.test.tsx
index 7a8889e1362..95dea55b5d4 100644
--- a/apps/desktop/src/app/hooks/use-config-record.test.tsx
+++ b/apps/desktop/src/app/hooks/use-config-record.test.tsx
@@ -20,18 +20,6 @@ afterEach(() => {
const wrapper = ({ children }: { children: React.ReactNode }) =>
createElement(QueryClientProvider, { client: queryClient }, children)
-it('keeps a cached record bound to the origin that served it before refetching', () => {
- const record = { display: { theme: 'dark' } }
- bindConfigReadOrigin(record, { connectionId: 'connection-a', profile: 'worker' })
- queryClient.setQueryData(HERMES_CONFIG_KEY, record)
- vi.mocked(getHermesConfigRecord).mockImplementation(() => new Promise(() => {}))
-
- const { result } = renderHook(() => useHermesConfigRecord(), { wrapper })
-
- expect(result.current.data).toBe(record)
- expect(result.current.writeScope).toEqual({ connectionId: 'connection-a', profile: 'worker' })
-})
-
it('updates the write origin when a refetch replaces the displayed record', async () => {
const first = { display: { theme: 'dark' } }
const second = { display: { theme: 'light' } }
@@ -41,6 +29,12 @@ it('updates the write origin when a refetch replaces the displayed record', asyn
const { result } = renderHook(() => useHermesConfigRecord(), { wrapper })
+ // Before the first GET resolves the scope must be `undefined` (not `null`):
+ // profileScoped(null) drops the active profile and targets the PRIMARY.
+ expect(result.current.data).toBeUndefined()
+ expect(result.current.writeScope).toBeUndefined()
+ expect(result.current.writeScope).not.toBeNull()
+
await waitFor(() => expect(result.current.data).toBe(first))
expect(result.current.writeScope).toEqual({ connectionId: 'connection-a', profile: 'worker' })