dsh-context-compression-improved 0.6.5 → 0.7.0-beta.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.
Files changed (70) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -211
  3. package/CHANGELOG.ko.md +211 -205
  4. package/CHANGELOG.md +392 -350
  5. package/CHANGELOG.zh.md +196 -190
  6. package/README.md +97 -96
  7. package/README.zh.md +86 -85
  8. package/eslint.config.js +76 -30
  9. package/package.json +3 -1
  10. package/packages/selector/dsh.plugin.json +1 -1
  11. package/packages/selector/lib/client.js +747 -3
  12. package/packages/selector/lib/index.js +92 -1
  13. package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
  14. package/packages/selector/lib/profiles.d.ts +9 -0
  15. package/packages/selector/lib/pruner.d.ts +59 -0
  16. package/packages/selector/lib/pruner.js +410 -8
  17. package/packages/selector/src/client/decode.ts +53 -49
  18. package/packages/selector/src/client/index.ts +30 -0
  19. package/packages/selector/src/client/locales/de.ts +98 -0
  20. package/packages/selector/src/client/locales/es.ts +98 -0
  21. package/packages/selector/src/client/locales/fr.ts +98 -0
  22. package/packages/selector/src/client/locales/it.ts +98 -0
  23. package/packages/selector/src/client/locales/ja.ts +98 -0
  24. package/packages/selector/src/client/locales/ko.ts +98 -0
  25. package/packages/selector/src/client/locales/ru.ts +98 -0
  26. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  27. package/packages/selector/src/index.ts +418 -411
  28. package/packages/selector/src/preset-overlay.ts +629 -626
  29. package/packages/selector/src/profiles.ts +414 -394
  30. package/packages/selector/src/pruner/content.ts +198 -198
  31. package/packages/selector/src/pruner/state.ts +57 -50
  32. package/packages/selector/src/pruner.ts +2665 -2421
  33. package/packages/selector/src/runtime/audit.ts +303 -286
  34. package/packages/selector/src/runtime/config.ts +731 -706
  35. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  36. package/packages/selector/src/runtime/summary-command.ts +133 -0
  37. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
  38. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
  39. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  40. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  41. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  42. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  43. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  44. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -303
  45. package/packages/selector/src/runtime/types.ts +358 -346
  46. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
  47. package/packages/selector/tests/built/client-artifact.spec.ts +61 -59
  48. package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
  49. package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
  50. package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
  51. package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
  52. package/packages/selector/tests/profiles.client.spec.tsx +436 -434
  53. package/packages/selector/tests/runtime/audit.spec.ts +275 -274
  54. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  55. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  56. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  57. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  58. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
  59. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  60. package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
  61. package/scripts/packed-components-smoke.mjs +734 -732
  62. package/scripts/packed-install-e2e.mjs +1275 -1273
  63. package/scripts/verify-release.mjs +318 -317
  64. package/tests/TEST_INVENTORY.md +41 -41
  65. package/tsconfig.tests.json +17 -15
  66. package/vitest.config.ts +57 -43
  67. package/.agents-stash-064.patch +0 -39
  68. package/_dsh_devdeps.json +0 -50
  69. package/_verify064/package/package.json +0 -162
  70. package/_verify064/package/packages/selector/src/client/index.ts +0 -232
@@ -1,213 +1,214 @@
1
- // @vitest-environment jsdom
2
-
3
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
- import { useSyncExternalStore } from 'react'
5
- import { afterEach, describe, expect, it, vi } from 'vitest'
6
- import {
7
- CompressionProfileSelector,
8
- ContextCompressionSettingsSection,
9
- type CompressionProfileSelectorProps,
10
- type ContextCompressionSettings,
11
- } from '../src/client/CompressionProfileSelector.tsx'
12
- import { en } from '../src/client/locales.ts'
13
-
14
- afterEach(cleanup)
15
-
16
- interface SettingsScopeSnapshot<T> {
17
- status: 'loading' | 'ready' | 'unavailable'
18
- value: T | undefined
19
- base: T | undefined
20
- user: T | undefined
21
- revision: number | undefined
22
- writable: boolean
23
- mode: 'host' | 'memory'
24
- }
25
-
26
- interface SnapshotStore<T> {
27
- readonly getSnapshot: () => T
28
- readonly subscribe: (listener: () => void) => () => void
29
- readonly update: (recipe: (draft: T) => void) => void
30
- }
31
-
32
- function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
33
- let snapshot = structuredClone(initial)
34
- const listeners = new Set<() => void>()
35
- return {
36
- getSnapshot: () => snapshot,
37
- subscribe(listener) {
38
- listeners.add(listener)
39
- return () => { listeners.delete(listener) }
40
- },
41
- update(recipe) {
42
- const draft = structuredClone(snapshot)
43
- recipe(draft)
44
- snapshot = draft
45
- for (const listener of listeners) listener()
46
- },
47
- }
48
- }
49
-
50
- function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
51
- return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
52
- return useSyncExternalStore(
53
- store.subscribe,
54
- () => selector(store.getSnapshot()),
55
- () => selector(store.getSnapshot()),
56
- )
57
- }
58
- }
59
-
60
- const DEFAULT_CUSTOM = {
61
- version: 1,
62
- unit: 'tokens',
63
- fresh: { enabled: true, trigger: 4_096, target: 2_048 },
64
- aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
65
- history: {
66
- enabled: true,
67
- trigger: 32_768,
68
- keepRecentTurns: 2,
69
- keepRecent: 16_384,
70
- minReclaim: 8_192,
71
- },
72
- prefixPolicy: 'pressure-break',
73
- } as const satisfies ContextCompressionSettings['custom']
74
-
75
- const t = (key: string) => en[key as keyof typeof en] ?? key
76
-
77
- interface MountOptions {
78
- readonly value?: ContextCompressionSettings
79
- readonly saveAutoCompact?: (thresholdPercent: number) => Promise<void>
80
- readonly settingsSection?: boolean
81
- readonly writable?: boolean
82
- readonly status?: 'loading' | 'ready'
83
- }
84
-
85
- function mountAutoCompact(options: MountOptions = {}) {
86
- const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
87
- status: options.status ?? 'ready',
88
- value: options.value ?? {
89
- profile: 'balanced',
90
- custom: structuredClone(DEFAULT_CUSTOM),
91
- autoCompact: { thresholdPercent: 80 },
92
- codeSkeleton: { enabled: false },
93
- },
94
- base: undefined,
95
- user: undefined,
96
- revision: 0,
97
- writable: options.writable ?? true,
98
- mode: 'host',
99
- })
100
- const sessions = createSnapshotStore({
101
- ids: ['s1'],
102
- byId: { s1: { id: 's1', displayTitle: 's1', running: false, blank: true, updatedAt: 0, agentPreset: 'standard' } },
103
- current: 's1',
104
- phase: 'ready',
105
- subagentsByParent: {},
106
- jobsBySession: {},
107
- currentAddress: undefined,
108
- })
109
- const saveAutoCompact = options.saveAutoCompact ?? vi.fn(() => Promise.resolve())
110
- const Component = options.settingsSection === false ? CompressionProfileSelector : ContextCompressionSettingsSection
111
- render(<Component {...({
112
- useCompression: bindSnapshotSelector(state),
113
- useSessions: bindSnapshotSelector(sessions),
114
- select: vi.fn(() => Promise.resolve()),
115
- saveCustom: vi.fn(() => Promise.resolve()),
116
- resetCustom: vi.fn(() => Promise.resolve()),
117
- saveAutoCompact,
118
- t,
119
- } as unknown as CompressionProfileSelectorProps)} />)
120
- return { state, saveAutoCompact }
121
- }
122
-
123
- const INPUT_LABEL = 'Auto Compact threshold (%)'
124
-
125
- describe('Auto Compact threshold controls', () => {
126
- it('renders the editor only inside the context-compression settings section', () => {
127
- mountAutoCompact({ settingsSection: true })
128
- expect(screen.getByLabelText(INPUT_LABEL)).not.toBeNull()
129
- expect(screen.queryByRole('slider')).toBeNull()
130
- for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
131
-
132
- // The compact workspace selector shows a summary, never a second editor.
133
- cleanup()
134
- mountAutoCompact({ settingsSection: false })
135
- expect(screen.queryByLabelText(INPUT_LABEL)).toBeNull()
136
- expect(screen.queryByRole('slider')).toBeNull()
137
- expect(screen.getByText(/Auto Compact threshold: 80%/)).not.toBeNull()
138
- })
139
-
140
- it('saves a non-quick value like 73 and reads the same value back after remount', async () => {
141
- const saving = vi.fn((thresholdPercent: number): Promise<void> => {
142
- mounted.state.update(draft => {
143
- if (draft.value !== undefined) draft.value.autoCompact = { thresholdPercent }
144
- })
145
- return Promise.resolve()
146
- })
147
- const mounted = mountAutoCompact({ settingsSection: true, saveAutoCompact: saving })
148
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
149
- fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
150
- await waitFor(() => { expect(mounted.state.getSnapshot().value?.autoCompact).toEqual({ thresholdPercent: 73 }) })
151
-
152
- // A fresh mount reads the same persisted settings.
153
- cleanup()
154
- mountAutoCompact({
155
- settingsSection: true,
156
- value: { profile: 'balanced', custom: structuredClone(DEFAULT_CUSTOM), autoCompact: { thresholdPercent: 73 }, codeSkeleton: { enabled: false } },
157
- })
158
- expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).value).toBe('73')
159
- })
160
-
161
- it.each(['49', '91', '72.5', 'abc', ''])('blocks saving the invalid draft %s', (draft) => {
162
- const { saveAutoCompact } = mountAutoCompact({ settingsSection: true })
163
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: draft } })
164
- expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
165
- expect(screen.getByText(/must be an integer between 50 and 90/)).not.toBeNull()
166
- expect(saveAutoCompact).not.toHaveBeenCalled()
167
- })
168
-
169
- it('uses the typed number input as the only threshold editor', () => {
170
- mountAutoCompact({ settingsSection: true })
171
- const input = screen.getByLabelText<HTMLInputElement>(INPUT_LABEL)
172
- fireEvent.change(input, { target: { value: '73' } })
173
- expect(input.value).toBe('73')
174
- expect(screen.queryByRole('slider')).toBeNull()
175
- for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
176
- })
177
-
178
- it('explains the risk outside the recommended 70–85 band but keeps saving available', () => {
179
- mountAutoCompact({ settingsSection: true })
180
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '65' } })
181
- expect(screen.getByText(/summarization calls and prefix rebuilds/)).not.toBeNull()
182
- expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
183
-
184
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '90' } })
185
- expect(screen.getByText(/shared by requests and output/)).not.toBeNull()
186
- expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
187
-
188
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '80' } })
189
- expect(screen.queryByText(/summarization calls and prefix rebuilds/)).toBeNull()
190
- expect(screen.queryByText(/shared by requests and output/)).toBeNull()
191
- })
192
-
193
- it('disables every control while saving or when the scope is not writable', () => {
194
- const { saveAutoCompact } = mountAutoCompact({ settingsSection: true, status: 'loading' })
195
- expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
196
- expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
197
- expect(saveAutoCompact).not.toHaveBeenCalled()
198
-
199
- cleanup()
200
- mountAutoCompact({ settingsSection: true, writable: false })
201
- expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
202
- expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
203
- })
204
-
205
- it('shows a failed threshold save inline', async () => {
206
- const rejected = Promise.reject(new Error('threshold write failed'))
207
- void rejected.catch(() => {})
208
- mountAutoCompact({ settingsSection: true, saveAutoCompact: () => rejected })
209
- fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
210
- fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
211
- await waitFor(() => { expect(screen.getByRole('alert').textContent).toContain('threshold write failed') })
212
- })
213
- })
1
+ // @vitest-environment jsdom
2
+
3
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+ import { useSyncExternalStore } from 'react'
5
+ import { afterEach, describe, expect, it, vi } from 'vitest'
6
+ import {
7
+ CompressionProfileSelector,
8
+ ContextCompressionSettingsSection,
9
+ type CompressionProfileSelectorProps,
10
+ type ContextCompressionSettings,
11
+ } from '../src/client/CompressionProfileSelector.tsx'
12
+ import { en } from '../src/client/locales.ts'
13
+
14
+ afterEach(cleanup)
15
+
16
+ interface SettingsScopeSnapshot<T> {
17
+ status: 'loading' | 'ready' | 'unavailable'
18
+ value: T | undefined
19
+ base: T | undefined
20
+ user: T | undefined
21
+ revision: number | undefined
22
+ writable: boolean
23
+ mode: 'host' | 'memory'
24
+ }
25
+
26
+ interface SnapshotStore<T> {
27
+ readonly getSnapshot: () => T
28
+ readonly subscribe: (listener: () => void) => () => void
29
+ readonly update: (recipe: (draft: T) => void) => void
30
+ }
31
+
32
+ function createSnapshotStore<T>(initial: T): SnapshotStore<T> {
33
+ let snapshot = structuredClone(initial)
34
+ const listeners = new Set<() => void>()
35
+ return {
36
+ getSnapshot: () => snapshot,
37
+ subscribe(listener) {
38
+ listeners.add(listener)
39
+ return () => { listeners.delete(listener) }
40
+ },
41
+ update(recipe) {
42
+ const draft = structuredClone(snapshot)
43
+ recipe(draft)
44
+ snapshot = draft
45
+ for (const listener of listeners) listener()
46
+ },
47
+ }
48
+ }
49
+
50
+ function bindSnapshotSelector<T>(store: SnapshotStore<T>) {
51
+ return function useSnapshotSelector<U>(selector: (snapshot: T) => U): U {
52
+ return useSyncExternalStore(
53
+ store.subscribe,
54
+ () => selector(store.getSnapshot()),
55
+ () => selector(store.getSnapshot()),
56
+ )
57
+ }
58
+ }
59
+
60
+ const DEFAULT_CUSTOM = {
61
+ version: 1,
62
+ unit: 'tokens',
63
+ fresh: { enabled: true, trigger: 4_096, target: 2_048 },
64
+ aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
65
+ history: {
66
+ enabled: true,
67
+ trigger: 32_768,
68
+ keepRecentTurns: 2,
69
+ keepRecent: 16_384,
70
+ minReclaim: 8_192,
71
+ },
72
+ prefixPolicy: 'pressure-break',
73
+ } as const satisfies ContextCompressionSettings['custom']
74
+
75
+ const t = (key: string) => en[key as keyof typeof en] ?? key
76
+
77
+ interface MountOptions {
78
+ readonly value?: ContextCompressionSettings
79
+ readonly saveAutoCompact?: (thresholdPercent: number) => Promise<void>
80
+ readonly settingsSection?: boolean
81
+ readonly writable?: boolean
82
+ readonly status?: 'loading' | 'ready'
83
+ }
84
+
85
+ function mountAutoCompact(options: MountOptions = {}) {
86
+ const state = createSnapshotStore<SettingsScopeSnapshot<ContextCompressionSettings>>({
87
+ status: options.status ?? 'ready',
88
+ value: options.value ?? {
89
+ profile: 'balanced',
90
+ custom: structuredClone(DEFAULT_CUSTOM),
91
+ autoCompact: { thresholdPercent: 80 },
92
+ codeSkeleton: { enabled: false },
93
+ intentSummary: { enabled: false },
94
+ },
95
+ base: undefined,
96
+ user: undefined,
97
+ revision: 0,
98
+ writable: options.writable ?? true,
99
+ mode: 'host',
100
+ })
101
+ const sessions = createSnapshotStore({
102
+ ids: ['s1'],
103
+ byId: { s1: { id: 's1', displayTitle: 's1', running: false, blank: true, updatedAt: 0, agentPreset: 'standard' } },
104
+ current: 's1',
105
+ phase: 'ready',
106
+ subagentsByParent: {},
107
+ jobsBySession: {},
108
+ currentAddress: undefined,
109
+ })
110
+ const saveAutoCompact = options.saveAutoCompact ?? vi.fn(() => Promise.resolve())
111
+ const Component = options.settingsSection === false ? CompressionProfileSelector : ContextCompressionSettingsSection
112
+ render(<Component {...({
113
+ useCompression: bindSnapshotSelector(state),
114
+ useSessions: bindSnapshotSelector(sessions),
115
+ select: vi.fn(() => Promise.resolve()),
116
+ saveCustom: vi.fn(() => Promise.resolve()),
117
+ resetCustom: vi.fn(() => Promise.resolve()),
118
+ saveAutoCompact,
119
+ t,
120
+ } as unknown as CompressionProfileSelectorProps)} />)
121
+ return { state, saveAutoCompact }
122
+ }
123
+
124
+ const INPUT_LABEL = 'Auto Compact threshold (%)'
125
+
126
+ describe('Auto Compact threshold controls', () => {
127
+ it('renders the editor only inside the context-compression settings section', () => {
128
+ mountAutoCompact({ settingsSection: true })
129
+ expect(screen.getByLabelText(INPUT_LABEL)).not.toBeNull()
130
+ expect(screen.queryByRole('slider')).toBeNull()
131
+ for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
132
+
133
+ // The compact workspace selector shows a summary, never a second editor.
134
+ cleanup()
135
+ mountAutoCompact({ settingsSection: false })
136
+ expect(screen.queryByLabelText(INPUT_LABEL)).toBeNull()
137
+ expect(screen.queryByRole('slider')).toBeNull()
138
+ expect(screen.getByText(/Auto Compact threshold: 80%/)).not.toBeNull()
139
+ })
140
+
141
+ it('saves a non-quick value like 73 and reads the same value back after remount', async () => {
142
+ const saving = vi.fn((thresholdPercent: number): Promise<void> => {
143
+ mounted.state.update(draft => {
144
+ if (draft.value !== undefined) draft.value.autoCompact = { thresholdPercent }
145
+ })
146
+ return Promise.resolve()
147
+ })
148
+ const mounted = mountAutoCompact({ settingsSection: true, saveAutoCompact: saving })
149
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
150
+ fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
151
+ await waitFor(() => { expect(mounted.state.getSnapshot().value?.autoCompact).toEqual({ thresholdPercent: 73 }) })
152
+
153
+ // A fresh mount reads the same persisted settings.
154
+ cleanup()
155
+ mountAutoCompact({
156
+ settingsSection: true,
157
+ value: { profile: 'balanced', custom: structuredClone(DEFAULT_CUSTOM), autoCompact: { thresholdPercent: 73 }, codeSkeleton: { enabled: false }, intentSummary: { enabled: false } },
158
+ })
159
+ expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).value).toBe('73')
160
+ })
161
+
162
+ it.each(['49', '91', '72.5', 'abc', ''])('blocks saving the invalid draft %s', (draft) => {
163
+ const { saveAutoCompact } = mountAutoCompact({ settingsSection: true })
164
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: draft } })
165
+ expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
166
+ expect(screen.getByText(/must be an integer between 50 and 90/)).not.toBeNull()
167
+ expect(saveAutoCompact).not.toHaveBeenCalled()
168
+ })
169
+
170
+ it('uses the typed number input as the only threshold editor', () => {
171
+ mountAutoCompact({ settingsSection: true })
172
+ const input = screen.getByLabelText<HTMLInputElement>(INPUT_LABEL)
173
+ fireEvent.change(input, { target: { value: '73' } })
174
+ expect(input.value).toBe('73')
175
+ expect(screen.queryByRole('slider')).toBeNull()
176
+ for (const quick of ['70%', '80%', '85%']) expect(screen.queryByRole('button', { name: quick })).toBeNull()
177
+ })
178
+
179
+ it('explains the risk outside the recommended 70–85 band but keeps saving available', () => {
180
+ mountAutoCompact({ settingsSection: true })
181
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '65' } })
182
+ expect(screen.getByText(/summarization calls and prefix rebuilds/)).not.toBeNull()
183
+ expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
184
+
185
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '90' } })
186
+ expect(screen.getByText(/shared by requests and output/)).not.toBeNull()
187
+ expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(false)
188
+
189
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '80' } })
190
+ expect(screen.queryByText(/summarization calls and prefix rebuilds/)).toBeNull()
191
+ expect(screen.queryByText(/shared by requests and output/)).toBeNull()
192
+ })
193
+
194
+ it('disables every control while saving or when the scope is not writable', () => {
195
+ const { saveAutoCompact } = mountAutoCompact({ settingsSection: true, status: 'loading' })
196
+ expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
197
+ expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
198
+ expect(saveAutoCompact).not.toHaveBeenCalled()
199
+
200
+ cleanup()
201
+ mountAutoCompact({ settingsSection: true, writable: false })
202
+ expect(screen.getByLabelText<HTMLInputElement>(INPUT_LABEL).disabled).toBe(true)
203
+ expect(screen.getByRole<HTMLButtonElement>('button', { name: 'Save Auto Compact threshold' }).disabled).toBe(true)
204
+ })
205
+
206
+ it('shows a failed threshold save inline', async () => {
207
+ const rejected = Promise.reject(new Error('threshold write failed'))
208
+ void rejected.catch(() => {})
209
+ mountAutoCompact({ settingsSection: true, saveAutoCompact: () => rejected })
210
+ fireEvent.change(screen.getByLabelText(INPUT_LABEL), { target: { value: '73' } })
211
+ fireEvent.click(screen.getByRole('button', { name: 'Save Auto Compact threshold' }))
212
+ await waitFor(() => { expect(screen.getByRole('alert').textContent).toContain('threshold write failed') })
213
+ })
214
+ })
@@ -1,59 +1,61 @@
1
- import { readFileSync } from 'node:fs'
2
- import { resolve } from 'node:path'
3
- import * as React from 'react'
4
- import * as jsxRuntime from 'react/jsx-runtime'
5
- import { describe, expect, it } from 'vitest'
6
-
7
- const artifact = resolve(import.meta.dirname, '../../lib/client.js')
8
-
9
- describe('built Harness client artifact', () => {
10
- it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
11
- const code = readFileSync(artifact, 'utf8')
12
- let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
13
- const moduleLoader = {
14
- load(value: typeof registration) {
15
- registration = value
16
- },
17
- }
18
- Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
19
-
20
- expect(() => Function(code)()).not.toThrow()
21
- expect(registration?.id).toBe('dsh-context-compression-improved')
22
-
23
- const modules = new Map<string, unknown>([
24
- ['react', React],
25
- ['react/jsx-runtime', jsxRuntime],
26
- // The current selector only keeps this official package as a side-effect
27
- // external. A minimal public-module stub proves the artifact asks the
28
- // Harness loader for it without importing the package's raw CSS in Node.
29
- ['@deepseek-ai/dsh-client-ui-primitives', {}],
30
- ])
31
- const exported = registration?.factory((id) => {
32
- if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
33
- return modules.get(id)
34
- }) as { apply?: unknown, inject?: unknown }
35
-
36
- expect(exported.apply).toBeTypeOf('function')
37
- // Declare every consumed service: cordis holds apply until each one is
38
- // provided, which is the official client-plugin pattern on this 0.1.5 host
39
- // line (dsh-thinking-levels does the same). The earlier lazy alternative —
40
- // resolving `locale` / `settingsScope` through ctx.get() inside apply —
41
- // raced the settings client's activation; on a loss the apply
42
- // early-returned and EVERY settings entry (the standalone section, the
43
- // plugins-tab card, the item card) silently vanished. See the rationale
44
- // recorded in src/client/index.ts.
45
- expect(exported.inject).toEqual(['slots', 'locale', 'settingsScope'])
46
- const style = document.querySelector<HTMLStyleElement>(
47
- 'style[data-plugin-css="dsh-context-compression-improved/CompressionProfileSelector.module.css"]',
48
- )
49
- expect(style?.dataset.plugin).toBe('dsh-context-compression-improved')
50
- expect(style?.textContent).toContain('profileGrid')
51
- expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
52
-
53
- registration?.factory((id) => modules.get(id))
54
- expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
55
- expect(code).not.toMatch(/^\s*(?:import|export)\s/mu)
56
- expect(code).not.toMatch(/(?:\/home\/|[A-Za-z]:\\Users\\)/u)
57
- expect(code).not.toContain('sourceMappingURL')
58
- })
59
- })
1
+ import { readFileSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
3
+ import * as React from 'react'
4
+ import * as jsxRuntime from 'react/jsx-runtime'
5
+ import { describe, expect, it } from 'vitest'
6
+
7
+ const artifact = resolve(import.meta.dirname, '../../lib/client.js')
8
+
9
+ describe('built Harness client artifact', () => {
10
+ it('registers a self-contained lazy-CJS factory and injects its CSS', () => {
11
+ const code = readFileSync(artifact, 'utf8')
12
+ let registration: { id: string, factory: (require: (id: string) => unknown) => unknown } | undefined
13
+ const moduleLoader = {
14
+ load(value: typeof registration) {
15
+ registration = value
16
+ },
17
+ }
18
+ Object.defineProperty(window, '__ModuleLoader__', { configurable: true, value: moduleLoader })
19
+
20
+ // The smoke evaluates the built IIFE bundle the same way a browser page would.
21
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
22
+ expect(() => Function(code)()).not.toThrow()
23
+ expect(registration?.id).toBe('dsh-context-compression-improved')
24
+
25
+ const modules = new Map<string, unknown>([
26
+ ['react', React],
27
+ ['react/jsx-runtime', jsxRuntime],
28
+ // The current selector only keeps this official package as a side-effect
29
+ // external. A minimal public-module stub proves the artifact asks the
30
+ // Harness loader for it without importing the package's raw CSS in Node.
31
+ ['@deepseek-ai/dsh-client-ui-primitives', {}],
32
+ ])
33
+ const exported = registration?.factory((id) => {
34
+ if (!modules.has(id)) throw new Error(`unexpected client dependency: ${id}`)
35
+ return modules.get(id)
36
+ }) as { apply?: unknown, inject?: unknown }
37
+
38
+ expect(exported.apply).toBeTypeOf('function')
39
+ // Declare every consumed service: cordis holds apply until each one is
40
+ // provided, which is the official client-plugin pattern on this 0.1.5 host
41
+ // line (dsh-thinking-levels does the same). The earlier lazy alternative —
42
+ // resolving `locale` / `settingsScope` through ctx.get() inside apply —
43
+ // raced the settings client's activation; on a loss the apply
44
+ // early-returned and EVERY settings entry (the standalone section, the
45
+ // plugins-tab card, the item card) silently vanished. See the rationale
46
+ // recorded in src/client/index.ts.
47
+ expect(exported.inject).toEqual(['slots', 'locale', 'settingsScope'])
48
+ const style = document.querySelector<HTMLStyleElement>(
49
+ 'style[data-plugin-css="dsh-context-compression-improved/CompressionProfileSelector.module.css"]',
50
+ )
51
+ expect(style?.dataset.plugin).toBe('dsh-context-compression-improved')
52
+ expect(style?.textContent).toContain('profileGrid')
53
+ expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
54
+
55
+ registration?.factory((id) => modules.get(id))
56
+ expect(document.querySelectorAll('style[data-plugin-css]').length).toBe(1)
57
+ expect(code).not.toMatch(/^\s*(?:import|export)\s/mu)
58
+ expect(code).not.toMatch(/(?:\/home\/|[A-Za-z]:\\Users\\)/u)
59
+ expect(code).not.toContain('sourceMappingURL')
60
+ })
61
+ })