dsh-context-compression-improved 0.5.4 → 0.6.0
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/README.md +10 -1
- package/package.json +162 -140
- package/packages/selector/README.md +6 -1
- package/packages/selector/README.zh.md +6 -1
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/advisor-state.js +1 -1
- package/packages/selector/lib/client.d.ts +19 -104
- package/packages/selector/lib/client.js +42 -5
- package/packages/selector/lib/index.d.ts +9 -0
- package/packages/selector/lib/index.js +18 -50
- package/packages/selector/lib/profiles.d.ts +105 -0
- package/packages/selector/lib/pruner.js +3 -2
- package/packages/selector/package.json +114 -114
- package/packages/selector/src/client/index.ts +71 -8
- package/packages/selector/src/index.ts +35 -86
- package/packages/selector/src/pruner.ts +12 -3
- package/packages/selector/src/runtime/config.ts +1 -1
- package/packages/selector/tests/code-skeleton.client.spec.ts +93 -90
- package/packages/selector/tests/custom-contract.client.spec.ts +19 -1
- package/packages/selector/tests/helpers/legacy-namespace.ts +31 -0
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +206 -206
- package/packages/selector/tests/preset-options-write.client.spec.ts +63 -82
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +206 -201
- package/packages/selector/tests/public/package-contract.client.spec.ts +2 -2
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +3 -2
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +20 -17
- package/packages/selector/tests/settings-seat.client.spec.ts +2 -2
- package/packages/selector/tests/standing-generation.host.spec.ts +704 -697
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Context } from '@deepseek-ai/cordis'
|
|
4
4
|
import z from '@deepseek-ai/schemastery'
|
|
5
|
-
import {
|
|
6
|
-
type SettingsScope,
|
|
7
|
-
type default as SettingsService,
|
|
8
|
-
} from '@deepseek-ai/dsh-settings'
|
|
9
5
|
import { buildEstimatorCatalog, type EstimatorCatalogDeps } from './estimator-catalog.ts'
|
|
6
|
+
import type { ContextCompressionSettings } from './profiles.ts'
|
|
10
7
|
import {
|
|
11
8
|
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
12
9
|
ContextCompressionSettingsSchema,
|
|
10
|
+
DEFAULT_CONTEXT_COMPRESSION_SETTINGS,
|
|
13
11
|
} from './runtime/config.ts'
|
|
14
12
|
|
|
15
13
|
import { getAdvisorState } from './runtime/tokenpilot/advisor-state.ts'
|
|
@@ -21,7 +19,6 @@ import { getAdvisorState } from './runtime/tokenpilot/advisor-state.ts'
|
|
|
21
19
|
// package, so the real schema is back and the daily Custom defaults are
|
|
22
20
|
// published again through settings.register(). The namespace value is
|
|
23
21
|
// unchanged ('context-compression').
|
|
24
|
-
const CONTEXT_COMPRESSION_NAMESPACE = CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never
|
|
25
22
|
import {
|
|
26
23
|
decorateAgentPresets,
|
|
27
24
|
resolveCompressionModulePaths,
|
|
@@ -295,31 +292,20 @@ function registerEstimatorCatalogRoute(ctx: Context): void {
|
|
|
295
292
|
log('warn', 'context-compression webServer not active yet — estimator catalog route pending: %s', ESTIMATOR_CATALOG_ROUTES.join(', '))
|
|
296
293
|
}
|
|
297
294
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
scope: SettingsScope<unknown>
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** One selector Host row able to own the registration effect. */
|
|
311
|
-
interface SettingsOwner {
|
|
312
|
-
/** Traceable service proxy binding register() to this row's fiber. */
|
|
313
|
-
readonly settings: SettingsService
|
|
295
|
+
/**
|
|
296
|
+
* Resolve one possibly-volatile field: a live ref on 0.1.7+, a plain value
|
|
297
|
+
* otherwise (0.1.7 hands `.volatile()` fields to `apply()` as live refs).
|
|
298
|
+
*/
|
|
299
|
+
function readVolatileValue<T>(value: T | { get(): T } | undefined): T | undefined {
|
|
300
|
+
if (value !== null && typeof value === 'object' && typeof (value as { get?: unknown }).get === 'function') {
|
|
301
|
+
return (value as { get(): T }).get()
|
|
302
|
+
}
|
|
303
|
+
return value as T | undefined
|
|
314
304
|
}
|
|
315
305
|
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
type SettingsCarrier = SettingsService & {
|
|
322
|
-
[SHARED_SETTINGS]?: SharedSettingsRegistration
|
|
306
|
+
/** The compression settings document carried by this row's composition entry. */
|
|
307
|
+
function readCompressionDoc(config: Config | undefined): ContextCompressionSettings | undefined {
|
|
308
|
+
return readVolatileValue(config?.settings)
|
|
323
309
|
}
|
|
324
310
|
|
|
325
311
|
/** Standalone Bundle behavior; the settings/UI owner remains safe when false. */
|
|
@@ -346,14 +332,25 @@ export interface Config {
|
|
|
346
332
|
* `presetOptions.advisor*` settings keys.
|
|
347
333
|
*/
|
|
348
334
|
advisorReportRoute?: boolean
|
|
335
|
+
/**
|
|
336
|
+
* 0.1.7: the compression settings document as ONE `.volatile()` whole-object
|
|
337
|
+
* field (the old dedicated namespace has no declarative equivalent). The
|
|
338
|
+
* browser selector writes it through `configForms`; the runtime reads the
|
|
339
|
+
* dereferenced value. Loose section schemas keep unknown keys — the strict
|
|
340
|
+
* validation stays in `decodeSettings` (client) and the runtime resolver.
|
|
341
|
+
*/
|
|
342
|
+
settings?: ContextCompressionSettings
|
|
349
343
|
}
|
|
350
344
|
|
|
351
345
|
/** Loader validation for the standalone Bundle opt-in. */
|
|
352
|
-
export const Config
|
|
346
|
+
export const Config = z.object({
|
|
353
347
|
presetOverlay: z.boolean().default(false),
|
|
354
348
|
estimatorCatalogRoute: z.boolean().default(false),
|
|
355
349
|
advisorReportRoute: z.boolean().default(false),
|
|
356
|
-
|
|
350
|
+
// The daily Custom defaults ride the field's schema default so every
|
|
351
|
+
// composition resolves a complete document without a stored user layer.
|
|
352
|
+
settings: z.any().default(DEFAULT_CONTEXT_COMPRESSION_SETTINGS).volatile(),
|
|
353
|
+
}) as unknown as z<Config>
|
|
357
354
|
|
|
358
355
|
/** Register the persisted default read by the currently mounted root pruner. */
|
|
359
356
|
export function apply(ctx: Context, config: Config = {}): void {
|
|
@@ -363,10 +360,6 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
363
360
|
// and quietly did nothing. Report it to a sink the host shows, then re-throw
|
|
364
361
|
// unchanged: behaviour is untouched, only observability is restored.
|
|
365
362
|
try {
|
|
366
|
-
ctx.inject(['settings'], (settingsCtx) => {
|
|
367
|
-
acquireSettingsRegistration(settingsCtx)
|
|
368
|
-
})
|
|
369
|
-
|
|
370
363
|
// The settings card's host-route dropdowns read this route; it lives on the
|
|
371
364
|
// top-level plugin fiber, not inside the isolated `toolResultPruner`
|
|
372
365
|
// service, because the route is host-wide rather than per-pruner-instance.
|
|
@@ -383,7 +376,7 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
383
376
|
{
|
|
384
377
|
modules: resolveCompressionModulePaths(),
|
|
385
378
|
excludedPresetIds: ['minimal'],
|
|
386
|
-
autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(presetsCtx),
|
|
379
|
+
autoCompactThresholdPercent: () => resolveAutoCompactThresholdPercent(config, presetsCtx),
|
|
387
380
|
},
|
|
388
381
|
)
|
|
389
382
|
presetsCtx.effect(() => () => installation.dispose(), 'contextCompressionSelector.agentPresets()')
|
|
@@ -399,8 +392,13 @@ export function apply(ctx: Context, config: Config = {}): void {
|
|
|
399
392
|
* values are revalidated here, and any unreadable value falls back to the 80%
|
|
400
393
|
* default rather than blocking preset composition.
|
|
401
394
|
*/
|
|
402
|
-
function resolveAutoCompactThresholdPercent(
|
|
403
|
-
|
|
395
|
+
function resolveAutoCompactThresholdPercent(config: Config | undefined, presetsCtx?: Context): number {
|
|
396
|
+
// 0.1.7: the volatile entry field is authoritative; the legacy per-namespace
|
|
397
|
+
// read stays as a fallback so a host that still serves the old service shape
|
|
398
|
+
// keeps working (test hosts do exactly that).
|
|
399
|
+
const raw = readCompressionDoc(config)
|
|
400
|
+
?? (presetsCtx?.get('settings') as { get?: (ns: never) => unknown } | undefined)
|
|
401
|
+
?.get?.(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never)
|
|
404
402
|
try {
|
|
405
403
|
const record = structuredClone(raw) as Record<string, unknown> | undefined
|
|
406
404
|
const threshold = record?.autoCompact as { thresholdPercent?: number } | undefined
|
|
@@ -411,53 +409,4 @@ function resolveAutoCompactThresholdPercent(presetsCtx: Context): number {
|
|
|
411
409
|
}
|
|
412
410
|
}
|
|
413
411
|
|
|
414
|
-
/**
|
|
415
|
-
* Lease one native settings registration across duplicate Host rows.
|
|
416
|
-
*
|
|
417
|
-
* The lease effect is intentionally registered before settings.register().
|
|
418
|
-
* Cordis disposes effects in reverse order, so the native registration first
|
|
419
|
-
* releases the namespace; this disposer can then transfer it to another live
|
|
420
|
-
* owner without a duplicate-registration window.
|
|
421
|
-
*/
|
|
422
|
-
function acquireSettingsRegistration(ctx: Context): void {
|
|
423
|
-
const settings = ctx.settings as SettingsCarrier
|
|
424
|
-
const owner: SettingsOwner = { settings }
|
|
425
|
-
let shared = settings[SHARED_SETTINGS]
|
|
426
|
-
if (shared === undefined) {
|
|
427
|
-
shared = {
|
|
428
|
-
owners: new Set(),
|
|
429
|
-
registrationOwner: owner,
|
|
430
|
-
scope: undefined as unknown as SettingsScope<unknown>,
|
|
431
|
-
}
|
|
432
|
-
Object.defineProperty(settings, SHARED_SETTINGS, {
|
|
433
|
-
configurable: true,
|
|
434
|
-
enumerable: false,
|
|
435
|
-
writable: false,
|
|
436
|
-
value: shared,
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
shared.owners.add(owner)
|
|
440
|
-
const state = shared
|
|
441
|
-
|
|
442
|
-
ctx.effect(() => () => {
|
|
443
|
-
state.owners.delete(owner)
|
|
444
|
-
if (state.registrationOwner === owner && state.owners.size > 0) {
|
|
445
|
-
const next = state.owners.values().next().value as SettingsOwner
|
|
446
|
-
state.registrationOwner = next
|
|
447
|
-
state.scope = next.settings.register(
|
|
448
|
-
CONTEXT_COMPRESSION_NAMESPACE,
|
|
449
|
-
ContextCompressionSettingsSchema,
|
|
450
|
-
)
|
|
451
|
-
}
|
|
452
|
-
if (state.owners.size === 0 && settings[SHARED_SETTINGS] === state) {
|
|
453
|
-
Reflect.deleteProperty(settings, SHARED_SETTINGS)
|
|
454
|
-
}
|
|
455
|
-
}, 'contextCompressionSelector.settingsLease()')
|
|
456
412
|
|
|
457
|
-
if (state.owners.size === 1) {
|
|
458
|
-
state.scope = settings.register(
|
|
459
|
-
CONTEXT_COMPRESSION_NAMESPACE,
|
|
460
|
-
ContextCompressionSettingsSchema,
|
|
461
|
-
)
|
|
462
|
-
}
|
|
463
|
-
}
|
|
@@ -423,9 +423,18 @@ export class ToolResultPruner extends Service {
|
|
|
423
423
|
private activeSettings(session: Session): ContextCompressionSettings {
|
|
424
424
|
const frozen = this.state.sessionSettings.get(session)
|
|
425
425
|
if (frozen !== undefined) return frozen
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
|
|
426
|
+
// 0.1.7: the compression document rides the selector row's entry config as a
|
|
427
|
+
// `.volatile()` field — read it through the settings service's describe()
|
|
428
|
+
// mirror (keyed by the profile entry id). The legacy per-namespace get stays
|
|
429
|
+
// as a fallback; both are undefined-safe and the caller handles absence.
|
|
430
|
+
const settingsHost = this.ctx.get('settings') as {
|
|
431
|
+
describe?: () => Array<{ ns: unknown; value?: unknown }>
|
|
432
|
+
get?: (ns: never) => unknown
|
|
433
|
+
} | undefined
|
|
434
|
+
const settings = (settingsHost?.describe?.().find(
|
|
435
|
+
(d) => String(d.ns) === 'context-compression-improved-bundle',
|
|
436
|
+
)?.value
|
|
437
|
+
?? settingsHost?.get?.(CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never)) as ContextCompressionSettings | undefined
|
|
429
438
|
let resolved: ContextCompressionSettings
|
|
430
439
|
let settingsSource: 'host-settings' | 'plugin-config-fallback' = settings === undefined
|
|
431
440
|
? 'plugin-config-fallback'
|
|
@@ -248,7 +248,7 @@ const isSupportedProfile = (value: unknown): boolean =>
|
|
|
248
248
|
const isUsableCustomDocument = (value: unknown): boolean =>
|
|
249
249
|
isPlainRecord(value)
|
|
250
250
|
|
|
251
|
-
const DEFAULT_CONTEXT_COMPRESSION_SETTINGS: ContextCompressionSettings = {
|
|
251
|
+
export const DEFAULT_CONTEXT_COMPRESSION_SETTINGS: ContextCompressionSettings = {
|
|
252
252
|
profile: 'balanced',
|
|
253
253
|
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
254
254
|
autoCompact: { thresholdPercent: AUTO_COMPACT_THRESHOLD_LIMITS.default },
|
|
@@ -1,90 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
-
import { apply } from '../src/client/index.ts'
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
subscribe: vi.fn(() => () => {}),
|
|
39
|
-
set: vi.fn(async (
|
|
40
|
-
if (!commit) return
|
|
41
|
-
revision += 1
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
accepted
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
apply
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
flipEnabled =
|
|
86
|
-
await expect(actions.saveCodeSkeleton(false)).
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
5
|
+
import { apply } from '../src/client/index.ts'
|
|
6
|
+
import type { CompressionSelectorInjected } from '../src/client/CompressionProfileSelector.tsx'
|
|
7
|
+
import type { ContextCompressionSettings } from '../src/profiles.ts'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 0.1.7 contract: `codeSkeleton` rides the entry config as part of the volatile
|
|
11
|
+
* `settings` whole-object field. Every write commits the full doc through
|
|
12
|
+
* `configForms.set('settings', doc)`; the confirm-on-write semantics are
|
|
13
|
+
* unchanged — a host that silently drops (or flips) the section fails the
|
|
14
|
+
* acceptance check on the post-commit snapshot.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
describe('codeSkeleton confirm-on-write client contract', () => {
|
|
18
|
+
it('resolves only when the host confirms the toggled value and rejects silent drops', async () => {
|
|
19
|
+
let revision = 3
|
|
20
|
+
let commit = false
|
|
21
|
+
let flipEnabled = false
|
|
22
|
+
let value: ContextCompressionSettings = {
|
|
23
|
+
profile: 'balanced',
|
|
24
|
+
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
25
|
+
autoCompact: { thresholdPercent: 80 },
|
|
26
|
+
codeSkeleton: { enabled: false },
|
|
27
|
+
}
|
|
28
|
+
const form = {
|
|
29
|
+
getSnapshot: vi.fn(() => ({
|
|
30
|
+
status: 'ready' as const,
|
|
31
|
+
value: { settings: value },
|
|
32
|
+
base: undefined,
|
|
33
|
+
user: undefined,
|
|
34
|
+
revision,
|
|
35
|
+
writable: true,
|
|
36
|
+
mode: 'host' as const,
|
|
37
|
+
})),
|
|
38
|
+
subscribe: vi.fn(() => () => {}),
|
|
39
|
+
set: vi.fn(async (_field: string, next: unknown) => {
|
|
40
|
+
if (!commit) return false
|
|
41
|
+
revision += 1
|
|
42
|
+
const doc = structuredClone(next) as ContextCompressionSettings
|
|
43
|
+
if (flipEnabled) {
|
|
44
|
+
const accepted = structuredClone(doc.codeSkeleton)
|
|
45
|
+
accepted.enabled = !accepted.enabled
|
|
46
|
+
value = { ...doc, codeSkeleton: accepted }
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
value = doc
|
|
50
|
+
return true
|
|
51
|
+
}),
|
|
52
|
+
unset: vi.fn(async () => false),
|
|
53
|
+
}
|
|
54
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
55
|
+
const ctx = {
|
|
56
|
+
effect: (install: () => unknown) => { install() },
|
|
57
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
58
|
+
configForms: { get: vi.fn(() => form) },
|
|
59
|
+
slots: {
|
|
60
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
61
|
+
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
62
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
63
|
+
if (typeof registration.inject === 'function') injected = registration.inject
|
|
64
|
+
return () => {}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
} as unknown as Parameters<typeof apply>[0]
|
|
68
|
+
|
|
69
|
+
apply(ctx)
|
|
70
|
+
const actions = injected?.()
|
|
71
|
+
expect(actions).toBeDefined()
|
|
72
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
73
|
+
|
|
74
|
+
// A silent host drop leaves the revision untouched: the write must reject.
|
|
75
|
+
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
76
|
+
|
|
77
|
+
// A committed write resolves and persists the exact section payload under
|
|
78
|
+
// the volatile `settings` field.
|
|
79
|
+
commit = true
|
|
80
|
+
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
81
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: true } }))
|
|
82
|
+
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
83
|
+
|
|
84
|
+
// A host that flips the toggled bit fails the acceptance check.
|
|
85
|
+
flipEnabled = true
|
|
86
|
+
await expect(actions.saveCodeSkeleton(false)).rejects.toThrow('were not saved')
|
|
87
|
+
|
|
88
|
+
flipEnabled = false
|
|
89
|
+
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
90
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: false } }))
|
|
91
|
+
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -145,7 +145,25 @@ describe('context compression browser contract', () => {
|
|
|
145
145
|
const ctx = {
|
|
146
146
|
effect: (install: () => unknown) => { install() },
|
|
147
147
|
locale: { register: vi.fn(() => () => {}) },
|
|
148
|
-
|
|
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
|
+
},
|
|
149
167
|
slots: {
|
|
150
168
|
inject: (_slot: string, install: () => unknown) => { install() },
|
|
151
169
|
register: (registration: { inject?: () => CompressionSelectorInjected }) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-host helper: registers the legacy `context-compression` settings
|
|
3
|
+
* namespace on a 0.1.5-shaped test settings service, so specs can drive the
|
|
4
|
+
* plugin through `settings.update(...)` exactly as they did before the 0.1.7
|
|
5
|
+
* declarative migration. Production code reads the volatile entry field first
|
|
6
|
+
* and falls back to this namespace; on a real 0.1.7 host neither the
|
|
7
|
+
* registration nor this helper exists.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
|
|
11
|
+
ContextCompressionSettingsSchema,
|
|
12
|
+
} from '../../src/runtime/config.ts'
|
|
13
|
+
|
|
14
|
+
export const LegacyNamespaceRegistrar = {
|
|
15
|
+
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> {
|
|
19
|
+
await new Promise<void>((resolve) => {
|
|
20
|
+
ctx.inject(['settings'], (s) => {
|
|
21
|
+
try {
|
|
22
|
+
s.settings.register(
|
|
23
|
+
CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
|
|
24
|
+
ContextCompressionSettingsSchema,
|
|
25
|
+
)
|
|
26
|
+
} catch { /* already registered by an earlier row */ }
|
|
27
|
+
resolve()
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
}
|