The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): pin the "Applies to" scope threading on the Config page and the server-side model write
liuhao1024b3446fbeaf5c
diff --git a/apps/desktop/src/app/settings/config-settings.test.tsx b/apps/desktop/src/app/settings/config-settings.test.tsxindex b9371b49f81..ba61c01fdcd 100644--- a/apps/desktop/src/app/settings/config-settings.test.tsx+++ b/apps/desktop/src/app/settings/config-settings.test.tsx@@ -6,9 +6,14 @@ import { MemoryRouter } from 'react-router'import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'import type * as ConfigApi from '@/api/config'+import { $settingsRequestProfile } from '@/store/settings-scope'import type { ConfigSettings as ConfigSettingsType } from './config-settings'+// The vi.mock factory below replaces the computed (read-only) atom with a+// writable one; narrow the import back so tests can drive it.+const scopeProfileMock = $settingsRequestProfile as unknown as { set: (value: string) => void }+const getHermesConfigRecord = vi.fn()const getHermesConfigSchema = vi.fn()const saveHermesConfig = vi.fn()@@ -18,7 +23,11 @@ const getElevenLabsVoices = vi.fn()// config hook reaches them through the barrel, and a bare mock would throw.vi.mock('@/hermes', async () => ({...(await vi.importActual<typeof ConfigApi>('@/api/config')),- getHermesConfigRecord: () => getHermesConfigRecord(),+ // use-config-record folds the scope into its cache key via the barrel; the+ // real one is a pure string fold, mirrored here for the string scopes this+ // suite passes.+ profileScopeKey: (scope?: unknown) => (typeof scope === 'string' && scope.trim()) || 'default',+ getHermesConfigRecord: (profile?: string) => getHermesConfigRecord(profile),getHermesConfigSchema: () => getHermesConfigSchema(),saveHermesConfig: (config: unknown, profile?: string) => saveHermesConfig(config, profile),getElevenLabsVoices: () => getElevenLabsVoices(),@@ -35,7 +44,10 @@ vi.mock('../hooks/use-on-profile-switch', () => ({// scope chip it renders also reads the selected profile and the loud-note// selector, so those are stubbed to the single-profile default shape.vi.mock('@/store/settings-scope', () => ({- $settingsRequestProfile: atom<string | undefined>(undefined),+ // The real store derives this from the displayed $settingsScopeProfile+ // (never undefined for a real profile — settings-scope.test.ts pins that);+ // here it is a plain atom so the page's threading of it can be driven.+ $settingsRequestProfile: atom<string | undefined>('default'),$settingsScopeEditsNonDefault: atom(false),$settingsScopeOverride: atom<null | string>(null),$settingsScopeProfile: atom<string>('default')@@ -57,6 +69,7 @@ beforeAll(async () => {}, 60_000)beforeEach(() => {+ scopeProfileMock.set('default')getElevenLabsVoices.mockResolvedValue({ available: false })getHermesConfigSchema.mockResolvedValue({ fields: {} })saveHermesConfig.mockResolvedValue({ ok: true })@@ -105,7 +118,7 @@ describe('ConfigSettings autosave', () => {await vi.advanceTimersByTimeAsync(700)await vi.waitFor(() =>- expect(saveHermesConfig).toHaveBeenCalledWith({ compression: { codex_gpt55_autoraise: false } }, undefined)+ expect(saveHermesConfig).toHaveBeenCalledWith({ compression: { codex_gpt55_autoraise: false } }, 'default'))} finally {vi.useRealTimers()@@ -143,4 +156,28 @@ describe('ConfigSettings autosave', () => {vi.useRealTimers()}})++ it('threads the "Applies to" request scope into both the config read and the autosave write', async () => {+ // #118432: the request scope is the concrete profile the page displays+ // (see settings-scope.test.ts). The page must carry it into the read AND+ // the write — a read scoped to B with a write that falls back to the+ // ambient (launch) profile is exactly the silent cross-profile write.+ scopeProfileMock.set('nash')+ getHermesConfigRecord.mockResolvedValue({ checkpoints: { enabled: false } })++ vi.useFakeTimers({ shouldAdvanceTime: true })++ try {+ renderConfigSettings()++ await vi.waitFor(() => expect(getHermesConfigRecord).toHaveBeenCalledWith('nash'))++ ;(await screen.findByRole('switch')).click()+ await vi.advanceTimersByTimeAsync(700)++ await vi.waitFor(() => expect(saveHermesConfig).toHaveBeenCalledWith({ checkpoints: { enabled: true } }, 'nash'))+ } finally {+ vi.useRealTimers()+ }+ })})diff --git a/tests/hermes_cli/test_web_profiles_model_scope.py b/tests/hermes_cli/test_web_profiles_model_scope.pyindex fe10987ba1a..78a28047c75 100644--- a/tests/hermes_cli/test_web_profiles_model_scope.py+++ b/tests/hermes_cli/test_web_profiles_model_scope.py@@ -112,3 +112,31 @@ def test_model_pick_for_default_from_named_profile_launch(homes, probe, monkeypaassert (load_config().get("model") or {}).get("default") == "acme/mini"with _hermes_home_scope(demo):assert (load_config().get("model") or {}).get("default") is None+++def test_model_set_without_a_profile_pins_to_the_launch_home(client, homes):+ """#118432: an omitted ``profile`` does NOT mean "the default profile" — it means+ whatever home this process launched with. That is why the desktop client must+ always send the concrete profile its "Applies to" chip names. This pins the+ server-side semantics so redefining "omitted → launch home" (e.g. to a+ fail-closed refusal like the destructive routes) stays a deliberate, reviewed+ decision instead of an accident."""+ root, demo = homes+ resp = client.post(+ "/api/model/set",+ json={+ "scope": "main",+ "provider": "acme",+ "model": "acme/mini",+ "confirm_expensive_model": True,+ },+ )++ assert resp.status_code == 200, resp.text+ from hermes_cli.config import load_config+ from hermes_cli.web_server_profiles import _hermes_home_scope++ with _hermes_home_scope(root):+ assert (load_config().get("model") or {}).get("default") == "acme/mini"+ with _hermes_home_scope(demo):+ assert (load_config().get("model") or {}).get("default") is None