dsh-context-compression-improved 0.6.1 → 0.6.2
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/package.json +162 -162
- package/packages/selector/lib/client.d.ts +27 -19
- package/packages/selector/lib/client.js +5 -5
- package/packages/selector/lib/pruner.d.ts +7 -0
- package/packages/selector/lib/pruner.js +20 -33
- package/packages/selector/lib/tail-trim.js +3 -6
- package/packages/selector/package.json +114 -114
- package/packages/selector/src/client/CompressionProfileControls.tsx +2 -2
- package/packages/selector/src/client/CompressionProfileSelector.tsx +1 -1
- package/packages/selector/src/client/index.ts +7 -8
- package/packages/selector/src/client/scope-face.ts +21 -0
- package/packages/selector/src/pruner/content.ts +0 -3
- package/packages/selector/src/pruner/session.ts +4 -2
- package/packages/selector/src/pruner.ts +26 -15
- package/packages/selector/src/runtime/measurement.ts +3 -8
- package/packages/selector/src/runtime/retrieve.ts +3 -3
- package/packages/selector/src/runtime/tail-trim.ts +4 -5
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/pnpm-workspace.yaml +42 -42
|
@@ -1,222 +1,222 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
-
import type { SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_CUSTOM_COMPRESSION_POLICY,
|
|
6
|
-
isCustomCompressionPolicy,
|
|
7
|
-
} from '../src/profiles.ts'
|
|
8
|
-
import { apply } from '../src/client/index.ts'
|
|
9
|
-
import { decodeSettings } from '../src/client/decode.ts'
|
|
10
|
-
import type {
|
|
11
|
-
CompressionSelectorInjected,
|
|
12
|
-
ContextCompressionSettings,
|
|
13
|
-
} from '../src/client/CompressionProfileSelector.tsx'
|
|
14
|
-
|
|
15
|
-
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
16
|
-
|
|
17
|
-
Menu: () => null,
|
|
18
|
-
}))
|
|
19
|
-
|
|
20
|
-
const CUSTOM = {
|
|
21
|
-
version: 1,
|
|
22
|
-
unit: 'tokens',
|
|
23
|
-
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
24
|
-
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
25
|
-
history: {
|
|
26
|
-
enabled: true,
|
|
27
|
-
trigger: 32_768,
|
|
28
|
-
keepRecentTurns: 2,
|
|
29
|
-
keepRecent: 16_384,
|
|
30
|
-
minReclaim: 8_192,
|
|
31
|
-
},
|
|
32
|
-
prefixPolicy: 'pressure-break',
|
|
33
|
-
} as const satisfies ContextCompressionSettings['custom']
|
|
34
|
-
|
|
35
|
-
describe('context compression browser contract', () => {
|
|
36
|
-
it('accepts legacy v1 and defaults new edits to v3 with TailTrim disabled', () => {
|
|
37
|
-
expect(isCustomCompressionPolicy(CUSTOM)).toBe(true)
|
|
38
|
-
expect(DEFAULT_CUSTOM_COMPRESSION_POLICY).toMatchObject({
|
|
39
|
-
version: 3,
|
|
40
|
-
tailTrim: { enabled: false, trigger: 700_000 },
|
|
41
|
-
})
|
|
42
|
-
expect(isCustomCompressionPolicy(DEFAULT_CUSTOM_COMPRESSION_POLICY)).toBe(true)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('fails the browser narrowing for unknown or invalid Custom fields', () => {
|
|
46
|
-
expect(isCustomCompressionPolicy({
|
|
47
|
-
...structuredClone(CUSTOM),
|
|
48
|
-
tailTrim: { enabled: true },
|
|
49
|
-
})).toBe(false)
|
|
50
|
-
expect(isCustomCompressionPolicy({
|
|
51
|
-
...structuredClone(CUSTOM),
|
|
52
|
-
fresh: { enabled: true, trigger: 100, target: 100 },
|
|
53
|
-
})).toBe(false)
|
|
54
|
-
for (const trigger of [0, -1]) {
|
|
55
|
-
expect(isCustomCompressionPolicy({
|
|
56
|
-
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
57
|
-
tailTrim: { enabled: true, trigger },
|
|
58
|
-
})).toBe(false)
|
|
59
|
-
}
|
|
60
|
-
expect(isCustomCompressionPolicy({
|
|
61
|
-
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
62
|
-
unit: 'context-percent',
|
|
63
|
-
tailTrim: { enabled: true, trigger: 101 },
|
|
64
|
-
})).toBe(false)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('decodes legacy settings to the default threshold and rejects malformed sections', async () => {
|
|
68
|
-
// Legacy documents stored before autoCompact existed inherit 80%.
|
|
69
|
-
const legacy = decodeSettings({ profile: 'balanced', custom: structuredClone(CUSTOM) })
|
|
70
|
-
expect(legacy).toMatchObject({ autoCompact: { thresholdPercent: 80 } })
|
|
71
|
-
// A present-but-invalid threshold fails the whole decode.
|
|
72
|
-
expect(decodeSettings({
|
|
73
|
-
profile: 'balanced',
|
|
74
|
-
custom: structuredClone(CUSTOM),
|
|
75
|
-
autoCompact: { thresholdPercent: 91 },
|
|
76
|
-
})).toBeUndefined()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('reports a recovered no-op write only on the selector boundary', async () => {
|
|
80
|
-
let revision = 7
|
|
81
|
-
let commit = false
|
|
82
|
-
let rewriteCustom = false
|
|
83
|
-
let rewriteReset = false
|
|
84
|
-
let dropTailTrim = false
|
|
85
|
-
let downgradeVersion = false
|
|
86
|
-
let value: ContextCompressionSettings = {
|
|
87
|
-
profile: 'balanced',
|
|
88
|
-
custom: structuredClone(CUSTOM),
|
|
89
|
-
autoCompact: { thresholdPercent: 80 },
|
|
90
|
-
codeSkeleton: { enabled: false },
|
|
91
|
-
}
|
|
92
|
-
const snapshot = (): SettingsScopeSnapshot<ContextCompressionSettings> => ({
|
|
93
|
-
status: 'ready',
|
|
94
|
-
value,
|
|
95
|
-
base: undefined,
|
|
96
|
-
user: undefined,
|
|
97
|
-
revision,
|
|
98
|
-
writable: true,
|
|
99
|
-
mode: 'host',
|
|
100
|
-
})
|
|
101
|
-
const scope = {
|
|
102
|
-
getSnapshot: snapshot,
|
|
103
|
-
subscribe: vi.fn(() => () => {}),
|
|
104
|
-
set: vi.fn(async (field: string, next: unknown) => {
|
|
105
|
-
if (!commit) return
|
|
106
|
-
revision += 1
|
|
107
|
-
if (field === 'custom' && rewriteCustom) {
|
|
108
|
-
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
109
|
-
accepted.fresh.trigger += 1
|
|
110
|
-
value = { ...value, custom: accepted }
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
if (field === 'custom' && rewriteReset) {
|
|
114
|
-
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
115
|
-
accepted.fresh.trigger += 1
|
|
116
|
-
value = { ...value, custom: accepted }
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
if (field === 'custom' && dropTailTrim) {
|
|
120
|
-
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
121
|
-
if (accepted.version === 3) {
|
|
122
|
-
accepted.tailTrim = { enabled: false, trigger: 700_000 }
|
|
123
|
-
}
|
|
124
|
-
value = { ...value, custom: accepted }
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
if (field === 'custom' && downgradeVersion) {
|
|
128
|
-
value = { ...value, custom: structuredClone(CUSTOM) }
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
value = { ...value, [field]: next }
|
|
132
|
-
}),
|
|
133
|
-
unset: vi.fn(async () => {
|
|
134
|
-
if (!commit) return
|
|
135
|
-
revision += 1
|
|
136
|
-
const custom: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
137
|
-
if (rewriteReset) {
|
|
138
|
-
custom.fresh.trigger = 8_192
|
|
139
|
-
custom.fresh.target = 4_096
|
|
140
|
-
}
|
|
141
|
-
value = { ...value, custom }
|
|
142
|
-
}),
|
|
143
|
-
}
|
|
144
|
-
let injected: (() => CompressionSelectorInjected) | undefined
|
|
145
|
-
const ctx = {
|
|
146
|
-
effect: (install: () => unknown) => { install() },
|
|
147
|
-
locale: { register: vi.fn(() => () => {}) },
|
|
148
|
-
// 0.1.7: the plugin commits the whole doc through configForms; the fake
|
|
149
|
-
// routes each changed top-level field back onto the old scope stub so
|
|
150
|
-
// the rewrite/drop semantics below stay observable per field.
|
|
151
|
-
configForms: {
|
|
152
|
-
get: vi.fn(() => ({
|
|
153
|
-
getSnapshot: () => ({ ...snapshot(), value: { settings: value } }),
|
|
154
|
-
subscribe: scope.subscribe,
|
|
155
|
-
set: async (_field: string, doc: unknown) => {
|
|
156
|
-
const next = doc as unknown as Record<string, unknown>
|
|
157
|
-
for (const key of Object.keys(next)) {
|
|
158
|
-
if (JSON.stringify((value as unknown as Record<string, unknown>)[key]) !== JSON.stringify(next[key])) {
|
|
159
|
-
await scope.set(key, (next as Record<string, unknown>)[key])
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return true
|
|
163
|
-
},
|
|
164
|
-
unset: scope.unset,
|
|
165
|
-
})),
|
|
166
|
-
},
|
|
167
|
-
slots: {
|
|
168
|
-
inject: (_slot: string, install: () => unknown) => { install() },
|
|
169
|
-
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
170
|
-
// The R4 overlay registration carries no inject face; keep the card's.
|
|
171
|
-
if (typeof registration.inject === 'function') injected = registration.inject
|
|
172
|
-
return () => {}
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
} as unknown as ClientContext
|
|
176
|
-
|
|
177
|
-
apply(ctx)
|
|
178
|
-
const actions = injected?.()
|
|
179
|
-
expect(actions).toBeDefined()
|
|
180
|
-
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
181
|
-
await expect(actions.select('native')).rejects.toThrow('were not saved')
|
|
182
|
-
|
|
183
|
-
commit = true
|
|
184
|
-
await expect(actions.select('native')).resolves.toBeUndefined()
|
|
185
|
-
expect(value.profile).toBe('native')
|
|
186
|
-
|
|
187
|
-
const requested: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
188
|
-
requested.fresh.trigger = 8_192
|
|
189
|
-
requested.fresh.target = 4_096
|
|
190
|
-
rewriteCustom = true
|
|
191
|
-
await expect(actions.saveCustom(requested)).rejects.toThrow('were not saved')
|
|
192
|
-
|
|
193
|
-
rewriteCustom = false
|
|
194
|
-
const requestedV3 = structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
195
|
-
if (requestedV3.version !== 3) throw new Error('Custom TailTrim persistence fixture requires policy v3')
|
|
196
|
-
requestedV3.tailTrim = { enabled: true, trigger: 49_152 }
|
|
197
|
-
dropTailTrim = true
|
|
198
|
-
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
199
|
-
|
|
200
|
-
dropTailTrim = false
|
|
201
|
-
downgradeVersion = true
|
|
202
|
-
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
203
|
-
|
|
204
|
-
downgradeVersion = false
|
|
205
|
-
rewriteReset = true
|
|
206
|
-
await expect(actions.resetCustom()).rejects.toThrow('were not saved')
|
|
207
|
-
|
|
208
|
-
rewriteReset = false
|
|
209
|
-
await expect(actions.resetCustom()).resolves.toBeUndefined()
|
|
210
|
-
expect(scope.set).toHaveBeenLastCalledWith('custom', DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
211
|
-
expect(scope.unset).not.toHaveBeenCalled()
|
|
212
|
-
|
|
213
|
-
// The Auto Compact threshold shares the same confirm-on-write boundary:
|
|
214
|
-
// committed writes resolve, and a silent host drop rejects.
|
|
215
|
-
commit = false
|
|
216
|
-
await expect(actions.saveAutoCompact(73)).rejects.toThrow('were not saved')
|
|
217
|
-
commit = true
|
|
218
|
-
await expect(actions.saveAutoCompact(73)).resolves.toBeUndefined()
|
|
219
|
-
expect(scope.set).toHaveBeenLastCalledWith('autoCompact', { thresholdPercent: 73 })
|
|
220
|
-
expect(value.autoCompact).toEqual({ thresholdPercent: 73 })
|
|
221
|
-
})
|
|
222
|
-
})
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
+
import type { SettingsScopeSnapshot } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_CUSTOM_COMPRESSION_POLICY,
|
|
6
|
+
isCustomCompressionPolicy,
|
|
7
|
+
} from '../src/profiles.ts'
|
|
8
|
+
import { apply } from '../src/client/index.ts'
|
|
9
|
+
import { decodeSettings } from '../src/client/decode.ts'
|
|
10
|
+
import type {
|
|
11
|
+
CompressionSelectorInjected,
|
|
12
|
+
ContextCompressionSettings,
|
|
13
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
14
|
+
|
|
15
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
16
|
+
IconChevronDownOutlineMedium: () => null,
|
|
17
|
+
Menu: () => null,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const CUSTOM = {
|
|
21
|
+
version: 1,
|
|
22
|
+
unit: 'tokens',
|
|
23
|
+
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
24
|
+
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
25
|
+
history: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
trigger: 32_768,
|
|
28
|
+
keepRecentTurns: 2,
|
|
29
|
+
keepRecent: 16_384,
|
|
30
|
+
minReclaim: 8_192,
|
|
31
|
+
},
|
|
32
|
+
prefixPolicy: 'pressure-break',
|
|
33
|
+
} as const satisfies ContextCompressionSettings['custom']
|
|
34
|
+
|
|
35
|
+
describe('context compression browser contract', () => {
|
|
36
|
+
it('accepts legacy v1 and defaults new edits to v3 with TailTrim disabled', () => {
|
|
37
|
+
expect(isCustomCompressionPolicy(CUSTOM)).toBe(true)
|
|
38
|
+
expect(DEFAULT_CUSTOM_COMPRESSION_POLICY).toMatchObject({
|
|
39
|
+
version: 3,
|
|
40
|
+
tailTrim: { enabled: false, trigger: 700_000 },
|
|
41
|
+
})
|
|
42
|
+
expect(isCustomCompressionPolicy(DEFAULT_CUSTOM_COMPRESSION_POLICY)).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('fails the browser narrowing for unknown or invalid Custom fields', () => {
|
|
46
|
+
expect(isCustomCompressionPolicy({
|
|
47
|
+
...structuredClone(CUSTOM),
|
|
48
|
+
tailTrim: { enabled: true },
|
|
49
|
+
})).toBe(false)
|
|
50
|
+
expect(isCustomCompressionPolicy({
|
|
51
|
+
...structuredClone(CUSTOM),
|
|
52
|
+
fresh: { enabled: true, trigger: 100, target: 100 },
|
|
53
|
+
})).toBe(false)
|
|
54
|
+
for (const trigger of [0, -1]) {
|
|
55
|
+
expect(isCustomCompressionPolicy({
|
|
56
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
57
|
+
tailTrim: { enabled: true, trigger },
|
|
58
|
+
})).toBe(false)
|
|
59
|
+
}
|
|
60
|
+
expect(isCustomCompressionPolicy({
|
|
61
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
62
|
+
unit: 'context-percent',
|
|
63
|
+
tailTrim: { enabled: true, trigger: 101 },
|
|
64
|
+
})).toBe(false)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('decodes legacy settings to the default threshold and rejects malformed sections', async () => {
|
|
68
|
+
// Legacy documents stored before autoCompact existed inherit 80%.
|
|
69
|
+
const legacy = decodeSettings({ profile: 'balanced', custom: structuredClone(CUSTOM) })
|
|
70
|
+
expect(legacy).toMatchObject({ autoCompact: { thresholdPercent: 80 } })
|
|
71
|
+
// A present-but-invalid threshold fails the whole decode.
|
|
72
|
+
expect(decodeSettings({
|
|
73
|
+
profile: 'balanced',
|
|
74
|
+
custom: structuredClone(CUSTOM),
|
|
75
|
+
autoCompact: { thresholdPercent: 91 },
|
|
76
|
+
})).toBeUndefined()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('reports a recovered no-op write only on the selector boundary', async () => {
|
|
80
|
+
let revision = 7
|
|
81
|
+
let commit = false
|
|
82
|
+
let rewriteCustom = false
|
|
83
|
+
let rewriteReset = false
|
|
84
|
+
let dropTailTrim = false
|
|
85
|
+
let downgradeVersion = false
|
|
86
|
+
let value: ContextCompressionSettings = {
|
|
87
|
+
profile: 'balanced',
|
|
88
|
+
custom: structuredClone(CUSTOM),
|
|
89
|
+
autoCompact: { thresholdPercent: 80 },
|
|
90
|
+
codeSkeleton: { enabled: false },
|
|
91
|
+
}
|
|
92
|
+
const snapshot = (): SettingsScopeSnapshot<ContextCompressionSettings> => ({
|
|
93
|
+
status: 'ready',
|
|
94
|
+
value,
|
|
95
|
+
base: undefined,
|
|
96
|
+
user: undefined,
|
|
97
|
+
revision,
|
|
98
|
+
writable: true,
|
|
99
|
+
mode: 'host',
|
|
100
|
+
})
|
|
101
|
+
const scope = {
|
|
102
|
+
getSnapshot: snapshot,
|
|
103
|
+
subscribe: vi.fn(() => () => {}),
|
|
104
|
+
set: vi.fn(async (field: string, next: unknown) => {
|
|
105
|
+
if (!commit) return
|
|
106
|
+
revision += 1
|
|
107
|
+
if (field === 'custom' && rewriteCustom) {
|
|
108
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
109
|
+
accepted.fresh.trigger += 1
|
|
110
|
+
value = { ...value, custom: accepted }
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
if (field === 'custom' && rewriteReset) {
|
|
114
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
115
|
+
accepted.fresh.trigger += 1
|
|
116
|
+
value = { ...value, custom: accepted }
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
if (field === 'custom' && dropTailTrim) {
|
|
120
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
121
|
+
if (accepted.version === 3) {
|
|
122
|
+
accepted.tailTrim = { enabled: false, trigger: 700_000 }
|
|
123
|
+
}
|
|
124
|
+
value = { ...value, custom: accepted }
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
if (field === 'custom' && downgradeVersion) {
|
|
128
|
+
value = { ...value, custom: structuredClone(CUSTOM) }
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
value = { ...value, [field]: next }
|
|
132
|
+
}),
|
|
133
|
+
unset: vi.fn(async () => {
|
|
134
|
+
if (!commit) return
|
|
135
|
+
revision += 1
|
|
136
|
+
const custom: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
137
|
+
if (rewriteReset) {
|
|
138
|
+
custom.fresh.trigger = 8_192
|
|
139
|
+
custom.fresh.target = 4_096
|
|
140
|
+
}
|
|
141
|
+
value = { ...value, custom }
|
|
142
|
+
}),
|
|
143
|
+
}
|
|
144
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
145
|
+
const ctx = {
|
|
146
|
+
effect: (install: () => unknown) => { install() },
|
|
147
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
148
|
+
// 0.1.7: the plugin commits the whole doc through configForms; the fake
|
|
149
|
+
// routes each changed top-level field back onto the old scope stub so
|
|
150
|
+
// the rewrite/drop semantics below stay observable per field.
|
|
151
|
+
configForms: {
|
|
152
|
+
get: vi.fn(() => ({
|
|
153
|
+
getSnapshot: () => ({ ...snapshot(), value: { settings: value } }),
|
|
154
|
+
subscribe: scope.subscribe,
|
|
155
|
+
set: async (_field: string, doc: unknown) => {
|
|
156
|
+
const next = doc as unknown as Record<string, unknown>
|
|
157
|
+
for (const key of Object.keys(next)) {
|
|
158
|
+
if (JSON.stringify((value as unknown as Record<string, unknown>)[key]) !== JSON.stringify(next[key])) {
|
|
159
|
+
await scope.set(key, (next as Record<string, unknown>)[key])
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return true
|
|
163
|
+
},
|
|
164
|
+
unset: scope.unset,
|
|
165
|
+
})),
|
|
166
|
+
},
|
|
167
|
+
slots: {
|
|
168
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
169
|
+
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
170
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
171
|
+
if (typeof registration.inject === 'function') injected = registration.inject
|
|
172
|
+
return () => {}
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
} as unknown as ClientContext
|
|
176
|
+
|
|
177
|
+
apply(ctx)
|
|
178
|
+
const actions = injected?.()
|
|
179
|
+
expect(actions).toBeDefined()
|
|
180
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
181
|
+
await expect(actions.select('native')).rejects.toThrow('were not saved')
|
|
182
|
+
|
|
183
|
+
commit = true
|
|
184
|
+
await expect(actions.select('native')).resolves.toBeUndefined()
|
|
185
|
+
expect(value.profile).toBe('native')
|
|
186
|
+
|
|
187
|
+
const requested: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
188
|
+
requested.fresh.trigger = 8_192
|
|
189
|
+
requested.fresh.target = 4_096
|
|
190
|
+
rewriteCustom = true
|
|
191
|
+
await expect(actions.saveCustom(requested)).rejects.toThrow('were not saved')
|
|
192
|
+
|
|
193
|
+
rewriteCustom = false
|
|
194
|
+
const requestedV3 = structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
195
|
+
if (requestedV3.version !== 3) throw new Error('Custom TailTrim persistence fixture requires policy v3')
|
|
196
|
+
requestedV3.tailTrim = { enabled: true, trigger: 49_152 }
|
|
197
|
+
dropTailTrim = true
|
|
198
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
199
|
+
|
|
200
|
+
dropTailTrim = false
|
|
201
|
+
downgradeVersion = true
|
|
202
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
203
|
+
|
|
204
|
+
downgradeVersion = false
|
|
205
|
+
rewriteReset = true
|
|
206
|
+
await expect(actions.resetCustom()).rejects.toThrow('were not saved')
|
|
207
|
+
|
|
208
|
+
rewriteReset = false
|
|
209
|
+
await expect(actions.resetCustom()).resolves.toBeUndefined()
|
|
210
|
+
expect(scope.set).toHaveBeenLastCalledWith('custom', DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
211
|
+
expect(scope.unset).not.toHaveBeenCalled()
|
|
212
|
+
|
|
213
|
+
// The Auto Compact threshold shares the same confirm-on-write boundary:
|
|
214
|
+
// committed writes resolve, and a silent host drop rejects.
|
|
215
|
+
commit = false
|
|
216
|
+
await expect(actions.saveAutoCompact(73)).rejects.toThrow('were not saved')
|
|
217
|
+
commit = true
|
|
218
|
+
await expect(actions.saveAutoCompact(73)).resolves.toBeUndefined()
|
|
219
|
+
expect(scope.set).toHaveBeenLastCalledWith('autoCompact', { thresholdPercent: 73 })
|
|
220
|
+
expect(value.autoCompact).toEqual({ thresholdPercent: 73 })
|
|
221
|
+
})
|
|
222
|
+
})
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
const root = resolve(import.meta.dirname, '../../..')
|
|
6
|
-
|
|
7
|
-
describe('standalone package contract', () => {
|
|
8
|
-
it('ships one install-facing package with no intra-repo dependency edge', () => {
|
|
9
|
-
const selector = JSON.parse(readFileSync(resolve(root, 'selector/package.json'), 'utf8')) as {
|
|
10
|
-
name: string
|
|
11
|
-
version: string
|
|
12
|
-
dependencies?: Record<string, string>
|
|
13
|
-
peerDependencies?: Record<string, string>
|
|
14
|
-
publishConfig?: { tag?: string }
|
|
15
|
-
}
|
|
16
|
-
expect(selector.name).toBe('dsh-context-compression-improved')
|
|
17
|
-
expect(selector.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
18
|
-
expect(Object.keys(selector.dependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
19
|
-
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
20
|
-
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('@deepseek-ai/dsh-compaction-tool-result-pruner')
|
|
21
|
-
expect(selector.peerDependencies?.['@deepseek-ai/dsh-compaction-basic'])
|
|
22
|
-
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
23
|
-
expect(selector.peerDependencies?.['@deepseek-ai/dsh-command-compact'])
|
|
24
|
-
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
25
|
-
expect(selector.publishConfig?.tag).toBe('latest')
|
|
26
|
-
expect(existsSync(resolve(root, '../runtime/package.json'))).toBe(false)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('makes the repository root the one git install surface', () => {
|
|
30
|
-
const rootManifest = JSON.parse(readFileSync(resolve(root, '../package.json'), 'utf8')) as {
|
|
31
|
-
name: string
|
|
32
|
-
exports?: Record<string, unknown>
|
|
33
|
-
dependencies?: Record<string, string>
|
|
34
|
-
engines?: Record<string, string>
|
|
35
|
-
dsh?: { bundle?: { patch?: string }, client?: { inject?: string[] } }
|
|
36
|
-
}
|
|
37
|
-
expect(rootManifest.name).toBe('dsh-context-compression-improved')
|
|
38
|
-
for (const specifier of ['.', './invariant', './pruner', './client']) {
|
|
39
|
-
expect(rootManifest.exports?.[specifier]).toBeDefined()
|
|
40
|
-
}
|
|
41
|
-
expect(rootManifest.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
42
|
-
expect(rootManifest.dependencies?.['js-yaml']).toBe('^4.3.2')
|
|
43
|
-
expect(rootManifest.dsh?.bundle?.patch).toBe('./packages/selector/cordis.patch.yml')
|
|
44
|
-
expect(rootManifest.dsh?.client?.inject).toEqual([
|
|
45
|
-
'@deepseek-ai/dsh-client-locale',
|
|
46
|
-
'@deepseek-ai/dsh-client-ui-primitives',
|
|
47
|
-
'@deepseek-ai/dsh-client-ui-slots',
|
|
48
|
-
'@deepseek-ai/dsh-client-ui-settings',
|
|
49
|
-
])
|
|
50
|
-
expect(rootManifest.engines?.dsh).toBe('>=0.1.
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('uses the community package in the one Bundle patch', () => {
|
|
54
|
-
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
55
|
-
expect(patch).toContain("name: 'dsh-context-compression-improved'")
|
|
56
|
-
expect(patch).not.toContain('@deepseek-ai/dsh-client-ui-context-compression-selector')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('never ships a retired plugin config key in the Bundle patch', () => {
|
|
60
|
-
// Negative control: the patch is loaded by the host and validated against
|
|
61
|
-
// the plugin's own Config schema, but nothing tied the two together — so
|
|
62
|
-
// the retired review gate's `reviewQueueRoute` survived in this file after
|
|
63
|
-
// the key was removed from the schema, advertising a route that can never
|
|
64
|
-
// register. A retired key must fail here instead of shipping quietly.
|
|
65
|
-
//
|
|
66
|
-
// The pin is on KEY-SETTING lines, not on the whole document: the comments
|
|
67
|
-
// above the rows deliberately name the retired key while explaining why it
|
|
68
|
-
// is gone, and prose must not be mistaken for configuration.
|
|
69
|
-
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
70
|
-
const lines = patch.split('\n')
|
|
71
|
-
for (const retired of ['reviewQueueRoute', 'reviewMode', 'reviewTimeoutTurns', 'reviewHighImpactTokens']) {
|
|
72
|
-
const setsRetired = lines.find(line => new RegExp(`^\\s*${retired}\\s*:`).test(line))
|
|
73
|
-
expect(setsRetired, `${retired} is still set in the Bundle patch`).toBeUndefined()
|
|
74
|
-
}
|
|
75
|
-
// And the live flag the routes row exists for is still wired.
|
|
76
|
-
expect(patch).toContain('estimatorCatalogRoute: true')
|
|
77
|
-
})
|
|
78
|
-
})
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
const root = resolve(import.meta.dirname, '../../..')
|
|
6
|
+
|
|
7
|
+
describe('standalone package contract', () => {
|
|
8
|
+
it('ships one install-facing package with no intra-repo dependency edge', () => {
|
|
9
|
+
const selector = JSON.parse(readFileSync(resolve(root, 'selector/package.json'), 'utf8')) as {
|
|
10
|
+
name: string
|
|
11
|
+
version: string
|
|
12
|
+
dependencies?: Record<string, string>
|
|
13
|
+
peerDependencies?: Record<string, string>
|
|
14
|
+
publishConfig?: { tag?: string }
|
|
15
|
+
}
|
|
16
|
+
expect(selector.name).toBe('dsh-context-compression-improved')
|
|
17
|
+
expect(selector.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
18
|
+
expect(Object.keys(selector.dependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
19
|
+
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('dsh-context-compression-improved-runtime')
|
|
20
|
+
expect(Object.keys(selector.peerDependencies ?? {})).not.toContain('@deepseek-ai/dsh-compaction-tool-result-pruner')
|
|
21
|
+
expect(selector.peerDependencies?.['@deepseek-ai/dsh-compaction-basic'])
|
|
22
|
+
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
23
|
+
expect(selector.peerDependencies?.['@deepseek-ai/dsh-command-compact'])
|
|
24
|
+
.toBe('>=0.1.7-rc.1 <0.2.0-0')
|
|
25
|
+
expect(selector.publishConfig?.tag).toBe('latest')
|
|
26
|
+
expect(existsSync(resolve(root, '../runtime/package.json'))).toBe(false)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('makes the repository root the one git install surface', () => {
|
|
30
|
+
const rootManifest = JSON.parse(readFileSync(resolve(root, '../package.json'), 'utf8')) as {
|
|
31
|
+
name: string
|
|
32
|
+
exports?: Record<string, unknown>
|
|
33
|
+
dependencies?: Record<string, string>
|
|
34
|
+
engines?: Record<string, string>
|
|
35
|
+
dsh?: { bundle?: { patch?: string }, client?: { inject?: string[] } }
|
|
36
|
+
}
|
|
37
|
+
expect(rootManifest.name).toBe('dsh-context-compression-improved')
|
|
38
|
+
for (const specifier of ['.', './invariant', './pruner', './client']) {
|
|
39
|
+
expect(rootManifest.exports?.[specifier]).toBeDefined()
|
|
40
|
+
}
|
|
41
|
+
expect(rootManifest.dependencies?.['@huggingface/tokenizers']).toBe('0.1.3')
|
|
42
|
+
expect(rootManifest.dependencies?.['js-yaml']).toBe('^4.3.2')
|
|
43
|
+
expect(rootManifest.dsh?.bundle?.patch).toBe('./packages/selector/cordis.patch.yml')
|
|
44
|
+
expect(rootManifest.dsh?.client?.inject).toEqual([
|
|
45
|
+
'@deepseek-ai/dsh-client-locale',
|
|
46
|
+
'@deepseek-ai/dsh-client-ui-primitives',
|
|
47
|
+
'@deepseek-ai/dsh-client-ui-slots',
|
|
48
|
+
'@deepseek-ai/dsh-client-ui-settings',
|
|
49
|
+
])
|
|
50
|
+
expect(rootManifest.engines?.dsh).toBe('>=0.1.7-rc.1 <0.1.8-0')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('uses the community package in the one Bundle patch', () => {
|
|
54
|
+
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
55
|
+
expect(patch).toContain("name: 'dsh-context-compression-improved'")
|
|
56
|
+
expect(patch).not.toContain('@deepseek-ai/dsh-client-ui-context-compression-selector')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('never ships a retired plugin config key in the Bundle patch', () => {
|
|
60
|
+
// Negative control: the patch is loaded by the host and validated against
|
|
61
|
+
// the plugin's own Config schema, but nothing tied the two together — so
|
|
62
|
+
// the retired review gate's `reviewQueueRoute` survived in this file after
|
|
63
|
+
// the key was removed from the schema, advertising a route that can never
|
|
64
|
+
// register. A retired key must fail here instead of shipping quietly.
|
|
65
|
+
//
|
|
66
|
+
// The pin is on KEY-SETTING lines, not on the whole document: the comments
|
|
67
|
+
// above the rows deliberately name the retired key while explaining why it
|
|
68
|
+
// is gone, and prose must not be mistaken for configuration.
|
|
69
|
+
const patch = readFileSync(resolve(root, 'selector/cordis.patch.yml'), 'utf8')
|
|
70
|
+
const lines = patch.split('\n')
|
|
71
|
+
for (const retired of ['reviewQueueRoute', 'reviewMode', 'reviewTimeoutTurns', 'reviewHighImpactTokens']) {
|
|
72
|
+
const setsRetired = lines.find(line => new RegExp(`^\\s*${retired}\\s*:`).test(line))
|
|
73
|
+
expect(setsRetired, `${retired} is still set in the Bundle patch`).toBeUndefined()
|
|
74
|
+
}
|
|
75
|
+
// And the live flag the routes row exists for is still wired.
|
|
76
|
+
expect(patch).toContain('estimatorCatalogRoute: true')
|
|
77
|
+
})
|
|
78
|
+
})
|