dsh-context-compression-improved 0.6.0 → 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 +6 -6
- 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 +1 -1
- 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/code-skeleton.client.spec.ts +93 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +222 -222
- package/packages/selector/tests/helpers/legacy-namespace.ts +31 -31
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +1 -1
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -206
- package/packages/selector/tests/public/package-contract.client.spec.ts +78 -78
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -3
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -20
- package/packages/selector/tests/settings-seat.client.spec.ts +118 -118
- package/packages/selector/tests/standing-generation.host.spec.ts +704 -704
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/pnpm-workspace.yaml +42 -42
|
@@ -36,7 +36,7 @@ import ToolRuntime from '@deepseek-ai/dsh-tools'
|
|
|
36
36
|
import { CompactionId } from '@deepseek-ai/dsh-compaction'
|
|
37
37
|
import InvariantRegistry from '@deepseek-ai/dsh-invariants'
|
|
38
38
|
import * as SelectorHost from '../../../src/index.ts'
|
|
39
|
-
import { LegacyNamespaceRegistrar } from '../../helpers/legacy-namespace.ts'
|
|
39
|
+
import { LegacyNamespaceRegistrar } from '../../helpers/legacy-namespace.ts'
|
|
40
40
|
import * as RuntimeInvariant from '../../../src/invariant.ts'
|
|
41
41
|
import { sessionEvents } from '../../../src/runtime/session-events.ts'
|
|
42
42
|
import ToolResultPruner, {
|
|
@@ -425,7 +425,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
425
425
|
// replacement → audit record) without ever touching the replacement text.
|
|
426
426
|
const ctx = await runtimeContext()
|
|
427
427
|
await ctx.plugin(TestSettings).await()
|
|
428
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
428
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
429
429
|
await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
|
|
430
430
|
profile: 'balanced',
|
|
431
431
|
codeSkeleton: { enabled: true },
|
|
@@ -590,7 +590,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
590
590
|
it('moves the capacity-pressure gate with the frozen Auto Compact threshold', async () => {
|
|
591
591
|
const ctx = await runtimeContext()
|
|
592
592
|
await ctx.plugin(TestSettings).await()
|
|
593
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
593
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
594
594
|
const audit = captureAudit(ctx)
|
|
595
595
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
596
596
|
|
|
@@ -626,7 +626,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
626
626
|
it('ages History earlier when the frozen Auto Compact threshold is low', async () => {
|
|
627
627
|
const ctx = await runtimeContext()
|
|
628
628
|
await ctx.plugin(TestSettings).await()
|
|
629
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
629
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
630
630
|
const audit = captureAudit(ctx)
|
|
631
631
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
632
632
|
|
|
@@ -660,7 +660,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
660
660
|
it('freezes the generation-owned threshold over later global settings changes', async () => {
|
|
661
661
|
const ctx = await runtimeContext()
|
|
662
662
|
await ctx.plugin(TestSettings).await()
|
|
663
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
663
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
664
664
|
const audit = captureAudit(ctx)
|
|
665
665
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
666
666
|
// The preset overlay captured 70% into this generation's deployment
|
|
@@ -696,7 +696,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
696
696
|
it('fails open to a lossless frozen policy when stored settings are malformed', async () => {
|
|
697
697
|
const ctx = await runtimeContext()
|
|
698
698
|
await ctx.plugin(TestSettings).await()
|
|
699
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
699
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
700
700
|
const audit = captureAudit(ctx)
|
|
701
701
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
702
702
|
// A hand-edited store can surface a document the schema rejects (unknown
|
|
@@ -746,7 +746,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
746
746
|
])('fails open to a lossless frozen policy when the stored document carries %s', async (label, malformed) => {
|
|
747
747
|
const ctx = await runtimeContext()
|
|
748
748
|
await ctx.plugin(TestSettings).await()
|
|
749
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
749
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
750
750
|
const audit = captureAudit(ctx)
|
|
751
751
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
752
752
|
// Schemastery `.default(...)` would silently replace these present-but-null
|
|
@@ -783,7 +783,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
783
783
|
|
|
784
784
|
const ctx = await runtimeContext()
|
|
785
785
|
await ctx.plugin(TestSettings).await()
|
|
786
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
786
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
787
787
|
const audit = captureAudit(ctx)
|
|
788
788
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
789
789
|
const malformed = {
|
|
@@ -883,7 +883,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
883
883
|
it('audits the Auto Compact coordination block on policy resolution', async () => {
|
|
884
884
|
const ctx = await runtimeContext()
|
|
885
885
|
await ctx.plugin(TestSettings).await()
|
|
886
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
886
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
887
887
|
const audit = captureAudit(ctx)
|
|
888
888
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
889
889
|
await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
|
|
@@ -920,7 +920,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
920
920
|
const overrideCtx = await runtimeContext()
|
|
921
921
|
await overrideCtx.plugin(TestSettings).await()
|
|
922
922
|
await overrideCtx.plugin(SelectorHost).await()
|
|
923
|
-
await overrideCtx.plugin(LegacyNamespaceRegistrar).await()
|
|
923
|
+
await overrideCtx.plugin(LegacyNamespaceRegistrar).await()
|
|
924
924
|
const overrideAudit = captureAudit(overrideCtx)
|
|
925
925
|
await overrideCtx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
|
|
926
926
|
await overrideCtx.plugin(ToolResultPruner, {
|
|
@@ -946,7 +946,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
946
946
|
const mixedCtx = await runtimeContext()
|
|
947
947
|
await mixedCtx.plugin(TestSettings).await()
|
|
948
948
|
await mixedCtx.plugin(SelectorHost).await()
|
|
949
|
-
await mixedCtx.plugin(LegacyNamespaceRegistrar).await()
|
|
949
|
+
await mixedCtx.plugin(LegacyNamespaceRegistrar).await()
|
|
950
950
|
const mixedAudit = captureAudit(mixedCtx)
|
|
951
951
|
await mixedCtx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
|
|
952
952
|
await mixedCtx.plugin(ToolResultPruner, {
|
|
@@ -982,7 +982,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
982
982
|
it('freezes the Auto Compact threshold per Session and applies new values only to new Sessions', async () => {
|
|
983
983
|
const ctx = await runtimeContext()
|
|
984
984
|
await ctx.plugin(TestSettings).await()
|
|
985
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
985
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
986
986
|
const audit = captureAudit(ctx)
|
|
987
987
|
const namespace = nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE)
|
|
988
988
|
await ctx.plugin(ToolResultPruner, { profile: 'balanced' }).await()
|
|
@@ -1506,7 +1506,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
1506
1506
|
it('still commits unlinked Custom History batches at the minimum reclaim', async () => {
|
|
1507
1507
|
const ctx = await runtimeContext()
|
|
1508
1508
|
await ctx.plugin(TestSettings).await()
|
|
1509
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1509
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1510
1510
|
const audit = captureAudit(ctx)
|
|
1511
1511
|
// A protected token tail larger than the trigger leaves the linked-style
|
|
1512
1512
|
// whole-excess demand unreachable; Custom stays manual and must still
|
|
@@ -1692,7 +1692,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
1692
1692
|
const ctx = new Context()
|
|
1693
1693
|
activeContexts.push(ctx)
|
|
1694
1694
|
await ctx.plugin(TestSettings).await()
|
|
1695
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1695
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1696
1696
|
await ctx.plugin(SessionStore).await()
|
|
1697
1697
|
await ctx.plugin(SystemPrompt).await()
|
|
1698
1698
|
await ctx.plugin(ToolRuntime).await()
|
|
@@ -1754,7 +1754,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
1754
1754
|
const ctx = new Context()
|
|
1755
1755
|
activeContexts.push(ctx)
|
|
1756
1756
|
await ctx.plugin(TestSettings).await()
|
|
1757
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1757
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1758
1758
|
await ctx.plugin(SessionStore).await()
|
|
1759
1759
|
await ctx.plugin(SystemPrompt).await()
|
|
1760
1760
|
await ctx.plugin(ToolRuntime).await()
|
|
@@ -1851,7 +1851,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
1851
1851
|
const ctx = new Context()
|
|
1852
1852
|
activeContexts.push(ctx)
|
|
1853
1853
|
await ctx.plugin(TestSettings).await()
|
|
1854
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1854
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1855
1855
|
await ctx.plugin(SessionStore).await()
|
|
1856
1856
|
await ctx.plugin(SystemPrompt).await()
|
|
1857
1857
|
await ctx.plugin(ToolRuntime).await()
|
|
@@ -1944,7 +1944,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
1944
1944
|
const ctx = new Context()
|
|
1945
1945
|
activeContexts.push(ctx)
|
|
1946
1946
|
await ctx.plugin(TestSettings).await()
|
|
1947
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1947
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
1948
1948
|
await ctx.plugin(SessionStore).await()
|
|
1949
1949
|
await ctx.plugin(InvariantRegistry).await()
|
|
1950
1950
|
await ctx.plugin(RuntimeInvariant).await()
|
|
@@ -2124,7 +2124,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
2124
2124
|
const ctx = new Context()
|
|
2125
2125
|
activeContexts.push(ctx)
|
|
2126
2126
|
await ctx.plugin(TestSettings).await()
|
|
2127
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2127
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2128
2128
|
await ctx.plugin(LlmRuntime).await()
|
|
2129
2129
|
await ctx.plugin(SessionStore).await()
|
|
2130
2130
|
await ctx.plugin(SystemPrompt).await()
|
|
@@ -2571,7 +2571,7 @@ describe('standalone runtime on published Harness APIs', () => {
|
|
|
2571
2571
|
it('never TailTrims a tool group whose results carry images', async () => {
|
|
2572
2572
|
const ctx = await runtimeContext()
|
|
2573
2573
|
await ctx.plugin(TestSettings).await()
|
|
2574
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2574
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2575
2575
|
const audit = captureAudit(ctx)
|
|
2576
2576
|
await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
|
|
2577
2577
|
profile: 'custom',
|
|
@@ -2663,7 +2663,7 @@ describe('character basis / model-id independence', () => {
|
|
|
2663
2663
|
async function characterBasisContext(): Promise<Context> {
|
|
2664
2664
|
const ctx = await runtimeContext()
|
|
2665
2665
|
await ctx.plugin(TestSettings).await()
|
|
2666
|
-
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2666
|
+
await ctx.plugin(LegacyNamespaceRegistrar).await()
|
|
2667
2667
|
await ctx.settings.update(nsBrand(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE), {
|
|
2668
2668
|
profile: 'balanced',
|
|
2669
2669
|
codeSkeleton: { enabled: true },
|
|
@@ -1,118 +1,118 @@
|
|
|
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
|
-
|
|
20
|
-
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
21
|
-
|
|
22
|
-
Menu: () => null,
|
|
23
|
-
}))
|
|
24
|
-
|
|
25
|
-
interface CapturedRegistration {
|
|
26
|
-
readonly slot: string
|
|
27
|
-
readonly options: Record<string, unknown>
|
|
28
|
-
readonly component: unknown
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Drive apply against a stub host and capture every slot registration.
|
|
33
|
-
* @param options - `registerThrows` models an older host that does not declare
|
|
34
|
-
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
35
|
-
* 0.1.2-era hosts had.
|
|
36
|
-
*/
|
|
37
|
-
function collectRegistrations(
|
|
38
|
-
options: { readonly registerThrows?: boolean } = {},
|
|
39
|
-
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
40
|
-
const declared: string[] = []
|
|
41
|
-
const registrations: CapturedRegistration[] = []
|
|
42
|
-
const ctx = {
|
|
43
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
44
|
-
configForms: { get: vi.fn(() => ({}) as never) },
|
|
45
|
-
slots: {
|
|
46
|
-
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
47
|
-
declared.push(slot)
|
|
48
|
-
const result = factory()
|
|
49
|
-
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
50
|
-
? (result as Generator<() => void>)
|
|
51
|
-
: [result as () => void]
|
|
52
|
-
for (const step of steps) { void step }
|
|
53
|
-
return () => {}
|
|
54
|
-
},
|
|
55
|
-
register: (record: Record<string, unknown>, component: unknown) => {
|
|
56
|
-
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
57
|
-
registrations.push({ slot: String(record['name']), options: record, component })
|
|
58
|
-
return () => {}
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
apply(ctx as unknown as ClientContext)
|
|
63
|
-
return { declared, registrations }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
describe('settings-seat contract (standalone settings.section only)', () => {
|
|
67
|
-
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
68
|
-
expect(inject).toEqual(['slots', 'locale', 'configForms'])
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('injects exactly the settings.section seat and nothing else', () => {
|
|
72
|
-
const { declared, registrations } = collectRegistrations()
|
|
73
|
-
expect(declared).toEqual(['settings.section'])
|
|
74
|
-
expect(registrations).toHaveLength(1)
|
|
75
|
-
expect(registrations[0]!.slot).toBe('settings.section')
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
79
|
-
const { declared } = collectRegistrations()
|
|
80
|
-
expect(declared).not.toContain('shell.overlay')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
84
|
-
const { registrations } = collectRegistrations()
|
|
85
|
-
const { options, component } = registrations[0]!
|
|
86
|
-
expect(options['id']).toBe('context-compression')
|
|
87
|
-
expect(options['order']).toBe(17)
|
|
88
|
-
expect(options['locale']).toBe('context-compression')
|
|
89
|
-
expect((options['label'] as () => string)()).toBe('nav')
|
|
90
|
-
expect(typeof options['inject']).toBe('function')
|
|
91
|
-
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
92
|
-
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
93
|
-
expect(component).toBe(ContextCompressionSettingsSection)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
97
|
-
const { declared } = collectRegistrations()
|
|
98
|
-
expect(declared).not.toContain('settings.plugins.tab')
|
|
99
|
-
expect(declared).not.toContain('settings.plugin.item')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
103
|
-
// Cross-version tolerance: a host without this seat rejects the
|
|
104
|
-
// registration at the slot boundary. apply() must swallow that and warn —
|
|
105
|
-
// the historical failure mode was apply() bailing out, which silently took
|
|
106
|
-
// EVERY settings entry down with it.
|
|
107
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
108
|
-
try {
|
|
109
|
-
const { declared } = collectRegistrations({ registerThrows: true })
|
|
110
|
-
// It tried the seat (so the degradation is "loud", not a silent no-op)…
|
|
111
|
-
expect(declared).toEqual(['settings.section'])
|
|
112
|
-
// …and the rejection never escaped apply().
|
|
113
|
-
expect(warn).toHaveBeenCalled()
|
|
114
|
-
} finally {
|
|
115
|
-
warn.mockRestore()
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
})
|
|
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
|
+
|
|
20
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
21
|
+
IconChevronDownOutlineMedium: () => null,
|
|
22
|
+
Menu: () => null,
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
interface CapturedRegistration {
|
|
26
|
+
readonly slot: string
|
|
27
|
+
readonly options: Record<string, unknown>
|
|
28
|
+
readonly component: unknown
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Drive apply against a stub host and capture every slot registration.
|
|
33
|
+
* @param options - `registerThrows` models an older host that does not declare
|
|
34
|
+
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
35
|
+
* 0.1.2-era hosts had.
|
|
36
|
+
*/
|
|
37
|
+
function collectRegistrations(
|
|
38
|
+
options: { readonly registerThrows?: boolean } = {},
|
|
39
|
+
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
40
|
+
const declared: string[] = []
|
|
41
|
+
const registrations: CapturedRegistration[] = []
|
|
42
|
+
const ctx = {
|
|
43
|
+
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
44
|
+
configForms: { get: vi.fn(() => ({}) as never) },
|
|
45
|
+
slots: {
|
|
46
|
+
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
47
|
+
declared.push(slot)
|
|
48
|
+
const result = factory()
|
|
49
|
+
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
50
|
+
? (result as Generator<() => void>)
|
|
51
|
+
: [result as () => void]
|
|
52
|
+
for (const step of steps) { void step }
|
|
53
|
+
return () => {}
|
|
54
|
+
},
|
|
55
|
+
register: (record: Record<string, unknown>, component: unknown) => {
|
|
56
|
+
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
57
|
+
registrations.push({ slot: String(record['name']), options: record, component })
|
|
58
|
+
return () => {}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
apply(ctx as unknown as ClientContext)
|
|
63
|
+
return { declared, registrations }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('settings-seat contract (standalone settings.section only)', () => {
|
|
67
|
+
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
68
|
+
expect(inject).toEqual(['slots', 'locale', 'configForms'])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('injects exactly the settings.section seat and nothing else', () => {
|
|
72
|
+
const { declared, registrations } = collectRegistrations()
|
|
73
|
+
expect(declared).toEqual(['settings.section'])
|
|
74
|
+
expect(registrations).toHaveLength(1)
|
|
75
|
+
expect(registrations[0]!.slot).toBe('settings.section')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
79
|
+
const { declared } = collectRegistrations()
|
|
80
|
+
expect(declared).not.toContain('shell.overlay')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
84
|
+
const { registrations } = collectRegistrations()
|
|
85
|
+
const { options, component } = registrations[0]!
|
|
86
|
+
expect(options['id']).toBe('context-compression')
|
|
87
|
+
expect(options['order']).toBe(17)
|
|
88
|
+
expect(options['locale']).toBe('context-compression')
|
|
89
|
+
expect((options['label'] as () => string)()).toBe('nav')
|
|
90
|
+
expect(typeof options['inject']).toBe('function')
|
|
91
|
+
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
92
|
+
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
93
|
+
expect(component).toBe(ContextCompressionSettingsSection)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
97
|
+
const { declared } = collectRegistrations()
|
|
98
|
+
expect(declared).not.toContain('settings.plugins.tab')
|
|
99
|
+
expect(declared).not.toContain('settings.plugin.item')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
103
|
+
// Cross-version tolerance: a host without this seat rejects the
|
|
104
|
+
// registration at the slot boundary. apply() must swallow that and warn —
|
|
105
|
+
// the historical failure mode was apply() bailing out, which silently took
|
|
106
|
+
// EVERY settings entry down with it.
|
|
107
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
108
|
+
try {
|
|
109
|
+
const { declared } = collectRegistrations({ registerThrows: true })
|
|
110
|
+
// It tried the seat (so the degradation is "loud", not a silent no-op)…
|
|
111
|
+
expect(declared).toEqual(['settings.section'])
|
|
112
|
+
// …and the rejection never escaped apply().
|
|
113
|
+
expect(warn).toHaveBeenCalled()
|
|
114
|
+
} finally {
|
|
115
|
+
warn.mockRestore()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
})
|