dsh-context-compression-improved 0.7.0-beta.1 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.ja.md +226 -220
  2. package/CHANGELOG.ko.md +220 -214
  3. package/CHANGELOG.md +366 -376
  4. package/CHANGELOG.zh.md +204 -199
  5. package/README.ja.md +85 -85
  6. package/README.ko.md +85 -85
  7. package/README.md +98 -97
  8. package/README.zh.md +85 -86
  9. package/eslint.config.js +30 -76
  10. package/package.json +53 -55
  11. package/packages/selector/dsh.plugin.json +2 -2
  12. package/packages/selector/lib/{intent-gate.js → advisor-state.js} +3 -91
  13. package/packages/selector/lib/client.js +3 -14
  14. package/packages/selector/lib/index.js +1 -92
  15. package/packages/selector/lib/profiles.d.ts +0 -9
  16. package/packages/selector/lib/pruner.d.ts +0 -59
  17. package/packages/selector/lib/pruner.js +7 -410
  18. package/packages/selector/lib/style.css +46 -46
  19. package/packages/selector/package.json +114 -114
  20. package/packages/selector/src/client/decode.ts +2 -6
  21. package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
  22. package/packages/selector/src/index.ts +411 -418
  23. package/packages/selector/src/preset-overlay.ts +0 -3
  24. package/packages/selector/src/profiles.ts +10 -30
  25. package/packages/selector/src/pruner/content.ts +1 -1
  26. package/packages/selector/src/pruner/state.ts +0 -7
  27. package/packages/selector/src/pruner.ts +9 -253
  28. package/packages/selector/src/runtime/audit.ts +0 -17
  29. package/packages/selector/src/runtime/config.ts +11 -36
  30. package/packages/selector/src/runtime/reducers.ts +1 -1
  31. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +1 -46
  32. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -55
  33. package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
  34. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +1 -4
  35. package/packages/selector/src/runtime/types.ts +0 -12
  36. package/packages/selector/tests/auto-compact.client.spec.tsx +213 -214
  37. package/packages/selector/tests/built/client-artifact.spec.ts +59 -61
  38. package/packages/selector/tests/code-skeleton.client.spec.ts +93 -94
  39. package/packages/selector/tests/custom-contract.client.spec.ts +222 -223
  40. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  41. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  42. package/packages/selector/tests/preset-options-write.client.spec.ts +187 -188
  43. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  44. package/packages/selector/tests/profiles.client.spec.tsx +434 -436
  45. package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
  46. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  47. package/packages/selector/tests/runtime/audit.spec.ts +274 -275
  48. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
  49. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
  50. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2736
  51. package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
  52. package/pnpm-workspace.yaml +66 -66
  53. package/scripts/packed-components-smoke.mjs +0 -2
  54. package/scripts/packed-install-e2e.mjs +5 -7
  55. package/scripts/verify-release.mjs +2 -3
  56. package/tsconfig.tests.json +1 -3
  57. package/vitest.config.ts +0 -14
  58. package/packages/selector/src/runtime/summary-command.ts +0 -133
  59. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  60. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  61. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  62. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  63. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  64. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  65. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
@@ -1,252 +1,252 @@
1
- // @vitest-environment jsdom
2
-
3
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
- import { useSyncExternalStore } from 'react'
5
- import { afterEach, describe, expect, it, vi } from 'vitest'
6
- import {
7
- ContextCompressionSettingsSection,
8
- type ContextCompressionSettings,
9
- } from '../src/client/CompressionProfileSelector.tsx'
10
- import { en } from '../src/client/locales.ts'
11
-
12
- afterEach(() => {
13
- cleanup()
14
- vi.unstubAllGlobals()
15
- })
16
-
17
- interface SettingsScopeSnapshot<T> {
18
- status: 'loading' | 'ready' | 'unavailable'
19
- value: T | undefined
20
- base: T | undefined
21
- user: T | undefined
22
- revision: number | undefined
23
- writable: boolean
24
- mode: 'host' | 'memory'
25
- }
26
-
27
- interface SnapshotStore<T> {
28
- readonly getSnapshot: () => T
29
- readonly subscribe: (listener: () => void) => () => void
30
- }
31
-
32
- function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
33
- const snapshot = structuredClone(initial)
34
- const listeners = new Set<() => void>()
35
- return {
36
- getSnapshot: () => snapshot,
37
- subscribe(listener) {
38
- listeners.add(listener)
39
- return () => { listeners.delete(listener) }
40
- },
41
- }
42
- }
43
-
44
- function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
45
- return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
46
- return useSyncExternalStore(
47
- store.subscribe,
48
- () => selector(store.getSnapshot()),
49
- () => selector(store.getSnapshot()),
50
- )
51
- }
52
- }
53
-
54
- const DEFAULT_CUSTOM = {
55
- version: 1,
56
- unit: 'tokens',
57
- fresh: { enabled: true, trigger: 4_096, target: 2_048 },
58
- aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
59
- history: {
60
- enabled: true,
61
- trigger: 32_768,
62
- keepRecentTurns: 2,
63
- keepRecent: 16_384,
64
- minReclaim: 8_192,
65
- },
66
- prefixPolicy: 'pressure-break',
67
- } as const satisfies ContextCompressionSettings['custom']
68
-
69
- const t = (key: string) => en[key as keyof typeof en] ?? key
70
-
71
- const PROVIDER_LABEL = 'Provider'
72
- const CHANNEL_LABEL = 'Channel'
73
- const MODEL_LABEL = 'Model'
74
- const API_KEY_LABEL = 'API key (write-only, never echoed)'
75
- const BASE_URL_LABEL = 'Endpoint base URL (/v1)'
76
-
77
- const CATALOG = {
78
- ok: true,
79
- providers: [
80
- {
81
- id: 'local-35b',
82
- name: 'local-35b',
83
- models: [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen3.6-35B-A3B' }, { id: 'Qwen38-27B', name: 'Qwen38-27B' }],
84
- },
85
- { id: 'deepseek-official', name: 'DeepSeek', models: [{ id: 'deepseek-flash', name: 'DeepSeek-V41-Flash' }] },
86
- ],
87
- selection: { provider: 'deepseek-official', model: 'deepseek-flash' },
88
- }
89
-
90
- function mountEstimator(
91
- presetOptions: ContextCompressionSettings['presetOptions'],
92
- options: { readonly catalog?: unknown, readonly profile?: ContextCompressionSettings['profile'] } = {},
93
- ) {
94
- const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
95
- status: 'ready',
96
- value: {
97
- profile: options.profile ?? 'tokenpilot-inspired',
98
- custom: structuredClone(DEFAULT_CUSTOM),
99
- autoCompact: { thresholdPercent: 80 },
100
- codeSkeleton: { enabled: false },
101
- intentSummary: { enabled: false },
102
- presetOptions: presetOptions ?? {},
103
- },
104
- base: undefined,
105
- user: undefined,
106
- revision: 0,
107
- writable: true,
108
- mode: 'host',
109
- })
110
- const savePresetOptions = vi.fn(() => Promise.resolve())
111
- if (options.catalog !== undefined) {
112
- vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({
113
- ok: true,
114
- json: () => Promise.resolve(options.catalog),
115
- })))
116
- }
117
- render(<ContextCompressionSettingsSection {...({
118
- useCompression: bindSnapshotSelector(state),
119
- select: vi.fn(() => Promise.resolve()),
120
- saveCustom: vi.fn(() => Promise.resolve()),
121
- resetCustom: vi.fn(() => Promise.resolve()),
122
- saveAutoCompact: vi.fn(() => Promise.resolve()),
123
- saveCodeSkeleton: vi.fn(() => Promise.resolve()),
124
- savePresetOptions,
125
- t,
126
- })} />)
127
- return { savePresetOptions }
128
- }
129
-
130
- describe('estimator channel card', () => {
131
- it('host mode fills comboboxes from the catalog, keeps custom typing, and asks for no API key', async () => {
132
- const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' }, { catalog: CATALOG })
133
-
134
- // Provider/model are always comboboxes (dsh-perm-gate receiver pattern):
135
- // a catalog pick fills the field, and the same input accepts a custom id.
136
- const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
137
- const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
138
- await waitFor(() => {
139
- const providerOptions = document.querySelectorAll('#estimator-provider-options option')
140
- expect([...providerOptions].map(option => (option as HTMLOptionElement).value))
141
- .toEqual(['local-35b', 'deepseek-official'])
142
- expect(provider.getAttribute('list')).toBe('estimator-provider-options')
143
- expect(model.getAttribute('list')).toBe('estimator-model-options')
144
- })
145
- expect(screen.getByText(/Effective route: deepseek-official \/ deepseek-flash/)).not.toBeNull()
146
- expect(screen.getByText(/no API key is needed/)).not.toBeNull()
147
-
148
- // No credential input and no base-URL field on this channel.
149
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
150
- expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
151
- expect(document.querySelectorAll('input[type="password"]').length).toBe(0)
152
-
153
- // A datalist pick fires change without blur: it commits immediately.
154
- fireEvent.change(provider, { target: { value: 'local-35b' } })
155
- await waitFor(() => {
156
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'local-35b' })
157
- })
158
- // Free typing only commits on blur, so mid-edit keystrokes never save.
159
- fireEvent.change(provider, { target: { value: 'my-custom-group' } })
160
- expect(savePresetOptions).not.toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
161
- fireEvent.blur(provider)
162
- await waitFor(() => {
163
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
164
- })
165
- })
166
-
167
- it('offers the catalog models of the chosen provider and commits one', async () => {
168
- const { savePresetOptions } = mountEstimator(
169
- { estimatorMode: 'host', estimatorProvider: 'local-35b' },
170
- { catalog: CATALOG },
171
- )
172
- // Query before the catalog lands: once the datalist has options, the
173
- // label's textContent includes them and getByLabelText's exact match
174
- // would no longer see a bare "Model".
175
- const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
176
- expect(model.value).toBe('')
177
- await waitFor(() => {
178
- const modelOptions = document.querySelectorAll('#estimator-model-options option')
179
- expect([...modelOptions].map(option => (option as HTMLOptionElement).value))
180
- .toEqual(['Qwen3.6-35B-A3B', 'Qwen38-27B'])
181
- })
182
- expect(screen.getByText(/Effective route: local-35b/)).not.toBeNull()
183
-
184
- fireEvent.change(model, { target: { value: 'Qwen38-27B' } })
185
- await waitFor(() => {
186
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorModel: 'Qwen38-27B' })
187
- })
188
- })
189
-
190
- it('still accepts custom names — without a credential field — when no catalog is served', async () => {
191
- vi.stubGlobal('fetch', vi.fn(() => Promise.reject(new Error('no route'))))
192
- const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' })
193
-
194
- const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
195
- // The model field stays present and editable without a served catalog.
196
- expect(screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)).toBeTruthy()
197
- expect(document.querySelectorAll('#estimator-provider-options option').length).toBe(0)
198
- expect(document.querySelectorAll('#estimator-model-options option').length).toBe(0)
199
- fireEvent.change(provider, { target: { value: 'manual-group' } })
200
- fireEvent.blur(provider)
201
- await waitFor(() => {
202
- expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'manual-group' })
203
- })
204
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
205
- expect(screen.getByText(/no API key is needed/)).not.toBeNull()
206
- expect(screen.getByText(/not determined yet/)).not.toBeNull()
207
- })
208
-
209
- it('keeps the endpoint and key fields on the direct channel alone', () => {
210
- mountEstimator({ estimatorMode: 'direct' })
211
-
212
- expect(screen.getByLabelText(BASE_URL_LABEL)).not.toBeNull()
213
- expect(screen.getByLabelText(MODEL_LABEL).tagName).toBe('INPUT')
214
- expect(screen.getByLabelText(API_KEY_LABEL)).not.toBeNull()
215
- expect(document.querySelectorAll('input[type="password"]').length).toBe(1)
216
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
217
- expect(screen.queryByText(/no API key is needed/)).toBeNull()
218
- })
219
-
220
- it('renders no channel controls while the estimator is off', () => {
221
- mountEstimator({})
222
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
223
- expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
224
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
225
- })
226
-
227
- // Regression guard for the first real-machine report: the card used to render
228
- // nothing at all off tokenpilot-inspired, which reads as a missing feature.
229
- it('keeps the estimator section, and names the unlocking profile, off tokenpilot-inspired', () => {
230
- mountEstimator({}, { profile: 'balanced' })
231
-
232
- // The heading and its stable anchor survive, so the panel is still findable
233
- // where the reader last saw it.
234
- expect(document.getElementById('context-compression-estimator-title')?.textContent)
235
- .toBe('Estimator (optional)')
236
- // The notice names the current profile and the profile that unlocks the card.
237
- const notice = screen.getByText(/ships only with the TokenPilot-inspired profile/)
238
- expect(notice.textContent).toContain('“Balanced”')
239
- expect(notice.textContent).toContain('Select TokenPilot-inspired')
240
- // Gating semantics are unchanged: no channel control exists here.
241
- expect(screen.queryByLabelText(CHANNEL_LABEL)).toBeNull()
242
- expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
243
- expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
244
- expect(document.querySelectorAll('input[list]').length).toBe(0)
245
- })
246
-
247
- it('drops the inactive notice once tokenpilot-inspired owns the selector', () => {
248
- mountEstimator({})
249
- expect(screen.queryByText(/ships only with the TokenPilot-inspired profile/)).toBeNull()
250
- expect(screen.getByLabelText(CHANNEL_LABEL)).not.toBeNull()
251
- })
252
- })
1
+ // @vitest-environment jsdom
2
+
3
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+ import { useSyncExternalStore } from 'react'
5
+ import { afterEach, describe, expect, it, vi } from 'vitest'
6
+ import {
7
+ ContextCompressionSettingsSection,
8
+ type CompressionProfileSelectorProps,
9
+ type ContextCompressionSettings,
10
+ } from '../src/client/CompressionProfileSelector.tsx'
11
+ import { en } from '../src/client/locales.ts'
12
+
13
+ afterEach(() => {
14
+ cleanup()
15
+ vi.unstubAllGlobals()
16
+ })
17
+
18
+ interface SettingsScopeSnapshot<T> {
19
+ status: 'loading' | 'ready' | 'unavailable'
20
+ value: T | undefined
21
+ base: T | undefined
22
+ user: T | undefined
23
+ revision: number | undefined
24
+ writable: boolean
25
+ mode: 'host' | 'memory'
26
+ }
27
+
28
+ interface SnapshotStore<T> {
29
+ readonly getSnapshot: () => T
30
+ readonly subscribe: (listener: () => void) => () => void
31
+ }
32
+
33
+ function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
34
+ const snapshot = structuredClone(initial)
35
+ const listeners = new Set<() => void>()
36
+ return {
37
+ getSnapshot: () => snapshot,
38
+ subscribe(listener) {
39
+ listeners.add(listener)
40
+ return () => { listeners.delete(listener) }
41
+ },
42
+ }
43
+ }
44
+
45
+ function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
46
+ return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
47
+ return useSyncExternalStore(
48
+ store.subscribe,
49
+ () => selector(store.getSnapshot()),
50
+ () => selector(store.getSnapshot()),
51
+ )
52
+ }
53
+ }
54
+
55
+ const DEFAULT_CUSTOM = {
56
+ version: 1,
57
+ unit: 'tokens',
58
+ fresh: { enabled: true, trigger: 4_096, target: 2_048 },
59
+ aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
60
+ history: {
61
+ enabled: true,
62
+ trigger: 32_768,
63
+ keepRecentTurns: 2,
64
+ keepRecent: 16_384,
65
+ minReclaim: 8_192,
66
+ },
67
+ prefixPolicy: 'pressure-break',
68
+ } as const satisfies ContextCompressionSettings['custom']
69
+
70
+ const t = (key: string) => en[key as keyof typeof en] ?? key
71
+
72
+ const PROVIDER_LABEL = 'Provider'
73
+ const CHANNEL_LABEL = 'Channel'
74
+ const MODEL_LABEL = 'Model'
75
+ const API_KEY_LABEL = 'API key (write-only, never echoed)'
76
+ const BASE_URL_LABEL = 'Endpoint base URL (/v1)'
77
+
78
+ const CATALOG = {
79
+ ok: true,
80
+ providers: [
81
+ {
82
+ id: 'local-35b',
83
+ name: 'local-35b',
84
+ models: [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen3.6-35B-A3B' }, { id: 'Qwen38-27B', name: 'Qwen38-27B' }],
85
+ },
86
+ { id: 'deepseek-official', name: 'DeepSeek', models: [{ id: 'deepseek-flash', name: 'DeepSeek-V41-Flash' }] },
87
+ ],
88
+ selection: { provider: 'deepseek-official', model: 'deepseek-flash' },
89
+ }
90
+
91
+ function mountEstimator(
92
+ presetOptions: ContextCompressionSettings['presetOptions'],
93
+ options: { readonly catalog?: unknown, readonly profile?: ContextCompressionSettings['profile'] } = {},
94
+ ) {
95
+ const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
96
+ status: 'ready',
97
+ value: {
98
+ profile: options.profile ?? 'tokenpilot-inspired',
99
+ custom: structuredClone(DEFAULT_CUSTOM),
100
+ autoCompact: { thresholdPercent: 80 },
101
+ codeSkeleton: { enabled: false },
102
+ presetOptions: presetOptions ?? {},
103
+ },
104
+ base: undefined,
105
+ user: undefined,
106
+ revision: 0,
107
+ writable: true,
108
+ mode: 'host',
109
+ })
110
+ const savePresetOptions = vi.fn(() => Promise.resolve())
111
+ if (options.catalog !== undefined) {
112
+ vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({
113
+ ok: true,
114
+ json: () => Promise.resolve(options.catalog),
115
+ })))
116
+ }
117
+ render(<ContextCompressionSettingsSection {...({
118
+ useCompression: bindSnapshotSelector(state),
119
+ select: vi.fn(() => Promise.resolve()),
120
+ saveCustom: vi.fn(() => Promise.resolve()),
121
+ resetCustom: vi.fn(() => Promise.resolve()),
122
+ saveAutoCompact: vi.fn(() => Promise.resolve()),
123
+ saveCodeSkeleton: vi.fn(() => Promise.resolve()),
124
+ savePresetOptions,
125
+ t,
126
+ } as unknown as CompressionProfileSelectorProps)} />)
127
+ return { savePresetOptions }
128
+ }
129
+
130
+ describe('estimator channel card', () => {
131
+ it('host mode fills comboboxes from the catalog, keeps custom typing, and asks for no API key', async () => {
132
+ const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' }, { catalog: CATALOG })
133
+
134
+ // Provider/model are always comboboxes (dsh-perm-gate receiver pattern):
135
+ // a catalog pick fills the field, and the same input accepts a custom id.
136
+ const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
137
+ const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
138
+ await waitFor(() => {
139
+ const providerOptions = document.querySelectorAll('#estimator-provider-options option')
140
+ expect([...providerOptions].map(option => (option as HTMLOptionElement).value))
141
+ .toEqual(['local-35b', 'deepseek-official'])
142
+ expect(provider.getAttribute('list')).toBe('estimator-provider-options')
143
+ expect(model.getAttribute('list')).toBe('estimator-model-options')
144
+ })
145
+ expect(screen.getByText(/Effective route: deepseek-official \/ deepseek-flash/)).not.toBeNull()
146
+ expect(screen.getByText(/no API key is needed/)).not.toBeNull()
147
+
148
+ // No credential input and no base-URL field on this channel.
149
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
150
+ expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
151
+ expect(document.querySelectorAll('input[type="password"]').length).toBe(0)
152
+
153
+ // A datalist pick fires change without blur: it commits immediately.
154
+ fireEvent.change(provider, { target: { value: 'local-35b' } })
155
+ await waitFor(() => {
156
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'local-35b' })
157
+ })
158
+ // Free typing only commits on blur, so mid-edit keystrokes never save.
159
+ fireEvent.change(provider, { target: { value: 'my-custom-group' } })
160
+ expect(savePresetOptions).not.toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
161
+ fireEvent.blur(provider)
162
+ await waitFor(() => {
163
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
164
+ })
165
+ })
166
+
167
+ it('offers the catalog models of the chosen provider and commits one', async () => {
168
+ const { savePresetOptions } = mountEstimator(
169
+ { estimatorMode: 'host', estimatorProvider: 'local-35b' },
170
+ { catalog: CATALOG },
171
+ )
172
+ // Query before the catalog lands: once the datalist has options, the
173
+ // label's textContent includes them and getByLabelText's exact match
174
+ // would no longer see a bare "Model".
175
+ const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
176
+ expect(model.value).toBe('')
177
+ await waitFor(() => {
178
+ const modelOptions = document.querySelectorAll('#estimator-model-options option')
179
+ expect([...modelOptions].map(option => (option as HTMLOptionElement).value))
180
+ .toEqual(['Qwen3.6-35B-A3B', 'Qwen38-27B'])
181
+ })
182
+ expect(screen.getByText(/Effective route: local-35b/)).not.toBeNull()
183
+
184
+ fireEvent.change(model, { target: { value: 'Qwen38-27B' } })
185
+ await waitFor(() => {
186
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorModel: 'Qwen38-27B' })
187
+ })
188
+ })
189
+
190
+ it('still accepts custom names — without a credential field — when no catalog is served', async () => {
191
+ vi.stubGlobal('fetch', vi.fn(() => Promise.reject(new Error('no route'))))
192
+ const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' })
193
+
194
+ const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
195
+ // The model field stays present and editable without a served catalog.
196
+ expect(screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)).toBeTruthy()
197
+ expect(document.querySelectorAll('#estimator-provider-options option').length).toBe(0)
198
+ expect(document.querySelectorAll('#estimator-model-options option').length).toBe(0)
199
+ fireEvent.change(provider, { target: { value: 'manual-group' } })
200
+ fireEvent.blur(provider)
201
+ await waitFor(() => {
202
+ expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'manual-group' })
203
+ })
204
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
205
+ expect(screen.getByText(/no API key is needed/)).not.toBeNull()
206
+ expect(screen.getByText(/not determined yet/)).not.toBeNull()
207
+ })
208
+
209
+ it('keeps the endpoint and key fields on the direct channel alone', () => {
210
+ mountEstimator({ estimatorMode: 'direct' })
211
+
212
+ expect(screen.getByLabelText(BASE_URL_LABEL)).not.toBeNull()
213
+ expect(screen.getByLabelText(MODEL_LABEL).tagName).toBe('INPUT')
214
+ expect(screen.getByLabelText(API_KEY_LABEL)).not.toBeNull()
215
+ expect(document.querySelectorAll('input[type="password"]').length).toBe(1)
216
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
217
+ expect(screen.queryByText(/no API key is needed/)).toBeNull()
218
+ })
219
+
220
+ it('renders no channel controls while the estimator is off', () => {
221
+ mountEstimator({})
222
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
223
+ expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
224
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
225
+ })
226
+
227
+ // Regression guard for the first real-machine report: the card used to render
228
+ // nothing at all off tokenpilot-inspired, which reads as a missing feature.
229
+ it('keeps the estimator section, and names the unlocking profile, off tokenpilot-inspired', () => {
230
+ mountEstimator({}, { profile: 'balanced' })
231
+
232
+ // The heading and its stable anchor survive, so the panel is still findable
233
+ // where the reader last saw it.
234
+ expect(document.getElementById('context-compression-estimator-title')?.textContent)
235
+ .toBe('Estimator (optional)')
236
+ // The notice names the current profile and the profile that unlocks the card.
237
+ const notice = screen.getByText(/ships only with the TokenPilot-inspired profile/)
238
+ expect(notice.textContent).toContain('“Balanced”')
239
+ expect(notice.textContent).toContain('Select TokenPilot-inspired')
240
+ // Gating semantics are unchanged: no channel control exists here.
241
+ expect(screen.queryByLabelText(CHANNEL_LABEL)).toBeNull()
242
+ expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
243
+ expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
244
+ expect(document.querySelectorAll('input[list]').length).toBe(0)
245
+ })
246
+
247
+ it('drops the inactive notice once tokenpilot-inspired owns the selector', () => {
248
+ mountEstimator({})
249
+ expect(screen.queryByText(/ships only with the TokenPilot-inspired profile/)).toBeNull()
250
+ expect(screen.getByLabelText(CHANNEL_LABEL)).not.toBeNull()
251
+ })
252
+ })