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,213 +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
|
-
expect(screen.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
expect(screen.
|
|
137
|
-
expect(screen.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
fireEvent.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
expect(screen.
|
|
166
|
-
expect(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
expect(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
expect(screen.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
expect(screen.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
expect(screen.queryByText(/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
expect(screen.
|
|
197
|
-
expect(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
expect(screen.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
fireEvent.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
})
|
|
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
|
+
})
|
|
@@ -17,6 +17,8 @@ describe('built Harness client artifact', () => {
|
|
|
17
17
|
}
|
|
18
18
|
Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
|
|
19
19
|
|
|
20
|
+
// The smoke evaluates the built IIFE bundle the same way a browser page would.
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
20
22
|
expect(() => Function(code)()).not.toThrow()
|
|
21
23
|
expect(registration?.id).toBe('dsh-context-compression-improved')
|
|
22
24
|
|
|
@@ -1,93 +1,94 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
-
import { apply } from '../src/client/index.ts'
|
|
6
|
-
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
-
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 0.1.7 contract: `codeSkeleton` rides the entry config as part of the volatile
|
|
11
|
-
* `settings` whole-object field. Every write commits the full doc through
|
|
12
|
-
* `configForms.set('settings', doc)`; the confirm-on-write semantics are
|
|
13
|
-
* unchanged — a host that silently drops (or flips) the section fails the
|
|
14
|
-
* acceptance check on the post-commit snapshot.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
18
|
-
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
19
|
-
let revision = 3
|
|
20
|
-
let commit = false
|
|
21
|
-
let flipEnabled = false
|
|
22
|
-
let value: ContextCompressionSettings = {
|
|
23
|
-
profile: 'balanced',
|
|
24
|
-
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
25
|
-
autoCompact: { thresholdPercent: 80 },
|
|
26
|
-
codeSkeleton: { enabled: false },
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
accepted
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// the
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
expect(
|
|
82
|
-
expect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
expect(
|
|
91
|
-
expect(
|
|
92
|
-
|
|
93
|
-
})
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
+
import { apply } from '../src/client/index.ts'
|
|
6
|
+
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
+
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 0.1.7 contract: `codeSkeleton` rides the entry config as part of the volatile
|
|
11
|
+
* `settings` whole-object field. Every write commits the full doc through
|
|
12
|
+
* `configForms.set('settings', doc)`; the confirm-on-write semantics are
|
|
13
|
+
* unchanged — a host that silently drops (or flips) the section fails the
|
|
14
|
+
* acceptance check on the post-commit snapshot.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
18
|
+
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
19
|
+
let revision = 3
|
|
20
|
+
let commit = false
|
|
21
|
+
let flipEnabled = false
|
|
22
|
+
let value: ContextCompressionSettings = {
|
|
23
|
+
profile: 'balanced',
|
|
24
|
+
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
25
|
+
autoCompact: { thresholdPercent: 80 },
|
|
26
|
+
codeSkeleton: { enabled: false },
|
|
27
|
+
intentSummary: { enabled: false },
|
|
28
|
+
}
|
|
29
|
+
const form = {
|
|
30
|
+
getSnapshot: vi.fn(() => ({
|
|
31
|
+
status: 'ready' as const,
|
|
32
|
+
value: { settings: value },
|
|
33
|
+
base: undefined,
|
|
34
|
+
user: undefined,
|
|
35
|
+
revision,
|
|
36
|
+
writable: true,
|
|
37
|
+
mode: 'host' as const,
|
|
38
|
+
})),
|
|
39
|
+
subscribe: vi.fn(() => () => {}),
|
|
40
|
+
set: vi.fn(async (_field: string, next: unknown) => {
|
|
41
|
+
if (!commit) return false
|
|
42
|
+
revision += 1
|
|
43
|
+
const doc = structuredClone(next) as ContextCompressionSettings
|
|
44
|
+
if (flipEnabled) {
|
|
45
|
+
const accepted = structuredClone(doc.codeSkeleton)
|
|
46
|
+
accepted.enabled = !accepted.enabled
|
|
47
|
+
value = { ...doc, codeSkeleton: accepted }
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
value = doc
|
|
51
|
+
return true
|
|
52
|
+
}),
|
|
53
|
+
unset: vi.fn(async () => false),
|
|
54
|
+
}
|
|
55
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
56
|
+
const ctx = {
|
|
57
|
+
effect: (install: () => unknown) => { install() },
|
|
58
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
59
|
+
configForms: { get: vi.fn(() => form) },
|
|
60
|
+
slots: {
|
|
61
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
62
|
+
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
63
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
64
|
+
if (typeof registration.inject === 'function') injected = registration.inject
|
|
65
|
+
return () => {}
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
} as unknown as Parameters<typeof apply>[0]
|
|
69
|
+
|
|
70
|
+
apply(ctx)
|
|
71
|
+
const actions = injected?.()
|
|
72
|
+
expect(actions).toBeDefined()
|
|
73
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
74
|
+
|
|
75
|
+
// A silent host drop leaves the revision untouched: the write must reject.
|
|
76
|
+
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
77
|
+
|
|
78
|
+
// A committed write resolves and persists the exact section payload under
|
|
79
|
+
// the volatile `settings` field.
|
|
80
|
+
commit = true
|
|
81
|
+
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
82
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: true } }))
|
|
83
|
+
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
84
|
+
|
|
85
|
+
// A host that flips the toggled bit fails the acceptance check.
|
|
86
|
+
flipEnabled = true
|
|
87
|
+
await expect(actions.saveCodeSkeleton(false)).rejects.toThrow('were not saved')
|
|
88
|
+
|
|
89
|
+
flipEnabled = false
|
|
90
|
+
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
91
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: false } }))
|
|
92
|
+
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
93
|
+
})
|
|
94
|
+
})
|