dsh-context-compression-improved 0.10.3 → 0.10.4
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.d.ts +4 -0
- package/{packages/selector/lib → lib}/client.js +70 -5
- package/{packages/selector/lib → lib}/invariant.js +1 -1
- package/{packages/selector/lib → lib}/profiles.d.ts +3 -1
- package/{packages/selector/lib → lib}/pruner.d.ts +4 -2
- package/{packages/selector/lib → lib}/pruner.js +40 -37
- package/{packages/selector/lib → lib}/savings-integral.js +83 -24
- package/{packages/selector/lib → lib}/tail-trim.js +2 -2
- package/{packages/selector/lib → lib}/tool-result.js +22 -1
- 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 -549
- 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/fab-pos.ts +0 -71
- 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 -431
- 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/fab-pos.client.spec.ts +0 -47
- 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 -240
- 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}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/index.js +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
-
import { parseContextCompressionSettings, DEFAULT_CONTEXT_COMPRESSION_SETTINGS } from '../../src/runtime/config.ts'
|
|
3
|
-
import { SavingsLedger } from '../../src/runtime/savings.ts'
|
|
4
|
-
import {
|
|
5
|
-
applySessionOverride,
|
|
6
|
-
drsTotalsFragment,
|
|
7
|
-
MONITOR_SUGGEST_PCT,
|
|
8
|
-
observeContextUsage,
|
|
9
|
-
buildMonitorSnapshot,
|
|
10
|
-
estimateSavingsPricing,
|
|
11
|
-
isSessionOverrideAction,
|
|
12
|
-
mergeCompositionByComponent,
|
|
13
|
-
} from '../../src/runtime/monitor.ts'
|
|
14
|
-
import { getSummaryOverride } from '../../src/runtime/tokenpilot/advisor-state.ts'
|
|
15
|
-
|
|
16
|
-
/** 每用例独立 sessionId:advisor-state 的覆盖表是模块级,防用例间串扰。 */
|
|
17
|
-
let seq = 0
|
|
18
|
-
const uniqueSession = (): string => `monitor-spec-${++seq}`
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
vi.restoreAllMocks()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe('buildMonitorSnapshot', () => {
|
|
25
|
-
it('savings aggregate plus the intent control block, defaults lossless', () => {
|
|
26
|
-
const snap = buildMonitorSnapshot(undefined, new SavingsLedger())
|
|
27
|
-
expect(snap.gross.exact).toBe(0)
|
|
28
|
-
expect(snap.sessionScope).toBeNull()
|
|
29
|
-
expect(snap.intent.override).toBeUndefined()
|
|
30
|
-
expect(snap.intent.observedEnabled).toBeUndefined()
|
|
31
|
-
expect(snap.intent.gate).toEqual({ floorFraction: 0.45, growthTokens: 50_000 })
|
|
32
|
-
expect(snap.intent.lastFold).toBeUndefined()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('session filter scopes the savings rows and the control block', () => {
|
|
36
|
-
const ledger = new SavingsLedger()
|
|
37
|
-
ledger.recordSaving({
|
|
38
|
-
sessionId: 's1',
|
|
39
|
-
component: 'fresh',
|
|
40
|
-
tokensBefore: 10_000,
|
|
41
|
-
tokensAfter: 2_000,
|
|
42
|
-
basis: 'exact-tokenizer',
|
|
43
|
-
sourceSeq: 1,
|
|
44
|
-
})
|
|
45
|
-
const scoped = buildMonitorSnapshot('s1', ledger)
|
|
46
|
-
expect(scoped.sessionScope).toBe('s1')
|
|
47
|
-
expect(scoped.gross.exact).toBe(8_000)
|
|
48
|
-
const other = buildMonitorSnapshot('s2', ledger)
|
|
49
|
-
expect(other.gross.exact).toBe(0)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('reuses the ledger verbatim — no second accounting', () => {
|
|
53
|
-
const ledger = new SavingsLedger()
|
|
54
|
-
ledger.recordSaving({
|
|
55
|
-
sessionId: 's1',
|
|
56
|
-
component: 'fresh',
|
|
57
|
-
tokensBefore: 1_000,
|
|
58
|
-
tokensAfter: 100,
|
|
59
|
-
basis: 'exact-tokenizer',
|
|
60
|
-
sourceSeq: 2,
|
|
61
|
-
originalText: 'x\n'.repeat(400),
|
|
62
|
-
})
|
|
63
|
-
const monitor = buildMonitorSnapshot('s1', ledger)
|
|
64
|
-
expect(monitor).toMatchObject(ledger.snapshot('s1'))
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
describe('applySessionOverride (the /ctx-summary state machine)', () => {
|
|
69
|
-
it('pins on/off and echoes the post-action truth', () => {
|
|
70
|
-
const sessionId = uniqueSession()
|
|
71
|
-
expect(applySessionOverride(sessionId, 'on').override).toBe('on')
|
|
72
|
-
expect(getSummaryOverride(sessionId)).toBe('on')
|
|
73
|
-
expect(applySessionOverride(sessionId, 'off').override).toBe('off')
|
|
74
|
-
expect(getSummaryOverride(sessionId)).toBe('off')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('clear returns the session to settings-driven', () => {
|
|
78
|
-
const sessionId = uniqueSession()
|
|
79
|
-
applySessionOverride(sessionId, 'off')
|
|
80
|
-
expect(applySessionOverride(sessionId, 'clear').override).toBeUndefined()
|
|
81
|
-
expect(getSummaryOverride(sessionId)).toBeUndefined()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('isSessionOverrideAction narrows exactly the three actions', () => {
|
|
85
|
-
expect(isSessionOverrideAction('on')).toBe(true)
|
|
86
|
-
expect(isSessionOverrideAction('off')).toBe(true)
|
|
87
|
-
expect(isSessionOverrideAction('clear')).toBe(true)
|
|
88
|
-
expect(isSessionOverrideAction('status')).toBe(false)
|
|
89
|
-
expect(isSessionOverrideAction(42)).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
describe('estimateSavingsPricing (moved from the entry — shared by savings and monitor routes)', () => {
|
|
94
|
-
const snapshot = {
|
|
95
|
-
startedAt: new Date().toISOString(),
|
|
96
|
-
net: { exact: 4_200, estimated: 0 },
|
|
97
|
-
usage: { requests: 3, inputTokens: 1_000, outputTokens: 500, cacheReadTokens: 200, cacheWriteTokens: 100 },
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
it('third-party routes fail closed to no pricing', () => {
|
|
101
|
-
const readService = (): unknown => ({ currentSelection: () => ({ provider: 'local-35b', model: 'Qwen3.6-35B-A3B' }) })
|
|
102
|
-
expect(estimateSavingsPricing(readService, snapshot)).toBeUndefined()
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('official routes carry actual cost and the labeled saved-cost estimate', () => {
|
|
106
|
-
const readService = (): unknown => ({ currentSelection: () => ({ provider: 'deepseek-official', model: 'deepseek-v4-flash' }) })
|
|
107
|
-
const pricing = estimateSavingsPricing(readService, snapshot)
|
|
108
|
-
expect(pricing?.currency).toBe('USD')
|
|
109
|
-
expect(typeof pricing?.actualCost).toBe('string')
|
|
110
|
-
expect(typeof pricing?.estimatedSavedCost).toBe('string')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('an empty ledger prices nothing', () => {
|
|
114
|
-
const readService = (): unknown => ({ currentSelection: () => ({ provider: 'deepseek-official', model: 'deepseek-v4-flash' }) })
|
|
115
|
-
expect(estimateSavingsPricing(readService, {
|
|
116
|
-
startedAt: new Date().toISOString(),
|
|
117
|
-
net: { exact: 0, estimated: 0 },
|
|
118
|
-
usage: { requests: 0, inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },
|
|
119
|
-
})).toBeUndefined()
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
import type { Context } from '@deepseek-ai/cordis'
|
|
125
|
-
import { registerMonitorRoute } from '../../src/index.ts'
|
|
126
|
-
|
|
127
|
-
/** Fake webServer: captures exact-path handlers; fake ctx wires direct arrival. */
|
|
128
|
-
function mountMonitorRoute(): { handler: (req: unknown, res: unknown) => void } {
|
|
129
|
-
let handler: (req: unknown, res: unknown) => void = () => {}
|
|
130
|
-
const webServer = { register: (def: { path: string, handler: typeof handler }) => { handler = def.handler; return () => undefined } }
|
|
131
|
-
const ctx = {
|
|
132
|
-
get: (name: string) => (name === 'webServer' ? webServer : undefined),
|
|
133
|
-
inject: (deps: string[], cb: (injected: Record<string, unknown>) => void) => cb({ webServer }),
|
|
134
|
-
effect: () => undefined,
|
|
135
|
-
} as unknown as Context
|
|
136
|
-
registerMonitorRoute(ctx)
|
|
137
|
-
return { handler }
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
interface CapturedResponse {
|
|
141
|
-
status: number
|
|
142
|
-
body: Record<string, unknown>
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function fakeRes(): { res: unknown, captured: CapturedResponse } {
|
|
146
|
-
const captured = {} as CapturedResponse
|
|
147
|
-
const res = {
|
|
148
|
-
writeHead: (status: number) => { captured.status = status },
|
|
149
|
-
end: (body?: string) => { captured.body = JSON.parse(body ?? '{}') as Record<string, unknown> },
|
|
150
|
-
}
|
|
151
|
-
return { res, captured }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function fakeReq(url: string, method: string, body?: string): unknown {
|
|
155
|
-
return {
|
|
156
|
-
url,
|
|
157
|
-
method,
|
|
158
|
-
on: (event: string, cb: (chunk?: Buffer) => void) => {
|
|
159
|
-
if (event === 'data' && body !== undefined) cb(Buffer.from(body, 'utf8'))
|
|
160
|
-
if (event === 'end') cb()
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
describe('monitor route (GET snapshot / POST override)', () => {
|
|
166
|
-
const PATH = '/api/dsh-context-compression-improved/monitor'
|
|
167
|
-
const { handler } = mountMonitorRoute()
|
|
168
|
-
|
|
169
|
-
it('GET returns ok + savings + intent block scoped to the query session', () => {
|
|
170
|
-
const { res, captured } = fakeRes()
|
|
171
|
-
handler(fakeReq(`${PATH}?sessionId=route-s1`, 'GET'), res)
|
|
172
|
-
expect(captured.status).toBe(200)
|
|
173
|
-
expect(captured.body.ok).toBe(true)
|
|
174
|
-
expect(captured.body.sessionScope).toBe('route-s1')
|
|
175
|
-
expect((captured.body.intent as Record<string, unknown>).gate).toEqual({ floorFraction: 0.45, growthTokens: 50_000 })
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
it('POST drives the /ctx-summary override state machine', () => {
|
|
179
|
-
const sessionId = `route-${uniqueSession()}`
|
|
180
|
-
const { res, captured } = fakeRes()
|
|
181
|
-
handler(fakeReq(`${PATH}?sessionId=${sessionId}`, 'POST', '{"action":"off"}'), res)
|
|
182
|
-
expect(captured.status).toBe(200)
|
|
183
|
-
expect(captured.body).toEqual({ ok: true, override: 'off', sessionScope: sessionId })
|
|
184
|
-
expect(getSummaryOverride(sessionId)).toBe('off')
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('POST rejects an unknown action with 400 and touches no state', () => {
|
|
188
|
-
const sessionId = uniqueSession()
|
|
189
|
-
const { res, captured } = fakeRes()
|
|
190
|
-
handler(fakeReq(`${PATH}?sessionId=${sessionId}`, 'POST', '{"action":"boom"}'), res)
|
|
191
|
-
expect(captured.status).toBe(400)
|
|
192
|
-
expect(captured.body.ok).toBe(false)
|
|
193
|
-
expect(getSummaryOverride(sessionId)).toBeUndefined()
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('POST rejects a non-JSON body with 400', () => {
|
|
197
|
-
const { res, captured } = fakeRes()
|
|
198
|
-
handler(fakeReq(PATH, 'POST', 'not-json'), res)
|
|
199
|
-
expect(captured.status).toBe(400)
|
|
200
|
-
expect(captured.body.ok).toBe(false)
|
|
201
|
-
})
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
describe('monitorPanel settings parsing (schema surface, mirrors intentSummary cases)', () => {
|
|
205
|
-
const base = {
|
|
206
|
-
profile: 'balanced' as const,
|
|
207
|
-
custom: structuredClone(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.custom),
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
it('defaults to hidden', () => {
|
|
211
|
-
expect(DEFAULT_CONTEXT_COMPRESSION_SETTINGS.monitorPanel).toEqual({ enabled: false })
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('absent section inherits the default', () => {
|
|
215
|
-
const parsed = parseContextCompressionSettings({ ...base, autoCompact: { thresholdPercent: 80 } })
|
|
216
|
-
expect(parsed.monitorPanel).toEqual({ enabled: false })
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('accepts exactly { enabled: boolean }', () => {
|
|
220
|
-
const parsed = parseContextCompressionSettings({ ...base, monitorPanel: { enabled: true } })
|
|
221
|
-
expect(parsed.monitorPanel).toEqual({ enabled: true })
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
it('rejects extra keys (present-but-invalid is never silently defaulted)', () => {
|
|
225
|
-
expect(() => parseContextCompressionSettings({
|
|
226
|
-
...base, monitorPanel: { enabled: true, position: 'left' },
|
|
227
|
-
})).toThrow(/expected exactly "enabled"/)
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('rejects non-boolean enabled', () => {
|
|
231
|
-
expect(() => parseContextCompressionSettings({
|
|
232
|
-
...base, monitorPanel: { enabled: 'yes' },
|
|
233
|
-
})).toThrow(/monitorPanel\.enabled must be a boolean/)
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('rejects non-object section', () => {
|
|
237
|
-
expect(() => parseContextCompressionSettings({ ...base, monitorPanel: 'yes' }))
|
|
238
|
-
.toThrow(/monitorPanel must be a plain object/)
|
|
239
|
-
})
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
describe('context occupancy observation (task_6.2)', () => {
|
|
243
|
-
it('scoped snapshot carries the observed occupancy block', () => {
|
|
244
|
-
const sessionId = uniqueSession()
|
|
245
|
-
observeContextUsage(sessionId, 60_000, 128_000)
|
|
246
|
-
const snap = buildMonitorSnapshot(sessionId, new SavingsLedger())
|
|
247
|
-
expect(snap.context).toEqual({ liveTokens: 60_000, contextWindow: 128_000, pct: 0.469, sessionId })
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('aggregate snapshot carries the most recently observed session', () => {
|
|
251
|
-
const a = uniqueSession()
|
|
252
|
-
const b = uniqueSession()
|
|
253
|
-
observeContextUsage(a, 10_000, 100_000)
|
|
254
|
-
observeContextUsage(b, 90_000, 100_000)
|
|
255
|
-
const snap = buildMonitorSnapshot(undefined, new SavingsLedger())
|
|
256
|
-
expect(snap.context?.sessionId).toBe(b)
|
|
257
|
-
expect(snap.context?.pct).toBe(0.9)
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
it('no observation yet — context block absent', () => {
|
|
261
|
-
const snap = buildMonitorSnapshot(uniqueSession(), new SavingsLedger())
|
|
262
|
-
expect(snap.context).toBeUndefined()
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
it('observation cap keeps the newest 64 sessions', () => {
|
|
266
|
-
for (let i = 0; i < 70; i++) observeContextUsage(`cap-${i}`, i, 1000)
|
|
267
|
-
const snap = buildMonitorSnapshot('cap-69', new SavingsLedger())
|
|
268
|
-
expect(snap.context?.sessionId).toBe('cap-69')
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
it('empty session id and non-finite tokens are ignored', () => {
|
|
272
|
-
observeContextUsage('', 5, 100)
|
|
273
|
-
observeContextUsage('fin-check', Number.NaN, 100)
|
|
274
|
-
expect(buildMonitorSnapshot('fin-check', new SavingsLedger()).context).toBeUndefined()
|
|
275
|
-
})
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
describe('catastrophic-forgetting suggestion (task: 建议压缩)', () => {
|
|
279
|
-
it('occupancy past the threshold suggests compression', () => {
|
|
280
|
-
const sessionId = uniqueSession()
|
|
281
|
-
observeContextUsage(sessionId, 90_000, 100_000)
|
|
282
|
-
const snap = buildMonitorSnapshot(sessionId, new SavingsLedger())
|
|
283
|
-
expect(snap.suggestion?.suggest).toBe(true)
|
|
284
|
-
expect(snap.suggestion?.thresholdPct).toBe(MONITOR_SUGGEST_PCT)
|
|
285
|
-
expect(snap.suggestion?.occupancyPct).toBe(0.9)
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
it('below the threshold stays silent', () => {
|
|
289
|
-
const sessionId = uniqueSession()
|
|
290
|
-
observeContextUsage(sessionId, 50_000, 100_000)
|
|
291
|
-
const snap = buildMonitorSnapshot(sessionId, new SavingsLedger())
|
|
292
|
-
expect(snap.suggestion?.suggest).toBe(false)
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
it('threshold sits below the host auto-compact default (提前一档人工干预窗口)', () => {
|
|
296
|
-
expect(MONITOR_SUGGEST_PCT).toBeLessThan(0.8)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('unobserved sessions carry no suggestion block', () => {
|
|
300
|
-
expect(buildMonitorSnapshot(uniqueSession(), new SavingsLedger()).suggestion).toBeUndefined()
|
|
301
|
-
})
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
describe('mergeCompositionByComponent (浮窗组成去重合并)', () => {
|
|
305
|
-
it('同路径跨口径合并一行(mixed),跨路径保留,tokens 降序', () => {
|
|
306
|
-
const merged = mergeCompositionByComponent([
|
|
307
|
-
{ component: 'projection', basis: 'characters', tokens: 200_000, events: 30 },
|
|
308
|
-
{ component: 'fresh', basis: 'exact-tokenizer', tokens: 5_000, events: 2 },
|
|
309
|
-
{ component: 'projection', basis: 'exact-tokenizer', tokens: 103_698, events: 8 },
|
|
310
|
-
])
|
|
311
|
-
expect(merged).toEqual([
|
|
312
|
-
{ component: 'projection', basis: 'mixed', tokens: 303_698, events: 38 },
|
|
313
|
-
{ component: 'fresh', basis: 'exact-tokenizer', tokens: 5_000, events: 2 },
|
|
314
|
-
])
|
|
315
|
-
})
|
|
316
|
-
it('空输入 = 空输出;不改动输入数组', () => {
|
|
317
|
-
const input: { component: string; basis: string; tokens: number; events: number }[] = []
|
|
318
|
-
expect(mergeCompositionByComponent(input)).toEqual([])
|
|
319
|
-
const single = [{ component: 'fresh', basis: 'characters', tokens: 1, events: 1 }]
|
|
320
|
-
const out = mergeCompositionByComponent(single)
|
|
321
|
-
expect(out).toHaveLength(1)
|
|
322
|
-
expect(out[0]).not.toBe(single[0])
|
|
323
|
-
})
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
describe('drsTotalsFragment(浮窗三值 DRS 主源,每次全量重导)', () => {
|
|
327
|
-
const index = {
|
|
328
|
-
sessionId: 's1', basis: 'ds-token', syncedAt: 'x', maxSeq: 100, turnCount: 2, segments: 5, turns: [],
|
|
329
|
-
pairs: [
|
|
330
|
-
{ seq: 8, startSeq: 1, endSeq: 3, aTokens: 500, bTokens: 100, kind: 'compress' as const, turn: 1, step: 1, live: 1 as const },
|
|
331
|
-
{ seq: 20, startSeq: 12, endSeq: 14, aTokens: 300, bTokens: 40, kind: 'compress' as const, turn: 1, step: 2, live: 1 as const },
|
|
332
|
-
{ seq: 30, startSeq: 18, endSeq: 18, aTokens: 0, bTokens: 60, kind: 'recall' as const, turn: 2, step: 1, live: 1 as const },
|
|
333
|
-
],
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
it('毛仅压缩对(不含回吐)、抵消仅召回对、净=毛−抵消;ds-token 落 exact 臂', () => {
|
|
337
|
-
const fragment = drsTotalsFragment(index)
|
|
338
|
-
expect(fragment.sessionTotals.gross).toEqual({ exact: 660, estimated: 0 }) // (500−100)+(300−40)
|
|
339
|
-
expect(fragment.sessionTotals.offsets).toEqual({ exact: 60, estimated: 0 })
|
|
340
|
-
expect(fragment.sessionTotals.net).toEqual({ exact: 600, estimated: 0 }) // 有召回 → 净异于毛
|
|
341
|
-
expect(fragment.lastDelta).toEqual({ saving: { tokens: 260, seq: 20 }, offset: { tokens: 60, seq: 30 } })
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
it('chars/4 口径落 estimated 臂;零对 → 全零且无 Δ 段(不伪造)', () => {
|
|
345
|
-
const charsIndex = { ...index, basis: 'chars/4', pairs: [] }
|
|
346
|
-
const fragment = drsTotalsFragment(charsIndex)
|
|
347
|
-
expect(fragment.sessionTotals).toEqual({
|
|
348
|
-
gross: { exact: 0, estimated: 0 },
|
|
349
|
-
offsets: { exact: 0, estimated: 0 },
|
|
350
|
-
net: { exact: 0, estimated: 0 },
|
|
351
|
-
})
|
|
352
|
-
expect(fragment.lastDelta).toBeUndefined()
|
|
353
|
-
})
|
|
354
|
-
})
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T29:/ccip 面板控制命令规格——子命令解析纯函数钉死 + execute 的偏好切换
|
|
3
|
-
* (meta 持久)、session latest、flush 与 backfill 开关接线。
|
|
4
|
-
*/
|
|
5
|
-
import { mkdtempSync, rmSync } from 'node:fs'
|
|
6
|
-
import { tmpdir } from 'node:os'
|
|
7
|
-
import { join } from 'node:path'
|
|
8
|
-
import { afterEach, describe, expect, it } from 'vitest'
|
|
9
|
-
import { closeStatsStore, ensureStatsStore, getStatsStore } from '../../src/runtime/stats-db.ts'
|
|
10
|
-
import { getDisplayPrefs, resetDisplayPrefsCache } from '../../src/runtime/display-prefs.ts'
|
|
11
|
-
import {
|
|
12
|
-
executePanelCommand,
|
|
13
|
-
parsePanelCommandArgs,
|
|
14
|
-
} from '../../src/runtime/panel-command.ts'
|
|
15
|
-
|
|
16
|
-
const dirs: string[] = []
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
closeStatsStore()
|
|
20
|
-
resetDisplayPrefsCache()
|
|
21
|
-
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe('/ccip 参数解析(纯函数)', () => {
|
|
25
|
-
it('合法子命令全表', () => {
|
|
26
|
-
expect(parsePanelCommandArgs('status')).toEqual({ op: 'status' })
|
|
27
|
-
expect(parsePanelCommandArgs('rows stock off')).toEqual({ op: 'rows', row: 'stock', on: false })
|
|
28
|
-
expect(parsePanelCommandArgs('ROWS MONEY ON')).toEqual({ op: 'rows', row: 'money', on: true })
|
|
29
|
-
expect(parsePanelCommandArgs('mode compact')).toEqual({ op: 'mode', mode: 'compact' })
|
|
30
|
-
expect(parsePanelCommandArgs('session off')).toEqual({ op: 'session', target: { kind: 'off' } })
|
|
31
|
-
expect(parsePanelCommandArgs('session latest')).toEqual({ op: 'session', target: { kind: 'latest' } })
|
|
32
|
-
expect(parsePanelCommandArgs('session abc-123')).toEqual({ op: 'session', target: { kind: 'id', id: 'abc-123' } })
|
|
33
|
-
expect(parsePanelCommandArgs('flush')).toEqual({ op: 'flush' })
|
|
34
|
-
expect(parsePanelCommandArgs('backfill pause')).toEqual({ op: 'backfill', action: 'pause' })
|
|
35
|
-
expect(parsePanelCommandArgs(' ')).toBeUndefined()
|
|
36
|
-
expect(parsePanelCommandArgs('rows bogus on')).toBeUndefined()
|
|
37
|
-
expect(parsePanelCommandArgs('mode sideways')).toBeUndefined()
|
|
38
|
-
expect(parsePanelCommandArgs('session')).toBeUndefined()
|
|
39
|
-
expect(parsePanelCommandArgs('backfill purge')).toBeUndefined()
|
|
40
|
-
expect(parsePanelCommandArgs('nonsense')).toBeUndefined()
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('/ccip execute(偏好落 meta、开关接线)', () => {
|
|
45
|
-
it('rows 切换写 displayPrefs 并持久到 meta(新句柄读回同值)', async () => {
|
|
46
|
-
const dir = mkdtempSync(join(tmpdir(), 'cci-ccip-'))
|
|
47
|
-
dirs.push(dir)
|
|
48
|
-
const path = join(dir, 'stats.sqlite')
|
|
49
|
-
await ensureStatsStore(path)
|
|
50
|
-
const result = executePanelCommand({ op: 'rows', row: 'stock', on: false })
|
|
51
|
-
expect(result.kind).toBe('success')
|
|
52
|
-
expect(getStatsStore()?.getMeta('displayPrefs')).toContain('"stock":false')
|
|
53
|
-
|
|
54
|
-
// 跨"重启"(关开句柄)后偏好仍在
|
|
55
|
-
closeStatsStore()
|
|
56
|
-
resetDisplayPrefsCache()
|
|
57
|
-
await ensureStatsStore(path)
|
|
58
|
-
expect(getDisplayPrefsForTest().rows.stock).toBe(false)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('session latest:空 store 报错,有会话时聚焦最近活跃', async () => {
|
|
62
|
-
await ensureStatsStore(join(mkdtempSyncForTest(), 'stats.sqlite'))
|
|
63
|
-
const empty = executePanelCommand({ op: 'session', target: { kind: 'latest' } })
|
|
64
|
-
expect(empty.kind).toBe('error')
|
|
65
|
-
|
|
66
|
-
const store = getStatsStore()
|
|
67
|
-
store?.setSessionWatermark('sess-latest-1', 10, { source: 'live' })
|
|
68
|
-
const ok = executePanelCommand({ op: 'session', target: { kind: 'latest' } })
|
|
69
|
-
expect(ok.kind).toBe('success')
|
|
70
|
-
expect(ok.text).toContain('sess-latest-1')
|
|
71
|
-
expect(getDisplayPrefsForTest().focusSessionId).toBe('sess-latest-1')
|
|
72
|
-
|
|
73
|
-
const off = executePanelCommand({ op: 'session', target: { kind: 'off' } })
|
|
74
|
-
expect(off.kind).toBe('success')
|
|
75
|
-
expect(getDisplayPrefsForTest().focusSessionId).toBeNull()
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('backfill pause/resume/status 与 flush 不抛错', async () => {
|
|
79
|
-
await ensureStatsStore(join(mkdtempSyncForTest(), 'stats.sqlite'))
|
|
80
|
-
expect(executePanelCommand({ op: 'backfill', action: 'pause' }).text).toContain('paused')
|
|
81
|
-
expect(executePanelCommand({ op: 'backfill', action: 'status' }).text).toContain('backfill:')
|
|
82
|
-
expect(executePanelCommand({ op: 'backfill', action: 'resume' }).text).toContain('resumed')
|
|
83
|
-
expect(executePanelCommand({ op: 'flush' }).kind).toBe('success')
|
|
84
|
-
expect(executePanelCommand({ op: 'status' }).text).toContain('ccip status:')
|
|
85
|
-
})
|
|
86
|
-
it('verify 子命令:无参/latest → 活跃指针目标;显式 id 透传;超参拒绝', () => {
|
|
87
|
-
expect(parsePanelCommandArgs('verify')).toEqual({ op: 'verify' })
|
|
88
|
-
expect(parsePanelCommandArgs('verify latest')).toEqual({ op: 'verify' })
|
|
89
|
-
expect(parsePanelCommandArgs('verify session-abc')).toEqual({ op: 'verify', sessionId: 'session-abc' })
|
|
90
|
-
expect(parsePanelCommandArgs('verify a b')).toBeUndefined()
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
function getDisplayPrefsForTest(): { rows: { stock: boolean; total: boolean; money: boolean }; mode: 'full' | 'compact'; focusSessionId: string | null } {
|
|
94
|
-
return getDisplayPrefs()
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function mkdtempSyncForTest(): string {
|
|
98
|
-
const dir = mkdtempSync(join(tmpdir(), 'cci-ccip-'))
|
|
99
|
-
dirs.push(dir)
|
|
100
|
-
return dir
|
|
101
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { codePointLength } from '../../src/runtime/config.ts'
|
|
3
|
-
import { reduceFreshToolResult, type ReducerInput } from '../../src/runtime/reducers.ts'
|
|
4
|
-
|
|
5
|
-
function input(overrides: Partial<ReducerInput> = {}): ReducerInput {
|
|
6
|
-
return {
|
|
7
|
-
toolName: 'mcp_remote_fetch',
|
|
8
|
-
argumentsText: '{}',
|
|
9
|
-
text: '',
|
|
10
|
-
budgetChars: 4_000,
|
|
11
|
-
sourceRef: 'session://s/event/1',
|
|
12
|
-
isError: false,
|
|
13
|
-
...overrides,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function markdownDoc(sections: number): string {
|
|
18
|
-
const parts: string[] = ['# User Guide', 'Intro paragraph with orientation prose.']
|
|
19
|
-
for (let index = 1; index <= sections; index++) {
|
|
20
|
-
parts.push(`## Section ${String(index)}: Installation`)
|
|
21
|
-
for (let line = 0; line < 12; line++) {
|
|
22
|
-
parts.push(`Section ${String(index)} line ${String(line)} with ordinary documentation prose content.`)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return parts.join('\n')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('document skeleton (R8)', () => {
|
|
29
|
-
it('keeps every H1-H3 heading and at least one sentence per section', () => {
|
|
30
|
-
const output = reduceFreshToolResult(input({ text: markdownDoc(8) }))
|
|
31
|
-
expect(output).not.toBeNull()
|
|
32
|
-
expect(output!.reducer).toBe('doc-skeleton')
|
|
33
|
-
for (let index = 1; index <= 8; index++) {
|
|
34
|
-
expect(output!.text).toContain(`## Section ${String(index)}: Installation`)
|
|
35
|
-
// 每节 ≥1 句:the section's first line survives.
|
|
36
|
-
expect(output!.text).toContain(`Section ${String(index)} line 0`)
|
|
37
|
-
}
|
|
38
|
-
expect(output!.text).toContain('# User Guide')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('keeps the first two rows of every table block', () => {
|
|
42
|
-
const doc = [
|
|
43
|
-
'# Report',
|
|
44
|
-
'Intro.',
|
|
45
|
-
'## Usage',
|
|
46
|
-
'Usage intro.',
|
|
47
|
-
'## Tables',
|
|
48
|
-
'Tables intro.',
|
|
49
|
-
...Array.from({ length: 30 }, (_, i) => `Intro filler sentence ${String(i)} to make the section elidable.`),
|
|
50
|
-
'| Name | Quota |',
|
|
51
|
-
'| --- | --- |',
|
|
52
|
-
'| Free | 5k |',
|
|
53
|
-
'| Pro | 50k |',
|
|
54
|
-
...Array.from({ length: 30 }, (_, i) => `Closing filler sentence ${String(i)} to make the section elidable.`),
|
|
55
|
-
'Trailing prose line.',
|
|
56
|
-
].join('\n')
|
|
57
|
-
const output = reduceFreshToolResult(input({ text: doc, toolName: 'mcp_fetch' }))
|
|
58
|
-
expect(output!.reducer).toBe('doc-skeleton')
|
|
59
|
-
expect(output!.text).toContain('| Name | Quota |')
|
|
60
|
-
expect(output!.text).toContain('| --- | --- |')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('cites original-event line ranges in elision markers (R9 spec)', () => {
|
|
64
|
-
const output = reduceFreshToolResult(input({ text: markdownDoc(6) }))
|
|
65
|
-
expect(output).not.toBeNull()
|
|
66
|
-
// Every elision marker carries an original line range and a line count.
|
|
67
|
-
const markers = output!.text.match(/\[\.\.\. lines \d+-\d+ elided \(\d+ lines\)[^\]]*\]/g) ?? []
|
|
68
|
-
expect(markers.length).toBeGreaterThan(0)
|
|
69
|
-
for (const marker of markers) {
|
|
70
|
-
const [, start, end, count] = /\[\.\.\. lines (\d+)-(\d+) elided \((\d+) lines\)/.exec(marker) ?? []
|
|
71
|
-
expect(Number(end) - Number(start) + 1).toBe(Number(count))
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('misjudgment guard: logs and build output are not documents', () => {
|
|
76
|
-
// Realistic build/log output carries no Markdown heading lines at all —
|
|
77
|
-
// timestamps, INFO frames, and stack locations never match `^#\\s`.
|
|
78
|
-
const log = [
|
|
79
|
-
'INFO 2026-01-01 starting build',
|
|
80
|
-
'WARN 2026-01-01 deprecated flag --legacy',
|
|
81
|
-
'INFO compiling modules',
|
|
82
|
-
'ERROR TS2345: cannot find name elsewhere',
|
|
83
|
-
...Array.from({ length: 40 }, (_, i) => `at /pkg/src/module${String(i)}.ts:12:5`),
|
|
84
|
-
].join('\n')
|
|
85
|
-
const output = reduceFreshToolResult(input({ text: log, toolName: 'bash', argumentsText: '{"command":"pnpm build"}' }))
|
|
86
|
-
expect(output?.reducer).not.toBe('doc-skeleton')
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
describe('prose head+tail keep (R8b)', () => {
|
|
91
|
-
const prose = [
|
|
92
|
-
...Array.from({ length: 60 }, (_, i) => `Early paragraph ${String(i)} with orientation prose for the reader.`),
|
|
93
|
-
...Array.from({ length: 60 }, (_, i) => `Middle paragraph ${String(i)} carries ordinary filler content.`),
|
|
94
|
-
...Array.from({ length: 60 }, (_, i) => `Final paragraph ${String(i)} holds the decisive conclusion about quotas.`),
|
|
95
|
-
].join('\n')
|
|
96
|
-
|
|
97
|
-
it('keeps head AND tail non-empty with an elision marker in between', () => {
|
|
98
|
-
const output = reduceFreshToolResult(input({ text: prose }))
|
|
99
|
-
expect(output).not.toBeNull()
|
|
100
|
-
expect(output!.reducer).toBe('prose-keep')
|
|
101
|
-
const lines = output!.text.split('\n')
|
|
102
|
-
expect(lines[0]).toContain('Early paragraph 0')
|
|
103
|
-
expect(lines.at(-1)).toContain('Final paragraph 59')
|
|
104
|
-
expect(output!.text).toMatch(/\[\.\.\. lines \d+-\d+ elided \(\d+ lines\)/)
|
|
105
|
-
// The tail keeps conclusions the old head-only reducer dropped.
|
|
106
|
-
expect(output!.text).toContain('decisive conclusion')
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('counter-proof: head-only retention provably loses the tail keyword', () => {
|
|
110
|
-
// The old landing spots for prose were head-only (pi-head) or a salience
|
|
111
|
-
// pass whose middle list is empty for prose. A head-only slice of B chars
|
|
112
|
-
// can never contain a keyword that starts after char B: the prose is
|
|
113
|
-
// ~11k chars and the decisive sentence sits in the last third, so any
|
|
114
|
-
// head-only output within a 4k budget drops it by construction.
|
|
115
|
-
const keywordIndex = prose.indexOf('decisive conclusion')
|
|
116
|
-
expect(codePointLength(prose)).toBeGreaterThan(2 * 4_000)
|
|
117
|
-
expect(keywordIndex).toBeGreaterThan(4_000)
|
|
118
|
-
// The R8b output keeps it anyway (also asserted above).
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('misjudgment guard: source code still stays off the prose path', () => {
|
|
122
|
-
const code = [
|
|
123
|
-
'import { createHash } from \'node:crypto\'',
|
|
124
|
-
'',
|
|
125
|
-
...Array.from({ length: 40 }, (_, i) => `export function handler${String(i)}(input: string): string {`),
|
|
126
|
-
...Array.from({ length: 40 }, (_, i) => ` return hash(input, ${String(i)})`),
|
|
127
|
-
'}',
|
|
128
|
-
].join('\n')
|
|
129
|
-
const output = reduceFreshToolResult(input({ text: code }))
|
|
130
|
-
expect(output?.reducer).not.toBe('prose-keep')
|
|
131
|
-
expect(output?.reducer).not.toBe('doc-skeleton')
|
|
132
|
-
})
|
|
133
|
-
})
|