dsh-context-compression-improved 0.6.4 → 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 +51 -0
- package/CHANGELOG.ko.md +47 -0
- package/CHANGELOG.md +72 -0
- package/CHANGELOG.zh.md +47 -0
- package/README.ja.md +2 -2
- package/README.ko.md +2 -2
- package/README.md +6 -3
- package/README.zh.md +3 -2
- package/eslint.config.js +76 -30
- package/package.json +164 -162
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.js +16 -4
- 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/package.json +114 -114
- package/packages/selector/src/client/decode.ts +6 -2
- package/packages/selector/src/client/index.ts +213 -232
- package/packages/selector/src/client/scope-face.ts +24 -24
- package/packages/selector/src/deepseek-v4-tokenizer.ts +1 -1
- package/packages/selector/src/index.ts +418 -412
- 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 -10
- 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 +3 -2
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- 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 +204 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -206
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- 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/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 +2736 -2727
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +165 -165
- package/packages/selector/tests/standing-generation.host.spec.ts +704 -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-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
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_CONTEXT_COMPRESSION_SETTINGS,
|
|
4
|
+
parseContextCompressionSettings,
|
|
5
|
+
} from '../../src/runtime/config.ts'
|
|
6
|
+
import {
|
|
7
|
+
getLastIntentFold,
|
|
8
|
+
getObservedIntentEnabled,
|
|
9
|
+
getSummaryOverride,
|
|
10
|
+
recordIntentFold,
|
|
11
|
+
setSummaryOverride,
|
|
12
|
+
observeIntentEnabled,
|
|
13
|
+
} from '../../src/runtime/tokenpilot/advisor-state.ts'
|
|
14
|
+
import {
|
|
15
|
+
parseSummaryCommandArgs,
|
|
16
|
+
registerSummaryCommand,
|
|
17
|
+
} from '../../src/runtime/summary-command.ts'
|
|
18
|
+
|
|
19
|
+
describe('intentSummary settings parsing', () => {
|
|
20
|
+
it('defaults to lossless off', () => {
|
|
21
|
+
expect(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.intentSummary).toEqual({ enabled: false })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('absent section inherits the default', () => {
|
|
25
|
+
const parsed = parseContextCompressionSettings({
|
|
26
|
+
profile: 'balanced',
|
|
27
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
28
|
+
autoCompact: { thresholdPercent: 80 },
|
|
29
|
+
codeSkeleton: { enabled: false },
|
|
30
|
+
})
|
|
31
|
+
expect(parsed.intentSummary).toEqual({ enabled: false })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('accepts exactly { enabled: boolean }', () => {
|
|
35
|
+
const parsed = parseContextCompressionSettings({
|
|
36
|
+
profile: 'balanced',
|
|
37
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
38
|
+
intentSummary: { enabled: true },
|
|
39
|
+
})
|
|
40
|
+
expect(parsed.intentSummary).toEqual({ enabled: true })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('rejects extra keys (present-but-invalid is never silently defaulted)', () => {
|
|
44
|
+
expect(() => parseContextCompressionSettings({
|
|
45
|
+
profile: 'balanced',
|
|
46
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
47
|
+
intentSummary: { enabled: true, gate: 1 },
|
|
48
|
+
})).toThrow(/expected exactly "enabled"/)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('rejects non-boolean enabled', () => {
|
|
52
|
+
expect(() => parseContextCompressionSettings({
|
|
53
|
+
profile: 'balanced',
|
|
54
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
55
|
+
intentSummary: { enabled: 'yes' },
|
|
56
|
+
})).toThrow(/intentSummary\.enabled must be a boolean/)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('rejects non-object section', () => {
|
|
60
|
+
expect(() => parseContextCompressionSettings({
|
|
61
|
+
profile: 'balanced',
|
|
62
|
+
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
63
|
+
intentSummary: true,
|
|
64
|
+
})).toThrow(/intentSummary must be a plain object/)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe('session-scoped summary override state', () => {
|
|
69
|
+
it('round-trips and clears per session id, isolated across sessions', () => {
|
|
70
|
+
expect(getSummaryOverride('s1')).toBeUndefined()
|
|
71
|
+
setSummaryOverride('s1', 'off')
|
|
72
|
+
setSummaryOverride('s2', 'on')
|
|
73
|
+
expect(getSummaryOverride('s1')).toBe('off')
|
|
74
|
+
expect(getSummaryOverride('s2')).toBe('on')
|
|
75
|
+
setSummaryOverride('s1', undefined)
|
|
76
|
+
expect(getSummaryOverride('s1')).toBeUndefined()
|
|
77
|
+
expect(getSummaryOverride('s2')).toBe('on')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('observed enabled flag round-trips independently', () => {
|
|
81
|
+
expect(getObservedIntentEnabled('sx')).toBeUndefined()
|
|
82
|
+
observeIntentEnabled('sx', true)
|
|
83
|
+
expect(getObservedIntentEnabled('sx')).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('last fold record is newest-wins per session', () => {
|
|
87
|
+
expect(getLastIntentFold('sy')).toBeUndefined()
|
|
88
|
+
recordIntentFold('sy', { turn: 3, startSeq: 10, endSeq: 20, liveTokensBefore: 100_000, at: 1 })
|
|
89
|
+
recordIntentFold('sy', { turn: 5, startSeq: 30, endSeq: 40, liveTokensBefore: 150_000, at: 2 })
|
|
90
|
+
expect(getLastIntentFold('sy')).toMatchObject({ turn: 5, startSeq: 30 })
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
describe('/ctx-summary command surface', () => {
|
|
95
|
+
it('parses exactly off|on|status (case-insensitive, trimmed)', () => {
|
|
96
|
+
expect(parseSummaryCommandArgs(' off ')).toBe('off')
|
|
97
|
+
expect(parseSummaryCommandArgs('ON')).toBe('on')
|
|
98
|
+
expect(parseSummaryCommandArgs('Status')).toBe('status')
|
|
99
|
+
expect(parseSummaryCommandArgs('')).toBeUndefined()
|
|
100
|
+
expect(parseSummaryCommandArgs('now')).toBeUndefined()
|
|
101
|
+
expect(parseSummaryCommandArgs('off extra')).toBeUndefined()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('handler sets and clears the override for the invocation session', async () => {
|
|
105
|
+
let registered: { name: string, handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: string, text: string }> } | undefined
|
|
106
|
+
const commands = { register: (definition: unknown): void => { registered = definition as typeof registered } }
|
|
107
|
+
const ctx = {
|
|
108
|
+
inject: (deps: readonly string[], callback: (injected: Record<string, unknown>) => void): void => {
|
|
109
|
+
if (deps.includes('commands')) callback({ commands })
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
registerSummaryCommand(ctx as never)
|
|
113
|
+
await vi.waitFor(() => expect(registered).toBeDefined())
|
|
114
|
+
expect(registered?.name).toBe('ctx-summary')
|
|
115
|
+
|
|
116
|
+
const agent = { session: { id: 'sess-1' } }
|
|
117
|
+
const off = await registered!.handler({ agent, rawInput: 'off' })
|
|
118
|
+
expect(off.kind).toBe('success')
|
|
119
|
+
expect(getSummaryOverride('sess-1')).toBe('off')
|
|
120
|
+
|
|
121
|
+
const on = await registered!.handler({ agent, rawInput: 'on' })
|
|
122
|
+
expect(on.kind).toBe('success')
|
|
123
|
+
expect(getSummaryOverride('sess-1')).toBe('on')
|
|
124
|
+
|
|
125
|
+
const bad = await registered!.handler({ agent, rawInput: 'wat' })
|
|
126
|
+
expect(bad.kind).toBe('error')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('status reports override, gate and last fold', async () => {
|
|
130
|
+
let registered: { handler: (invocation: { agent?: unknown, rawInput?: unknown }) => Promise<{ kind: string, text: string }> } | undefined
|
|
131
|
+
const commands = { register: (definition: unknown): void => { registered = definition as typeof registered } }
|
|
132
|
+
registerSummaryCommand({
|
|
133
|
+
inject: (_deps: readonly string[], callback: (injected: Record<string, unknown>) => void) => callback({ commands }),
|
|
134
|
+
} as never)
|
|
135
|
+
await vi.waitFor(() => expect(registered).toBeDefined())
|
|
136
|
+
recordIntentFold('sess-9', { turn: 7, startSeq: 5, endSeq: 9, liveTokensBefore: 120_000, at: 42 })
|
|
137
|
+
const out = await registered!.handler({ agent: { session: { id: 'sess-9' } }, rawInput: 'status' })
|
|
138
|
+
expect(out.kind).toBe('success')
|
|
139
|
+
expect(out.text).toContain('override: default')
|
|
140
|
+
expect(out.text).toContain('seq 5..9')
|
|
141
|
+
expect(out.text).toContain('45% of window')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('stays quiet when the commands service never mounts', () => {
|
|
145
|
+
const ctx = {
|
|
146
|
+
inject: (deps: readonly string[], callback: (injected: Record<string, unknown>) => void) => {
|
|
147
|
+
// cordis semantics: the callback never runs when a dependency is absent.
|
|
148
|
+
void deps
|
|
149
|
+
void callback
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
expect(() => registerSummaryCommand(ctx as never)).not.toThrow()
|
|
153
|
+
})
|
|
154
|
+
})
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings-seat contract pin for dsh-context-compression-improved's client.
|
|
3
|
-
*
|
|
4
|
-
* This spec locks WHERE the compression settings panel mounts: exactly ONE
|
|
5
|
-
* seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
|
|
6
|
-
* explicitly NOT the Plugins-section surfaces, and NOT a `shell.overlay` float
|
|
7
|
-
* (the retired review panel's seat was removed with the gate). History this
|
|
8
|
-
* pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
|
|
9
|
-
* locale/settingsScope raced the settings client and apply bailed), then showed
|
|
10
|
-
* the panel twice (item card + tab on top of the standalone section). Both were
|
|
11
|
-
* fixed by the declarative-inject + single-section shape below. When a future
|
|
12
|
-
* DSH line moves the seat again, migrate src/client/index.ts AND this file
|
|
13
|
-
* together.
|
|
14
|
-
*/
|
|
15
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
16
|
-
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
17
|
-
import { apply, inject } from '../src/client/index.ts'
|
|
18
|
-
import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
|
|
19
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
20
|
-
|
|
21
|
-
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
22
|
-
IconChevronDownOutlineMedium: () => null,
|
|
23
|
-
Menu: () => null,
|
|
24
|
-
}))
|
|
25
|
-
|
|
26
|
-
interface CapturedRegistration {
|
|
27
|
-
readonly slot: string
|
|
28
|
-
readonly options: Record<string, unknown>
|
|
29
|
-
readonly component: unknown
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Drive apply against a stub host and capture every slot registration.
|
|
34
|
-
* @param options - `registerThrows` models an older host that does not declare
|
|
35
|
-
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
36
|
-
* 0.1.2-era hosts had.
|
|
37
|
-
*/
|
|
38
|
-
function collectRegistrations(
|
|
39
|
-
options: { readonly registerThrows?: boolean } = {},
|
|
40
|
-
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
41
|
-
const declared: string[] = []
|
|
42
|
-
const registrations: CapturedRegistration[] = []
|
|
43
|
-
const ctx = {
|
|
44
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
45
|
-
configForms: { get: vi.fn(() => ({}) as never) },
|
|
46
|
-
slots: {
|
|
47
|
-
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
48
|
-
declared.push(slot)
|
|
49
|
-
const result = factory()
|
|
50
|
-
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
51
|
-
? (result as Generator<() => void>)
|
|
52
|
-
: [result as () => void]
|
|
53
|
-
for (const step of steps) { void step }
|
|
54
|
-
return () => {}
|
|
55
|
-
},
|
|
56
|
-
register: (record: Record<string, unknown>, component: unknown) => {
|
|
57
|
-
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
58
|
-
registrations.push({ slot: String(record['name']), options: record, component })
|
|
59
|
-
return () => {}
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
apply(ctx as unknown as ClientContext)
|
|
64
|
-
return { declared, registrations }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
describe('settings-seat contract (standalone settings.section only)', () => {
|
|
68
|
-
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
69
|
-
expect(inject).toEqual(['slots', 'locale', 'configForms'])
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('injects exactly the settings.section seat and nothing else', () => {
|
|
73
|
-
const { declared, registrations } = collectRegistrations()
|
|
74
|
-
expect(declared).toEqual(['settings.section'])
|
|
75
|
-
expect(registrations).toHaveLength(1)
|
|
76
|
-
expect(registrations[0]!.slot).toBe('settings.section')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
80
|
-
const { declared } = collectRegistrations()
|
|
81
|
-
expect(declared).not.toContain('shell.overlay')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
85
|
-
const { registrations } = collectRegistrations()
|
|
86
|
-
const { options, component } = registrations[0]!
|
|
87
|
-
expect(options['id']).toBe('context-compression')
|
|
88
|
-
expect(options['order']).toBe(17)
|
|
89
|
-
expect(options['locale']).toBe('context-compression')
|
|
90
|
-
expect((options['label'] as () => string)()).toBe('nav')
|
|
91
|
-
expect(typeof options['inject']).toBe('function')
|
|
92
|
-
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
93
|
-
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
94
|
-
expect(component).toBe(ContextCompressionSettingsSection)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
98
|
-
const { declared } = collectRegistrations()
|
|
99
|
-
expect(declared).not.toContain('settings.plugins.tab')
|
|
100
|
-
expect(declared).not.toContain('settings.plugin.item')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('projects an identity-stable snapshot between form changes (React #185 regression)', () => {
|
|
104
|
-
// The 0.1.7 adapter wraps configForms into the legacy scope shape. Its
|
|
105
|
-
// getSnapshot MUST return the same object reference until the underlying
|
|
106
|
-
// form snapshot changes: a fresh literal per call re-renders
|
|
107
|
-
// useSyncExternalStore forever — "Minified React error #185" (maximum
|
|
108
|
-
// update depth exceeded), and the slot boundary abdicates the whole
|
|
109
|
-
// settings.section on the production host.
|
|
110
|
-
let source = {
|
|
111
|
-
status: 'ready' as const,
|
|
112
|
-
value: { settings: { profile: 'balanced', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } },
|
|
113
|
-
revision: 1, writable: true, base: undefined, user: undefined, mode: 'host' as const,
|
|
114
|
-
}
|
|
115
|
-
const listeners: (() => void)[] = []
|
|
116
|
-
const ctx = {
|
|
117
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
118
|
-
configForms: { get: () => ({
|
|
119
|
-
getSnapshot: () => source,
|
|
120
|
-
subscribe: (listener: () => void) => { listeners.push(listener); return () => {} },
|
|
121
|
-
set: async () => true,
|
|
122
|
-
}) },
|
|
123
|
-
slots: {
|
|
124
|
-
inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
|
|
125
|
-
register: (record: Record<string, unknown>) => {
|
|
126
|
-
registrations.push({ slot: String(record['name']), options: record, component: null })
|
|
127
|
-
return () => {}
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
const registrations: CapturedRegistration[] = []
|
|
132
|
-
apply(ctx as unknown as ClientContext)
|
|
133
|
-
const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown; subscribe(l: () => void): () => void } } })()
|
|
134
|
-
const scope = face.hooks.compression
|
|
135
|
-
|
|
136
|
-
const first = scope.getSnapshot()
|
|
137
|
-
expect(scope.getSnapshot()).toBe(first)
|
|
138
|
-
// value decodes through the whole strict validator
|
|
139
|
-
expect(first && typeof first === 'object' && 'value' in first && (first as { value?: { profile?: string } }).value?.profile).toBe('balanced')
|
|
140
|
-
|
|
141
|
-
// Host accepts a change → NEW form snapshot object → projection recomputes
|
|
142
|
-
source = { ...source, revision: 2, value: { settings: { profile: 'off', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } } }
|
|
143
|
-
for (const listener of listeners) listener()
|
|
144
|
-
const second = scope.getSnapshot()
|
|
145
|
-
expect(second).not.toBe(first)
|
|
146
|
-
expect(second && typeof second === 'object' && 'value' in second && (second as { value?: { profile?: string } }).value?.profile).toBe('off')
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
150
|
-
// Cross-version tolerance: a host without this seat rejects the
|
|
151
|
-
// registration at the slot boundary. apply() must swallow that and warn —
|
|
152
|
-
// the historical failure mode was apply() bailing out, which silently took
|
|
153
|
-
// EVERY settings entry down with it.
|
|
154
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
155
|
-
try {
|
|
156
|
-
const { declared } = collectRegistrations({ registerThrows: true })
|
|
157
|
-
// It tried the seat (so the degradation is "loud", not a silent no-op)…
|
|
158
|
-
expect(declared).toEqual(['settings.section'])
|
|
159
|
-
// …and the rejection never escaped apply().
|
|
160
|
-
expect(warn).toHaveBeenCalled()
|
|
161
|
-
} finally {
|
|
162
|
-
warn.mockRestore()
|
|
163
|
-
}
|
|
164
|
-
})
|
|
165
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* Settings-seat contract pin for dsh-context-compression-improved's client.
|
|
3
|
+
*
|
|
4
|
+
* This spec locks WHERE the compression settings panel mounts: exactly ONE
|
|
5
|
+
* seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
|
|
6
|
+
* explicitly NOT the Plugins-section surfaces, and NOT a `shell.overlay` float
|
|
7
|
+
* (the retired review panel's seat was removed with the gate). History this
|
|
8
|
+
* pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
|
|
9
|
+
* locale/settingsScope raced the settings client and apply bailed), then showed
|
|
10
|
+
* the panel twice (item card + tab on top of the standalone section). Both were
|
|
11
|
+
* fixed by the declarative-inject + single-section shape below. When a future
|
|
12
|
+
* DSH line moves the seat again, migrate src/client/index.ts AND this file
|
|
13
|
+
* together.
|
|
14
|
+
*/
|
|
15
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
16
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
17
|
+
import { apply, inject } from '../src/client/index.ts'
|
|
18
|
+
import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
|
|
19
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
20
|
+
|
|
21
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
22
|
+
IconChevronDownOutlineMedium: () => null,
|
|
23
|
+
Menu: () => null,
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
interface CapturedRegistration {
|
|
27
|
+
readonly slot: string
|
|
28
|
+
readonly options: Record<string, unknown>
|
|
29
|
+
readonly component: unknown
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Drive apply against a stub host and capture every slot registration.
|
|
34
|
+
* @param options - `registerThrows` models an older host that does not declare
|
|
35
|
+
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
36
|
+
* 0.1.2-era hosts had.
|
|
37
|
+
*/
|
|
38
|
+
function collectRegistrations(
|
|
39
|
+
options: { readonly registerThrows?: boolean } = {},
|
|
40
|
+
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
41
|
+
const declared: string[] = []
|
|
42
|
+
const registrations: CapturedRegistration[] = []
|
|
43
|
+
const ctx = {
|
|
44
|
+
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
45
|
+
configForms: { get: vi.fn(() => ({}) as never) },
|
|
46
|
+
slots: {
|
|
47
|
+
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
48
|
+
declared.push(slot)
|
|
49
|
+
const result = factory()
|
|
50
|
+
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
51
|
+
? (result as Generator<() => void>)
|
|
52
|
+
: [result as () => void]
|
|
53
|
+
for (const step of steps) { void step }
|
|
54
|
+
return () => {}
|
|
55
|
+
},
|
|
56
|
+
register: (record: Record<string, unknown>, component: unknown) => {
|
|
57
|
+
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
58
|
+
registrations.push({ slot: String(record['name']), options: record, component })
|
|
59
|
+
return () => {}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
apply(ctx as unknown as ClientContext)
|
|
64
|
+
return { declared, registrations }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe('settings-seat contract (standalone settings.section only)', () => {
|
|
68
|
+
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
69
|
+
expect(inject).toEqual(['slots', 'locale', 'configForms'])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('injects exactly the settings.section seat and nothing else', () => {
|
|
73
|
+
const { declared, registrations } = collectRegistrations()
|
|
74
|
+
expect(declared).toEqual(['settings.section'])
|
|
75
|
+
expect(registrations).toHaveLength(1)
|
|
76
|
+
expect(registrations[0]!.slot).toBe('settings.section')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
80
|
+
const { declared } = collectRegistrations()
|
|
81
|
+
expect(declared).not.toContain('shell.overlay')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
85
|
+
const { registrations } = collectRegistrations()
|
|
86
|
+
const { options, component } = registrations[0]!
|
|
87
|
+
expect(options['id']).toBe('context-compression')
|
|
88
|
+
expect(options['order']).toBe(17)
|
|
89
|
+
expect(options['locale']).toBe('context-compression')
|
|
90
|
+
expect((options['label'] as () => string)()).toBe('nav')
|
|
91
|
+
expect(typeof options['inject']).toBe('function')
|
|
92
|
+
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
93
|
+
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
94
|
+
expect(component).toBe(ContextCompressionSettingsSection)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
98
|
+
const { declared } = collectRegistrations()
|
|
99
|
+
expect(declared).not.toContain('settings.plugins.tab')
|
|
100
|
+
expect(declared).not.toContain('settings.plugin.item')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('projects an identity-stable snapshot between form changes (React #185 regression)', () => {
|
|
104
|
+
// The 0.1.7 adapter wraps configForms into the legacy scope shape. Its
|
|
105
|
+
// getSnapshot MUST return the same object reference until the underlying
|
|
106
|
+
// form snapshot changes: a fresh literal per call re-renders
|
|
107
|
+
// useSyncExternalStore forever — "Minified React error #185" (maximum
|
|
108
|
+
// update depth exceeded), and the slot boundary abdicates the whole
|
|
109
|
+
// settings.section on the production host.
|
|
110
|
+
let source = {
|
|
111
|
+
status: 'ready' as const,
|
|
112
|
+
value: { settings: { profile: 'balanced', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } },
|
|
113
|
+
revision: 1, writable: true, base: undefined, user: undefined, mode: 'host' as const,
|
|
114
|
+
}
|
|
115
|
+
const listeners: (() => void)[] = []
|
|
116
|
+
const ctx = {
|
|
117
|
+
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
118
|
+
configForms: { get: () => ({
|
|
119
|
+
getSnapshot: () => source,
|
|
120
|
+
subscribe: (listener: () => void) => { listeners.push(listener); return () => {} },
|
|
121
|
+
set: async () => true,
|
|
122
|
+
}) },
|
|
123
|
+
slots: {
|
|
124
|
+
inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
|
|
125
|
+
register: (record: Record<string, unknown>) => {
|
|
126
|
+
registrations.push({ slot: String(record['name']), options: record, component: null })
|
|
127
|
+
return () => {}
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
const registrations: CapturedRegistration[] = []
|
|
132
|
+
apply(ctx as unknown as ClientContext)
|
|
133
|
+
const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown; subscribe(l: () => void): () => void } } })()
|
|
134
|
+
const scope = face.hooks.compression
|
|
135
|
+
|
|
136
|
+
const first = scope.getSnapshot()
|
|
137
|
+
expect(scope.getSnapshot()).toBe(first)
|
|
138
|
+
// value decodes through the whole strict validator
|
|
139
|
+
expect(first && typeof first === 'object' && 'value' in first && (first as { value?: { profile?: string } }).value?.profile).toBe('balanced')
|
|
140
|
+
|
|
141
|
+
// Host accepts a change → NEW form snapshot object → projection recomputes
|
|
142
|
+
source = { ...source, revision: 2, value: { settings: { profile: 'off', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } } }
|
|
143
|
+
for (const listener of listeners) listener()
|
|
144
|
+
const second = scope.getSnapshot()
|
|
145
|
+
expect(second).not.toBe(first)
|
|
146
|
+
expect(second && typeof second === 'object' && 'value' in second && (second as { value?: { profile?: string } }).value?.profile).toBe('off')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
150
|
+
// Cross-version tolerance: a host without this seat rejects the
|
|
151
|
+
// registration at the slot boundary. apply() must swallow that and warn —
|
|
152
|
+
// the historical failure mode was apply() bailing out, which silently took
|
|
153
|
+
// EVERY settings entry down with it.
|
|
154
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
155
|
+
try {
|
|
156
|
+
const { declared } = collectRegistrations({ registerThrows: true })
|
|
157
|
+
// It tried the seat (so the degradation is "loud", not a silent no-op)…
|
|
158
|
+
expect(declared).toEqual(['settings.section'])
|
|
159
|
+
// …and the rejection never escaped apply().
|
|
160
|
+
expect(warn).toHaveBeenCalled()
|
|
161
|
+
} finally {
|
|
162
|
+
warn.mockRestore()
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
})
|