dsh-context-compression-improved 0.6.5 → 0.7.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.
- package/CHANGELOG.ja.md +9 -0
- package/CHANGELOG.ko.md +9 -0
- package/CHANGELOG.md +26 -0
- package/CHANGELOG.zh.md +9 -0
- package/README.md +1 -0
- package/README.zh.md +1 -0
- package/eslint.config.js +76 -30
- package/package.json +18 -17
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +14 -3
- package/packages/selector/lib/index.js +92 -1
- package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +59 -0
- package/packages/selector/lib/pruner.js +410 -8
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/src/client/decode.ts +6 -2
- package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
- package/packages/selector/src/index.ts +418 -411
- package/packages/selector/src/preset-overlay.ts +3 -0
- package/packages/selector/src/profiles.ts +30 -10
- package/packages/selector/src/pruner/content.ts +1 -1
- package/packages/selector/src/pruner/state.ts +7 -0
- package/packages/selector/src/pruner.ts +253 -9
- package/packages/selector/src/runtime/audit.ts +17 -0
- package/packages/selector/src/runtime/config.ts +36 -11
- package/packages/selector/src/runtime/reducers.ts +1 -1
- package/packages/selector/src/runtime/summary-command.ts +133 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +46 -1
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +55 -0
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +2 -2
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +4 -1
- package/packages/selector/src/runtime/types.ts +12 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +2 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +3 -3
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +4 -4
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
- package/scripts/packed-components-smoke.mjs +2 -0
- package/scripts/packed-install-e2e.mjs +1275 -1273
- package/scripts/verify-release.mjs +318 -317
- package/tsconfig.tests.json +3 -1
- package/vitest.config.ts +14 -0
- package/.agents-stash-064.patch +0 -39
- package/_dsh_devdeps.json +0 -50
- package/_verify064/package/package.json +0 -162
- package/_verify064/package/packages/selector/src/client/index.ts +0 -232
|
@@ -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
|
|
9
|
-
|
|
10
|
-
} from '../src/client/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
listeners.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
store.
|
|
49
|
-
() => selector(store.getSnapshot()),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
name: '
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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 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,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Legacy test-host settings seam.
|
|
3
|
-
*
|
|
4
|
-
* Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
|
|
5
|
-
* (`lib/types/index.js` + `lib/types/redact.js`, with the
|
|
6
|
-
* `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
|
|
7
|
-
* `./legacy/util-values.js`): the 0.1.7 host replaced the
|
|
8
|
-
* namespace-registry provider with declarative `SettingsForms`, while the
|
|
9
|
-
* plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
|
|
10
|
-
* fallback (see src/index.ts). The host specs mount a provider subclassing
|
|
11
|
-
* this base to exercise exactly that fallback against the real 0.1.7
|
|
12
|
-
* baseline. Type declarations: `./legacy/provider.d.ts`.
|
|
13
|
-
*/
|
|
14
|
-
export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
|
|
15
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Legacy test-host settings seam.
|
|
3
|
+
*
|
|
4
|
+
* Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
|
|
5
|
+
* (`lib/types/index.js` + `lib/types/redact.js`, with the
|
|
6
|
+
* `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
|
|
7
|
+
* `./legacy/util-values.js`): the 0.1.7 host replaced the
|
|
8
|
+
* namespace-registry provider with declarative `SettingsForms`, while the
|
|
9
|
+
* plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
|
|
10
|
+
* fallback (see src/index.ts). The host specs mount a provider subclassing
|
|
11
|
+
* this base to exercise exactly that fallback against the real 0.1.7
|
|
12
|
+
* baseline. Type declarations: `./legacy/provider.d.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
|
|
15
|
+
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
|
|
3
|
-
*
|
|
4
|
-
* The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
|
|
5
|
-
* provider with the declarative `SettingsForms` projector, but the plugin
|
|
6
|
-
* deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
|
|
7
|
-
* "so a host that still serves the old service shape keeps working (test
|
|
8
|
-
* hosts do exactly that)" (src/index.ts). The host specs drive that fallback
|
|
9
|
-
* through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
|
|
10
|
-
* not a behavioral re-implementation.
|
|
11
|
-
*
|
|
12
|
-
* Only the members the specs and the production fallback actually touch are
|
|
13
|
-
* declared; the full 0.1.5 surface exists at runtime in provider.js.
|
|
14
|
-
*/
|
|
15
|
-
import { Service } from '@deepseek-ai/cordis'
|
|
16
|
-
|
|
17
|
-
export declare abstract class SettingsProvider extends Service {
|
|
18
|
-
/** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
|
|
19
|
-
constructor(ctx: Context)
|
|
20
|
-
/** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
|
|
21
|
-
abstract readonly writable: boolean
|
|
22
|
-
/** Load the provider's raw document (namespace → raw section) once at init. */
|
|
23
|
-
protected abstract load(): Promise<Record<string, unknown>>
|
|
24
|
-
/** Durably store one namespace's merged user section. */
|
|
25
|
-
protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
|
|
26
|
-
/** Register a namespace schema; duplicate registration fails loud. */
|
|
27
|
-
register(ns: string, schema: unknown, options?: unknown): unknown
|
|
28
|
-
/** Read one registered namespace's resolved value (undefined while unregistered). */
|
|
29
|
-
get(ns: string): unknown
|
|
30
|
-
/** Merge a patch into one registered namespace's user layer, validate, persist. */
|
|
31
|
-
update(ns: string, patch: object, expectedRevision?: number): Promise<void>
|
|
32
|
-
/** Replace one registered namespace's user section wholesale, validate, persist. */
|
|
33
|
-
replace(ns: string, section: object, expectedRevision?: number): Promise<void>
|
|
34
|
-
/** Apply path-addressed edits to one registered namespace's user section. */
|
|
35
|
-
mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
|
|
36
|
-
/** Describe every registered namespace for configuration surfaces. */
|
|
37
|
-
describe(options?: { redactSecrets?: boolean }): unknown[]
|
|
38
|
-
/** Non-file providers expose no open-document affordance. */
|
|
39
|
-
get documentPath(): string | undefined
|
|
40
|
-
prepareDocument(): Promise<string | undefined>
|
|
41
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
|
|
3
|
+
*
|
|
4
|
+
* The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
|
|
5
|
+
* provider with the declarative `SettingsForms` projector, but the plugin
|
|
6
|
+
* deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
|
|
7
|
+
* "so a host that still serves the old service shape keeps working (test
|
|
8
|
+
* hosts do exactly that)" (src/index.ts). The host specs drive that fallback
|
|
9
|
+
* through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
|
|
10
|
+
* not a behavioral re-implementation.
|
|
11
|
+
*
|
|
12
|
+
* Only the members the specs and the production fallback actually touch are
|
|
13
|
+
* declared; the full 0.1.5 surface exists at runtime in provider.js.
|
|
14
|
+
*/
|
|
15
|
+
import { Service } from '@deepseek-ai/cordis'
|
|
16
|
+
|
|
17
|
+
export declare abstract class SettingsProvider extends Service {
|
|
18
|
+
/** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
|
|
19
|
+
constructor(ctx: Context)
|
|
20
|
+
/** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
|
|
21
|
+
abstract readonly writable: boolean
|
|
22
|
+
/** Load the provider's raw document (namespace → raw section) once at init. */
|
|
23
|
+
protected abstract load(): Promise<Record<string, unknown>>
|
|
24
|
+
/** Durably store one namespace's merged user section. */
|
|
25
|
+
protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
|
|
26
|
+
/** Register a namespace schema; duplicate registration fails loud. */
|
|
27
|
+
register(ns: string, schema: unknown, options?: unknown): unknown
|
|
28
|
+
/** Read one registered namespace's resolved value (undefined while unregistered). */
|
|
29
|
+
get(ns: string): unknown
|
|
30
|
+
/** Merge a patch into one registered namespace's user layer, validate, persist. */
|
|
31
|
+
update(ns: string, patch: object, expectedRevision?: number): Promise<void>
|
|
32
|
+
/** Replace one registered namespace's user section wholesale, validate, persist. */
|
|
33
|
+
replace(ns: string, section: object, expectedRevision?: number): Promise<void>
|
|
34
|
+
/** Apply path-addressed edits to one registered namespace's user section. */
|
|
35
|
+
mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
|
|
36
|
+
/** Describe every registered namespace for configuration surfaces. */
|
|
37
|
+
describe(options?: { redactSecrets?: boolean }): unknown[]
|
|
38
|
+
/** Non-file providers expose no open-document affordance. */
|
|
39
|
+
get documentPath(): string | undefined
|
|
40
|
+
prepareDocument(): Promise<string | undefined>
|
|
41
|
+
}
|