dsh-context-compression-improved 0.10.2 → 0.10.3
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/.agents/plans/improve/checklist.md +32 -0
- package/.agents/plans/improve/findings.md +102 -0
- package/.agents/plans/improve/spec.md +53 -0
- package/.agents/plans/improve/tasks.md +70 -0
- package/.gitattributes +2 -0
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +39 -0
- package/CHANGELOG.de.md +580 -0
- package/CHANGELOG.es.md +588 -0
- package/CHANGELOG.fr.md +576 -0
- package/CHANGELOG.it.md +577 -0
- package/CHANGELOG.ja.md +261 -0
- package/CHANGELOG.ko.md +254 -0
- package/CHANGELOG.md +549 -0
- package/CHANGELOG.ru.md +554 -0
- package/CHANGELOG.zh.md +238 -0
- package/CONTRIBUTING.md +22 -0
- package/README.de.md +96 -0
- package/README.es.md +96 -0
- package/README.fr.md +96 -0
- package/README.it.md +96 -0
- package/README.ja.md +102 -0
- package/README.ko.md +102 -0
- package/README.md +110 -15
- package/README.ru.md +96 -0
- package/README.zh.md +104 -14
- package/SECURITY.md +18 -0
- package/THIRD_PARTY_NOTICES.md +7 -25
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/docs/assets/context-compression-selector-profiles.jpg +0 -0
- package/docs/assets/context-compression-selector-settings.png +0 -0
- package/docs/compat-0.1.5-report.md +77 -0
- package/docs/installation.de.md +104 -0
- package/docs/installation.es.md +104 -0
- package/docs/installation.fr.md +104 -0
- package/docs/installation.it.md +104 -0
- package/docs/installation.ja.md +78 -0
- package/docs/installation.ko.md +78 -0
- package/docs/installation.md +103 -0
- package/docs/installation.ru.md +104 -0
- package/docs/installation.zh.md +100 -0
- package/docs/repair-log.md +657 -0
- package/eslint.config.js +30 -0
- package/package.json +116 -129
- package/packages/selector/LICENSE +21 -0
- package/packages/selector/README.md +26 -0
- package/packages/selector/README.zh.md +24 -0
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -0
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
- package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +2 -2
- package/packages/selector/lib/style.css +350 -0
- package/packages/selector/package.json +178 -0
- package/packages/selector/screenshots.json +3 -0
- package/packages/selector/src/client/CompressionProfileControls.tsx +293 -0
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +85 -0
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
- package/packages/selector/src/client/EstimatorControls.tsx +277 -0
- package/packages/selector/src/client/bridge-scope.ts +125 -0
- package/packages/selector/src/client/decode.ts +57 -0
- package/packages/selector/src/client/fab-pos.ts +71 -0
- package/packages/selector/src/client/index.ts +424 -0
- package/packages/selector/src/client/locales/de.ts +158 -0
- package/packages/selector/src/client/locales/es.ts +158 -0
- package/packages/selector/src/client/locales/fr.ts +158 -0
- package/packages/selector/src/client/locales/it.ts +158 -0
- package/packages/selector/src/client/locales/ja.ts +158 -0
- package/packages/selector/src/client/locales/ko.ts +158 -0
- package/packages/selector/src/client/locales/ru.ts +158 -0
- package/packages/selector/src/client/locales.ts +316 -0
- package/packages/selector/src/client/monitor-fab.ts +431 -0
- package/packages/selector/src/client/preset-options.ts +88 -0
- package/packages/selector/src/client/savings-card.tsx +269 -0
- package/packages/selector/src/client/scope-face.ts +24 -0
- package/packages/selector/src/client/settings-section.tsx +140 -0
- package/packages/selector/src/compat/host-generation.ts +96 -0
- package/packages/selector/src/compat/llm-messages.ts +50 -0
- package/packages/selector/src/compat/settings-lease.ts +108 -0
- package/packages/selector/src/compat/tool-result.ts +91 -0
- package/packages/selector/src/css-modules.d.ts +6 -0
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -0
- package/packages/selector/src/estimator-catalog.ts +104 -0
- package/packages/selector/src/index.ts +890 -0
- package/packages/selector/src/invariant.ts +113 -0
- package/packages/selector/src/preset-overlay.ts +749 -0
- package/packages/selector/src/profiles.ts +431 -0
- package/packages/selector/src/pruner/content.ts +198 -0
- package/packages/selector/src/pruner/session.ts +97 -0
- package/packages/selector/src/pruner/state.ts +61 -0
- package/packages/selector/src/pruner/tuning.ts +23 -0
- package/packages/selector/src/pruner/types.ts +78 -0
- package/packages/selector/src/pruner.ts +2914 -0
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -0
- package/packages/selector/src/runtime/audit.ts +320 -0
- package/packages/selector/src/runtime/config.ts +756 -0
- package/packages/selector/src/runtime/custom-policy.ts +278 -0
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
- package/packages/selector/src/runtime/display-prefs.ts +98 -0
- package/packages/selector/src/runtime/measurement.ts +444 -0
- package/packages/selector/src/runtime/monitor.ts +310 -0
- package/packages/selector/src/runtime/panel-command.ts +213 -0
- package/packages/selector/src/runtime/reducers.ts +1754 -0
- package/packages/selector/src/runtime/retrieve.ts +503 -0
- package/packages/selector/src/runtime/savings-integral.ts +117 -0
- package/packages/selector/src/runtime/savings-projection.ts +229 -0
- package/packages/selector/src/runtime/savings-verify.ts +446 -0
- package/packages/selector/src/runtime/savings.ts +526 -0
- package/packages/selector/src/runtime/session-events.ts +30 -0
- package/packages/selector/src/runtime/session-file-decode.ts +523 -0
- package/packages/selector/src/runtime/stats-backfill.ts +541 -0
- package/packages/selector/src/runtime/stats-db.ts +492 -0
- package/packages/selector/src/runtime/stats-schema.ts +123 -0
- package/packages/selector/src/runtime/stats-sync.ts +307 -0
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +176 -0
- package/packages/selector/src/runtime/token-count.ts +72 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -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 +128 -0
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -0
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
- package/packages/selector/src/runtime/toolclass.ts +103 -0
- package/packages/selector/src/runtime/types.ts +365 -0
- package/packages/selector/src/runtime/value.ts +48 -0
- package/packages/selector/src/settings-bridge.ts +175 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -0
- package/packages/selector/tests/built/client-artifact.spec.ts +56 -0
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +98 -0
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
- package/packages/selector/tests/custom-contract.client.spec.ts +226 -0
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -0
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +202 -0
- package/packages/selector/tests/fab-pos.client.spec.ts +47 -0
- package/packages/selector/tests/helpers/legacy-namespace.ts +35 -0
- 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 -0
- package/packages/selector/tests/monitor-fab.client.spec.ts +240 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +192 -0
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -0
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -0
- package/packages/selector/tests/profiles.client.spec.tsx +436 -0
- package/packages/selector/tests/public/package-contract.client.spec.ts +86 -0
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -0
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -0
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +46 -0
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
- 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/jsonl-reducer.spec.ts +79 -0
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +354 -0
- package/packages/selector/tests/runtime/panel-command.spec.ts +101 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2781 -0
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +291 -0
- package/packages/selector/tests/runtime/savings-integral.spec.ts +169 -0
- package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
- package/packages/selector/tests/runtime/savings-verify.spec.ts +226 -0
- package/packages/selector/tests/runtime/savings.spec.ts +139 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +281 -0
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +167 -0
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +348 -0
- package/packages/selector/tests/runtime/stats-db.spec.ts +361 -0
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +55 -0
- package/packages/selector/tests/runtime/stats-sync.spec.ts +278 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -0
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +119 -0
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -0
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
- package/packages/selector/tests/runtime/value.spec.ts +23 -0
- package/packages/selector/tests/savings-sessions.client.spec.tsx +140 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +215 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -0
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -0
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
- package/packages/selector/tests/support/mock-adapter.ts +37 -0
- package/packages/selector/tests/support/ui-primitives.tsx +34 -0
- package/packages/selector/tsconfig.json +11 -0
- package/packages/selector/tsdown.client.config.ts +102 -0
- package/packages/selector/tsdown.config.ts +20 -0
- package/pnpm-workspace.yaml +76 -0
- package/screenshots.json +6 -3
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/cell-browser-e2e.mjs +354 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -0
- package/scripts/generate-vision-fixtures.py +208 -0
- package/scripts/hosts.mjs +78 -0
- package/scripts/packed-components-smoke.mjs +763 -0
- package/scripts/packed-install-e2e.mjs +1346 -0
- package/scripts/sync-hosts.mjs +174 -0
- package/scripts/toolclass-corpus-replay.mjs +281 -0
- package/scripts/verify-release.mjs +338 -0
- package/tests/TEST_INVENTORY.md +41 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +15 -0
- package/vitest.built.config.ts +9 -0
- package/vitest.config.ts +54 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
- /package/{lib → packages/selector/lib}/client.d.ts +0 -0
- /package/{lib → packages/selector/lib}/client.js +0 -0
- /package/{lib → packages/selector/lib}/index.d.ts +0 -0
- /package/{lib → packages/selector/lib}/index.js +0 -0
- /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
- /package/{lib → packages/selector/lib}/invariant.js +0 -0
- /package/{lib → packages/selector/lib}/profiles.d.ts +0 -0
- /package/{lib → packages/selector/lib}/pruner.d.ts +0 -0
- /package/{lib → packages/selector/lib}/pruner.js +0 -0
- /package/{lib → packages/selector/lib}/savings-integral.js +0 -0
- /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
- /package/{lib → packages/selector/lib}/tool-result.js +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
intentSummary: { enabled: false },
|
|
28
|
+
}
|
|
29
|
+
const form = {
|
|
30
|
+
getSnapshot: vi.fn(() => ({
|
|
31
|
+
status: 'ready' as const,
|
|
32
|
+
value: { settings: value },
|
|
33
|
+
base: undefined,
|
|
34
|
+
user: undefined,
|
|
35
|
+
revision,
|
|
36
|
+
writable: true,
|
|
37
|
+
mode: 'host' as const,
|
|
38
|
+
})),
|
|
39
|
+
subscribe: vi.fn(() => () => {}),
|
|
40
|
+
set: vi.fn(async (_field: string, next: unknown) => {
|
|
41
|
+
if (!commit) return false
|
|
42
|
+
revision += 1
|
|
43
|
+
const doc = structuredClone(next) as ContextCompressionSettings
|
|
44
|
+
if (flipEnabled) {
|
|
45
|
+
const accepted = structuredClone(doc.codeSkeleton)
|
|
46
|
+
accepted.enabled = !accepted.enabled
|
|
47
|
+
value = { ...doc, codeSkeleton: accepted }
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
value = doc
|
|
51
|
+
return true
|
|
52
|
+
}),
|
|
53
|
+
unset: vi.fn(async () => false),
|
|
54
|
+
}
|
|
55
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
56
|
+
const ctx = {
|
|
57
|
+
effect: (install: () => unknown) => { install() },
|
|
58
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
59
|
+
configForms: { get: vi.fn(() => form) },
|
|
60
|
+
// Scoped sub-inject seam: host resolves configForms and fires the arm
|
|
61
|
+
inject: (services: string[], cb: (service: unknown) => void) => {
|
|
62
|
+
if (services.includes('configForms')) cb(ctx.configForms)
|
|
63
|
+
},
|
|
64
|
+
slots: {
|
|
65
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
66
|
+
register: (registration: { name?: string, inject?: () => CompressionSelectorInjected }) => {
|
|
67
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
68
|
+
if (registration.name === 'settings.section' && typeof registration.inject === 'function') injected = registration.inject
|
|
69
|
+
return () => {}
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
} as unknown as Parameters<typeof apply>[0]
|
|
73
|
+
|
|
74
|
+
apply(ctx)
|
|
75
|
+
const actions = injected?.()
|
|
76
|
+
expect(actions).toBeDefined()
|
|
77
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
78
|
+
|
|
79
|
+
// A silent host drop leaves the revision untouched: the write must reject.
|
|
80
|
+
await expect(actions.saveCodeSkeleton(true)).rejects.toThrow('were not saved')
|
|
81
|
+
|
|
82
|
+
// A committed write resolves and persists the exact section payload under
|
|
83
|
+
// the volatile `settings` field.
|
|
84
|
+
commit = true
|
|
85
|
+
await expect(actions.saveCodeSkeleton(true)).resolves.toBeUndefined()
|
|
86
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: true } }))
|
|
87
|
+
expect(value.codeSkeleton).toEqual({ enabled: true })
|
|
88
|
+
|
|
89
|
+
// A host that flips the toggled bit fails the acceptance check.
|
|
90
|
+
flipEnabled = true
|
|
91
|
+
await expect(actions.saveCodeSkeleton(false)).rejects.toThrow('were not saved')
|
|
92
|
+
|
|
93
|
+
flipEnabled = false
|
|
94
|
+
await expect(actions.saveCodeSkeleton(false)).resolves.toBeUndefined()
|
|
95
|
+
expect(form.set).toHaveBeenLastCalledWith('settings', expect.objectContaining({ codeSkeleton: { enabled: false } }))
|
|
96
|
+
expect(value.codeSkeleton).toEqual({ enabled: false })
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* compat narrow-waist unit tests: tool-result triple view, legacy source-kind
|
|
3
|
+
* escape, generation probe, and the settings lease no-op on modern hosts.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest'
|
|
6
|
+
import { viewToolResult, compressionMessageSource } from '../../src/compat/tool-result.ts'
|
|
7
|
+
import { detectHostGeneration, resetHostGenerationCache, noteResolvedSettingsService, hostGenerationSnapshot } from '../../src/compat/host-generation.ts'
|
|
8
|
+
import { acquireSettingsLease } from '../../src/compat/settings-lease.ts'
|
|
9
|
+
|
|
10
|
+
const MODERN_TOOL_RESULT = {
|
|
11
|
+
content: [{ type: 'text', text: 'hello' }, { type: 'text', text: 'world' }],
|
|
12
|
+
isError: true,
|
|
13
|
+
toolCallId: 'call-modern',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const LEGACY_TOOL_RESULT = {
|
|
17
|
+
content: [{
|
|
18
|
+
type: 'tool-result',
|
|
19
|
+
content: [{ type: 'text', text: 'legacy body' }],
|
|
20
|
+
isError: true,
|
|
21
|
+
}],
|
|
22
|
+
source: { callId: 'call-legacy' },
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('viewToolResult (three-axis envelope adapter)', () => {
|
|
26
|
+
it('reads the flat modern shape', () => {
|
|
27
|
+
const view = viewToolResult(MODERN_TOOL_RESULT, 'modern')
|
|
28
|
+
expect(view.blocks).toHaveLength(2)
|
|
29
|
+
expect(view.isError).toBe(true)
|
|
30
|
+
expect(view.callId).toBe('call-modern')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('reads the enveloped legacy shape (strict signature overrides the flag)', () => {
|
|
34
|
+
const view = viewToolResult(LEGACY_TOOL_RESULT, 'modern')
|
|
35
|
+
expect(view.blocks).toEqual([{ type: 'text', text: 'legacy body' }])
|
|
36
|
+
expect(view.isError).toBe(true)
|
|
37
|
+
expect(view.callId).toBe('call-legacy')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('honors the legacy flag when the signature check is inconclusive', () => {
|
|
41
|
+
const loose = {
|
|
42
|
+
content: [{ something: 'else' }],
|
|
43
|
+
source: { callId: 'call-loose' },
|
|
44
|
+
}
|
|
45
|
+
const view = viewToolResult(loose, 'legacy')
|
|
46
|
+
expect(view.blocks).toEqual([{ something: 'else' }])
|
|
47
|
+
expect(view.callId).toBe('call-loose')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('keeps the modern axes on an inconclusive modern message', () => {
|
|
51
|
+
const view = viewToolResult(MODERN_TOOL_RESULT, 'legacy')
|
|
52
|
+
expect(view.blocks).toEqual(MODERN_TOOL_RESULT.content)
|
|
53
|
+
expect(view.isError).toBe(true)
|
|
54
|
+
expect(view.callId).toBe('call-modern')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('never throws on absent fields', () => {
|
|
58
|
+
const view = viewToolResult({}, 'modern')
|
|
59
|
+
expect(view.blocks).toEqual([])
|
|
60
|
+
expect(view.isError).toBe(false)
|
|
61
|
+
expect(view.callId).toBeUndefined()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('compressionMessageSource (legacy kind escape)', () => {
|
|
66
|
+
it('returns the per-producer kind on modern hosts', () => {
|
|
67
|
+
expect(compressionMessageSource('modern')).toEqual({ kind: 'dsh-context-compression' })
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('escapes to the shared plugin kind on legacy hosts', () => {
|
|
71
|
+
const source = compressionMessageSource('legacy')
|
|
72
|
+
expect(source.kind).toBe('plugin')
|
|
73
|
+
expect((source as { plugin?: string }).plugin).toBe('dsh-context-compression-improved')
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('detectHostGeneration (capability probe)', () => {
|
|
78
|
+
it('classifies a register-capable settings service as legacy', () => {
|
|
79
|
+
resetHostGenerationCache()
|
|
80
|
+
expect(detectHostGeneration({ get: (name) => (name === 'settings' ? { register: () => ({}) } : undefined) })).toBe('legacy')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('classifies a register-less settings service as modern', () => {
|
|
84
|
+
resetHostGenerationCache()
|
|
85
|
+
expect(detectHostGeneration({ get: (name) => (name === 'settings' ? { describe: () => [] } : undefined) })).toBe('modern')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('defaults to modern when the settings service is absent', () => {
|
|
89
|
+
resetHostGenerationCache()
|
|
90
|
+
expect(detectHostGeneration({ get: () => undefined })).toBe('modern')
|
|
91
|
+
resetHostGenerationCache()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('does not cache the provisional verdict taken while the service is absent', () => {
|
|
95
|
+
// Measured on the real 0.1.0-rc.2 cell: rows compose before the host
|
|
96
|
+
// settings service, and the old probe cached that absence as 'modern'
|
|
97
|
+
// forever — the legacy lease arm went dead on the line it was built for.
|
|
98
|
+
resetHostGenerationCache()
|
|
99
|
+
expect(detectHostGeneration({ get: () => undefined })).toBe('modern')
|
|
100
|
+
// Later evidence (the settings inject callback) must still flip it.
|
|
101
|
+
expect(noteResolvedSettingsService({ register: () => ({}) })).toBe('legacy')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('noteResolvedSettingsService overrides even a definitive earlier verdict', () => {
|
|
105
|
+
resetHostGenerationCache()
|
|
106
|
+
expect(detectHostGeneration({ get: () => ({ describe: () => [] }) })).toBe('modern')
|
|
107
|
+
expect(noteResolvedSettingsService({ register: () => ({}) })).toBe('legacy')
|
|
108
|
+
expect(hostGenerationSnapshot()).toBe('legacy')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('hostGenerationSnapshot defaults to modern without any evidence', () => {
|
|
112
|
+
resetHostGenerationCache()
|
|
113
|
+
expect(hostGenerationSnapshot()).toBe('modern')
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('acquireSettingsLease', () => {
|
|
118
|
+
it('is a no-op face on modern hosts (register absent, P1-13)', async () => {
|
|
119
|
+
resetHostGenerationCache()
|
|
120
|
+
const effects: Array<{ name?: string }> = []
|
|
121
|
+
const ctx = {
|
|
122
|
+
effect: (factory: () => unknown, name?: string) => { effects.push(name === undefined ? {} : { name }); void factory },
|
|
123
|
+
settings: { describe: () => [] },
|
|
124
|
+
} as unknown as Parameters<typeof acquireSettingsLease>[0]
|
|
125
|
+
const face = acquireSettingsLease(ctx, 'context-compression', {})
|
|
126
|
+
expect(face.get()).toBeUndefined()
|
|
127
|
+
await expect(face.update({ marker: 1 })).resolves.toBe(false)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('registers once and reads/writes through the host service on legacy hosts', async () => {
|
|
131
|
+
const registrations: string[] = []
|
|
132
|
+
const stored = new Map<string, Record<string, unknown>>()
|
|
133
|
+
const settings = {
|
|
134
|
+
register: (ns: string) => { registrations.push(ns); return { get: () => stored.get(ns) } },
|
|
135
|
+
get: (ns: string) => stored.get(ns),
|
|
136
|
+
update: async (ns: string, patch: Record<string, unknown>) => { stored.set(ns, patch) },
|
|
137
|
+
}
|
|
138
|
+
const effects: Array<() => void> = []
|
|
139
|
+
const ctx = {
|
|
140
|
+
effect: (factory: () => () => void) => { effects.push(factory()) },
|
|
141
|
+
settings,
|
|
142
|
+
} as unknown as Parameters<typeof acquireSettingsLease>[0]
|
|
143
|
+
const face = acquireSettingsLease(ctx, 'context-compression', {})
|
|
144
|
+
expect(registrations).toEqual(['context-compression'])
|
|
145
|
+
await expect(face.update({ profile: 'balanced' })).resolves.toBe(true)
|
|
146
|
+
expect(face.get()).toEqual({ profile: 'balanced' })
|
|
147
|
+
// Disposal must not throw when this was the only owner.
|
|
148
|
+
for (const dispose of effects) dispose()
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
3
|
+
import type { ScopeSnapshot } from '../src/client/scope-face.ts'
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_CUSTOM_COMPRESSION_POLICY,
|
|
6
|
+
isCustomCompressionPolicy,
|
|
7
|
+
} from '../src/profiles.ts'
|
|
8
|
+
import { apply } from '../src/client/index.ts'
|
|
9
|
+
import { decodeSettings } from '../src/client/decode.ts'
|
|
10
|
+
import type {
|
|
11
|
+
CompressionSelectorInjected,
|
|
12
|
+
ContextCompressionSettings,
|
|
13
|
+
} from '../src/client/CompressionProfileSelector.tsx'
|
|
14
|
+
|
|
15
|
+
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
16
|
+
IconChevronDownOutlineMedium: () => null,
|
|
17
|
+
Menu: () => null,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const CUSTOM = {
|
|
21
|
+
version: 1,
|
|
22
|
+
unit: 'tokens',
|
|
23
|
+
fresh: { enabled: true, trigger: 4_096, target: 2_048 },
|
|
24
|
+
aggregate: { enabled: true, trigger: 16_384, target: 8_192 },
|
|
25
|
+
history: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
trigger: 32_768,
|
|
28
|
+
keepRecentTurns: 2,
|
|
29
|
+
keepRecent: 16_384,
|
|
30
|
+
minReclaim: 8_192,
|
|
31
|
+
},
|
|
32
|
+
prefixPolicy: 'pressure-break',
|
|
33
|
+
} as const satisfies ContextCompressionSettings['custom']
|
|
34
|
+
|
|
35
|
+
describe('context compression browser contract', () => {
|
|
36
|
+
it('accepts legacy v1 and defaults new edits to v3 with TailTrim disabled', () => {
|
|
37
|
+
expect(isCustomCompressionPolicy(CUSTOM)).toBe(true)
|
|
38
|
+
expect(DEFAULT_CUSTOM_COMPRESSION_POLICY).toMatchObject({
|
|
39
|
+
version: 3,
|
|
40
|
+
tailTrim: { enabled: false, trigger: 700_000 },
|
|
41
|
+
})
|
|
42
|
+
expect(isCustomCompressionPolicy(DEFAULT_CUSTOM_COMPRESSION_POLICY)).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('fails the browser narrowing for unknown or invalid Custom fields', () => {
|
|
46
|
+
expect(isCustomCompressionPolicy({
|
|
47
|
+
...structuredClone(CUSTOM),
|
|
48
|
+
tailTrim: { enabled: true },
|
|
49
|
+
})).toBe(false)
|
|
50
|
+
expect(isCustomCompressionPolicy({
|
|
51
|
+
...structuredClone(CUSTOM),
|
|
52
|
+
fresh: { enabled: true, trigger: 100, target: 100 },
|
|
53
|
+
})).toBe(false)
|
|
54
|
+
for (const trigger of [0, -1]) {
|
|
55
|
+
expect(isCustomCompressionPolicy({
|
|
56
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
57
|
+
tailTrim: { enabled: true, trigger },
|
|
58
|
+
})).toBe(false)
|
|
59
|
+
}
|
|
60
|
+
expect(isCustomCompressionPolicy({
|
|
61
|
+
...structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
62
|
+
unit: 'context-percent',
|
|
63
|
+
tailTrim: { enabled: true, trigger: 101 },
|
|
64
|
+
})).toBe(false)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('decodes legacy settings to the default threshold and rejects malformed sections', async () => {
|
|
68
|
+
// Legacy documents stored before autoCompact existed inherit 80%.
|
|
69
|
+
const legacy = decodeSettings({ profile: 'balanced', custom: structuredClone(CUSTOM) })
|
|
70
|
+
expect(legacy).toMatchObject({ autoCompact: { thresholdPercent: 80 } })
|
|
71
|
+
// A present-but-invalid threshold fails the whole decode.
|
|
72
|
+
expect(decodeSettings({
|
|
73
|
+
profile: 'balanced',
|
|
74
|
+
custom: structuredClone(CUSTOM),
|
|
75
|
+
autoCompact: { thresholdPercent: 91 },
|
|
76
|
+
})).toBeUndefined()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('reports a recovered no-op write only on the selector boundary', async () => {
|
|
80
|
+
let revision = 7
|
|
81
|
+
let commit = false
|
|
82
|
+
let rewriteCustom = false
|
|
83
|
+
let rewriteReset = false
|
|
84
|
+
let dropTailTrim = false
|
|
85
|
+
let downgradeVersion = false
|
|
86
|
+
let value: ContextCompressionSettings = {
|
|
87
|
+
profile: 'balanced',
|
|
88
|
+
custom: structuredClone(CUSTOM),
|
|
89
|
+
autoCompact: { thresholdPercent: 80 },
|
|
90
|
+
codeSkeleton: { enabled: false },
|
|
91
|
+
intentSummary: { enabled: false },
|
|
92
|
+
}
|
|
93
|
+
const snapshot = (): ScopeSnapshot<ContextCompressionSettings> => ({
|
|
94
|
+
status: 'ready',
|
|
95
|
+
value,
|
|
96
|
+
base: undefined,
|
|
97
|
+
user: undefined,
|
|
98
|
+
revision,
|
|
99
|
+
writable: true,
|
|
100
|
+
mode: 'host',
|
|
101
|
+
})
|
|
102
|
+
const scope = {
|
|
103
|
+
getSnapshot: snapshot,
|
|
104
|
+
subscribe: vi.fn(() => () => {}),
|
|
105
|
+
set: vi.fn(async (field: string, next: unknown) => {
|
|
106
|
+
if (!commit) return
|
|
107
|
+
revision += 1
|
|
108
|
+
if (field === 'custom' && rewriteCustom) {
|
|
109
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
110
|
+
accepted.fresh.trigger += 1
|
|
111
|
+
value = { ...value, custom: accepted }
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
if (field === 'custom' && rewriteReset) {
|
|
115
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
116
|
+
accepted.fresh.trigger += 1
|
|
117
|
+
value = { ...value, custom: accepted }
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (field === 'custom' && dropTailTrim) {
|
|
121
|
+
const accepted = structuredClone(next as ContextCompressionSettings['custom'])
|
|
122
|
+
if (accepted.version === 3) {
|
|
123
|
+
accepted.tailTrim = { enabled: false, trigger: 700_000 }
|
|
124
|
+
}
|
|
125
|
+
value = { ...value, custom: accepted }
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
if (field === 'custom' && downgradeVersion) {
|
|
129
|
+
value = { ...value, custom: structuredClone(CUSTOM) }
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
value = { ...value, [field]: next }
|
|
133
|
+
}),
|
|
134
|
+
unset: vi.fn(async () => {
|
|
135
|
+
if (!commit) return
|
|
136
|
+
revision += 1
|
|
137
|
+
const custom: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
138
|
+
if (rewriteReset) {
|
|
139
|
+
custom.fresh.trigger = 8_192
|
|
140
|
+
custom.fresh.target = 4_096
|
|
141
|
+
}
|
|
142
|
+
value = { ...value, custom }
|
|
143
|
+
}),
|
|
144
|
+
}
|
|
145
|
+
let injected: (() => CompressionSelectorInjected) | undefined
|
|
146
|
+
const ctx = {
|
|
147
|
+
effect: (install: () => unknown) => { install() },
|
|
148
|
+
locale: { register: vi.fn(() => () => {}) },
|
|
149
|
+
// 0.1.7: the plugin commits the whole doc through configForms; the fake
|
|
150
|
+
// routes each changed top-level field back onto the old scope stub so
|
|
151
|
+
// the rewrite/drop semantics below stay observable per field.
|
|
152
|
+
inject: (services: string[], cb: (service: unknown) => void) => {
|
|
153
|
+
if (services.includes('configForms')) cb(ctx.configForms)
|
|
154
|
+
},
|
|
155
|
+
configForms: {
|
|
156
|
+
get: vi.fn(() => ({
|
|
157
|
+
getSnapshot: () => ({ ...snapshot(), value: { settings: value } }),
|
|
158
|
+
subscribe: scope.subscribe,
|
|
159
|
+
set: async (_field: string, doc: unknown) => {
|
|
160
|
+
const next = doc as unknown as Record<string, unknown>
|
|
161
|
+
for (const key of Object.keys(next)) {
|
|
162
|
+
if (JSON.stringify((value as unknown as Record<string, unknown>)[key]) !== JSON.stringify(next[key])) {
|
|
163
|
+
await scope.set(key, (next as Record<string, unknown>)[key])
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return true
|
|
167
|
+
},
|
|
168
|
+
unset: scope.unset,
|
|
169
|
+
})),
|
|
170
|
+
},
|
|
171
|
+
slots: {
|
|
172
|
+
inject: (_slot: string, install: () => unknown) => { install() },
|
|
173
|
+
register: (registration: { name?: string, inject?: () => CompressionSelectorInjected }) => {
|
|
174
|
+
// The R4 overlay registration carries no inject face; keep the card's.
|
|
175
|
+
if (registration.name === 'settings.section' && typeof registration.inject === 'function') injected = registration.inject
|
|
176
|
+
return () => {}
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
} as unknown as ClientContext
|
|
180
|
+
|
|
181
|
+
apply(ctx)
|
|
182
|
+
const actions = injected?.()
|
|
183
|
+
expect(actions).toBeDefined()
|
|
184
|
+
if (actions === undefined) throw new Error('selector injection was not registered')
|
|
185
|
+
await expect(actions.select('native')).rejects.toThrow('were not saved')
|
|
186
|
+
|
|
187
|
+
commit = true
|
|
188
|
+
await expect(actions.select('native')).resolves.toBeUndefined()
|
|
189
|
+
expect(value.profile).toBe('native')
|
|
190
|
+
|
|
191
|
+
const requested: ContextCompressionSettings['custom'] = structuredClone(CUSTOM)
|
|
192
|
+
requested.fresh.trigger = 8_192
|
|
193
|
+
requested.fresh.target = 4_096
|
|
194
|
+
rewriteCustom = true
|
|
195
|
+
await expect(actions.saveCustom(requested)).rejects.toThrow('were not saved')
|
|
196
|
+
|
|
197
|
+
rewriteCustom = false
|
|
198
|
+
const requestedV3 = structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
199
|
+
if (requestedV3.version !== 3) throw new Error('Custom TailTrim persistence fixture requires policy v3')
|
|
200
|
+
requestedV3.tailTrim = { enabled: true, trigger: 49_152 }
|
|
201
|
+
dropTailTrim = true
|
|
202
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
203
|
+
|
|
204
|
+
dropTailTrim = false
|
|
205
|
+
downgradeVersion = true
|
|
206
|
+
await expect(actions.saveCustom(requestedV3)).rejects.toThrow('were not saved')
|
|
207
|
+
|
|
208
|
+
downgradeVersion = false
|
|
209
|
+
rewriteReset = true
|
|
210
|
+
await expect(actions.resetCustom()).rejects.toThrow('were not saved')
|
|
211
|
+
|
|
212
|
+
rewriteReset = false
|
|
213
|
+
await expect(actions.resetCustom()).resolves.toBeUndefined()
|
|
214
|
+
expect(scope.set).toHaveBeenLastCalledWith('custom', DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
215
|
+
expect(scope.unset).not.toHaveBeenCalled()
|
|
216
|
+
|
|
217
|
+
// The Auto Compact threshold shares the same confirm-on-write boundary:
|
|
218
|
+
// committed writes resolve, and a silent host drop rejects.
|
|
219
|
+
commit = false
|
|
220
|
+
await expect(actions.saveAutoCompact(73)).rejects.toThrow('were not saved')
|
|
221
|
+
commit = true
|
|
222
|
+
await expect(actions.saveAutoCompact(73)).resolves.toBeUndefined()
|
|
223
|
+
expect(scope.set).toHaveBeenLastCalledWith('autoCompact', { thresholdPercent: 73 })
|
|
224
|
+
expect(value.autoCompact).toEqual({ thresholdPercent: 73 })
|
|
225
|
+
})
|
|
226
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Estimator catalog projection: never throws, selection precedence, inline errors. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import {
|
|
5
|
+
buildEstimatorCatalog, resolveHostRoute,
|
|
6
|
+
type EstimatorCatalogDeps,
|
|
7
|
+
} from '../src/estimator-catalog.ts'
|
|
8
|
+
|
|
9
|
+
describe('resolveHostRoute', () => {
|
|
10
|
+
it('prefers explicit overrides over the host default selection', () => {
|
|
11
|
+
expect(resolveHostRoute({
|
|
12
|
+
overrideProvider: 'p1',
|
|
13
|
+
overrideModel: 'm1',
|
|
14
|
+
currentSelection: () => ({ provider: 'p2', model: 'm2' }),
|
|
15
|
+
})).toEqual({ provider: 'p1', model: 'm1' })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('falls back to the host default selection when overrides are empty', () => {
|
|
19
|
+
expect(resolveHostRoute({
|
|
20
|
+
overrideProvider: '',
|
|
21
|
+
overrideModel: '',
|
|
22
|
+
currentSelection: () => ({ provider: 'p2', model: 'm2' }),
|
|
23
|
+
})).toEqual({ provider: 'p2', model: 'm2' })
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('fills missing override fields from the selection, per field', () => {
|
|
27
|
+
expect(resolveHostRoute({ overrideProvider: 'p1', currentSelection: () => ({ model: 'm2' }) }))
|
|
28
|
+
.toEqual({ provider: 'p1', model: 'm2' })
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('reports undefined when neither source yields a complete route', () => {
|
|
32
|
+
expect(resolveHostRoute({ currentSelection: () => ({ provider: 'p' }) })).toBeUndefined()
|
|
33
|
+
expect(resolveHostRoute({})).toBeUndefined()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('buildEstimatorCatalog', () => {
|
|
38
|
+
it('lists every provider with its models and never throws on one broken group', async () => {
|
|
39
|
+
const llm = {
|
|
40
|
+
listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }, { id: 'broken', name: 'Broken' }],
|
|
41
|
+
listModels: async (providerId: string) => {
|
|
42
|
+
if (providerId === 'broken') throw new Error('adapter offline')
|
|
43
|
+
return [{ id: 'm1', name: 'Model 1' }]
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
const catalog = await buildEstimatorCatalog({ llm })
|
|
47
|
+
expect(catalog.providers).toHaveLength(2)
|
|
48
|
+
expect(catalog.providers[0]).toEqual({ id: 'deepseek', name: 'DeepSeek', models: [{ id: 'm1', name: 'Model 1' }] })
|
|
49
|
+
expect(catalog.providers[1]?.error).toBe('adapter offline')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('uses route discovery when listModels is absent or silent', async () => {
|
|
53
|
+
const llm: NonNullable<EstimatorCatalogDeps['llm']> = {
|
|
54
|
+
listProviders: () => [{ id: 'self-hosted', name: 'Self hosted' }],
|
|
55
|
+
listConfigurableProviders: () => [{ provider: 'self-hosted', settingsNs: 'llm.self-hosted' }],
|
|
56
|
+
discoverModels: async () => [{ id: 'm9' }],
|
|
57
|
+
}
|
|
58
|
+
const catalog = await buildEstimatorCatalog({ llm })
|
|
59
|
+
expect(catalog.providers[0]?.models).toEqual([{ id: 'm9', name: 'm9' }])
|
|
60
|
+
expect(catalog.providers[0]?.error).toBeUndefined()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('returns the host selection even when the llm service is unavailable', async () => {
|
|
64
|
+
const catalog = await buildEstimatorCatalog({
|
|
65
|
+
currentSelection: () => ({ provider: 'p', model: 'm' }),
|
|
66
|
+
})
|
|
67
|
+
expect(catalog.providers).toEqual([])
|
|
68
|
+
expect(catalog.selection).toEqual({ provider: 'p', model: 'm' })
|
|
69
|
+
})
|
|
70
|
+
})
|