dsh-context-compression-improved 0.2.4 → 0.2.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/.gitattributes +2 -1
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +8 -8
- package/CHANGELOG.ja.md +169 -39
- package/CHANGELOG.ko.md +167 -39
- package/CHANGELOG.md +212 -16
- package/CHANGELOG.zh.md +152 -39
- package/CONTRIBUTING.md +22 -22
- package/README.ja.md +85 -104
- package/README.ko.md +85 -103
- package/README.md +1 -19
- package/README.zh.md +85 -101
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.ja.md +78 -76
- package/docs/installation.ko.md +78 -76
- package/docs/installation.md +103 -76
- package/docs/installation.zh.md +100 -76
- package/docs/repair-log.md +657 -582
- package/eslint.config.js +30 -30
- package/package.json +75 -54
- package/packages/selector/README.md +7 -12
- package/packages/selector/README.zh.md +6 -13
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -38
- package/packages/selector/cordis.patch.yml +27 -19
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.d.ts +97 -5
- package/packages/selector/lib/client.js +1884 -92
- package/packages/selector/lib/config.js +863 -6
- package/packages/selector/lib/index.d.ts +29 -21
- package/packages/selector/lib/index.js +424 -18
- package/packages/selector/lib/invariant.js +4 -4
- package/packages/selector/lib/pruner.d.ts +179 -4
- package/packages/selector/lib/pruner.js +1406 -371
- package/packages/selector/lib/style.css +42 -0
- package/packages/selector/lib/tail-trim.js +13 -4
- package/packages/selector/package.json +18 -27
- package/packages/selector/screenshots.json +3 -6
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -229
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -170
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -79
- package/packages/selector/src/client/EstimatorControls.tsx +277 -281
- package/packages/selector/src/client/decode.ts +57 -49
- package/packages/selector/src/client/index.ts +200 -62
- package/packages/selector/src/client/locales/de.ts +141 -0
- package/packages/selector/src/client/locales/es.ts +141 -0
- package/packages/selector/src/client/locales/fr.ts +141 -0
- package/packages/selector/src/client/locales/it.ts +141 -0
- package/packages/selector/src/client/locales/ja.ts +141 -0
- package/packages/selector/src/client/locales/ko.ts +141 -0
- package/packages/selector/src/client/locales/ru.ts +141 -0
- package/packages/selector/src/client/locales.ts +282 -198
- package/packages/selector/src/client/monitor-fab.ts +336 -0
- package/packages/selector/src/client/preset-options.ts +88 -70
- package/packages/selector/src/client/savings-card.tsx +150 -0
- package/packages/selector/src/client/settings-section.tsx +140 -126
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -210
- package/packages/selector/src/index.ts +671 -327
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/profiles.ts +431 -342
- package/packages/selector/src/pruner/state.ts +57 -43
- package/packages/selector/src/pruner.ts +2736 -2154
- package/packages/selector/src/runtime/audit.ts +303 -231
- package/packages/selector/src/runtime/config.ts +756 -642
- package/packages/selector/src/runtime/measurement.ts +436 -432
- package/packages/selector/src/runtime/monitor.ts +235 -0
- package/packages/selector/src/runtime/retrieve.ts +479 -457
- package/packages/selector/src/runtime/savings.ts +337 -0
- package/packages/selector/src/runtime/session-events.ts +30 -17
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +166 -166
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -183
- 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/sidechannel.ts +303 -275
- package/packages/selector/src/runtime/types.ts +365 -325
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -226
- package/packages/selector/tests/built/client-artifact.spec.ts +59 -51
- package/packages/selector/tests/code-skeleton.client.spec.ts +91 -88
- package/packages/selector/tests/custom-contract.client.spec.ts +205 -202
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -247
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +194 -176
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +138 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +207 -181
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +201 -196
- package/packages/selector/tests/preset-overlay.host.spec.ts +8 -18
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -33
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +232 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -172
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- 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 +301 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2724 -2702
- package/packages/selector/tests/runtime/savings.spec.ts +120 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -56
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -100
- package/packages/selector/tests/settings-seat.client.spec.ts +130 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +142 -87
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +253 -250
- package/pnpm-workspace.yaml +66 -19
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/{packed-components-smoke.ts → packed-components-smoke.mjs} +732 -713
- package/scripts/{packed-install-e2e.ts → packed-install-e2e.mjs} +1273 -1072
- package/scripts/toolclass-corpus-replay.mjs +281 -273
- package/scripts/{verify-release.ts → verify-release.mjs} +318 -300
- package/tests/TEST_INVENTORY.md +41 -42
- package/scripts/capture-profile-baseline.ts +0 -80
- package/tsconfig.scripts.json +0 -13
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-profiles.jpg +0 -0
- /package/{packages/selector/assets/screenshots → docs/assets}/context-compression-selector-settings.png +0 -0
|
@@ -1,226 +1,214 @@
|
|
|
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
|
-
CompressionProfileSelector,
|
|
8
|
-
ContextCompressionSettingsSection,
|
|
9
|
-
type CompressionProfileSelectorProps,
|
|
10
|
-
type ContextCompressionSettings,
|
|
11
|
-
} from '../src/client/CompressionProfileSelector.tsx'
|
|
12
|
-
import { en } from '../src/client/locales.ts'
|
|
13
|
-
|
|
14
|
-
afterEach(cleanup)
|
|
15
|
-
|
|
16
|
-
interface SettingsScopeSnapshot<T> {
|
|
17
|
-
status: 'loading' | 'ready' | 'unavailable'
|
|
18
|
-
value: T | undefined
|
|
19
|
-
base: T | undefined
|
|
20
|
-
user: T | undefined
|
|
21
|
-
revision: number | undefined
|
|
22
|
-
writable: boolean
|
|
23
|
-
mode: 'host' | 'memory'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface SnapshotStore<T> {
|
|
27
|
-
readonly getSnapshot: () => T
|
|
28
|
-
readonly subscribe: (listener: () => void) => () => void
|
|
29
|
-
readonly update: (recipe: (draft: T) => void) => void
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
|
|
33
|
-
let 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
|
-
update(recipe) {
|
|
42
|
-
const draft = structuredClone(snapshot)
|
|
43
|
-
recipe(draft)
|
|
44
|
-
snapshot = draft
|
|
45
|
-
for (const listener of listeners) listener()
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
|
|
51
|
-
return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
|
|
52
|
-
return useSyncExternalStore(
|
|
53
|
-
store.subscribe,
|
|
54
|
-
() => selector(store.getSnapshot()),
|
|
55
|
-
() => selector(store.getSnapshot()),
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const DEFAULT_CUSTOM = {
|
|
61
|
-
version: 1,
|
|
62
|
-
unit: 'tokens',
|
|
63
|
-
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
64
|
-
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
65
|
-
history: {
|
|
66
|
-
enabled: true,
|
|
67
|
-
trigger: 32_768,
|
|
68
|
-
keepRecentTurns: 2,
|
|
69
|
-
keepRecent: 16_384,
|
|
70
|
-
minReclaim: 8_192,
|
|
71
|
-
},
|
|
72
|
-
prefixPolicy: 'pressure-break',
|
|
73
|
-
} as const satisfies ContextCompressionSettings['custom']
|
|
74
|
-
|
|
75
|
-
const t = (key: string) => en[key as keyof typeof en] ?? key
|
|
76
|
-
|
|
77
|
-
interface MountOptions {
|
|
78
|
-
readonly value?: ContextCompressionSettings
|
|
79
|
-
readonly saveAutoCompact?: (thresholdPercent: number) => Promise<void>
|
|
80
|
-
readonly settingsSection?: boolean
|
|
81
|
-
readonly writable?: boolean
|
|
82
|
-
readonly status?: 'loading' | 'ready'
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function mountAutoCompact(options: MountOptions = {}) {
|
|
86
|
-
const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
|
|
87
|
-
status: options.status ?? 'ready',
|
|
88
|
-
value: options.value ?? {
|
|
89
|
-
profile: 'balanced',
|
|
90
|
-
custom: structuredClone(DEFAULT_CUSTOM),
|
|
91
|
-
autoCompact: { thresholdPercent: 80 },
|
|
92
|
-
codeSkeleton: { enabled: false },
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
expect(screen.
|
|
131
|
-
expect(screen.queryByRole('
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
expect(screen.
|
|
138
|
-
expect(screen.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
fireEvent.change(
|
|
186
|
-
expect(
|
|
187
|
-
expect(screen.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expect(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
expect(screen.
|
|
203
|
-
expect(screen.
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
it('shows a failed threshold save inline', async () => {
|
|
219
|
-
const rejected = Promise.reject(new Error('threshold write failed'))
|
|
220
|
-
void rejected.catch(() => {})
|
|
221
|
-
mountAutoCompact({ settingsSection: true, saveAutoCompact: () => rejected })
|
|
222
|
-
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
|
|
223
|
-
fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
|
|
224
|
-
await waitFor(() => { expect(screen.getByRole('alert').textContent).toContain('threshold write failed') })
|
|
225
|
-
})
|
|
226
|
-
})
|
|
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
|
+
CompressionProfileSelector,
|
|
8
|
+
ContextCompressionSettingsSection,
|
|
9
|
+
type CompressionProfileSelectorProps,
|
|
10
|
+
type ContextCompressionSettings,
|
|
11
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
12
|
+
import { en } from '../src/client/locales.ts'
|
|
13
|
+
|
|
14
|
+
afterEach(cleanup)
|
|
15
|
+
|
|
16
|
+
interface SettingsScopeSnapshot<T> {
|
|
17
|
+
status: 'loading' | 'ready' | 'unavailable'
|
|
18
|
+
value: T | undefined
|
|
19
|
+
base: T | undefined
|
|
20
|
+
user: T | undefined
|
|
21
|
+
revision: number | undefined
|
|
22
|
+
writable: boolean
|
|
23
|
+
mode: 'host' | 'memory'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface SnapshotStore<T> {
|
|
27
|
+
readonly getSnapshot: () => T
|
|
28
|
+
readonly subscribe: (listener: () => void) => () => void
|
|
29
|
+
readonly update: (recipe: (draft: T) => void) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
|
|
33
|
+
let 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
|
+
update(recipe) {
|
|
42
|
+
const draft = structuredClone(snapshot)
|
|
43
|
+
recipe(draft)
|
|
44
|
+
snapshot = draft
|
|
45
|
+
for (const listener of listeners) listener()
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
|
|
51
|
+
return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
|
|
52
|
+
return useSyncExternalStore(
|
|
53
|
+
store.subscribe,
|
|
54
|
+
() => selector(store.getSnapshot()),
|
|
55
|
+
() => selector(store.getSnapshot()),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const DEFAULT_CUSTOM = {
|
|
61
|
+
version: 1,
|
|
62
|
+
unit: 'tokens',
|
|
63
|
+
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
64
|
+
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
65
|
+
history: {
|
|
66
|
+
enabled: true,
|
|
67
|
+
trigger: 32_768,
|
|
68
|
+
keepRecentTurns: 2,
|
|
69
|
+
keepRecent: 16_384,
|
|
70
|
+
minReclaim: 8_192,
|
|
71
|
+
},
|
|
72
|
+
prefixPolicy: 'pressure-break',
|
|
73
|
+
} as const satisfies ContextCompressionSettings['custom']
|
|
74
|
+
|
|
75
|
+
const t = (key: string) => en[key as keyof typeof en] ?? key
|
|
76
|
+
|
|
77
|
+
interface MountOptions {
|
|
78
|
+
readonly value?: ContextCompressionSettings
|
|
79
|
+
readonly saveAutoCompact?: (thresholdPercent: number) => Promise<void>
|
|
80
|
+
readonly settingsSection?: boolean
|
|
81
|
+
readonly writable?: boolean
|
|
82
|
+
readonly status?: 'loading' | 'ready'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function mountAutoCompact(options: MountOptions = {}) {
|
|
86
|
+
const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
|
|
87
|
+
status: options.status ?? 'ready',
|
|
88
|
+
value: options.value ?? {
|
|
89
|
+
profile: 'balanced',
|
|
90
|
+
custom: structuredClone(DEFAULT_CUSTOM),
|
|
91
|
+
autoCompact: { thresholdPercent: 80 },
|
|
92
|
+
codeSkeleton: { enabled: false },
|
|
93
|
+
intentSummary: { enabled: false },
|
|
94
|
+
},
|
|
95
|
+
base: undefined,
|
|
96
|
+
user: undefined,
|
|
97
|
+
revision: 0,
|
|
98
|
+
writable: options.writable ?? true,
|
|
99
|
+
mode: 'host',
|
|
100
|
+
})
|
|
101
|
+
const sessions = createSnapshotStore({
|
|
102
|
+
ids: ['s1'],
|
|
103
|
+
byId: { s1: { id: 's1', displayTitle: 's1', running: false, blank: true, updatedAt: 0, agentPreset: 'standard' } },
|
|
104
|
+
current: 's1',
|
|
105
|
+
phase: 'ready',
|
|
106
|
+
subagentsByParent: {},
|
|
107
|
+
jobsBySession: {},
|
|
108
|
+
currentAddress: undefined,
|
|
109
|
+
})
|
|
110
|
+
const saveAutoCompact = options.saveAutoCompact ?? vi.fn(() => Promise.resolve())
|
|
111
|
+
const Component = options.settingsSection === false ? CompressionProfileSelector : ContextCompressionSettingsSection
|
|
112
|
+
render(<Component {...({
|
|
113
|
+
useCompression: bindSnapshotSelector(state),
|
|
114
|
+
useSessions: bindSnapshotSelector(sessions),
|
|
115
|
+
select: vi.fn(() => Promise.resolve()),
|
|
116
|
+
saveCustom: vi.fn(() => Promise.resolve()),
|
|
117
|
+
resetCustom: vi.fn(() => Promise.resolve()),
|
|
118
|
+
saveAutoCompact,
|
|
119
|
+
t,
|
|
120
|
+
} as unknown as CompressionProfileSelectorProps)} />)
|
|
121
|
+
return { state, saveAutoCompact }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const INPUT_LABEL = 'Auto Compact threshold (%)'
|
|
125
|
+
|
|
126
|
+
describe('Auto Compact threshold controls', () => {
|
|
127
|
+
it('renders the editor only inside the context-compression settings section', () => {
|
|
128
|
+
mountAutoCompact({ settingsSection: true })
|
|
129
|
+
expect(screen.getByLabelText(INPUT_LABEL)).not.toBeNull()
|
|
130
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
131
|
+
for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
|
|
132
|
+
|
|
133
|
+
// The compact workspace selector shows a summary, never a second editor.
|
|
134
|
+
cleanup()
|
|
135
|
+
mountAutoCompact({ settingsSection: false })
|
|
136
|
+
expect(screen.queryByLabelText(INPUT_LABEL)).toBeNull()
|
|
137
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
138
|
+
expect(screen.getByText(/Auto Compact threshold: 80%/)).not.toBeNull()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('saves a non-quick value like 73 and reads the same value back after remount', async () => {
|
|
142
|
+
const saving = vi.fn((thresholdPercent: number): Promise<void> => {
|
|
143
|
+
mounted.state.update(draft => {
|
|
144
|
+
if (draft.value !== undefined) draft.value.autoCompact = { thresholdPercent }
|
|
145
|
+
})
|
|
146
|
+
return Promise.resolve()
|
|
147
|
+
})
|
|
148
|
+
const mounted = mountAutoCompact({ settingsSection: true, saveAutoCompact: saving })
|
|
149
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
|
|
150
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
|
|
151
|
+
await waitFor(() => { expect(mounted.state.getSnapshot().value?.autoCompact).toEqual({ thresholdPercent: 73 }) })
|
|
152
|
+
|
|
153
|
+
// A fresh mount reads the same persisted settings.
|
|
154
|
+
cleanup()
|
|
155
|
+
mountAutoCompact({
|
|
156
|
+
settingsSection: true,
|
|
157
|
+
value: { profile: 'balanced', custom: structuredClone(DEFAULT_CUSTOM), autoCompact: { thresholdPercent: 73 }, codeSkeleton: { enabled: false }, intentSummary: { enabled: false } },
|
|
158
|
+
})
|
|
159
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).value).toBe('73')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it.each(['49', '91', '72.5', 'abc', ''])('blocks saving the invalid draft %s', (draft) => {
|
|
163
|
+
const { saveAutoCompact } = mountAutoCompact({ settingsSection: true })
|
|
164
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: draft } })
|
|
165
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
166
|
+
expect(screen.getByText(/must be an integer between 50 and 90/)).not.toBeNull()
|
|
167
|
+
expect(saveAutoCompact).not.toHaveBeenCalled()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('uses the typed number input as the only threshold editor', () => {
|
|
171
|
+
mountAutoCompact({ settingsSection: true })
|
|
172
|
+
const input = screen.getByLabelText<HTMLInputElement>(INPUT_LABEL)
|
|
173
|
+
fireEvent.change(input, { target: { value: '73' } })
|
|
174
|
+
expect(input.value).toBe('73')
|
|
175
|
+
expect(screen.queryByRole('slider')).toBeNull()
|
|
176
|
+
for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('explains the risk outside the recommended 70–85 band but keeps saving available', () => {
|
|
180
|
+
mountAutoCompact({ settingsSection: true })
|
|
181
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '65' } })
|
|
182
|
+
expect(screen.getByText(/summarization calls and prefix rebuilds/)).not.toBeNull()
|
|
183
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
|
|
184
|
+
|
|
185
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '90' } })
|
|
186
|
+
expect(screen.getByText(/shared by requests and output/)).not.toBeNull()
|
|
187
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
|
|
188
|
+
|
|
189
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '80' } })
|
|
190
|
+
expect(screen.queryByText(/summarization calls and prefix rebuilds/)).toBeNull()
|
|
191
|
+
expect(screen.queryByText(/shared by requests and output/)).toBeNull()
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('disables every control while saving or when the scope is not writable', () => {
|
|
195
|
+
const { saveAutoCompact } = mountAutoCompact({ settingsSection: true, status: 'loading' })
|
|
196
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
|
|
197
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
198
|
+
expect(saveAutoCompact).not.toHaveBeenCalled()
|
|
199
|
+
|
|
200
|
+
cleanup()
|
|
201
|
+
mountAutoCompact({ settingsSection: true, writable: false })
|
|
202
|
+
expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
|
|
203
|
+
expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('shows a failed threshold save inline', async () => {
|
|
207
|
+
const rejected = Promise.reject(new Error('threshold write failed'))
|
|
208
|
+
void rejected.catch(() => {})
|
|
209
|
+
mountAutoCompact({ settingsSection: true, saveAutoCompact: () => rejected })
|
|
210
|
+
fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
|
|
211
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
|
|
212
|
+
await waitFor(() => { expect(screen.getByRole('alert').textContent).toContain('threshold write failed') })
|
|
213
|
+
})
|
|
214
|
+
})
|
|
@@ -1,51 +1,59 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
import * as React from 'react'
|
|
4
|
-
import * as jsxRuntime from 'react/jsx-runtime'
|
|
5
|
-
import { describe, expect, it } from 'vitest'
|
|
6
|
-
|
|
7
|
-
const artifact = resolve(import.meta.dirname, '../../lib/client.js')
|
|
8
|
-
|
|
9
|
-
describe('built Harness client artifact', () => {
|
|
10
|
-
it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
|
|
11
|
-
const code = readFileSync(artifact, 'utf8')
|
|
12
|
-
let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
|
|
13
|
-
const moduleLoader = {
|
|
14
|
-
load(value: typeof registration) {
|
|
15
|
-
registration = value
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
|
-
|
|
20
|
-
expect(() => Function(code)()).not.toThrow()
|
|
21
|
-
expect(registration?.id).toBe('dsh-context-compression-improved')
|
|
22
|
-
|
|
23
|
-
const modules = new Map<string, unknown>([
|
|
24
|
-
['react', React],
|
|
25
|
-
['react/jsx-runtime', jsxRuntime],
|
|
26
|
-
// The current selector only keeps this official package as a side-effect
|
|
27
|
-
// external. A minimal public-module stub proves the artifact asks the
|
|
28
|
-
// Harness loader for it without importing the package's raw CSS in Node.
|
|
29
|
-
['@deepseek-ai/dsh-client-ui-primitives', {}],
|
|
30
|
-
])
|
|
31
|
-
const exported = registration?.factory((id) => {
|
|
32
|
-
if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
|
|
33
|
-
return modules.get(id)
|
|
34
|
-
}) as { apply?: unknown, inject?: unknown }
|
|
35
|
-
|
|
36
|
-
expect(exported.apply).toBeTypeOf('function')
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import * as jsxRuntime from 'react/jsx-runtime'
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
const artifact = resolve(import.meta.dirname, '../../lib/client.js')
|
|
8
|
+
|
|
9
|
+
describe('built Harness client artifact', () => {
|
|
10
|
+
it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
|
|
11
|
+
const code = readFileSync(artifact, 'utf8')
|
|
12
|
+
let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
|
|
13
|
+
const moduleLoader = {
|
|
14
|
+
load(value: typeof registration) {
|
|
15
|
+
registration = value
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
|
+
|
|
20
|
+
expect(() => Function(code)()).not.toThrow()
|
|
21
|
+
expect(registration?.id).toBe('dsh-context-compression-improved')
|
|
22
|
+
|
|
23
|
+
const modules = new Map<string, unknown>([
|
|
24
|
+
['react', React],
|
|
25
|
+
['react/jsx-runtime', jsxRuntime],
|
|
26
|
+
// The current selector only keeps this official package as a side-effect
|
|
27
|
+
// external. A minimal public-module stub proves the artifact asks the
|
|
28
|
+
// Harness loader for it without importing the package's raw CSS in Node.
|
|
29
|
+
['@deepseek-ai/dsh-client-ui-primitives', {}],
|
|
30
|
+
])
|
|
31
|
+
const exported = registration?.factory((id) => {
|
|
32
|
+
if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
|
|
33
|
+
return modules.get(id)
|
|
34
|
+
}) as { apply?: unknown, inject?: unknown }
|
|
35
|
+
|
|
36
|
+
expect(exported.apply).toBeTypeOf('function')
|
|
37
|
+
// Declare every consumed service: cordis holds apply until each one is
|
|
38
|
+
// provided, which is the official client-plugin pattern on this 0.1.5 host
|
|
39
|
+
// line (dsh-thinking-levels does the same). The earlier lazy alternative —
|
|
40
|
+
// resolving `locale` / `settingsScope` through ctx.get() inside apply —
|
|
41
|
+
// raced the settings client's activation; on a loss the apply
|
|
42
|
+
// early-returned and EVERY settings entry (the standalone section, the
|
|
43
|
+
// plugins-tab card, the item card) silently vanished. See the rationale
|
|
44
|
+
// recorded in src/client/index.ts.
|
|
45
|
+
expect(exported.inject).toEqual(['slots', 'locale', 'settingsScope'])
|
|
46
|
+
const style = document.querySelector<HTMLStyleElement>(
|
|
47
|
+
'style[data-plugin-css="dsh-context-compression-improved/CompressionProfileSelector.module.css"]',
|
|
48
|
+
)
|
|
49
|
+
expect(style?.dataset.plugin).toBe('dsh-context-compression-improved')
|
|
50
|
+
expect(style?.textContent).toContain('profileGrid')
|
|
51
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
52
|
+
|
|
53
|
+
registration?.factory((id) => modules.get(id))
|
|
54
|
+
expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
|
|
55
|
+
expect(code).not.toMatch(/^\s*(?:import|export)\s/mu)
|
|
56
|
+
expect(code).not.toMatch(/(?:\/home\/|[A-Za-z]:\\Users\\)/u)
|
|
57
|
+
expect(code).not.toContain('sourceMappingURL')
|
|
58
|
+
})
|
|
59
|
+
})
|