dsh-context-compression-improved 0.6.0 → 0.6.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.
@@ -1,93 +1,93 @@
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
- })
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
+ })
@@ -1,31 +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
- }
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
+ }