dsh-context-compression-improved 0.8.0-beta.3 → 0.8.0-beta.5
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.md +20 -0
- package/eslint.config.js +30 -30
- package/package.json +163 -163
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +28 -0
- package/packages/selector/lib/client.js +631 -7
- package/packages/selector/lib/{advisor-state.js → config.js} +170 -65
- package/packages/selector/lib/index.d.ts +13 -1
- package/packages/selector/lib/index.js +306 -50
- package/packages/selector/lib/profiles.d.ts +15 -0
- package/packages/selector/lib/pruner.d.ts +65 -0
- package/packages/selector/lib/pruner.js +408 -5
- package/packages/selector/src/client/CompressionProfileControls.tsx +67 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +2 -0
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +41 -0
- package/packages/selector/src/client/locales/de.ts +26 -0
- package/packages/selector/src/client/locales/es.ts +26 -0
- package/packages/selector/src/client/locales/fr.ts +26 -0
- package/packages/selector/src/client/locales/it.ts +26 -0
- package/packages/selector/src/client/locales/ja.ts +26 -0
- package/packages/selector/src/client/locales/ko.ts +26 -0
- package/packages/selector/src/client/locales/ru.ts +26 -0
- package/packages/selector/src/client/locales.ts +52 -0
- package/packages/selector/src/client/monitor-fab.ts +307 -0
- package/packages/selector/src/client/settings-section.tsx +16 -2
- package/packages/selector/src/index.ts +133 -60
- package/packages/selector/src/profiles.ts +431 -394
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +241 -1
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +756 -706
- package/packages/selector/src/runtime/monitor.ts +149 -0
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- 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/types.ts +365 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- 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 +253 -252
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +8 -6
- package/packages/selector/tests/monitor-fab.client.spec.ts +117 -0
- 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/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +236 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2734 -2731
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +1 -1
- package/scripts/packed-install-e2e.mjs +1 -1
- package/scripts/verify-release.mjs +2 -1
|
@@ -1,252 +1,253 @@
|
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
expect(screen.getByText(/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
expect(screen.queryByLabelText(
|
|
151
|
-
expect(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
expect(
|
|
198
|
-
expect(document.querySelectorAll('#estimator-
|
|
199
|
-
|
|
200
|
-
fireEvent.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
expect(screen.
|
|
206
|
-
expect(screen.getByText(/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
expect(screen.getByLabelText(
|
|
214
|
-
expect(screen.getByLabelText(
|
|
215
|
-
expect(
|
|
216
|
-
expect(
|
|
217
|
-
expect(screen.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
expect(screen.queryByLabelText(
|
|
224
|
-
expect(screen.queryByLabelText(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
//
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
expect(notice.textContent).toContain('
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
expect(screen.queryByLabelText(
|
|
243
|
-
expect(screen.queryByLabelText(
|
|
244
|
-
expect(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
expect(screen.
|
|
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
|
+
intentSummary: { enabled: false },
|
|
103
|
+
presetOptions: presetOptions ?? {},
|
|
104
|
+
},
|
|
105
|
+
base: undefined,
|
|
106
|
+
user: undefined,
|
|
107
|
+
revision: 0,
|
|
108
|
+
writable: true,
|
|
109
|
+
mode: 'host',
|
|
110
|
+
})
|
|
111
|
+
const savePresetOptions = vi.fn(() => Promise.resolve())
|
|
112
|
+
if (options.catalog !== undefined) {
|
|
113
|
+
vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({
|
|
114
|
+
ok: true,
|
|
115
|
+
json: () => Promise.resolve(options.catalog),
|
|
116
|
+
})))
|
|
117
|
+
}
|
|
118
|
+
render(<ContextCompressionSettingsSection {...({
|
|
119
|
+
useCompression: bindSnapshotSelector(state),
|
|
120
|
+
select: vi.fn(() => Promise.resolve()),
|
|
121
|
+
saveCustom: vi.fn(() => Promise.resolve()),
|
|
122
|
+
resetCustom: vi.fn(() => Promise.resolve()),
|
|
123
|
+
saveAutoCompact: vi.fn(() => Promise.resolve()),
|
|
124
|
+
saveCodeSkeleton: vi.fn(() => Promise.resolve()),
|
|
125
|
+
savePresetOptions,
|
|
126
|
+
t,
|
|
127
|
+
} as unknown as CompressionProfileSelectorProps)} />)
|
|
128
|
+
return { savePresetOptions }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
describe('estimator channel card', () => {
|
|
132
|
+
it('host mode fills comboboxes from the catalog, keeps custom typing, and asks for no API key', async () => {
|
|
133
|
+
const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' }, { catalog: CATALOG })
|
|
134
|
+
|
|
135
|
+
// Provider/model are always comboboxes (dsh-perm-gate receiver pattern):
|
|
136
|
+
// a catalog pick fills the field, and the same input accepts a custom id.
|
|
137
|
+
const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
|
|
138
|
+
const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
|
|
139
|
+
await waitFor(() => {
|
|
140
|
+
const providerOptions = document.querySelectorAll('#estimator-provider-options option')
|
|
141
|
+
expect([...providerOptions].map(option => (option as HTMLOptionElement).value))
|
|
142
|
+
.toEqual(['local-35b', 'deepseek-official'])
|
|
143
|
+
expect(provider.getAttribute('list')).toBe('estimator-provider-options')
|
|
144
|
+
expect(model.getAttribute('list')).toBe('estimator-model-options')
|
|
145
|
+
})
|
|
146
|
+
expect(screen.getByText(/Effective route: deepseek-official \/ deepseek-flash/)).not.toBeNull()
|
|
147
|
+
expect(screen.getByText(/no API key is needed/)).not.toBeNull()
|
|
148
|
+
|
|
149
|
+
// No credential input and no base-URL field on this channel.
|
|
150
|
+
expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
|
|
151
|
+
expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
|
|
152
|
+
expect(document.querySelectorAll('input[type="password"]').length).toBe(0)
|
|
153
|
+
|
|
154
|
+
// A datalist pick fires change without blur: it commits immediately.
|
|
155
|
+
fireEvent.change(provider, { target: { value: 'local-35b' } })
|
|
156
|
+
await waitFor(() => {
|
|
157
|
+
expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'local-35b' })
|
|
158
|
+
})
|
|
159
|
+
// Free typing only commits on blur, so mid-edit keystrokes never save.
|
|
160
|
+
fireEvent.change(provider, { target: { value: 'my-custom-group' } })
|
|
161
|
+
expect(savePresetOptions).not.toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
|
|
162
|
+
fireEvent.blur(provider)
|
|
163
|
+
await waitFor(() => {
|
|
164
|
+
expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'my-custom-group' })
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('offers the catalog models of the chosen provider and commits one', async () => {
|
|
169
|
+
const { savePresetOptions } = mountEstimator(
|
|
170
|
+
{ estimatorMode: 'host', estimatorProvider: 'local-35b' },
|
|
171
|
+
{ catalog: CATALOG },
|
|
172
|
+
)
|
|
173
|
+
// Query before the catalog lands: once the datalist has options, the
|
|
174
|
+
// label's textContent includes them and getByLabelText's exact match
|
|
175
|
+
// would no longer see a bare "Model".
|
|
176
|
+
const model = screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)
|
|
177
|
+
expect(model.value).toBe('')
|
|
178
|
+
await waitFor(() => {
|
|
179
|
+
const modelOptions = document.querySelectorAll('#estimator-model-options option')
|
|
180
|
+
expect([...modelOptions].map(option => (option as HTMLOptionElement).value))
|
|
181
|
+
.toEqual(['Qwen3.6-35B-A3B', 'Qwen38-27B'])
|
|
182
|
+
})
|
|
183
|
+
expect(screen.getByText(/Effective route: local-35b/)).not.toBeNull()
|
|
184
|
+
|
|
185
|
+
fireEvent.change(model, { target: { value: 'Qwen38-27B' } })
|
|
186
|
+
await waitFor(() => {
|
|
187
|
+
expect(savePresetOptions).toHaveBeenCalledWith({ estimatorModel: 'Qwen38-27B' })
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('still accepts custom names — without a credential field — when no catalog is served', async () => {
|
|
192
|
+
vi.stubGlobal('fetch', vi.fn(() => Promise.reject(new Error('no route'))))
|
|
193
|
+
const { savePresetOptions } = mountEstimator({ estimatorMode: 'host' })
|
|
194
|
+
|
|
195
|
+
const provider = screen.getByLabelText<HTMLInputElement>(PROVIDER_LABEL)
|
|
196
|
+
// The model field stays present and editable without a served catalog.
|
|
197
|
+
expect(screen.getByLabelText<HTMLInputElement>(MODEL_LABEL)).toBeTruthy()
|
|
198
|
+
expect(document.querySelectorAll('#estimator-provider-options option').length).toBe(0)
|
|
199
|
+
expect(document.querySelectorAll('#estimator-model-options option').length).toBe(0)
|
|
200
|
+
fireEvent.change(provider, { target: { value: 'manual-group' } })
|
|
201
|
+
fireEvent.blur(provider)
|
|
202
|
+
await waitFor(() => {
|
|
203
|
+
expect(savePresetOptions).toHaveBeenCalledWith({ estimatorProvider: 'manual-group' })
|
|
204
|
+
})
|
|
205
|
+
expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
|
|
206
|
+
expect(screen.getByText(/no API key is needed/)).not.toBeNull()
|
|
207
|
+
expect(screen.getByText(/not determined yet/)).not.toBeNull()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('keeps the endpoint and key fields on the direct channel alone', () => {
|
|
211
|
+
mountEstimator({ estimatorMode: 'direct' })
|
|
212
|
+
|
|
213
|
+
expect(screen.getByLabelText(BASE_URL_LABEL)).not.toBeNull()
|
|
214
|
+
expect(screen.getByLabelText(MODEL_LABEL).tagName).toBe('INPUT')
|
|
215
|
+
expect(screen.getByLabelText(API_KEY_LABEL)).not.toBeNull()
|
|
216
|
+
expect(document.querySelectorAll('input[type="password"]').length).toBe(1)
|
|
217
|
+
expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
|
|
218
|
+
expect(screen.queryByText(/no API key is needed/)).toBeNull()
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('renders no channel controls while the estimator is off', () => {
|
|
222
|
+
mountEstimator({})
|
|
223
|
+
expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
|
|
224
|
+
expect(screen.queryByLabelText(BASE_URL_LABEL)).toBeNull()
|
|
225
|
+
expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
// Regression guard for the first real-machine report: the card used to render
|
|
229
|
+
// nothing at all off tokenpilot-inspired, which reads as a missing feature.
|
|
230
|
+
it('keeps the estimator section, and names the unlocking profile, off tokenpilot-inspired', () => {
|
|
231
|
+
mountEstimator({}, { profile: 'balanced' })
|
|
232
|
+
|
|
233
|
+
// The heading and its stable anchor survive, so the panel is still findable
|
|
234
|
+
// where the reader last saw it.
|
|
235
|
+
expect(document.getElementById('context-compression-estimator-title')?.textContent)
|
|
236
|
+
.toBe('Estimator (optional)')
|
|
237
|
+
// The notice names the current profile and the profile that unlocks the card.
|
|
238
|
+
const notice = screen.getByText(/ships only with the TokenPilot-inspired profile/)
|
|
239
|
+
expect(notice.textContent).toContain('“Balanced”')
|
|
240
|
+
expect(notice.textContent).toContain('Select TokenPilot-inspired')
|
|
241
|
+
// Gating semantics are unchanged: no channel control exists here.
|
|
242
|
+
expect(screen.queryByLabelText(CHANNEL_LABEL)).toBeNull()
|
|
243
|
+
expect(screen.queryByLabelText(PROVIDER_LABEL)).toBeNull()
|
|
244
|
+
expect(screen.queryByLabelText(API_KEY_LABEL)).toBeNull()
|
|
245
|
+
expect(document.querySelectorAll('input[list]').length).toBe(0)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('drops the inactive notice once tokenpilot-inspired owns the selector', () => {
|
|
249
|
+
mountEstimator({})
|
|
250
|
+
expect(screen.queryByText(/ships only with the TokenPilot-inspired profile/)).toBeNull()
|
|
251
|
+
expect(screen.getByLabelText(CHANNEL_LABEL)).not.toBeNull()
|
|
252
|
+
})
|
|
253
|
+
})
|
|
@@ -17,6 +17,8 @@ const CATALOG_ROUTE = '/api/dsh-context-compression-improved/estimator-catalog'
|
|
|
17
17
|
const LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/estimator-catalog'
|
|
18
18
|
const SAVINGS_ROUTE = '/api/dsh-context-compression-improved/savings'
|
|
19
19
|
const SAVINGS_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/savings'
|
|
20
|
+
const MONITOR_ROUTE = '/api/dsh-context-compression-improved/monitor'
|
|
21
|
+
const MONITOR_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/monitor'
|
|
20
22
|
|
|
21
23
|
interface RegisteredRoute {
|
|
22
24
|
kind: string
|
|
@@ -106,7 +108,7 @@ describe('estimator catalog route registration', () => {
|
|
|
106
108
|
apply(runtime, { estimatorCatalogRoute: true })
|
|
107
109
|
await settle()
|
|
108
110
|
|
|
109
|
-
expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE])
|
|
111
|
+
expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
|
|
110
112
|
expect(routes.every(route => route.kind === 'exact')).toBe(true)
|
|
111
113
|
})
|
|
112
114
|
|
|
@@ -122,7 +124,7 @@ describe('estimator catalog route registration', () => {
|
|
|
122
124
|
await mountWebServer(runtime, routes)
|
|
123
125
|
await settle()
|
|
124
126
|
|
|
125
|
-
expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE])
|
|
127
|
+
expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
|
|
126
128
|
})
|
|
127
129
|
|
|
128
130
|
it('registers nothing twice when the estimator services arrive later', async () => {
|
|
@@ -176,9 +178,9 @@ describe('estimator catalog route registration', () => {
|
|
|
176
178
|
expect(JSON.parse(String(response.body))).toMatchObject({ ok: true, providers: [] })
|
|
177
179
|
})
|
|
178
180
|
|
|
179
|
-
it('without the estimator opt-in only the always-on savings
|
|
180
|
-
// savings 路由是有意常开的只读面(纯 token
|
|
181
|
-
// catalog 才是 opt-in 行。默认面 = 恰好两条 savings 前缀。
|
|
181
|
+
it('without the estimator opt-in only the always-on read routes register (savings + monitor)', async () => {
|
|
182
|
+
// savings 与 monitor 路由是有意常开的只读面(纯 token 聚合与折叠状态,无会话内容);estimator
|
|
183
|
+
// catalog 才是 opt-in 行。默认面 = 恰好两条 savings 前缀 + 两条 monitor 前缀。
|
|
182
184
|
const routes: RegisteredRoute[] = []
|
|
183
185
|
const runtime = new Context()
|
|
184
186
|
ctx = runtime
|
|
@@ -187,6 +189,6 @@ describe('estimator catalog route registration', () => {
|
|
|
187
189
|
apply(runtime, { presetOverlay: false })
|
|
188
190
|
await settle()
|
|
189
191
|
|
|
190
|
-
expect(routes.map(route => route.path)).toEqual([SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE])
|
|
192
|
+
expect(routes.map(route => route.path)).toEqual([SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
|
|
191
193
|
})
|
|
192
194
|
})
|