dsh-context-compression-improved 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -110
- package/README.zh.md +14 -104
- package/THIRD_PARTY_NOTICES.md +25 -7
- package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
- package/{packages/selector/lib → lib}/client.js +73 -12
- package/package.json +129 -116
- package/screenshots.json +3 -6
- package/.agents/plans/improve/checklist.md +0 -32
- package/.agents/plans/improve/findings.md +0 -102
- package/.agents/plans/improve/spec.md +0 -53
- package/.agents/plans/improve/tasks.md +0 -70
- package/.gitattributes +0 -2
- package/.githooks/pre-push +0 -37
- package/.github/workflows/ci.yml +0 -39
- package/CHANGELOG.de.md +0 -580
- package/CHANGELOG.es.md +0 -588
- package/CHANGELOG.fr.md +0 -576
- package/CHANGELOG.it.md +0 -577
- package/CHANGELOG.ja.md +0 -261
- package/CHANGELOG.ko.md +0 -254
- package/CHANGELOG.md +0 -544
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -238
- package/CONTRIBUTING.md +0 -22
- package/README.de.md +0 -96
- package/README.es.md +0 -96
- package/README.fr.md +0 -96
- package/README.it.md +0 -96
- package/README.ja.md +0 -102
- package/README.ko.md +0 -102
- package/README.ru.md +0 -96
- package/SECURITY.md +0 -18
- 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 +0 -77
- package/docs/installation.de.md +0 -104
- package/docs/installation.es.md +0 -104
- package/docs/installation.fr.md +0 -104
- package/docs/installation.it.md +0 -104
- package/docs/installation.ja.md +0 -78
- package/docs/installation.ko.md +0 -78
- package/docs/installation.md +0 -103
- package/docs/installation.ru.md +0 -104
- package/docs/installation.zh.md +0 -100
- package/docs/repair-log.md +0 -657
- package/eslint.config.js +0 -30
- package/packages/selector/LICENSE +0 -21
- package/packages/selector/README.md +0 -26
- package/packages/selector/README.zh.md +0 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
- package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
- package/packages/selector/lib/style.css +0 -350
- package/packages/selector/package.json +0 -178
- package/packages/selector/screenshots.json +0 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
- package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
- package/packages/selector/src/client/EstimatorControls.tsx +0 -277
- package/packages/selector/src/client/bridge-scope.ts +0 -125
- package/packages/selector/src/client/decode.ts +0 -57
- package/packages/selector/src/client/index.ts +0 -424
- package/packages/selector/src/client/locales/de.ts +0 -158
- package/packages/selector/src/client/locales/es.ts +0 -158
- package/packages/selector/src/client/locales/fr.ts +0 -158
- package/packages/selector/src/client/locales/it.ts +0 -158
- package/packages/selector/src/client/locales/ja.ts +0 -158
- package/packages/selector/src/client/locales/ko.ts +0 -158
- package/packages/selector/src/client/locales/ru.ts +0 -158
- package/packages/selector/src/client/locales.ts +0 -316
- package/packages/selector/src/client/monitor-fab.ts +0 -419
- package/packages/selector/src/client/preset-options.ts +0 -88
- package/packages/selector/src/client/savings-card.tsx +0 -269
- package/packages/selector/src/client/scope-face.ts +0 -24
- package/packages/selector/src/client/settings-section.tsx +0 -140
- package/packages/selector/src/compat/host-generation.ts +0 -96
- package/packages/selector/src/compat/llm-messages.ts +0 -50
- package/packages/selector/src/compat/settings-lease.ts +0 -108
- package/packages/selector/src/compat/tool-result.ts +0 -91
- package/packages/selector/src/css-modules.d.ts +0 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
- package/packages/selector/src/estimator-catalog.ts +0 -104
- package/packages/selector/src/index.ts +0 -890
- package/packages/selector/src/invariant.ts +0 -113
- package/packages/selector/src/preset-overlay.ts +0 -749
- package/packages/selector/src/profiles.ts +0 -431
- package/packages/selector/src/pruner/content.ts +0 -198
- package/packages/selector/src/pruner/session.ts +0 -97
- package/packages/selector/src/pruner/state.ts +0 -61
- package/packages/selector/src/pruner/tuning.ts +0 -23
- package/packages/selector/src/pruner/types.ts +0 -78
- package/packages/selector/src/pruner.ts +0 -2914
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -320
- package/packages/selector/src/runtime/config.ts +0 -756
- package/packages/selector/src/runtime/custom-policy.ts +0 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
- package/packages/selector/src/runtime/display-prefs.ts +0 -98
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -310
- package/packages/selector/src/runtime/panel-command.ts +0 -213
- package/packages/selector/src/runtime/reducers.ts +0 -1754
- package/packages/selector/src/runtime/retrieve.ts +0 -503
- package/packages/selector/src/runtime/savings-integral.ts +0 -117
- package/packages/selector/src/runtime/savings-projection.ts +0 -229
- package/packages/selector/src/runtime/savings-verify.ts +0 -446
- package/packages/selector/src/runtime/savings.ts +0 -526
- package/packages/selector/src/runtime/session-events.ts +0 -30
- package/packages/selector/src/runtime/session-file-decode.ts +0 -523
- package/packages/selector/src/runtime/stats-backfill.ts +0 -541
- package/packages/selector/src/runtime/stats-db.ts +0 -492
- package/packages/selector/src/runtime/stats-schema.ts +0 -123
- package/packages/selector/src/runtime/stats-sync.ts +0 -307
- package/packages/selector/src/runtime/summary-command.ts +0 -127
- package/packages/selector/src/runtime/tail-trim.ts +0 -176
- package/packages/selector/src/runtime/token-count.ts +0 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
- package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/types.ts +0 -365
- package/packages/selector/src/runtime/value.ts +0 -48
- package/packages/selector/src/settings-bridge.ts +0 -175
- package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
- package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
- package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
- package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
- package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
- package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +0 -220
- package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
- package/packages/selector/tests/profiles.client.spec.tsx +0 -436
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
- package/packages/selector/tests/runtime/audit.spec.ts +0 -275
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
- package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
- package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
- package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
- package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
- package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
- package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2781
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
- package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
- package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
- package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
- package/packages/selector/tests/runtime/savings.spec.ts +0 -139
- package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
- package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -348
- package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
- package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
- package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
- package/packages/selector/tests/runtime/value.spec.ts +0 -23
- package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
- package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
- package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
- package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
- package/packages/selector/tests/support/mock-adapter.ts +0 -37
- package/packages/selector/tests/support/ui-primitives.tsx +0 -34
- package/packages/selector/tsconfig.json +0 -11
- package/packages/selector/tsdown.client.config.ts +0 -102
- package/packages/selector/tsdown.config.ts +0 -20
- package/pnpm-workspace.yaml +0 -76
- package/scripts/capture-profile-baseline.mjs +0 -42
- package/scripts/cell-browser-e2e.mjs +0 -354
- package/scripts/generate-tokenizer-fixtures.py +0 -81
- package/scripts/generate-vision-fixtures.py +0 -208
- package/scripts/hosts.mjs +0 -78
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -338
- package/tests/TEST_INVENTORY.md +0 -41
- package/tsconfig.base.json +0 -18
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -15
- package/vitest.built.config.ts +0 -9
- package/vitest.config.ts +0 -54
- /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
- /package/{packages/selector/lib → lib}/client.d.ts +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/index.js +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.js +0 -0
- /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.js +0 -0
- /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
- /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
- /package/{packages/selector/lib → lib}/tool-result.js +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { classifyToolSource } from '../../src/runtime/toolclass.ts'
|
|
3
|
-
import { extractCommand, reduceFreshToolResult } from '../../src/runtime/reducers.ts'
|
|
4
|
-
|
|
5
|
-
/** Checklist C1–C15 against the FOUR-class narrowing (tasks v2 G4): web/memory
|
|
6
|
-
* search and research/sql names fall to generic, glob is path-listing, only
|
|
7
|
-
* grep/rg/ripgrep are search, and the content fallback never overrides a
|
|
8
|
-
* whitelist hit. */
|
|
9
|
-
describe('classifyToolSource — name whitelist', () => {
|
|
10
|
-
it('keeps web_search out of search (C1)', () => {
|
|
11
|
-
expect(classifyToolSource('web_search', '')).toBe('generic')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('routes glob to path-listing (C2)', () => {
|
|
15
|
-
expect(classifyToolSource('glob', '')).toBe('path-listing')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('keeps memory/conversation search generic — four classes only (C3, v2)', () => {
|
|
19
|
-
expect(classifyToolSource('memory_search', '')).toBe('generic')
|
|
20
|
-
expect(classifyToolSource('conversation_search', '')).toBe('generic')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('routes grep/rg/ripgrep to search (C4)', () => {
|
|
24
|
-
expect(classifyToolSource('grep', '')).toBe('search')
|
|
25
|
-
expect(classifyToolSource('rg', '')).toBe('search')
|
|
26
|
-
expect(classifyToolSource('ripgrep', '')).toBe('search')
|
|
27
|
-
expect(classifyToolSource('grep_search', '')).toBe('search')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('routes shell/bash/pwsh/terminal to shell-exec (C5)', () => {
|
|
31
|
-
expect(classifyToolSource('shell', '')).toBe('shell')
|
|
32
|
-
expect(classifyToolSource('bash', '')).toBe('shell')
|
|
33
|
-
expect(classifyToolSource('pwsh', '')).toBe('shell')
|
|
34
|
-
expect(classifyToolSource('powershell', '')).toBe('shell')
|
|
35
|
-
expect(classifyToolSource('terminal', '')).toBe('shell')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('routes read/read_file/cat/view/open_file to file-read (C6)', () => {
|
|
39
|
-
expect(classifyToolSource('read', '')).toBe('read')
|
|
40
|
-
expect(classifyToolSource('read_file', '')).toBe('read')
|
|
41
|
-
expect(classifyToolSource('cat', '')).toBe('read')
|
|
42
|
-
expect(classifyToolSource('view', '')).toBe('read')
|
|
43
|
-
expect(classifyToolSource('view_file', '')).toBe('read')
|
|
44
|
-
expect(classifyToolSource('open_file', '')).toBe('read')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('is generic for mutation tools — no file-mutate class in the four-class set (C7, v2)', () => {
|
|
48
|
-
expect(classifyToolSource('write', '')).toBe('generic')
|
|
49
|
-
expect(classifyToolSource('edit', '')).toBe('generic')
|
|
50
|
-
expect(classifyToolSource('apply_patch', '')).toBe('generic')
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('returns generic for any name with an mcp token, before content evidence (C8)', () => {
|
|
54
|
-
expect(classifyToolSource('mcp__server__grep', '', 'src/a.ts:1: x')).toBe('generic')
|
|
55
|
-
expect(classifyToolSource('mcp-grep', '', 'src/a.ts:1: x')).toBe('generic')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('never misroutes `research` into a search class (C9)', () => {
|
|
59
|
-
expect(classifyToolSource('research', '')).toBe('generic')
|
|
60
|
-
expect(classifyToolSource('deep_research', '')).toBe('generic')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('never misroutes `execute_sql` into shell-exec (C10)', () => {
|
|
64
|
-
expect(classifyToolSource('execute_sql', '')).toBe('generic')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('matches tokens exactly — no substring bleed (task_11)', () => {
|
|
68
|
-
expect(classifyToolSource('advanced_search', '')).toBe('generic')
|
|
69
|
-
expect(classifyToolSource('free_search_test', '')).toBe('generic')
|
|
70
|
-
expect(classifyToolSource('theme_global', '')).toBe('generic')
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('classifyToolSource — command and content fallback', () => {
|
|
75
|
-
it('routes rg/grep commands to search even from an unknown tool name', () => {
|
|
76
|
-
expect(classifyToolSource('run_tool', 'rg pattern src/')).toBe('search')
|
|
77
|
-
expect(classifyToolSource('run_tool', 'grep -n TODO .')).toBe('search')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('routes find/fd/ls/tree commands to path-listing, not search', () => {
|
|
81
|
-
expect(classifyToolSource('run_tool', 'find . -name "*.ts"')).toBe('path-listing')
|
|
82
|
-
expect(classifyToolSource('run_tool', 'fd config')).toBe('path-listing')
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('falls back to search on a path:line:content line (C13)', () => {
|
|
86
|
-
expect(classifyToolSource('unknown_tool', '', 'src/index.ts:12: export const x')).toBe('search')
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('does not let prose colons or URLs masquerade as grep output (C13 guard)', () => {
|
|
90
|
-
expect(classifyToolSource('unknown_tool', '', 'Note: 2024 - something happened')).toBe('generic')
|
|
91
|
-
expect(classifyToolSource('unknown_tool', '', 'see https://host.example:8080 - login')).toBe('generic')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('falls back to path-listing when ≥80% of lines are pure paths (C14)', () => {
|
|
95
|
-
const listing = ['src/index.ts', 'src/main.ts', 'src/util.ts', 'README.md'].join('\n')
|
|
96
|
-
expect(classifyToolSource('unknown_tool', '', listing)).toBe('path-listing')
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('never overrides a whitelist hit with content evidence (C15)', () => {
|
|
100
|
-
expect(classifyToolSource('bash', '', 'src/index.ts:12: export const x')).toBe('shell')
|
|
101
|
-
expect(classifyToolSource('glob', '', 'src/index.ts:12: export const x')).toBe('path-listing')
|
|
102
|
-
expect(classifyToolSource('read', '', 'src/index.ts')).toBe('read')
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
describe('extractCommand — input key removed (C11/C12)', () => {
|
|
107
|
-
it('returns empty for an input-only payload (C11)', () => {
|
|
108
|
-
expect(extractCommand('{"input":"arbitrary model text"}')).toBe('')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('still reads the command key (C12)', () => {
|
|
112
|
-
expect(extractCommand('{"command":"npm test"}')).toBe('npm test')
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('still reads cmd/script fallbacks', () => {
|
|
116
|
-
expect(extractCommand('{"cmd":"pnpm build"}')).toBe('pnpm build')
|
|
117
|
-
expect(extractCommand('{"script":"ls"}')).toBe('ls')
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
/** End-to-end dispatch guard for the misroute fixes: a `glob` result and an
|
|
122
|
-
* `execute_sql` result must not land on the search reducer even when they
|
|
123
|
-
* exceed every form gate. */
|
|
124
|
-
describe('toolclass dispatch integration', () => {
|
|
125
|
-
const paths = Array.from({ length: 200 }, (_, index) => `pkg/dir${String(index)}/file${String(index)}.ts`)
|
|
126
|
-
const globText = paths.join('\n')
|
|
127
|
-
|
|
128
|
-
it('routes a large glob result away from search-salience (task_11)', () => {
|
|
129
|
-
const output = reduceFreshToolResult({
|
|
130
|
-
toolName: 'glob',
|
|
131
|
-
argumentsText: '{}',
|
|
132
|
-
text: globText,
|
|
133
|
-
budgetChars: 4_000,
|
|
134
|
-
sourceRef: 'session://probe/glob',
|
|
135
|
-
isError: false,
|
|
136
|
-
})
|
|
137
|
-
expect(output).not.toBeNull()
|
|
138
|
-
expect(output!.reducer).not.toBe('search-by-file')
|
|
139
|
-
expect(output!.reducer).not.toBe('search-salience')
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('routes a large mcp web_search result away from the search reducer (C1/AD1)', () => {
|
|
143
|
-
const web = Array.from({ length: 60 }, (_, index) =>
|
|
144
|
-
`- [Result ${String(index)}](https://example.com/${String(index)}) — a summary paragraph of the ${String(index)}th hit.`).join('\n')
|
|
145
|
-
const output = reduceFreshToolResult({
|
|
146
|
-
toolName: 'mcp__web__web_search',
|
|
147
|
-
argumentsText: '{}',
|
|
148
|
-
text: web,
|
|
149
|
-
budgetChars: 2_000,
|
|
150
|
-
sourceRef: 'session://probe/web',
|
|
151
|
-
isError: false,
|
|
152
|
-
})
|
|
153
|
-
expect(output).not.toBeNull()
|
|
154
|
-
expect(output!.reducer).not.toBe('search-by-file')
|
|
155
|
-
})
|
|
156
|
-
})
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { assertNever, deepFreeze } from '../../src/runtime/value.ts'
|
|
3
|
-
|
|
4
|
-
describe('version-neutral runtime values', () => {
|
|
5
|
-
it('freezes nested and cyclic data without freezing a live AbortSignal', () => {
|
|
6
|
-
const controller = new AbortController()
|
|
7
|
-
const value: { nested: { value: number }, self?: unknown, signal: AbortSignal } = {
|
|
8
|
-
nested: { value: 1 },
|
|
9
|
-
signal: controller.signal,
|
|
10
|
-
}
|
|
11
|
-
value.self = value
|
|
12
|
-
|
|
13
|
-
expect(deepFreeze(value)).toBe(value)
|
|
14
|
-
expect(Object.isFrozen(value)).toBe(true)
|
|
15
|
-
expect(Object.isFrozen(value.nested)).toBe(true)
|
|
16
|
-
expect(Object.isFrozen(controller.signal)).toBe(false)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('reports an escaped closed-union member with its switch context', () => {
|
|
20
|
-
expect(() => assertNever({ kind: 'unexpected' } as never, 'value test'))
|
|
21
|
-
.toThrow('unreachable variant in value test: {"kind":"unexpected"}')
|
|
22
|
-
})
|
|
23
|
-
})
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* T28:节省卡片 per-session 面板(T26/T32)jsdom 规格——累计/省钱行、持久化
|
|
5
|
-
* 徽标与降级标注、displayPrefs 行开关与 compact、会话账本分页翻页。
|
|
6
|
-
* fetch 全局打桩:按 URL 分流 /savings 与 /savings/sessions。
|
|
7
|
-
*/
|
|
8
|
-
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
9
|
-
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
10
|
-
import { SavingsCard } from '../src/client/savings-card.tsx'
|
|
11
|
-
import { en } from '../src/client/locales.ts'
|
|
12
|
-
|
|
13
|
-
const t = (key: string) => en[key as keyof typeof en] ?? key
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
cleanup()
|
|
17
|
-
vi.unstubAllGlobals()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const SAVINGS_SNAPSHOT = {
|
|
21
|
-
ok: true,
|
|
22
|
-
startedAt: '2026-10-19T00:00:00.000Z',
|
|
23
|
-
sessions: 1,
|
|
24
|
-
gross: { exact: 1000, estimated: 0 },
|
|
25
|
-
offsets: { exact: 100, estimated: 0 },
|
|
26
|
-
net: { exact: 900, estimated: 0 },
|
|
27
|
-
perComponent: [],
|
|
28
|
-
recentOffsets: [],
|
|
29
|
-
usage: { requests: 3, inputTokens: 500, outputTokens: 100, cacheReadTokens: 400, cacheWriteTokens: 0, cacheHitRate: 0.8 },
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const INTEGRAL = { netExact: 2500, netEstimated: 0, cachedInput: 60_000, uncachedInput: 40_000, calls: 7 }
|
|
33
|
-
|
|
34
|
-
function sessionsPayload(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
|
35
|
-
return {
|
|
36
|
-
ok: true,
|
|
37
|
-
persisted: { persisted: true, driver: 'node:sqlite' },
|
|
38
|
-
displayPrefs: { rows: { stock: true, total: true, money: true }, mode: 'full', focusSessionId: null },
|
|
39
|
-
total: 2,
|
|
40
|
-
offset: 0,
|
|
41
|
-
limit: 20,
|
|
42
|
-
integralTotal: INTEGRAL,
|
|
43
|
-
integralMoney: { decimal: '0.1', currency: 'USD' },
|
|
44
|
-
sessions: [
|
|
45
|
-
{ sessionId: 'aaaaaaaa-1', net: { exact: 1500, estimated: 0 }, integral: { ...INTEGRAL, netExact: 1500, calls: 4 }, source: 'live' },
|
|
46
|
-
{ sessionId: 'bbbbbbbb-2', net: { exact: 1000, estimated: 0 }, integral: { ...INTEGRAL, netExact: 1000, calls: 3 }, source: 'backfill' },
|
|
47
|
-
],
|
|
48
|
-
liveOnly: [],
|
|
49
|
-
...overrides,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function stubFetch(savings: unknown, sessions: Record<string, unknown>): { calls: string[] } {
|
|
54
|
-
const calls: string[] = []
|
|
55
|
-
vi.stubGlobal('fetch', vi.fn(async (input: unknown) => {
|
|
56
|
-
const url = String(input)
|
|
57
|
-
calls.push(url)
|
|
58
|
-
if (url.includes('/savings/sessions')) {
|
|
59
|
-
return { ok: true, json: async () => sessions } as Response
|
|
60
|
-
}
|
|
61
|
-
return { ok: true, json: async () => savings } as Response
|
|
62
|
-
}))
|
|
63
|
-
return { calls }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function mountCard(): void {
|
|
67
|
-
render(<SavingsCard t={t} />)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
describe('savings card per-session panel (T26/T32)', () => {
|
|
71
|
-
it('渲染累计(按 N 次 call)/省钱行与持久化徽标', async () => {
|
|
72
|
-
stubFetch(SAVINGS_SNAPSHOT, sessionsPayload())
|
|
73
|
-
mountCard()
|
|
74
|
-
await waitFor(() => {
|
|
75
|
-
expect(screen.getByTestId('savings-cumulative')).toBeDefined()
|
|
76
|
-
expect(screen.getByTestId('savings-money')).toBeDefined()
|
|
77
|
-
expect(screen.getByTestId('savings-persisted').textContent).toContain('✓')
|
|
78
|
-
})
|
|
79
|
-
expect(screen.getByTestId('savings-cumulative').textContent).toContain('7')
|
|
80
|
-
expect(screen.getByTestId('savings-money').textContent).toContain('USD 0.1')
|
|
81
|
-
expect(screen.getByTestId('savings-session-list').textContent).toContain('aaaaaaaa')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('persisted:false → 降级标注', async () => {
|
|
85
|
-
stubFetch(SAVINGS_SNAPSHOT, sessionsPayload({ persisted: { persisted: false, reason: 'no-driver' } }))
|
|
86
|
-
mountCard()
|
|
87
|
-
await waitFor(() => {
|
|
88
|
-
expect(screen.getByTestId('savings-persisted').textContent).toContain('⚠')
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('displayPrefs 行开关:stock off 隐藏存量,compact 隐藏分项', async () => {
|
|
93
|
-
stubFetch(SAVINGS_SNAPSHOT, sessionsPayload({
|
|
94
|
-
displayPrefs: { rows: { stock: false, total: true, money: true }, mode: 'compact', focusSessionId: 'aaaaaaaa-1' },
|
|
95
|
-
}))
|
|
96
|
-
mountCard()
|
|
97
|
-
await waitFor(() => {
|
|
98
|
-
expect(screen.queryByTestId('savings-stock-exact')).toBeNull()
|
|
99
|
-
expect(screen.queryByTestId('savings-cumulative')).not.toBeNull()
|
|
100
|
-
})
|
|
101
|
-
// 聚焦会话带 focus 标记
|
|
102
|
-
expect(screen.getByTestId('savings-session-list').textContent).toContain('focus')
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('分页:下一页以 offset=20 重取,上一页回到 0', async () => {
|
|
106
|
-
const many = Array.from({ length: 30 }, (_, index) => ({
|
|
107
|
-
sessionId: `sess-${String(index).padStart(3, '0')}`,
|
|
108
|
-
net: { exact: index, estimated: 0 },
|
|
109
|
-
integral: { ...INTEGRAL, calls: 1 },
|
|
110
|
-
source: 'backfill',
|
|
111
|
-
}))
|
|
112
|
-
const { calls } = stubFetch(SAVINGS_SNAPSHOT, sessionsPayload({ total: 30, sessions: many.slice(0, 20) }))
|
|
113
|
-
mountCard()
|
|
114
|
-
await waitFor(() => {
|
|
115
|
-
expect(screen.getByTestId('savings-page-next')).toBeDefined()
|
|
116
|
-
})
|
|
117
|
-
fireEvent.click(screen.getByTestId('savings-page-next'))
|
|
118
|
-
await waitFor(() => {
|
|
119
|
-
expect(calls.some(url => url.includes('offset=20'))).toBe(true)
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('存量与积分双空 → 空态', async () => {
|
|
124
|
-
stubFetch({ ...SAVINGS_SNAPSHOT, gross: { exact: 0, estimated: 0 }, offsets: { exact: 0, estimated: 0 }, net: { exact: 0, estimated: 0 } }, sessionsPayload({ integralTotal: { netExact: 0, netEstimated: 0, cachedInput: 0, uncachedInput: 0, calls: 0 }, sessions: [], integralMoney: undefined }))
|
|
125
|
-
mountCard()
|
|
126
|
-
await waitFor(() => {
|
|
127
|
-
expect(screen.getByText(t('savings.empty'))).toBeDefined()
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('存量/积分双空但账本有回填 → 不早退,账本照常渲染(空存量的历史节省可见)', async () => {
|
|
132
|
-
stubFetch({ ...SAVINGS_SNAPSHOT, gross: { exact: 0, estimated: 0 }, offsets: { exact: 0, estimated: 0 }, net: { exact: 0, estimated: 0 } }, sessionsPayload({ integralTotal: { netExact: 0, netEstimated: 0, cachedInput: 0, uncachedInput: 0, calls: 0 }, integralMoney: undefined }))
|
|
133
|
-
mountCard()
|
|
134
|
-
await waitFor(() => {
|
|
135
|
-
expect(screen.getByTestId('savings-session-list')).toBeDefined()
|
|
136
|
-
})
|
|
137
|
-
expect(screen.queryByText(t('savings.empty'))).toBeNull()
|
|
138
|
-
expect(screen.getByTestId('savings-session-list').textContent).toContain('bbbbbbbb')
|
|
139
|
-
})
|
|
140
|
-
})
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings-seat contract pin for dsh-context-compression-improved's client.
|
|
3
|
-
*
|
|
4
|
-
* This spec locks WHERE the compression settings panel mounts: exactly ONE
|
|
5
|
-
* seat — the standalone `settings.section` entry (设置 → 上下文压缩) — and
|
|
6
|
-
* explicitly NOT the Plugins-section config surfaces (settings.plugins.tab /
|
|
7
|
-
* settings.plugin.item), and NOT a `shell.overlay` float
|
|
8
|
-
* (the retired review panel's seat was removed with the gate). History this
|
|
9
|
-
* pins against: the 0.1.5 line first lost every entry (a lazy `ctx.get` of
|
|
10
|
-
* locale/settingsScope raced the settings client and apply bailed), then showed
|
|
11
|
-
* the panel twice (item card + tab on top of the standalone section). Both were
|
|
12
|
-
* fixed by the declarative-inject + single-section shape below. When a future
|
|
13
|
-
* DSH line moves the seat again, migrate src/client/index.ts AND this file
|
|
14
|
-
* together.
|
|
15
|
-
*/
|
|
16
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
17
|
-
import type { Context as ClientContext } from '@deepseek-ai/cordis'
|
|
18
|
-
import { apply, inject } from '../src/client/index.ts'
|
|
19
|
-
import { ContextCompressionSettingsSection } from '../src/client/CompressionProfileSelector.tsx'
|
|
20
|
-
import { DEFAULT_CUSTOM_COMPRESSION_POLICY } from '../src/profiles.ts'
|
|
21
|
-
|
|
22
|
-
vi.mock('@deepseek-ai/dsh-client-ui-primitives', () => ({
|
|
23
|
-
IconChevronDownOutlineMedium: () => null,
|
|
24
|
-
Menu: () => null,
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
interface CapturedRegistration {
|
|
28
|
-
readonly slot: string
|
|
29
|
-
readonly options: Record<string, unknown>
|
|
30
|
-
readonly component: unknown
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Drive apply against a stub host and capture every slot registration.
|
|
35
|
-
* @param options - `registerThrows` models an older host that does not declare
|
|
36
|
-
* the seat: the slot boundary rejects the registration, exactly the shape the
|
|
37
|
-
* 0.1.2-era hosts had.
|
|
38
|
-
*/
|
|
39
|
-
function collectRegistrations(
|
|
40
|
-
options: { readonly registerThrows?: boolean } = {},
|
|
41
|
-
): { declared: string[]; registrations: CapturedRegistration[] } {
|
|
42
|
-
const declared: string[] = []
|
|
43
|
-
const registrations: CapturedRegistration[] = []
|
|
44
|
-
const ctx = {
|
|
45
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
46
|
-
configForms: { get: vi.fn(() => ({}) as never) },
|
|
47
|
-
// Scoped sub-inject seam: the host resolves declared services and fires
|
|
48
|
-
// the callback (configForms arm — 0.1.7+ lines only).
|
|
49
|
-
inject: (services: string[], cb: (service: unknown) => void) => {
|
|
50
|
-
if (services.includes('configForms')) cb(ctx.configForms)
|
|
51
|
-
},
|
|
52
|
-
slots: {
|
|
53
|
-
inject: (slot: string, factory: () => (() => void) | Generator<() => void>) => {
|
|
54
|
-
declared.push(slot)
|
|
55
|
-
const result = factory()
|
|
56
|
-
const steps: Iterable<() => void> = typeof (result as { [Symbol.iterator]?: unknown })?.[Symbol.iterator] === 'function'
|
|
57
|
-
? (result as Generator<() => void>)
|
|
58
|
-
: [result as () => void]
|
|
59
|
-
for (const step of steps) { void step }
|
|
60
|
-
return () => {}
|
|
61
|
-
},
|
|
62
|
-
register: (record: Record<string, unknown>, component: unknown) => {
|
|
63
|
-
if (options.registerThrows === true) throw new Error(`unknown slot ${String(record['name'])}`)
|
|
64
|
-
registrations.push({ slot: String(record['name']), options: record, component })
|
|
65
|
-
return () => {}
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
apply(ctx as unknown as ClientContext)
|
|
70
|
-
return { declared, registrations }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
describe('settings-seat contract (settings.section + input-bar session view binder + bundle detail card)', () => {
|
|
74
|
-
it('declares the services apply consumes (cordis waits; no lazy-get race)', () => {
|
|
75
|
-
// compat-legacy 单版本(B8):顶层只声明六线通用服务;数据面由 scoped
|
|
76
|
-
// sub-inject 双臂选择(桥默认 + configForms 升级),不再出现在顶层表。
|
|
77
|
-
expect(inject).toEqual(['slots', 'locale'])
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('injects exactly three seats: the settings.section panel + the input-bar session view binder + the 0.1.7+ bundle detail card', () => {
|
|
81
|
-
const { declared, registrations } = collectRegistrations()
|
|
82
|
-
expect(declared).toEqual(['settings.section', 'conversation.input.left', 'plugins.bundle.config'])
|
|
83
|
-
expect(registrations).toHaveLength(3)
|
|
84
|
-
expect(registrations[0]!.slot).toBe('settings.section')
|
|
85
|
-
expect(registrations[1]!.slot).toBe('conversation.input.left')
|
|
86
|
-
expect(registrations[2]!.slot).toBe('plugins.bundle.config')
|
|
87
|
-
// bundle 卡 keyed=包名,0.1.x 宿主无此槽时由 registerThrows 分支另行覆盖
|
|
88
|
-
expect(registrations[2]!.options['key']).toBe('dsh-context-compression-improved')
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('pins the input-bar view binder: invisible component consumes the reactive sessionId standard prop', () => {
|
|
92
|
-
// 绑定源 = session 作用域槽的 sessionId 标准 prop(宿主按当前页面会话
|
|
93
|
-
// 响应式下发);inject 回调只在装载时发一次,不作绑定源(陈旧教训)。
|
|
94
|
-
const { registrations } = collectRegistrations()
|
|
95
|
-
const inputSeat = registrations[1]!
|
|
96
|
-
expect(inputSeat.options['id']).toBe('context-compression-session-bind')
|
|
97
|
-
expect(inputSeat.options['order']).toBe(170)
|
|
98
|
-
const component = inputSeat.component as ((props: { sessionId?: string }) => unknown) | undefined
|
|
99
|
-
expect(typeof component).toBe('function')
|
|
100
|
-
expect(component?.({ sessionId: 'sess-view-1' })).toBeNull()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('no longer claims a shell.overlay float (the review panel it served is gone)', () => {
|
|
104
|
-
const { declared } = collectRegistrations()
|
|
105
|
-
expect(declared).not.toContain('shell.overlay')
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('pins the section identity (id/order/label/locale) and the panel component', () => {
|
|
109
|
-
const { registrations } = collectRegistrations()
|
|
110
|
-
const { options, component } = registrations[0]!
|
|
111
|
-
expect(options['id']).toBe('context-compression')
|
|
112
|
-
expect(options['order']).toBe(17)
|
|
113
|
-
expect(options['locale']).toBe('context-compression')
|
|
114
|
-
expect((options['label'] as () => string)()).toBe('nav')
|
|
115
|
-
expect(typeof options['inject']).toBe('function')
|
|
116
|
-
const face = (options['inject'] as () => Record<string, unknown>)()
|
|
117
|
-
expect(Object.keys(face).sort()).toEqual(['hooks', 'saveAutoCompact', 'saveCodeSkeleton', 'saveCustom', 'saveIntentSummary', 'saveMonitorPanel', 'savePresetOptions', 'select', 'resetCustom'].sort())
|
|
118
|
-
expect(component).toBe(ContextCompressionSettingsSection)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('never adds a Plugins-section card or tab alongside the standalone section', () => {
|
|
122
|
-
const { declared } = collectRegistrations()
|
|
123
|
-
expect(declared).not.toContain('settings.plugins.tab')
|
|
124
|
-
expect(declared).not.toContain('settings.plugin.item')
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('projects an identity-stable snapshot between form changes (React #185 regression)', () => {
|
|
128
|
-
// The 0.1.7 adapter wraps configForms into the legacy scope shape. Its
|
|
129
|
-
// getSnapshot MUST return the same object reference until the underlying
|
|
130
|
-
// form snapshot changes: a fresh literal per call re-renders
|
|
131
|
-
// useSyncExternalStore forever — "Minified React error #185" (maximum
|
|
132
|
-
// update depth exceeded), and the slot boundary abdicates the whole
|
|
133
|
-
// settings.section on the production host.
|
|
134
|
-
let source = {
|
|
135
|
-
status: 'ready' as const,
|
|
136
|
-
value: { settings: { profile: 'balanced', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } },
|
|
137
|
-
revision: 1, writable: true, base: undefined, user: undefined, mode: 'host' as const,
|
|
138
|
-
}
|
|
139
|
-
const listeners: (() => void)[] = []
|
|
140
|
-
const ctx = {
|
|
141
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
142
|
-
configForms: { get: () => ({
|
|
143
|
-
getSnapshot: () => source,
|
|
144
|
-
subscribe: (listener: () => void) => { listeners.push(listener); return () => {} },
|
|
145
|
-
set: async () => true,
|
|
146
|
-
}) },
|
|
147
|
-
inject: (services: string[], cb: (service: unknown) => void) => {
|
|
148
|
-
if (services.includes('configForms')) cb(ctx.configForms)
|
|
149
|
-
},
|
|
150
|
-
slots: {
|
|
151
|
-
inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
|
|
152
|
-
register: (record: Record<string, unknown>) => {
|
|
153
|
-
registrations.push({ slot: String(record['name']), options: record, component: null })
|
|
154
|
-
return () => {}
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
}
|
|
158
|
-
const registrations: CapturedRegistration[] = []
|
|
159
|
-
apply(ctx as unknown as ClientContext)
|
|
160
|
-
const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown; subscribe(l: () => void): () => void } } })()
|
|
161
|
-
const scope = face.hooks.compression
|
|
162
|
-
|
|
163
|
-
const first = scope.getSnapshot()
|
|
164
|
-
expect(scope.getSnapshot()).toBe(first)
|
|
165
|
-
// value decodes through the whole strict validator
|
|
166
|
-
expect(first && typeof first === 'object' && 'value' in first && (first as { value?: { profile?: string } }).value?.profile).toBe('balanced')
|
|
167
|
-
|
|
168
|
-
// Host accepts a change → NEW form snapshot object → projection recomputes
|
|
169
|
-
source = { ...source, revision: 2, value: { settings: { profile: 'off', custom: DEFAULT_CUSTOM_COMPRESSION_POLICY } } }
|
|
170
|
-
for (const listener of listeners) listener()
|
|
171
|
-
const second = scope.getSnapshot()
|
|
172
|
-
expect(second).not.toBe(first)
|
|
173
|
-
expect(second && typeof second === 'object' && 'value' in second && (second as { value?: { profile?: string } }).value?.profile).toBe('off')
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('defaults to the bridge scope when the configForms arm never resolves (pre-0.1.7 lines)', () => {
|
|
177
|
-
// B8 dual-arm: on 0.1.x hosts configForms does not exist, the scoped
|
|
178
|
-
// sub-inject never fires, and the selector must stand on the HTTP bridge
|
|
179
|
-
// scope (status loading until the first GET returns).
|
|
180
|
-
const registrations: CapturedRegistration[] = []
|
|
181
|
-
const ctx = {
|
|
182
|
-
locale: { register: vi.fn(() => () => {}), bind: () => (key: string) => key },
|
|
183
|
-
// No `inject` at all: neither arm resolves, bridge stays the scope.
|
|
184
|
-
slots: {
|
|
185
|
-
inject: (_slot: string, factory: () => (() => void) | Generator<() => void>) => { void factory() },
|
|
186
|
-
register: (record: Record<string, unknown>) => {
|
|
187
|
-
registrations.push({ slot: String(record['name']), options: record, component: null })
|
|
188
|
-
return () => {}
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
}
|
|
192
|
-
apply(ctx as unknown as ClientContext)
|
|
193
|
-
const face = (registrations[0]!.options['inject'] as () => { hooks: { compression: { getSnapshot(): unknown } } })()
|
|
194
|
-
const scope = face.hooks.compression
|
|
195
|
-
const snapshot = scope.getSnapshot() as { status?: string }
|
|
196
|
-
expect(snapshot.status).toBe('loading')
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it('survives an older host that does not declare the seat, warning instead of crashing', () => {
|
|
200
|
-
// Cross-version tolerance: a host without this seat rejects the
|
|
201
|
-
// registration at the slot boundary. apply() must swallow that and warn —
|
|
202
|
-
// the historical failure mode was apply() bailing out, which silently took
|
|
203
|
-
// EVERY settings entry down with it.
|
|
204
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
205
|
-
try {
|
|
206
|
-
const { declared } = collectRegistrations({ registerThrows: true })
|
|
207
|
-
// It tried all three seats (so the degradation is "loud", not a silent no-op)…
|
|
208
|
-
expect(declared).toEqual(['settings.section', 'conversation.input.left', 'plugins.bundle.config'])
|
|
209
|
-
// …and the rejection never escaped apply().
|
|
210
|
-
expect(warn).toHaveBeenCalled()
|
|
211
|
-
} finally {
|
|
212
|
-
warn.mockRestore()
|
|
213
|
-
}
|
|
214
|
-
})
|
|
215
|
-
})
|