dsh-context-compression-improved 0.11.0 → 0.11.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}/index.js +101 -0
- 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 -47
- 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 -557
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -247
- 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/docs/shallow-teaching-preset-template.md +0 -46
- 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 -352
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
- 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 -68
- package/packages/selector/src/client/fab-pos.ts +0 -71
- package/packages/selector/src/client/index.ts +0 -438
- package/packages/selector/src/client/locales/de.ts +0 -167
- package/packages/selector/src/client/locales/es.ts +0 -167
- package/packages/selector/src/client/locales/fr.ts +0 -167
- package/packages/selector/src/client/locales/it.ts +0 -167
- package/packages/selector/src/client/locales/ja.ts +0 -167
- package/packages/selector/src/client/locales/ko.ts +0 -167
- package/packages/selector/src/client/locales/ru.ts +0 -167
- package/packages/selector/src/client/locales.ts +0 -334
- package/packages/selector/src/client/monitor-fab.ts +0 -445
- 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 -156
- 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 -554
- package/packages/selector/src/pruner/content.ts +0 -199
- 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 -3222
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -321
- package/packages/selector/src/runtime/config.ts +0 -887
- package/packages/selector/src/runtime/custom-policy.ts +0 -300
- 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/fold-router.ts +0 -143
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -341
- package/packages/selector/src/runtime/panel-command.ts +0 -213
- package/packages/selector/src/runtime/reducers.ts +0 -1755
- package/packages/selector/src/runtime/retrieve.ts +0 -505
- 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/sediment-card.ts +0 -126
- package/packages/selector/src/runtime/sediment-clock.ts +0 -87
- package/packages/selector/src/runtime/sediment-guard.ts +0 -136
- package/packages/selector/src/runtime/sediment-publish.ts +0 -144
- package/packages/selector/src/runtime/sediment-span.ts +0 -170
- package/packages/selector/src/runtime/sediment.ts +0 -209
- 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/shallow-tools.ts +0 -342
- 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 -177
- 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 -82
- 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 -129
- 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/tool-names.ts +0 -42
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/triage/masks.ts +0 -128
- package/packages/selector/src/runtime/triage/shallow.ts +0 -132
- package/packages/selector/src/runtime/triage/signals.ts +0 -167
- package/packages/selector/src/runtime/triage/types.ts +0 -125
- package/packages/selector/src/runtime/types.ts +0 -396
- 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/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
- 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/ptc-custom-write.client.spec.ts +0 -86
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
- 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/fold-router.spec.ts +0 -140
- 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/ptc-profile.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
- 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/sediment-card.spec.ts +0 -111
- package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
- package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
- package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
- package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
- package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
- package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
- package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
- package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
- package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
- package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
- 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/shallow-primitives.spec.ts +0 -135
- 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 -350
- 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 -121
- 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.d.mts +0 -3
- package/scripts/hosts.mjs +0 -79
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sediment-latency-report.mjs +0 -63
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -343
- 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}/client.js +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +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,281 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T19/T22:session-file-decode 叶子模块的代次契约与解码链路测试。
|
|
3
|
-
*
|
|
4
|
-
* fixture 策略(T22):
|
|
5
|
-
* - 真实样例:`fixtures/session-v4-dump.jsonl`(284KB,从本机 v4 会话解包样本转码);
|
|
6
|
-
* 测试内 zstd 压缩后走完整解码链,源文件本身只读。
|
|
7
|
-
* - 合成样例:v3/v4 header + 打包行 + provenance 区间,直接在内存构造。
|
|
8
|
-
* - 撕裂尾帧:完整帧 + 尾部截断帧,ZSTD_e_flush 抢救断言。
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
11
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
12
|
-
import { tmpdir } from 'node:os'
|
|
13
|
-
import { join } from 'node:path'
|
|
14
|
-
import { describe, expect, it } from 'vitest'
|
|
15
|
-
import zlib from 'node:zlib'
|
|
16
|
-
import {
|
|
17
|
-
classifyGenerationFilename,
|
|
18
|
-
classifySessionHeader,
|
|
19
|
-
decodeRecordLocal,
|
|
20
|
-
decodeSeqRangesStorage,
|
|
21
|
-
decodeSessionLogBytes,
|
|
22
|
-
generationLogFilename,
|
|
23
|
-
isMigrationStagingFilename,
|
|
24
|
-
parseGenerationLogFilename,
|
|
25
|
-
readSessionGenerations,
|
|
26
|
-
scanZstdFrames,
|
|
27
|
-
type DecodedEvent,
|
|
28
|
-
type OfficialDecoders,
|
|
29
|
-
} from '../../src/runtime/session-file-decode.ts'
|
|
30
|
-
|
|
31
|
-
/** 规范历史代文件名(测试内同样避免 D7 字面量:拼接构造)。 */
|
|
32
|
-
const LEGACY_NAME = `session${'.'}jsonl.zstd`
|
|
33
|
-
|
|
34
|
-
function sessionHeader(version: number): string {
|
|
35
|
-
return JSON.stringify({ type: 'session', version, id: 'session-test', createdAt: 1_700_000_000_000, cwd: '/tmp' })
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** 由 header 代次与若干记录行合成一份 zstd 单帧日志(每条一行,seq 由调用方保证连续)。 */
|
|
39
|
-
function synthesizeLog(headerVersion: number | null, rows: readonly string[]): Buffer {
|
|
40
|
-
const headerLine = headerVersion === null ? 'not-json-at-all' : sessionHeader(headerVersion)
|
|
41
|
-
const text = [headerLine, ...rows, ''].join('\n')
|
|
42
|
-
return zlib.zstdCompressSync(Buffer.from(text, 'utf8'))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('session-file-decode / 代次文件名契约', () => {
|
|
46
|
-
it('代次名推导与解析互逆;历史代名按拼接构造(不留 D7 字面量)', () => {
|
|
47
|
-
expect(generationLogFilename(0)).toBe(LEGACY_NAME)
|
|
48
|
-
expect(generationLogFilename(4)).toBe('session.v4.jsonl.zstd')
|
|
49
|
-
expect(parseGenerationLogFilename(LEGACY_NAME)).toBe(0)
|
|
50
|
-
expect(parseGenerationLogFilename('session.v4.jsonl.zstd')).toBe(4)
|
|
51
|
-
expect(parseGenerationLogFilename('session.v12.jsonl', 'none')).toBe(12)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('非法名一律不猜:前导零、.v0、大写 V、错后缀都拒绝', () => {
|
|
55
|
-
expect(parseGenerationLogFilename('session.v0.jsonl.zstd')).toBeUndefined()
|
|
56
|
-
expect(parseGenerationLogFilename('session.v01.jsonl.zstd')).toBeUndefined()
|
|
57
|
-
expect(parseGenerationLogFilename('session.V1.jsonl.zstd')).toBeUndefined()
|
|
58
|
-
expect(parseGenerationLogFilename('session.v1.jsonl.gz.zstd')).toBeUndefined()
|
|
59
|
-
expect(parseGenerationLogFilename('session.v1.backup.jsonl.zstd')).toBeUndefined()
|
|
60
|
-
expect(classifyGenerationFilename('session.v3.jsonl')).toEqual({ version: 3, compression: 'none' })
|
|
61
|
-
expect(classifyGenerationFilename('readme.txt')).toBeUndefined()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('非法代次参数拒绝', () => {
|
|
65
|
-
expect(() => generationLogFilename(-1)).toThrow(/non-negative safe integer/)
|
|
66
|
-
expect(() => generationLogFilename(1.5)).toThrow(/non-negative safe integer/)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('迁移暂存名识别(token 长度可变,只固定形状)', () => {
|
|
70
|
-
expect(isMigrationStagingFilename('session.migration.0123456789abcdef.jsonl.zstd.tmp')).toBe(true)
|
|
71
|
-
expect(isMigrationStagingFilename('session.migration.deadbeef.jsonl.tmp')).toBe(true)
|
|
72
|
-
expect(isMigrationStagingFilename('session.migration.XYZ.jsonl.zstd.tmp')).toBe(false)
|
|
73
|
-
expect(isMigrationStagingFilename('session.v4.jsonl.zstd')).toBe(false)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('readSessionGenerations:目录实测最高代=当前代,只读不猜', async () => {
|
|
77
|
-
const dir = await mkdtemp(join(tmpdir(), 'sfd-gen-'))
|
|
78
|
-
try {
|
|
79
|
-
await writeFile(join(dir, LEGACY_NAME), 'legacy')
|
|
80
|
-
await writeFile(join(dir, 'session.v4.jsonl.zstd'), 'current')
|
|
81
|
-
await writeFile(join(dir, 'session.migration.aabbccddeeff0011.jsonl.zstd.tmp'), 'staging')
|
|
82
|
-
await writeFile(join(dir, 'session.v01.jsonl.zstd'), 'not-canonical')
|
|
83
|
-
const facts = readSessionGenerations(dir)
|
|
84
|
-
expect(facts.canonical.map(a => a.version)).toEqual([0, 4])
|
|
85
|
-
expect(facts.current?.version).toBe(4)
|
|
86
|
-
expect(facts.legacy?.name).toBe(LEGACY_NAME)
|
|
87
|
-
expect(facts.staging).toHaveLength(1)
|
|
88
|
-
expect(facts.legacyOnly).toBe(false)
|
|
89
|
-
// 目录不存在:如实返回空事实,不抛
|
|
90
|
-
const missing = readSessionGenerations(join(dir, 'no-such-dir'))
|
|
91
|
-
expect(missing.canonical).toEqual([])
|
|
92
|
-
} finally {
|
|
93
|
-
await rm(dir, { recursive: true, force: true })
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
describe('session-file-decode / zstd 多帧与撕裂尾帧', () => {
|
|
99
|
-
it('多帧拼接逐帧解码(zstdDecompressSync 整体解只出首帧,帧扫描是必需路径)', () => {
|
|
100
|
-
const frameA = zlib.zstdCompressSync(Buffer.from('{"a":1}\n', 'utf8'))
|
|
101
|
-
const frameB = zlib.zstdCompressSync(Buffer.from('{"b":2}\n', 'utf8'))
|
|
102
|
-
const both = Buffer.concat([frameA, frameB])
|
|
103
|
-
// 官方整体解码只覆盖首帧——这正是要自己做帧扫描的原因
|
|
104
|
-
expect(zlib.zstdDecompressSync(both).toString('utf8')).toBe('{"a":1}\n')
|
|
105
|
-
const scan = scanZstdFrames(both)
|
|
106
|
-
expect(scan.frames).toHaveLength(2)
|
|
107
|
-
expect(scan.tornStart).toBeUndefined()
|
|
108
|
-
const text = scan.frames
|
|
109
|
-
.map(f => zlib.zstdDecompressSync(both.subarray(f.start, f.end)).toString('utf8'))
|
|
110
|
-
.join('')
|
|
111
|
-
expect(text).toBe('{"a":1}\n{"b":2}\n')
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('撕裂尾帧:tornStart 定位 + ZSTD_e_flush 抢救部分明文,完整帧不受影响', () => {
|
|
115
|
-
const frameA = zlib.zstdCompressSync(Buffer.from('header-line\n', 'utf8'))
|
|
116
|
-
const frameB = zlib.zstdCompressSync(Buffer.from('tail-line-contents-here\n', 'utf8'))
|
|
117
|
-
const torn = Buffer.concat([frameA, frameB.subarray(0, frameB.length - 3)])
|
|
118
|
-
const scan = scanZstdFrames(torn)
|
|
119
|
-
expect(scan.frames).toHaveLength(1)
|
|
120
|
-
expect(scan.tornStart).toBe(frameA.length)
|
|
121
|
-
const recovered = zlib.zstdDecompressSync(torn.subarray(scan.tornStart!), {
|
|
122
|
-
finishFlush: zlib.constants.ZSTD_e_flush,
|
|
123
|
-
}).toString('utf8')
|
|
124
|
-
expect(recovered.length).toBeGreaterThan(0)
|
|
125
|
-
expect('tail-line-contents-here\n'.startsWith(recovered)).toBe(true)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('非 zstd 明文开头:整段判为撕裂起点、零完整帧(decode 侧按抢救处理)', () => {
|
|
129
|
-
const plain = Buffer.from('{"type":"session"}\n', 'utf8')
|
|
130
|
-
const scan = scanZstdFrames(plain)
|
|
131
|
-
expect(scan.frames).toHaveLength(0)
|
|
132
|
-
expect(scan.tornStart).toBe(0)
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
describe('session-file-decode / 记录解码与 provenance', () => {
|
|
137
|
-
it('打包行解包:text-chunks 展开为 assistant/chunk,dt 为时间增量', () => {
|
|
138
|
-
const row = {
|
|
139
|
-
type: 'text-chunks',
|
|
140
|
-
seq0: 3,
|
|
141
|
-
time0: 100,
|
|
142
|
-
data: { turn: 0, step: 1, index: 2, texts: ['ab', 'cd', 'ef'], dt: [5, 7] },
|
|
143
|
-
}
|
|
144
|
-
const events = decodeRecordLocal(row)
|
|
145
|
-
expect(events.map(e => e.seq)).toEqual([3, 4, 5])
|
|
146
|
-
expect(events.map(e => e.time)).toEqual([100, 105, 112])
|
|
147
|
-
expect(events[0]).toMatchObject({ type: 'assistant/chunk', data: { turn: 0, step: 1 } })
|
|
148
|
-
expect((events[2]!.data as { chunk: Record<string, unknown> }).chunk).toMatchObject({ type: 'text-delta', text: 'ef', index: 2 })
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('tool-call-chunks 用 args 载荷并带 id/name', () => {
|
|
152
|
-
const row = {
|
|
153
|
-
type: 'tool-call-chunks',
|
|
154
|
-
seq0: 0,
|
|
155
|
-
time0: 10,
|
|
156
|
-
data: { turn: 1, step: 0, index: 0, id: 'call-1', name: 'bash', args: ['{"cmd":', '"ls"}'], dt: [1] },
|
|
157
|
-
}
|
|
158
|
-
const events = decodeRecordLocal(row)
|
|
159
|
-
const chunk = events[1]!.data as { chunk: Record<string, unknown> }
|
|
160
|
-
expect(chunk.chunk).toMatchObject({ type: 'tool-call-delta', id: 'call-1', name: 'bash', argumentsDelta: '"ls"}' })
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('打包行形状错误:拒绝(dt 长度不符/载荷非字符串数组)', () => {
|
|
164
|
-
expect(() => decodeRecordLocal({ type: 'text-chunks', seq0: 0, time0: 0, data: { texts: ['a', 'b'], dt: [] } }))
|
|
165
|
-
.toThrow(/dt length/)
|
|
166
|
-
expect(() => decodeRecordLocal({ type: 'text-chunks', seq0: 0, time0: 0, data: { texts: [1, 2], dt: [0] } }))
|
|
167
|
-
.toThrow(/non-empty string array/)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('provenance 区间编码展开 + 前向引用校验', () => {
|
|
171
|
-
expect(decodeSeqRangesStorage([[0, 2], 5], 6)).toEqual([0, 1, 2, 5])
|
|
172
|
-
expect(() => decodeSeqRangesStorage([[3, 1]], 6)).toThrow(/malformed/)
|
|
173
|
-
expect(() => decodeSeqRangesStorage([6], 6)).toThrow(/reference earlier/)
|
|
174
|
-
expect(() => decodeSeqRangesStorage('x', 6)).toThrow(/must be an array/)
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
it('seq 缺口按 prefix 语义截断并记问题', () => {
|
|
178
|
-
const rows = [
|
|
179
|
-
JSON.stringify({ type: 'user/message', seq: 0, time: 1, data: {} }),
|
|
180
|
-
JSON.stringify({ type: 'user/message', seq: 2, time: 2, data: {} }), // 缺 seq 1
|
|
181
|
-
]
|
|
182
|
-
const log = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
183
|
-
expect(log.events).toHaveLength(1)
|
|
184
|
-
expect(log.issues).toHaveLength(1)
|
|
185
|
-
expect(log.issues[0]!.why).toMatch(/seq gap \(expected 1, got 2\)/)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
it('官方解码器可用时走 official 臂且来源如实标注', () => {
|
|
189
|
-
const official: OfficialDecoders = {
|
|
190
|
-
decodeStorageRecord: value => [value as DecodedEvent],
|
|
191
|
-
decodeSeqRanges: (value, seq) => decodeSeqRangesStorage(value, seq),
|
|
192
|
-
}
|
|
193
|
-
const rows = [
|
|
194
|
-
JSON.stringify({ type: 'user/message', seq: 0, time: 1, data: {} }),
|
|
195
|
-
JSON.stringify({ type: 'tool/result', seq: 1, time: 2, sourceEventSeqs: [[0, 0]], data: {} }),
|
|
196
|
-
]
|
|
197
|
-
const log = decodeSessionLogBytes(synthesizeLog(4, rows), official)
|
|
198
|
-
expect(log.decoder).toBe('official')
|
|
199
|
-
expect(log.events).toHaveLength(2)
|
|
200
|
-
expect(log.events[1]?.sourceEventSeqs).toEqual([0])
|
|
201
|
-
const local = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
202
|
-
expect(local.decoder).toBe('local')
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('findOpenStep:尾部未收尾的 step 报出,step/end 后清零', () => {
|
|
206
|
-
const rows = [
|
|
207
|
-
JSON.stringify({ type: 'step/start', seq: 0, time: 1, data: { turn: 2, step: 3 } }),
|
|
208
|
-
JSON.stringify({ type: 'step/end', seq: 1, time: 2, data: { turn: 2, step: 3 } }),
|
|
209
|
-
JSON.stringify({ type: 'step/start', seq: 2, time: 3, data: { turn: 2, step: 4 } }),
|
|
210
|
-
]
|
|
211
|
-
const log = decodeSessionLogBytes(synthesizeLog(4, rows))
|
|
212
|
-
expect(log.openStep).toEqual({ turn: 2, step: 4 })
|
|
213
|
-
})
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
describe('session-file-decode / header 代次 fail-soft 分类', () => {
|
|
217
|
-
it('v3/v4 已知代次放行', () => {
|
|
218
|
-
for (const version of [3, 4]) {
|
|
219
|
-
const log = decodeSessionLogBytes(synthesizeLog(version, []))
|
|
220
|
-
expect(classifySessionHeader(log.header)).toMatchObject({ state: 'known', version })
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
it('未知代次/无 header/非 session 头都归为不可回填(调用方跳过该会话)', () => {
|
|
225
|
-
const unknown = decodeSessionLogBytes(synthesizeLog(9, []))
|
|
226
|
-
expect(classifySessionHeader(unknown.header)).toMatchObject({ state: 'unknown-version', version: 9 })
|
|
227
|
-
// 首行不是 zstd 可解内容:整体抢救失败也不抛,header 如实缺失
|
|
228
|
-
const broken = decodeSessionLogBytes(Buffer.from('not-json-at-all\n', 'utf8'))
|
|
229
|
-
expect(classifySessionHeader(broken.header)).toEqual({ state: 'missing-header' })
|
|
230
|
-
const foreign = decodeSessionLogBytes(synthesizeLog(4, []))
|
|
231
|
-
expect(classifySessionHeader({ ...foreign.header!, type: 'other' })).toEqual({ state: 'not-session' })
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('空文件:header 缺失、零事件、零问题(不抛)', () => {
|
|
235
|
-
const log = decodeSessionLogBytes(Buffer.alloc(0))
|
|
236
|
-
expect(log).toMatchObject({ events: [], frames: 0, recoveredFromTorn: 0, issues: [], decoder: 'local' })
|
|
237
|
-
expect(classifySessionHeader(log.header)).toEqual({ state: 'missing-header' })
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
describe('session-file-decode / 真实 v4 解包样本', () => {
|
|
242
|
-
const fixture = new URL('fixtures/session-v4-dump.jsonl', import.meta.url)
|
|
243
|
-
const present = existsSync(fixture)
|
|
244
|
-
|
|
245
|
-
it.skipIf(!present)('真实会话(v4 header + 45 事件)转码为 zstd 后完整解码、零问题', () => {
|
|
246
|
-
const text = readFileSync(fixture, 'utf8')
|
|
247
|
-
const log = decodeSessionLogBytes(zlib.zstdCompressSync(Buffer.from(text, 'utf8')))
|
|
248
|
-
expect(classifySessionHeader(log.header)).toMatchObject({ state: 'known', version: 4 })
|
|
249
|
-
expect(log.events.length).toBeGreaterThan(40)
|
|
250
|
-
expect(log.issues).toEqual([])
|
|
251
|
-
expect(log.frames).toBeGreaterThanOrEqual(1)
|
|
252
|
-
expect(log.tornStart).toBeUndefined()
|
|
253
|
-
// seq 连续(0..n-1)由解码链的 prefix 语义保证:无 issue 即连续
|
|
254
|
-
expect(log.events.at(-1)!.seq).toBe(log.events.length - 1)
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
it.skipIf(!present)('真实样本多帧切分后再拼接解码结果一致', () => {
|
|
258
|
-
const text = readFileSync(fixture, 'utf8')
|
|
259
|
-
const whole = zlib.zstdCompressSync(Buffer.from(text, 'utf8'))
|
|
260
|
-
const half = Math.floor(text.length / 2)
|
|
261
|
-
const multi = Buffer.concat([
|
|
262
|
-
zlib.zstdCompressSync(Buffer.from(text.slice(0, half), 'utf8')),
|
|
263
|
-
zlib.zstdCompressSync(Buffer.from(text.slice(half), 'utf8')),
|
|
264
|
-
])
|
|
265
|
-
const a = decodeSessionLogBytes(whole)
|
|
266
|
-
const b = decodeSessionLogBytes(multi)
|
|
267
|
-
expect(b.frames).toBeGreaterThanOrEqual(2)
|
|
268
|
-
expect(b.issues).toEqual([])
|
|
269
|
-
expect(b.events).toEqual(a.events)
|
|
270
|
-
expect(b.header).toEqual(a.header)
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
describe('session-file-decode / D7 静态纪律', () => {
|
|
275
|
-
it('模块源码不含检查器正则的连续字面量', () => {
|
|
276
|
-
const source = readFileSync(new URL('../../src/runtime/session-file-decode.ts', import.meta.url), 'utf8')
|
|
277
|
-
expect(source).not.toMatch(/session\.jsonl|SESSION_FORMAT_VERSION|sessionFormatVersion/u)
|
|
278
|
-
// 用等价文本正则再扫一遍(点为真实点),防止拼接改写引入漏网
|
|
279
|
-
expect(/session[.]jsonl/.test(source)).toBe(false)
|
|
280
|
-
})
|
|
281
|
-
})
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { unwrapSettingsEntry } from '../../src/pruner.ts'
|
|
3
|
-
import { parseContextCompressionSettings } from '../../src/runtime/config.ts'
|
|
4
|
-
|
|
5
|
-
// The desktop 0.2.0 host hands back the whole entry config `{ settings: <subtree> }`;
|
|
6
|
-
// the parser only understands the subtree. Regression guard for the fail-open-to-off
|
|
7
|
-
// bug that silently disabled fresh/aggregate on the desktop (0 compression).
|
|
8
|
-
const SUBTREE = {
|
|
9
|
-
profile: 'tokenpilot-inspired',
|
|
10
|
-
custom: {
|
|
11
|
-
version: 3,
|
|
12
|
-
unit: 'tokens',
|
|
13
|
-
fresh: { enabled: true, trigger: 8192, target: 3072 },
|
|
14
|
-
aggregate: { enabled: true, trigger: 32768, target: 12288 },
|
|
15
|
-
history: { enabled: true, trigger: 500000, keepRecentToolCalls: 10, keepRecentTokens: 64000, minReclaim: 96000 },
|
|
16
|
-
prefixPolicy: 'pressure-break',
|
|
17
|
-
tailTrim: { enabled: false, trigger: 700000 },
|
|
18
|
-
},
|
|
19
|
-
autoCompact: { thresholdPercent: 80 },
|
|
20
|
-
codeSkeleton: { enabled: true },
|
|
21
|
-
intentSummary: { enabled: true },
|
|
22
|
-
monitorPanel: { enabled: true },
|
|
23
|
-
presetOptions: { estimatorMode: 'host', estimatorProvider: 'local-35', estimatorModel: 'Qwen3.6-35B-A3B' },
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('unwrapSettingsEntry (0.2.0 host config wrapper)', () => {
|
|
27
|
-
it('descends a single {settings:<obj>} wrapper when the root has no profile', () => {
|
|
28
|
-
expect(unwrapSettingsEntry({ settings: SUBTREE })).toBe(SUBTREE)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('leaves a bare subtree (root already has profile) untouched', () => {
|
|
32
|
-
expect(unwrapSettingsEntry(SUBTREE)).toBe(SUBTREE)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('leaves non-object and array values untouched', () => {
|
|
36
|
-
expect(unwrapSettingsEntry(undefined)).toBe(undefined)
|
|
37
|
-
expect(unwrapSettingsEntry(null)).toBe(null)
|
|
38
|
-
expect(unwrapSettingsEntry('x')).toBe('x')
|
|
39
|
-
const arr = [1, 2]
|
|
40
|
-
expect(unwrapSettingsEntry(arr)).toBe(arr)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('does NOT descend when `settings` is not an object (keeps exotic rejection intact)', () => {
|
|
44
|
-
const exotic = { settings: 'not-an-object' }
|
|
45
|
-
expect(unwrapSettingsEntry(exotic)).toBe(exotic)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('round-trips the wrapped desktop value where the bare parse would throw', () => {
|
|
49
|
-
// The exact desktop failure: wrapped shape → parse throws "missing its
|
|
50
|
-
// complete shape" → activeSettings fails open to profile:'off'. After the
|
|
51
|
-
// one-level unwrap the same value parses to tokenpilot-inspired (fresh on).
|
|
52
|
-
const wrapped = { settings: SUBTREE }
|
|
53
|
-
expect(() => parseContextCompressionSettings(wrapped)).toThrow(/complete shape|plain/)
|
|
54
|
-
const parsed = parseContextCompressionSettings(unwrapSettingsEntry(wrapped) as never)
|
|
55
|
-
expect(parsed.profile).toBe('tokenpilot-inspired')
|
|
56
|
-
expect(parsed.presetOptions?.estimatorMode).toBe('host')
|
|
57
|
-
})
|
|
58
|
-
})
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* T4.7/T4.8/T4.11/T4.12 red tests: shallow primitives and tool-side pure cores
|
|
3
|
-
* (plan cci-sedimentation-triage Phase 4.5).
|
|
4
|
-
*/
|
|
5
|
-
import { describe, expect, it } from 'vitest'
|
|
6
|
-
import {
|
|
7
|
-
buildShallowFooter,
|
|
8
|
-
classifyShallowSample,
|
|
9
|
-
evaluateDiscardGuard,
|
|
10
|
-
normalizeToolPath,
|
|
11
|
-
renderCheckpointLine,
|
|
12
|
-
} from '../../src/runtime/triage/shallow.ts'
|
|
13
|
-
import { buildShallowView, parseReadCoverage } from '../../src/runtime/shallow-tools.ts'
|
|
14
|
-
import { skeletonFromRead } from '../../src/runtime/triage/masks.ts'
|
|
15
|
-
|
|
16
|
-
describe('normalizeToolPath (pairing key, three shapes)', () => {
|
|
17
|
-
it('unifies drive letters, separators, and relative segments', () => {
|
|
18
|
-
expect(normalizeToolPath('E:\\Repo\\A\\b.ts')).toBe('e:/Repo/A/b.ts')
|
|
19
|
-
expect(normalizeToolPath('./src/app.ts')).toBe('src/app.ts')
|
|
20
|
-
expect(normalizeToolPath('src/../src/app.ts')).toBe('src/app.ts')
|
|
21
|
-
expect(normalizeToolPath('E:/Repo//A/./b.ts')).toBe('e:/Repo/A/b.ts')
|
|
22
|
-
// case of the path TAIL is preserved (filesystems may be case-sensitive)
|
|
23
|
-
expect(normalizeToolPath('e:/repo/App.TS')).toBe('e:/repo/App.TS')
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('classifyShallowSample (T4.12 five families)', () => {
|
|
28
|
-
it('routes JSON / TS source / CSV / markdown / unknown-large correctly', () => {
|
|
29
|
-
expect(classifyShallowSample('{"a":1', '.json', 9_000).method).toBe('json-skeleton')
|
|
30
|
-
expect(classifyShallowSample('import x from "y"\n', '.ts', 9_000).method).toBe('code-skeleton')
|
|
31
|
-
expect(classifyShallowSample('name,size\na,1\nb,2\nc,3', '.csv', 9_000).method).toBe('csv-header')
|
|
32
|
-
expect(classifyShallowSample('# Title\nbody', '.md', 9_000).method).toBe('toc-lines')
|
|
33
|
-
expect(classifyShallowSample('random bytes', '.bin', 9_000).method).toBe('toc-lines')
|
|
34
|
-
expect(classifyShallowSample('tiny', '', 30).method).toBe('head-tail')
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe('evaluateDiscardGuard (T4.7 asymmetric guard)', () => {
|
|
39
|
-
const mapFull = { seq: 10, path: 'E:\\repo\\big.ts', coverage: { kind: 'full' } as const }
|
|
40
|
-
|
|
41
|
-
it('refuses map discard when the covering read is a slice (window-gap and full-map shapes)', () => {
|
|
42
|
-
expect(evaluateDiscardGuard({
|
|
43
|
-
map: mapFull,
|
|
44
|
-
covering: { seq: 20, path: 'e:/repo/big.ts', coverage: { kind: 'slice', from: 100, to: 300 } },
|
|
45
|
-
}).allowed).toBe(false)
|
|
46
|
-
})
|
|
47
|
-
it('allows map discard under a full covering read, path case/shape differing', () => {
|
|
48
|
-
const verdict = evaluateDiscardGuard({
|
|
49
|
-
map: mapFull,
|
|
50
|
-
covering: { seq: 20, path: 'E:/repo/big.ts', coverage: { kind: 'full' } },
|
|
51
|
-
})
|
|
52
|
-
expect(verdict.allowed).toBe(true)
|
|
53
|
-
})
|
|
54
|
-
it('window containment for a map that covers a window', () => {
|
|
55
|
-
const mapWindow = { seq: 10, path: 'a.ts', coverage: { kind: 'slice', from: 50, to: 150 } as const }
|
|
56
|
-
expect(evaluateDiscardGuard({
|
|
57
|
-
map: mapWindow,
|
|
58
|
-
covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 40, to: 160 } },
|
|
59
|
-
}).allowed).toBe(true)
|
|
60
|
-
expect(evaluateDiscardGuard({
|
|
61
|
-
map: mapWindow,
|
|
62
|
-
covering: { seq: 20, path: 'a.ts', coverage: { kind: 'slice', from: 60, to: 140 } },
|
|
63
|
-
}).allowed).toBe(false)
|
|
64
|
-
})
|
|
65
|
-
it('path mismatch refuses before any coverage math', () => {
|
|
66
|
-
expect(evaluateDiscardGuard({
|
|
67
|
-
map: mapFull,
|
|
68
|
-
covering: { seq: 20, path: 'e:/repo/other.ts', coverage: { kind: 'full' } },
|
|
69
|
-
}).reason).toContain('path-mismatch')
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
describe('buildShallowView (T4.11 checkpoint layer)', () => {
|
|
74
|
-
const code = `import fs from "node:fs"\n${' const v = compute()\n'.repeat(200)}export function go() { return 1 }`
|
|
75
|
-
|
|
76
|
-
it('code-skeleton view carries the four checkpoint fields', () => {
|
|
77
|
-
const { body, checkpoint } = buildShallowView(code, 'code-skeleton', 'E:\\src\\big.ts', 77)
|
|
78
|
-
expect(body).toContain('import fs')
|
|
79
|
-
expect(body).toContain('elided')
|
|
80
|
-
expect(checkpoint).not.toBeNull()
|
|
81
|
-
expect(checkpoint?.path).toBe('e:/src/big.ts')
|
|
82
|
-
expect(checkpoint?.coverage).toContain('lines')
|
|
83
|
-
expect(checkpoint?.ref).toBe('event/77')
|
|
84
|
-
expect(checkpoint?.fingerprint).toMatch(/^[0-9a-f]+-[0-9a-f]+$/)
|
|
85
|
-
})
|
|
86
|
-
it('json-skeleton lists keys, csv-header keeps rows count, toc-lines keeps headings', () => {
|
|
87
|
-
const json = buildShallowView(JSON.stringify({ a: { b: 1 }, list: [1, 2] }), 'json-skeleton', 'x.json', 1)
|
|
88
|
-
expect(json.body).toContain('a.b')
|
|
89
|
-
expect(json.body).toContain('list[] (2)')
|
|
90
|
-
const csv = buildShallowView('h1,h2\n1,2\n3,4\n5,6', 'csv-header', 'x.csv', 1)
|
|
91
|
-
expect(csv.body).toContain('1 data rows elided')
|
|
92
|
-
const md = buildShallowView('# A\ntext\n## B\nmore', 'toc-lines', 'x.md', 1)
|
|
93
|
-
expect(md.body).toContain('## B')
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
describe('parseReadCoverage (pairing input)', () => {
|
|
98
|
-
it('bare read is full; offset/limit is a window; broken args match nothing', () => {
|
|
99
|
-
expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts' }))).toEqual({ kind: 'full' })
|
|
100
|
-
expect(parseReadCoverage(JSON.stringify({ file_path: 'a.ts', offset: 100, limit: 50 })))
|
|
101
|
-
.toEqual({ kind: 'slice', from: 101, to: 150 })
|
|
102
|
-
expect(parseReadCoverage('{broken')).toMatchObject({ kind: 'slice', to: 0 })
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
describe('footer and checkpoint rendering (T4.8 data-shaped teaching)', () => {
|
|
107
|
-
const checkpoint = {
|
|
108
|
-
path: 'e:/src/big.ts', coverage: '900 lines', ref: 'session://s1/event/77', fingerprint: '3c-91',
|
|
109
|
-
}
|
|
110
|
-
it('footer names the sibling ref, the saving, and forbids reconstitution', () => {
|
|
111
|
-
const footer = buildShallowFooter(checkpoint, 1_800)
|
|
112
|
-
expect(footer).toContain('session://s1/event/77')
|
|
113
|
-
expect(footer).toContain('1800')
|
|
114
|
-
expect(footer).toContain('不要凭本行推测补写')
|
|
115
|
-
})
|
|
116
|
-
it('checkpoint line keeps all four fields on one line', () => {
|
|
117
|
-
const line = renderCheckpointLine(checkpoint)
|
|
118
|
-
for (const part of ['e:/src/big.ts', '900 lines', 'session://s1/event/77', '3c-91']) {
|
|
119
|
-
expect(line).toContain(part)
|
|
120
|
-
}
|
|
121
|
-
expect(line.split('\n')).toHaveLength(1)
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
describe('skeletonFromRead checkpoint back-compat', () => {
|
|
126
|
-
const padded = `import fs from "node:fs"\n${' const x = 1\n'.repeat(400)}`
|
|
127
|
-
it('stays checkpoint-free without a path (existing callers unaffected)', () => {
|
|
128
|
-
const verdict = skeletonFromRead(padded, 5)
|
|
129
|
-
expect(verdict?.kind === 'skeleton' && verdict.checkpoint === undefined).toBe(true)
|
|
130
|
-
})
|
|
131
|
-
it('gains the checkpoint with a path', () => {
|
|
132
|
-
const verdict = skeletonFromRead(padded, 5, 'src/a.ts')
|
|
133
|
-
expect(verdict?.kind === 'skeleton' && verdict.checkpoint?.path).toBe('src/a.ts')
|
|
134
|
-
})
|
|
135
|
-
})
|