dsh-context-compression-improved 0.6.3 → 0.6.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/.agents-stash-064.patch +39 -0
- package/CHANGELOG.ja.md +42 -0
- package/CHANGELOG.ko.md +38 -0
- package/CHANGELOG.md +46 -0
- package/CHANGELOG.zh.md +38 -0
- package/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +5 -3
- package/README.zh.md +2 -2
- package/_dsh_devdeps.json +50 -0
- package/_verify064/package/package.json +162 -0
- package/_verify064/package/packages/selector/src/client/index.ts +232 -0
- package/package.json +50 -49
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.js +2 -1
- package/packages/selector/lib/style.css +46 -46
- package/packages/selector/package.json +114 -114
- package/packages/selector/src/client/index.ts +213 -225
- package/packages/selector/src/client/scope-face.ts +24 -24
- package/packages/selector/src/index.ts +0 -1
- package/packages/selector/src/pruner.ts +0 -1
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
- package/packages/selector/tests/helpers/legacy-namespace.ts +8 -4
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +3 -5
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -206
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -233
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2731 -2727
- package/packages/selector/tests/settings-seat.client.spec.ts +165 -165
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -704
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +18 -2
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/pnpm-workspace.yaml +1 -1
- package/scripts/packed-install-e2e.mjs +6 -6
- package/scripts/verify-release.mjs +1 -1
|
@@ -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 { ScopeSnapshot } from '../src/client/scope-face.ts'
|
|
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 = (): ScopeSnapshot<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 { ScopeSnapshot } from '../src/client/scope-face.ts'
|
|
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 = (): ScopeSnapshot<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
|
+
})
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* and falls back to this namespace; on a real 0.1.7 host neither the
|
|
7
7
|
* registration nor this helper exists.
|
|
8
8
|
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
9
10
|
import {
|
|
10
11
|
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
11
12
|
ContextCompressionSettingsSchema,
|
|
@@ -13,13 +14,16 @@ import {
|
|
|
13
14
|
|
|
14
15
|
export const LegacyNamespaceRegistrar = {
|
|
15
16
|
name: 'context-compression:test/legacy-namespace-registrar',
|
|
16
|
-
async apply(ctx: {
|
|
17
|
-
inject(deps: readonly string[], fn: (s: { settings: { register(ns: never, schema: unknown): unknown } }) => void): void
|
|
18
|
-
}): Promise<void> {
|
|
17
|
+
async apply(ctx: Context): Promise<void> {
|
|
19
18
|
await new Promise<void>((resolve) => {
|
|
20
19
|
ctx.inject(['settings'], (s) => {
|
|
21
20
|
try {
|
|
22
|
-
|
|
21
|
+
// The test host mounts a vendored 0.1.5-shaped provider whose
|
|
22
|
+
// static type is the 0.1.7 Context augmentation (`SettingsForms`);
|
|
23
|
+
// narrow to the legacy registry surface at the seam.
|
|
24
|
+
;(s.settings as unknown as {
|
|
25
|
+
register(ns: never, schema: unknown): unknown
|
|
26
|
+
}).register(
|
|
23
27
|
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
|
|
24
28
|
ContextCompressionSettingsSchema,
|
|
25
29
|
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Legacy test-host settings seam.
|
|
3
|
+
*
|
|
4
|
+
* Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
|
|
5
|
+
* (`lib/types/index.js` + `lib/types/redact.js`, with the
|
|
6
|
+
* `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
|
|
7
|
+
* `./legacy/util-values.js`): the 0.1.7 host replaced the
|
|
8
|
+
* namespace-registry provider with declarative `SettingsForms`, while the
|
|
9
|
+
* plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
|
|
10
|
+
* fallback (see src/index.ts). The host specs mount a provider subclassing
|
|
11
|
+
* this base to exercise exactly that fallback against the real 0.1.7
|
|
12
|
+
* baseline. Type declarations: `./legacy/provider.d.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
|
|
15
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
|
|
3
|
+
*
|
|
4
|
+
* The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
|
|
5
|
+
* provider with the declarative `SettingsForms` projector, but the plugin
|
|
6
|
+
* deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
|
|
7
|
+
* "so a host that still serves the old service shape keeps working (test
|
|
8
|
+
* hosts do exactly that)" (src/index.ts). The host specs drive that fallback
|
|
9
|
+
* through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
|
|
10
|
+
* not a behavioral re-implementation.
|
|
11
|
+
*
|
|
12
|
+
* Only the members the specs and the production fallback actually touch are
|
|
13
|
+
* declared; the full 0.1.5 surface exists at runtime in provider.js.
|
|
14
|
+
*/
|
|
15
|
+
import { Service } from '@deepseek-ai/cordis'
|
|
16
|
+
|
|
17
|
+
export declare abstract class SettingsProvider extends Service {
|
|
18
|
+
/** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
|
|
19
|
+
constructor(ctx: Context)
|
|
20
|
+
/** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
|
|
21
|
+
abstract readonly writable: boolean
|
|
22
|
+
/** Load the provider's raw document (namespace → raw section) once at init. */
|
|
23
|
+
protected abstract load(): Promise<Record<string, unknown>>
|
|
24
|
+
/** Durably store one namespace's merged user section. */
|
|
25
|
+
protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
|
|
26
|
+
/** Register a namespace schema; duplicate registration fails loud. */
|
|
27
|
+
register(ns: string, schema: unknown, options?: unknown): unknown
|
|
28
|
+
/** Read one registered namespace's resolved value (undefined while unregistered). */
|
|
29
|
+
get(ns: string): unknown
|
|
30
|
+
/** Merge a patch into one registered namespace's user layer, validate, persist. */
|
|
31
|
+
update(ns: string, patch: object, expectedRevision?: number): Promise<void>
|
|
32
|
+
/** Replace one registered namespace's user section wholesale, validate, persist. */
|
|
33
|
+
replace(ns: string, section: object, expectedRevision?: number): Promise<void>
|
|
34
|
+
/** Apply path-addressed edits to one registered namespace's user section. */
|
|
35
|
+
mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
|
|
36
|
+
/** Describe every registered namespace for configuration surfaces. */
|
|
37
|
+
describe(options?: { redactSecrets?: boolean }): unknown[]
|
|
38
|
+
/** Non-file providers expose no open-document affordance. */
|
|
39
|
+
get documentPath(): string | undefined
|
|
40
|
+
prepareDocument(): Promise<string | undefined>
|
|
41
|
+
}
|