@jjh32456/dsh-longlive 1.6.7 → 1.8.0
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/CHANGELOG.md +70 -1508
- package/LICENSE +1 -1
- package/QUICKSTART.md +34 -13
- package/README.en.md +18 -7
- package/README.md +34 -9
- package/SPEC.md +5 -5
- package/cordis.patch.yml +23 -9
- package/docs/ANSWER-GUARD.md +92 -0
- package/docs/ARCHITECTURE.md +4 -3
- package/docs/AUTO-RECALL-WIRING.md +1 -1
- package/docs/AUTO-RECALL.md +15 -9
- package/docs/CONFIG.md +168 -35
- package/docs/ERRORS.md +17 -5
- package/docs/FAQ.md +7 -7
- package/docs/FEATURES.md +96 -28
- package/docs/MIGRATION-1.6.0.md +2 -2
- package/docs/OPERATIONS.md +6 -6
- package/docs/PANEL-INTEGRATION.md +6 -0
- package/docs/PRIVACY.md +88 -0
- package/docs/QUICKSTART.md +5 -5
- package/docs/README.en.md +4 -2
- package/docs/RESIDENT-WATCHER.md +1 -1
- package/docs/SESSION-WATCH.md +6 -6
- package/docs/TROUBLESHOOTING.md +4 -4
- package/package.json +47 -117
- package/runbook.md +2 -2
- package/scripts/backfill-auto-cards.mjs +98 -0
- package/scripts/install-surgery-task.ps1 +5 -2
- package/scripts/lib/session-watch-fixture.mjs +1 -1
- package/scripts/longlive-doctor.mjs +6 -0
- package/scripts/migrate-180.mjs +163 -0
- package/scripts/recall-index-build.mjs +128 -0
- package/scripts/session-watch-drill.mjs +1 -1
- package/scripts/surgery-run.cmd +1 -1
- package/scripts/unattended-surgery.ps1 +5 -2
- package/scripts/verify-card-anchors.mjs +138 -0
- package/src/actions/audit.js +125 -0
- package/src/actions/evidence.js +122 -0
- package/src/actions/fs.js +162 -0
- package/src/activity/index.js +760 -0
- package/src/activity/model.js +351 -0
- package/src/activity/store.js +644 -0
- package/src/activity/thinking.js +176 -0
- package/src/adapters/constants.js +11 -0
- package/src/adapters/engram/data/aliases.json +51 -0
- package/src/adapters/engram/data/policy.json +8 -0
- package/src/adapters/engram/data/routing-rules.json +546 -0
- package/src/adapters/engram/index.js +235 -0
- package/src/adapters/registry.js +315 -0
- package/src/answer/audit.js +193 -0
- package/src/answer/evidence.js +30 -0
- package/src/answer/guard.js +1370 -0
- package/src/answer/index.js +1067 -0
- package/src/answer/query.js +111 -0
- package/src/answer/second-hop.mjs +101 -0
- package/src/auto-truncate.js +1 -1
- package/src/config.js +171 -47
- package/src/deps.js +6 -4
- package/src/features.js +182 -6
- package/src/heartbeat.js +156 -23
- package/src/identity/handover.js +52 -1
- package/src/identity/index.js +13 -5
- package/src/identity/inject-position.js +2 -2
- package/src/index.js +97 -7
- package/src/lifecycle/gap-clocks.js +328 -0
- package/src/lifecycle/index.js +269 -0
- package/src/live.js +22 -2
- package/src/memory/activity-capture.js +229 -0
- package/src/memory/anchors.js +194 -0
- package/src/memory/audit-records.js +222 -0
- package/src/memory/auto-cards.js +401 -0
- package/src/memory/capture.js +442 -0
- package/src/memory/card-anchors.js +203 -0
- package/src/memory/conflicts.js +106 -0
- package/src/memory/decay.js +311 -0
- package/src/memory/distill.js +471 -0
- package/src/memory/event-index.js +917 -0
- package/src/memory/evidence-chain.js +295 -0
- package/src/memory/evidence.js +145 -0
- package/src/memory/filter-runner.js +1 -1
- package/src/memory/filter.js +5 -1
- package/src/memory/forget-v2.js +410 -0
- package/src/memory/forget.js +71 -0
- package/src/memory/frames-activation.js +247 -0
- package/src/memory/fts-query.js +174 -0
- package/src/memory/governance.js +604 -0
- package/src/memory/index.js +1 -0
- package/src/memory/l2-gate.js +169 -0
- package/src/memory/lock.js +121 -0
- package/src/memory/migrate.js +139 -0
- package/src/memory/recall-v2.js +223 -0
- package/src/memory/recall.js +65 -2
- package/src/memory/records.js +425 -0
- package/src/memory/retention.js +128 -0
- package/src/memory/review.js +124 -0
- package/src/memory/trust.js +88 -0
- package/src/memory/version-chain.js +264 -0
- package/src/memory/wal.js +137 -0
- package/src/memory/working-frame.js +516 -0
- package/src/metrics/classify.mjs +5 -3
- package/src/metrics/index.mjs +21 -1
- package/src/metrics/prestep-latency.mjs +300 -0
- package/src/metrics/store.mjs +25 -0
- package/src/policy-profile.js +18 -3
- package/src/recall/anaphora.mjs +87 -0
- package/src/recall/cards.mjs +7 -0
- package/src/recall/embedding.mjs +8 -8
- package/src/recall/entities.mjs +112 -0
- package/src/recall/index.js +235 -19
- package/src/recall/inject-order.mjs +10 -8
- package/src/recall/privacy.mjs +105 -16
- package/src/recall/recall-core.mjs +116 -10
- package/src/recall/shared-visibility.js +302 -0
- package/src/recall/time-normalizer.mjs +196 -0
- package/src/role/activation.js +191 -0
- package/src/role/attention.js +318 -0
- package/src/role/base.js +36 -0
- package/src/role/channels.js +423 -0
- package/src/role/index.js +425 -0
- package/src/role/interfaces.js +115 -0
- package/src/role/personality.js +370 -0
- package/src/role/readers.js +151 -0
- package/src/role/relationships.js +477 -0
- package/src/role/store.js +202 -0
- package/src/role/writeprotect.js +373 -0
- package/src/router/aliases.json +176 -25
- package/src/router/background/agent-runner.mjs +1 -1
- package/src/router/background/anchor.mjs +1 -1
- package/src/router/background/audit.mjs +2 -2
- package/src/router/background/budget-ledger.mjs +2 -2
- package/src/router/background/host-sim.mjs +1 -1
- package/src/router/background/memory.mjs +4 -4
- package/src/router/background/queue.mjs +1 -1
- package/src/router/background/retry.mjs +1 -1
- package/src/router/background/router.mjs +1 -1
- package/src/router/background/stream.mjs +1 -1
- package/src/router/background/tool-policy.mjs +1 -1
- package/src/router/design-headings.json +5 -5
- package/src/router/face/config.mjs +1 -1
- package/src/router/face/identity.mjs +3 -3
- package/src/router/judge.mjs +8 -7
- package/src/router/policies/generic.json +21 -4
- package/src/router/route.js +109 -22
- package/src/router/router.mjs +10 -6
- package/src/router/routing-rules.json +260 -445
- package/src/router/run-sim.mjs +8 -8
- package/src/router/runtime.js +23 -12
- package/src/router/service/board.mjs +95 -15
- package/src/router/service/config.mjs +5 -5
- package/src/router/service/context.mjs +1 -1
- package/src/router/service/hint.mjs +14 -0
- package/src/router/service/queue.mjs +1 -1
- package/src/router/service/service.mjs +27 -11
- package/src/router/shadow.mjs +4 -3
- package/src/surgery-recovery.js +2 -2
- package/src/tool-output.js +2 -2
- package/src/tools.js +39 -7
- package/src/truncate-visible.js +2 -2
- package/src/ui/actions.js +1312 -0
- package/src/ui/panel-api.js +367 -0
- package/src/ui/panel-auth.js +251 -0
- package/src/ui/panel-integrity.js +243 -0
- package/src/ui/routes-readonly.js +695 -0
- package/src/ui/routes.js +3 -0
- package/docs/DEV.md +0 -279
- package/docs/PRESENCE-BUS-WIRING.md +0 -491
- package/docs/PRESENCE-BUS.md +0 -694
- package/docs/SURGERY.md +0 -186
- package/scripts/mark-core-cards.mjs +0 -289
- package/scripts/pack.mjs +0 -392
- package/scripts/router-proposals.mjs +0 -386
- package/src/router/fixtures/M1.json +0 -16
- package/src/router/fixtures/M2.json +0 -16
- package/src/router/fixtures/M3.json +0 -20
- package/src/router/fixtures/M4.json +0 -20
- package/src/router/fixtures/M5.json +0 -45
- package/src/router/fixtures/M6.json +0 -53
- package/src/router/fixtures/M7.json +0 -46
- package/src/router/fixtures/S1.json +0 -20
- package/src/router/fixtures/S2.json +0 -23
- package/src/router/fixtures/S3.json +0 -20
- package/src/router/fixtures/S4.json +0 -34
- package/src/router/fixtures/S5.json +0 -43
- package/src/router/fixtures/S6.json +0 -47
- package/src/router/fixtures/T1.json +0 -23
- package/src/router/fixtures/T2.json +0 -16
- package/src/router/fixtures/T3.json +0 -19
- package/src/router/fixtures/T4.json +0 -16
- package/src/router/fixtures/X1.json +0 -17
- package/src/router/fixtures/X2.json +0 -20
- package/src/router/gen-design-headings.mjs +0 -107
- package/src/router/policies/owner-rulings-2026-11-03.json +0 -62
- package/test/auto-recall.test.mjs +0 -474
- package/test/auto-truncate.test.mjs +0 -931
- package/test/autobind.test.mjs +0 -385
- package/test/bus.test.mjs +0 -1572
- package/test/cli-guard.test.mjs +0 -198
- package/test/conclusion.test.mjs +0 -408
- package/test/config-schema.test.mjs +0 -204
- package/test/d6-output.test.mjs +0 -194
- package/test/d6.test.mjs +0 -395
- package/test/deps.test.mjs +0 -342
- package/test/doctor-setup.test.mjs +0 -297
- package/test/embedding-recall.test.mjs +0 -347
- package/test/feature-flags.test.mjs +0 -568
- package/test/filter-shadow.test.mjs +0 -170
- package/test/fixtures/baseline-0.8.0-registration.json +0 -556
- package/test/fixtures/d6-header-tools.json +0 -1
- package/test/fixtures/lock-child.mjs +0 -67
- package/test/fixtures/pre-step-container.mjs +0 -100
- package/test/fixtures/privacy-memory/topics/pii-unmarked.md +0 -9
- package/test/fixtures/privacy-memory/topics/secret-local-only.md +0 -11
- package/test/fixtures/profile-session-longlive-config.json +0 -20
- package/test/fixtures/proposal-cas-child.mjs +0 -66
- package/test/host-engine-status.test.mjs +0 -307
- package/test/hot-truncate.test.mjs +0 -1349
- package/test/identity-card-marker.test.mjs +0 -307
- package/test/identity-router/run.mjs +0 -721
- package/test/integration-pre-step.test.mjs +0 -553
- package/test/live.test.mjs +0 -1020
- package/test/maintenance-schedule.test.mjs +0 -538
- package/test/memory.test.mjs +0 -2828
- package/test/metrics.test.mjs +0 -478
- package/test/orchestrator.test.mjs +0 -266
- package/test/p1_probe.mjs +0 -97
- package/test/packaging.test.mjs +0 -182
- package/test/portability.test.mjs +0 -343
- package/test/rc4-regressions.test.mjs +0 -562
- package/test/rc5-regressions.test.mjs +0 -197
- package/test/rc6-chinese.test.mjs +0 -394
- package/test/router-1100/apply-off.test.mjs +0 -175
- package/test/router-1100/budget-reconcile.test.mjs +0 -215
- package/test/router-1100/config-context.test.mjs +0 -211
- package/test/router-1100/helpers.mjs +0 -129
- package/test/router-1100/hint-envelope.test.mjs +0 -150
- package/test/router-1100/lock-crossproc.test.mjs +0 -206
- package/test/router-1100/proposal-cas-crossproc.test.mjs +0 -184
- package/test/router-1100/router-apply.test.mjs +0 -372
- package/test/router-1100/router-fixb.test.mjs +0 -602
- package/test/router-1100/router-proposals.test.mjs +0 -405
- package/test/router-1100/router-queue-lease-wal.test.mjs +0 -355
- package/test/router-1100/router-security-cr.test.mjs +0 -333
- package/test/router-1100/service-lifecycle.test.mjs +0 -220
- package/test/router-1100/tools-contract.test.mjs +0 -164
- package/test/router-1100/turn-reflect-tick.test.mjs +0 -89
- package/test/router-1100/v6-contract.test.mjs +0 -158
- package/test/router-1100/v6b-contract.test.mjs +0 -293
- package/test/router-1100/v6c-contract.test.mjs +0 -249
- package/test/router-1100/wal-rotation.test.mjs +0 -375
- package/test/router-1100/wp1-config.test.mjs +0 -170
- package/test/router-1100/wp1-default-off.test.mjs +0 -77
- package/test/router-1100/wp1-model-status.test.mjs +0 -90
- package/test/router-1100/wp1-status.test.mjs +0 -220
- package/test/router-1100/wp1-tools.test.mjs +0 -146
- package/test/router-1100/wp5-cli.test.mjs +0 -240
- package/test/router-1100/wp5-model-auto.test.mjs +0 -418
- package/test/router-1100/wp6-merge.test.mjs +0 -386
- package/test/router-1100/wp6-wake.test.mjs +0 -502
- package/test/router-background/audit.test.mjs +0 -37
- package/test/router-background/budget-ledger.test.mjs +0 -330
- package/test/router-background/cross-process.test.mjs +0 -222
- package/test/router-background/fixtures/cross-child.mjs +0 -85
- package/test/router-background/fixtures/real-shapes.mjs +0 -239
- package/test/router-background/router.test.mjs +0 -1044
- package/test/router-background/stream-retry.test.mjs +0 -358
- package/test/router-background/tool-agent.test.mjs +0 -384
- package/test/router-face/bridge.test.mjs +0 -169
- package/test/router-face/face.test.mjs +0 -316
- package/test/router-failclosed.test.mjs +0 -466
- package/test/router-identity.test.mjs +0 -384
- package/test/router-l1-l2.contract.test.mjs +0 -1075
- package/test/router-memory-tools.test.mjs +0 -262
- package/test/router-policy.test.mjs +0 -225
- package/test/router-runtime.test.mjs +0 -438
- package/test/router-shadow.test.mjs +0 -287
- package/test/router.test.mjs +0 -903
- package/test/run-rc.mjs +0 -299
- package/test/run.mjs +0 -2469
- package/test/safety-defaults.test.mjs +0 -179
- package/test/seeded-load.test.mjs +0 -436
- package/test/session-original.test.mjs +0 -338
- package/test/surgery-recovery.test.mjs +0 -936
- package/test/t7_drive.mjs +0 -151
- package/test/tool-output.test.mjs +0 -393
- package/test/tool-schema.test.mjs +0 -177
- package/test/tools_contract.test.mjs +0 -716
- package/test/truncate-visible.test.mjs +0 -1150
- package/test/ui-flags.test.mjs +0 -477
- package/test/v4-hardening.test.mjs +0 -427
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
// 1.6.0 safety defaults — hard acceptance for the pre-release merge.
|
|
2
|
-
//
|
|
3
|
-
// One suite pins the five changes that came out of the abuse assessment and
|
|
4
|
-
// the settings-panel contract:
|
|
5
|
-
// 1. autoTruncate code default is off/dryrun and matches cordis.patch.yml;
|
|
6
|
-
// 2. routerRuntime defaults to off (shadow is opt-in only);
|
|
7
|
-
// 3. worker_spawn/worker_status/worker_kill stay in the 22-tool surface but
|
|
8
|
-
// every Host invocation returns "unavailable" until workers.enabled:true;
|
|
9
|
-
// 4. the settings client registers plugins.row.config under the renamed
|
|
10
|
-
// package key `dsh-longlive#session-longlive` (row id unchanged);
|
|
11
|
-
// 5. README's two absolute claims are qualified, the Chinese token default is
|
|
12
|
-
// 300000, and the package ships a real MIT LICENSE.
|
|
13
|
-
//
|
|
14
|
-
// These are behavioural/static checks on purpose: the release gate is the
|
|
15
|
-
// packaged tree, not a design document.
|
|
16
|
-
|
|
17
|
-
import test from 'node:test';
|
|
18
|
-
import assert from 'node:assert/strict';
|
|
19
|
-
import fs from 'node:fs';
|
|
20
|
-
import path from 'node:path';
|
|
21
|
-
import { fileURLToPath } from 'node:url';
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
AUTO_TRUNCATE_DEFAULTS,
|
|
25
|
-
normalizeAutoTruncateConfig,
|
|
26
|
-
} from '../src/auto-truncate.js';
|
|
27
|
-
import { CONFIG_SCHEMA_AVAILABLE, Config } from '../src/config.js';
|
|
28
|
-
import {
|
|
29
|
-
TOOLS,
|
|
30
|
-
WORKERS_DEFAULTS,
|
|
31
|
-
WORKER_TOOL_NAMES,
|
|
32
|
-
WORKERS_DISABLED_MESSAGE,
|
|
33
|
-
registerTools,
|
|
34
|
-
} from '../src/tools.js';
|
|
35
|
-
import {
|
|
36
|
-
FLAGS_PACKAGE,
|
|
37
|
-
FLAGS_ROW_ID,
|
|
38
|
-
FLAGS_SLOT_KEY,
|
|
39
|
-
} from '../src/ui/flags.js';
|
|
40
|
-
|
|
41
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
42
|
-
const ROOT = path.resolve(HERE, '..');
|
|
43
|
-
const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
|
|
44
|
-
const read = (rel) => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
|
45
|
-
|
|
46
|
-
test('autoTruncate: code default and shipped patch are both enabled:false / dryrun', () => {
|
|
47
|
-
assert.equal(AUTO_TRUNCATE_DEFAULTS.enabled, false, 'AUTO_TRUNCATE_DEFAULTS.enabled 必须为 false');
|
|
48
|
-
assert.equal(AUTO_TRUNCATE_DEFAULTS.mode, 'dryrun', 'AUTO_TRUNCATE_DEFAULTS.mode 必须为 dryrun');
|
|
49
|
-
const normalized = normalizeAutoTruncateConfig(undefined);
|
|
50
|
-
assert.equal(normalized.enabled, false, 'autoTruncate.enabled 代码默认必须为 false');
|
|
51
|
-
assert.equal(normalized.mode, 'dryrun', 'autoTruncate.mode 代码默认必须为 dryrun');
|
|
52
|
-
assert.equal(normalized.tokensThreshold, 300000);
|
|
53
|
-
|
|
54
|
-
const yml = read('cordis.patch.yml');
|
|
55
|
-
assert.match(
|
|
56
|
-
yml,
|
|
57
|
-
/autoTruncate:\s*\r?\n\s+enabled:\s*false\s*\r?\n\s+mode:\s*['"]?dryrun['"]?/,
|
|
58
|
-
'cordis.patch.yml 必须显式写 autoTruncate enabled:false / mode:dryrun',
|
|
59
|
-
);
|
|
60
|
-
// An empty object must not silently re-enable log mode.
|
|
61
|
-
const empty = normalizeAutoTruncateConfig({});
|
|
62
|
-
assert.equal(empty.enabled, false);
|
|
63
|
-
assert.equal(empty.mode, 'dryrun');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('routerRuntime: runtime default is off, patch is explicit, shadow stays opt-in', () => {
|
|
67
|
-
const index = read('src/index.js');
|
|
68
|
-
assert.match(index, /const runtimeMode = config\.routerRuntime \?\? 'off';/,
|
|
69
|
-
"index.js 的 routerRuntime 缺省值必须是 'off'");
|
|
70
|
-
assert.equal(/: 'shadow'\);\s*\n\s*let routerRuntime/.test(index), false,
|
|
71
|
-
'index.js 仍残留 shadow 作为缺省值');
|
|
72
|
-
|
|
73
|
-
const yml = read('cordis.patch.yml');
|
|
74
|
-
assert.match(yml, /routerRuntime:\s*['"]off['"]/, "cordis.patch.yml 必须显式写 routerRuntime: 'off'");
|
|
75
|
-
|
|
76
|
-
// The schema must not materialise a default that would override the runtime
|
|
77
|
-
// decision: routerRuntime intentionally has no default.
|
|
78
|
-
if (CONFIG_SCHEMA_AVAILABLE) {
|
|
79
|
-
assert.equal(Config({}).routerRuntime, undefined,
|
|
80
|
-
'routerRuntime 在 schema 里不能有默认值(缺省=off 由 index.js 决定)');
|
|
81
|
-
assert.match(Config.dict.routerRuntime.meta.description.zh, /默认 off/);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('workers: fan-out tools are visible but unavailable until workers.enabled:true', async () => {
|
|
86
|
-
assert.equal(WORKERS_DEFAULTS.enabled, false);
|
|
87
|
-
assert.deepEqual([...WORKER_TOOL_NAMES], ['worker_spawn', 'worker_status', 'worker_kill']);
|
|
88
|
-
assert.equal(TOOLS.length, 22, '默认工具表仍是 22 个(开关不改变表面)');
|
|
89
|
-
|
|
90
|
-
async function capture(config) {
|
|
91
|
-
const captured = [];
|
|
92
|
-
const ctx = { tools: { register: (definition) => { captured.push(definition); return () => {}; } } };
|
|
93
|
-
const count = await registerTools(ctx, {
|
|
94
|
-
defineTool: (definition) => definition,
|
|
95
|
-
...config,
|
|
96
|
-
});
|
|
97
|
-
return { captured, count };
|
|
98
|
-
}
|
|
99
|
-
const byName = (defs) => new Map(defs.map((definition) => [definition.name, definition]));
|
|
100
|
-
|
|
101
|
-
const off = await capture({});
|
|
102
|
-
assert.equal(off.count, 22);
|
|
103
|
-
const offTools = byName(off.captured);
|
|
104
|
-
for (const name of WORKER_TOOL_NAMES) {
|
|
105
|
-
const result = await offTools.get(name).execute({ prompt: 'x', workerId: 'w1' }, {});
|
|
106
|
-
assert.equal(result.ok, false, `${name} 默认必须不可用`);
|
|
107
|
-
assert.equal(result.status, 'unavailable');
|
|
108
|
-
assert.equal(result.available, false);
|
|
109
|
-
assert.match(result.message, /workers\.enabled/);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const on = await capture({ workers: { enabled: true } });
|
|
113
|
-
const onTools = byName(on.captured);
|
|
114
|
-
const spawn = await onTools.get('worker_spawn').execute({}, {});
|
|
115
|
-
assert.match(spawn.message, /缺少必填参数 prompt/, 'workers.enabled:true 后应越过开关');
|
|
116
|
-
assert.equal(spawn.message.includes(WORKERS_DISABLED_MESSAGE), false);
|
|
117
|
-
const status = await onTools.get('worker_status').execute({}, {});
|
|
118
|
-
assert.match(status.message, /缺少必填参数 workerId/);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('settings client: slot key is @jjh32456/dsh-longlive#session-longlive (row id unchanged)', () => {
|
|
122
|
-
assert.equal(PKG.name, '@jjh32456/dsh-longlive');
|
|
123
|
-
assert.equal(FLAGS_PACKAGE, '@jjh32456/dsh-longlive');
|
|
124
|
-
assert.equal(FLAGS_ROW_ID, 'session-longlive');
|
|
125
|
-
assert.equal(FLAGS_SLOT_KEY, '@jjh32456/dsh-longlive#session-longlive');
|
|
126
|
-
assert.equal(FLAGS_SLOT_KEY, `${PKG.name}#${FLAGS_ROW_ID}`);
|
|
127
|
-
|
|
128
|
-
const bundle = read('lib/client.js');
|
|
129
|
-
assert.ok(bundle.includes('id: "@jjh32456/dsh-longlive"'), 'client 模块 id 必须与包名一致');
|
|
130
|
-
assert.ok(bundle.includes('const SLOT_KEY = "@jjh32456/dsh-longlive#session-longlive";'),
|
|
131
|
-
'client 注册的 slot key 必须是 @jjh32456/dsh-longlive#session-longlive');
|
|
132
|
-
assert.equal(bundle.includes('dsh-session-longlive#session-longlive'), false,
|
|
133
|
-
'client 仍残留旧包名 slot key');
|
|
134
|
-
assert.equal(bundle.includes('"dsh-session-longlive"'), false,
|
|
135
|
-
'client 仍残留旧包名 id');
|
|
136
|
-
assert.equal(bundle.includes('id: "dsh-longlive"'), false,
|
|
137
|
-
'client 仍残留未 scoped 的模块 id');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('Config schema: 85 nodes (1.6.4 adds hotTruncate), safety defaults visible, descriptions in zh+en', { skip: !CONFIG_SCHEMA_AVAILABLE }, () => {
|
|
141
|
-
function countNodes(schema) {
|
|
142
|
-
const dict = schema?.dict;
|
|
143
|
-
if (!dict || typeof dict !== 'object') return 1;
|
|
144
|
-
let total = 1;
|
|
145
|
-
for (const key of Object.keys(dict)) total += countNodes(dict[key]);
|
|
146
|
-
return total;
|
|
147
|
-
}
|
|
148
|
-
// The schema object itself is the root, not a field: subtract it so the count
|
|
149
|
-
// matches the configured nodes. 1.6.0 had 80; 1.6.4 adds the hotTruncate
|
|
150
|
-
// block (1 parent + 4 leaves), so the budget is 85.
|
|
151
|
-
assert.equal(countNodes(Config) - 1, 85, 'Config schema 节点数必须保持 85');
|
|
152
|
-
|
|
153
|
-
const parsed = Config({});
|
|
154
|
-
assert.equal(parsed.autoTruncate.enabled, false);
|
|
155
|
-
assert.equal(parsed.autoTruncate.mode, 'dryrun');
|
|
156
|
-
assert.match(Config.dict.autoTruncate.dict.enabled.meta.description.zh, /默认关闭/);
|
|
157
|
-
assert.match(Config.dict.routerRuntime.meta.description.en, /default off/);
|
|
158
|
-
assert.equal(Config.dict.memoryRoot.meta.disabled, true);
|
|
159
|
-
assert.equal(Config.dict.memRoot.meta.disabled, true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('README claims are qualified, token default is 300000, LICENSE ships', () => {
|
|
163
|
-
const zh = read('README.md');
|
|
164
|
-
assert.ok(zh.includes('30 万'), '中文 README 的默认阈值必须写 30 万');
|
|
165
|
-
assert.equal(zh.includes('默认 20 万 token'), false, '中文 README 仍写默认 20 万');
|
|
166
|
-
assert.ok(zh.includes('默认配置不联网'), '中文 README 需要限定“不联网”');
|
|
167
|
-
assert.ok(zh.includes('默认不自动杀进程'), '中文 README 需要限定“不自动杀进程”');
|
|
168
|
-
|
|
169
|
-
const en = read('README.en.md');
|
|
170
|
-
assert.ok(en.includes('network requests or telemetry in the default configuration'),
|
|
171
|
-
'英文 README 需要限定 no network');
|
|
172
|
-
assert.ok(en.includes('300000'), '英文 README 的恢复阈值应为 300000');
|
|
173
|
-
assert.equal(en.includes('200000'), false, '英文 README 仍写 200000');
|
|
174
|
-
|
|
175
|
-
const license = read('LICENSE');
|
|
176
|
-
assert.match(license, /^MIT License/);
|
|
177
|
-
assert.match(license, /Copyright \(c\) 2026 阿恒、听澜/);
|
|
178
|
-
assert.ok(PKG.files.includes('LICENSE'), 'package.json files 必须显式包含 LICENSE');
|
|
179
|
-
});
|
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
// @local/dsh-longlive — seeded-session load regression (0.7.5)
|
|
2
|
-
//
|
|
3
|
-
// A released v4 log carries its inherited cut as a MARKER EVENT, not as a
|
|
4
|
-
// header field: one `session/end-seed` row with `data.inherited === true`, and
|
|
5
|
-
// the decoder derives `inheritedEventCount` from the LAST such row
|
|
6
|
-
// (`@deepseek-ai/dsh-session-format-v1-to-v2` finish()). The physical header
|
|
7
|
-
// line has no `inheritedEventCount` field at all — the persistence layer's
|
|
8
|
-
// isHeaderLine() rejects unknown keys — so 0.7.4's
|
|
9
|
-
// `header.inheritedEventCount = 0` never reached disk. Truncating a seeded
|
|
10
|
-
// session therefore produced a header that still said `isSeeded: true` with no
|
|
11
|
-
// marker left anywhere, and the real host refused to load it:
|
|
12
|
-
//
|
|
13
|
-
// SessionPersistenceCorruptionError: stored log is corrupt:
|
|
14
|
-
// SessionFormatError: released v2 seeded Session lacks an inherited end-seed
|
|
15
|
-
// marker
|
|
16
|
-
//
|
|
17
|
-
// The CLI's read-back stayed green because it only reparsed with src/codec.js,
|
|
18
|
-
// which never looks at this metadata. So these cases pin both halves:
|
|
19
|
-
// * the metadata the writers must emit (unit, no host needed);
|
|
20
|
-
// * a real load of the truncated log through the host's own persistence and
|
|
21
|
-
// Session packages (no model API key involved — this decodes a log only).
|
|
22
|
-
//
|
|
23
|
-
// A seeded log's inherited prefix is exactly what a prefix cut removes, so the
|
|
24
|
-
// writers now keep `isSeeded` and write one fresh marker at index 0: an
|
|
25
|
-
// explicitly empty inherited prefix, a shape `@deepseek-ai/dsh-subagent`
|
|
26
|
-
// documents as supported and the decoder accepts as `inheritedEventCount: 0`.
|
|
27
|
-
// Rewriting `isSeeded` to false instead would silently re-label a detached
|
|
28
|
-
// child as a fresh session, so that route is deliberately not taken.
|
|
29
|
-
|
|
30
|
-
import fs from 'node:fs';
|
|
31
|
-
import path from 'node:path';
|
|
32
|
-
import { spawnSync } from 'node:child_process';
|
|
33
|
-
|
|
34
|
-
import { parseSession, encodeSession, assertContiguous } from '../src/codec.js';
|
|
35
|
-
import { truncateSession, CONFIRM_WORD } from '../src/truncate.js';
|
|
36
|
-
import { truncateVisibleSession, VISIBLE_CONFIRM_WORD, isInheritedSeedMarker } from '../src/truncate-visible.js';
|
|
37
|
-
|
|
38
|
-
// The host is discovered at run time (see findAppRoot): the suite must not
|
|
39
|
-
// publish a machine path. Overridable via DSH_LONGLIVE_APP_EXE when the app
|
|
40
|
-
// lives somewhere the walk-up cannot see; when nothing is found the real-load
|
|
41
|
-
// half SKIPs instead of pretending to pass.
|
|
42
|
-
// app.asar is a virtual archive: plain Node cannot stat anything INSIDE it, so
|
|
43
|
-
// the readiness check stops at the archive file itself and the per-package
|
|
44
|
-
// existence is proven by the loader actually requiring them.
|
|
45
|
-
const ASAR_DIR = 'app.asar';
|
|
46
|
-
|
|
47
|
-
function buildSeeded({ id, turns = 18, markerTurns = [3, 5, 7], seeded = true, checkpointAt = null }) {
|
|
48
|
-
const events = [];
|
|
49
|
-
const surface = [];
|
|
50
|
-
const base = Date.now() - 600_000;
|
|
51
|
-
const push = (event) => {
|
|
52
|
-
event.seq = events.length;
|
|
53
|
-
event.time = base + events.length;
|
|
54
|
-
events.push(event);
|
|
55
|
-
if (event.surfaceOp === 'append') surface.push(event.seq);
|
|
56
|
-
};
|
|
57
|
-
push({
|
|
58
|
-
type: 'system/message',
|
|
59
|
-
surfaceOp: 'append',
|
|
60
|
-
data: {
|
|
61
|
-
message: {
|
|
62
|
-
role: 'system',
|
|
63
|
-
id: 'system-1',
|
|
64
|
-
source: { kind: 'system-prompt' },
|
|
65
|
-
content: [{ type: 'text', text: 'inherited system prompt' }],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
push({ type: 'session/title', data: { title: '子代理(继承)', messageSeqs: [], source: { kind: 'user' } } });
|
|
70
|
-
for (let turn = 1; turn <= turns; turn += 1) {
|
|
71
|
-
push({ type: 'turn/start', data: { turn } });
|
|
72
|
-
push({ type: 'step/start', data: { turn, step: 1 } });
|
|
73
|
-
push({
|
|
74
|
-
type: 'user/message',
|
|
75
|
-
surfaceOp: 'append',
|
|
76
|
-
data: {
|
|
77
|
-
turn,
|
|
78
|
-
step: 1,
|
|
79
|
-
role: 'user',
|
|
80
|
-
id: `user-${turn}`,
|
|
81
|
-
content: [{ type: 'text', text: `question ${turn}` }],
|
|
82
|
-
source: { kind: 'user', clientTimeZone: 'Asia/Shanghai' },
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
push({
|
|
86
|
-
type: 'assistant/message',
|
|
87
|
-
surfaceOp: 'append',
|
|
88
|
-
data: {
|
|
89
|
-
turn,
|
|
90
|
-
step: 1,
|
|
91
|
-
stream: [],
|
|
92
|
-
message: {
|
|
93
|
-
role: 'assistant',
|
|
94
|
-
id: `assistant-${turn}`,
|
|
95
|
-
source: { kind: 'model', provider: 'deepseek-official', model: 'deepseek-chat' },
|
|
96
|
-
content: [{ type: 'text', text: `answer ${turn} ${'x'.repeat(200)}` }],
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
if (turn === checkpointAt) {
|
|
101
|
-
// Real logs are compacted long before they are cut: a checkpoint replaces
|
|
102
|
-
// the visible surface so far, which is the only way the log truncator's
|
|
103
|
-
// "never cut a visible message" boundary can sit deep in the file.
|
|
104
|
-
const compactionId = 'ckpt-seeded';
|
|
105
|
-
const startSeq = surface[0];
|
|
106
|
-
const endSeq = surface[surface.length - 1];
|
|
107
|
-
push({ type: 'compaction/start', data: { compactionId, turn } });
|
|
108
|
-
push({
|
|
109
|
-
type: 'compaction/summary',
|
|
110
|
-
data: {
|
|
111
|
-
compactionId,
|
|
112
|
-
turn,
|
|
113
|
-
summary: '(压缩摘要)',
|
|
114
|
-
shadowedRange: { start: startSeq, end: endSeq },
|
|
115
|
-
shadowedSeqs: [...surface],
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
push({
|
|
119
|
-
type: 'user/message',
|
|
120
|
-
surfaceOp: { op: 'replace', startSeq, endSeq },
|
|
121
|
-
sourceEventSeqs: [...surface],
|
|
122
|
-
data: {
|
|
123
|
-
turn,
|
|
124
|
-
step: 1,
|
|
125
|
-
role: 'user',
|
|
126
|
-
id: `checkpoint-${turn}`,
|
|
127
|
-
content: [{ type: 'text', text: '(压缩摘要)' }],
|
|
128
|
-
source: { kind: 'compact-checkpoint', compactionId },
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
push({ type: 'compaction/end', data: { compactionId, turn } });
|
|
132
|
-
surface.length = 0;
|
|
133
|
-
surface.push(events.length - 1);
|
|
134
|
-
}
|
|
135
|
-
push({ type: 'step/end', data: { turn, step: 1 } });
|
|
136
|
-
push({ type: 'turn/end', data: { turn } });
|
|
137
|
-
if (seeded && markerTurns.includes(turn)) {
|
|
138
|
-
push({ type: 'session/end-seed', data: { inherited: true } });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const header = {
|
|
142
|
-
type: 'session',
|
|
143
|
-
version: 4,
|
|
144
|
-
id,
|
|
145
|
-
createdAt: base,
|
|
146
|
-
cwd: 'C:\\fixtures',
|
|
147
|
-
isSeeded: seeded,
|
|
148
|
-
delegationDepth: seeded ? 1 : 0,
|
|
149
|
-
...(seeded ? { parentSession: 'session-parent-fixture', origin: 'subagent' } : {}),
|
|
150
|
-
};
|
|
151
|
-
return { header, events };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// The host identifies a stored log by resolving its path against
|
|
155
|
-
// header.cwd (projectKey -> `--C-fixtures--`), so the fixture must live at the
|
|
156
|
-
// path the header claims: sessions/<projectKey>/<id>/session.v4.jsonl.zstd.
|
|
157
|
-
function writeLog(TMP, name, options) {
|
|
158
|
-
const { header, events } = buildSeeded({ id: `session-seeded-${name}`, ...options });
|
|
159
|
-
const file = path.join(TMP, 'seeded-load', name, 'sessions', '--C-fixtures--', header.id, 'session.v4.jsonl.zstd');
|
|
160
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
161
|
-
fs.writeFileSync(file, encodeSession(header, events));
|
|
162
|
-
return { file, header, events };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Locates the installed app without hardcoding a drive: the suite's own node is
|
|
166
|
-
// usually the app's bundled runtime, so walking up from process.execPath finds
|
|
167
|
-
// `<app>\resources\app.asar`. Overrides win (DSH_LONGLIVE_APP_EXE /
|
|
168
|
-
// DSH_LONGLIVE_ASAR), and when nothing is found the load cases skip instead of
|
|
169
|
-
// pretending to pass.
|
|
170
|
-
function findAppRoot() {
|
|
171
|
-
const seen = new Set();
|
|
172
|
-
let dir = path.dirname(process.execPath);
|
|
173
|
-
for (let i = 0; i < 8; i += 1) {
|
|
174
|
-
if (seen.has(dir)) break;
|
|
175
|
-
seen.add(dir);
|
|
176
|
-
if (fs.existsSync(path.join(dir, 'app.asar'))) return path.dirname(dir);
|
|
177
|
-
if (fs.existsSync(path.join(dir, 'resources', ASAR_DIR))) return dir;
|
|
178
|
-
const parent = path.dirname(dir);
|
|
179
|
-
if (parent === dir) break;
|
|
180
|
-
dir = parent;
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function findAppExe(root) {
|
|
186
|
-
if (!root) return null;
|
|
187
|
-
let names;
|
|
188
|
-
try { names = fs.readdirSync(root); } catch { return null; }
|
|
189
|
-
const exes = names.filter((name) => name.toLowerCase().endsWith('.exe'));
|
|
190
|
-
if (exes.length === 0) return null;
|
|
191
|
-
const preferred = exes.find((name) => /harness|deepseek/i.test(name)) ?? exes[0];
|
|
192
|
-
return path.join(root, preferred);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function hostRuntime() {
|
|
196
|
-
const envExe = process.env.DSH_LONGLIVE_APP_EXE;
|
|
197
|
-
const appRoot = findAppRoot();
|
|
198
|
-
const exe = envExe || (process.versions.electron ? process.execPath : findAppExe(appRoot));
|
|
199
|
-
if (!exe || !fs.existsSync(exe)) {
|
|
200
|
-
return { ok: false, reason: 'no installed app found (set DSH_LONGLIVE_APP_EXE; the load half needs the real packages)' };
|
|
201
|
-
}
|
|
202
|
-
const archive = process.env.DSH_LONGLIVE_ASAR
|
|
203
|
-
? path.dirname(path.dirname(process.env.DSH_LONGLIVE_ASAR))
|
|
204
|
-
: (appRoot ? path.join(appRoot, 'resources', ASAR_DIR)
|
|
205
|
-
: path.join(path.dirname(exe), 'resources', ASAR_DIR));
|
|
206
|
-
const asar = process.env.DSH_LONGLIVE_ASAR
|
|
207
|
-
|| path.join(archive, 'dsh', 'node_modules');
|
|
208
|
-
if (!fs.existsSync(archive)) {
|
|
209
|
-
return { ok: false, reason: `host archive not found at ${archive} (set DSH_LONGLIVE_ASAR)` };
|
|
210
|
-
}
|
|
211
|
-
return { ok: true, exe, asar };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Runs inside the host's own Electron binary with ELECTRON_RUN_AS_NODE=1: same
|
|
215
|
-
// V8, same packages the app loads sessions with. Prints one JSON line.
|
|
216
|
-
const LOADER_SOURCE = `'use strict';
|
|
217
|
-
const path = require('node:path');
|
|
218
|
-
const file = process.argv[2];
|
|
219
|
-
const asar = process.argv[3];
|
|
220
|
-
(async () => {
|
|
221
|
-
try {
|
|
222
|
-
const cordis = require(path.join(asar, '@deepseek-ai', 'cordis'));
|
|
223
|
-
const persistence = require(path.join(asar, '@deepseek-ai', 'dsh-session-persistence-jsonl'));
|
|
224
|
-
const sessionMod = require(path.join(asar, '@deepseek-ai', 'dsh-session'));
|
|
225
|
-
const root = path.dirname(path.dirname(path.dirname(file)));
|
|
226
|
-
const id = path.basename(path.dirname(file));
|
|
227
|
-
const ctx = new cordis.Context();
|
|
228
|
-
await ctx.plugin(persistence, { root, compression: 'zstd' });
|
|
229
|
-
const stored = await ctx.sessionPersistence.readStoredLog(file, id);
|
|
230
|
-
const session = sessionMod.Session.fromRestore(
|
|
231
|
-
stored.meta.id, stored.events, stored.meta, stored.inheritedEventCount, stored.eventState, [],
|
|
232
|
-
);
|
|
233
|
-
const messages = session.deriveMessages();
|
|
234
|
-
process.stdout.write(JSON.stringify({
|
|
235
|
-
ok: true,
|
|
236
|
-
status: stored.status,
|
|
237
|
-
events: stored.events.length,
|
|
238
|
-
inheritedEventCount: stored.inheritedEventCount,
|
|
239
|
-
isSeeded: stored.meta.isSeeded === true,
|
|
240
|
-
messages: messages.length,
|
|
241
|
-
}) + '\\n');
|
|
242
|
-
} catch (error) {
|
|
243
|
-
process.stdout.write(JSON.stringify({
|
|
244
|
-
ok: false,
|
|
245
|
-
name: error && error.name,
|
|
246
|
-
error: error && String(error.message),
|
|
247
|
-
cause: error && error.cause ? String(error.cause.message || error.cause) : null,
|
|
248
|
-
}) + '\\n');
|
|
249
|
-
process.exitCode = 1;
|
|
250
|
-
}
|
|
251
|
-
})();
|
|
252
|
-
`;
|
|
253
|
-
|
|
254
|
-
function realLoad(TMP, file) {
|
|
255
|
-
const runtime = hostRuntime();
|
|
256
|
-
if (!runtime.ok) return { fail: runtime.reason };
|
|
257
|
-
const loader = path.join(TMP, 'seeded-load', 'load-session.cjs');
|
|
258
|
-
fs.mkdirSync(path.dirname(loader), { recursive: true });
|
|
259
|
-
fs.writeFileSync(loader, LOADER_SOURCE);
|
|
260
|
-
const run = spawnSync(runtime.exe, [loader, file, runtime.asar], {
|
|
261
|
-
encoding: 'utf8',
|
|
262
|
-
timeout: 180_000,
|
|
263
|
-
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
264
|
-
});
|
|
265
|
-
const text = `${run.stdout ?? ''}\n${run.stderr ?? ''}`;
|
|
266
|
-
const line = text.split(/\r?\n/).filter((row) => row.trim().startsWith('{')).pop();
|
|
267
|
-
if (!line) {
|
|
268
|
-
return { fail: `host loader printed no JSON: ${text.slice(0, 400)}` };
|
|
269
|
-
}
|
|
270
|
-
try {
|
|
271
|
-
return { result: JSON.parse(line) };
|
|
272
|
-
} catch (error) {
|
|
273
|
-
return { fail: `host loader JSON unreadable: ${line.slice(0, 200)}` };
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function seedMarkers(events) {
|
|
278
|
-
return events.filter(isInheritedSeedMarker);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Rebuilds the 0.7.4 shape on purpose: seeded header, every inherited marker
|
|
282
|
-
// stripped. The host must refuse it, and this case is what proves the failure
|
|
283
|
-
// mode the fix removes still is what it says it is.
|
|
284
|
-
function stripMarkers(file) {
|
|
285
|
-
const parsed = parseSession(fs.readFileSync(file));
|
|
286
|
-
const events = parsed.events
|
|
287
|
-
.filter((event) => !isInheritedSeedMarker(event))
|
|
288
|
-
.map((event, index) => ({ ...event, seq: index }));
|
|
289
|
-
fs.writeFileSync(file, encodeSession(parsed.header, events));
|
|
290
|
-
return parsed.header;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export function runSeededLoadSuite({ runCase, recordSkip, assert, TMP }) {
|
|
294
|
-
// The real-load cases need the app's own packages. When the app is not
|
|
295
|
-
// installed here they SKIP with the reason — never a fake pass, never a fail.
|
|
296
|
-
const runtime = hostRuntime();
|
|
297
|
-
const hostCase = (id, name, fn) => {
|
|
298
|
-
if (runtime.ok) runCase(id, name, fn);
|
|
299
|
-
else recordSkip(id, name, runtime.reason);
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
runCase('S1', 'seeded 会话可见截断:保留 isSeeded 并在 index 0 写一个 inherited 标记', () => {
|
|
303
|
-
const { file } = writeLog(TMP, 'visible', { turns: 18, markerTurns: [3, 5, 7] });
|
|
304
|
-
const result = truncateVisibleSession(file, {
|
|
305
|
-
dryRun: false,
|
|
306
|
-
confirm: VISIBLE_CONFIRM_WORD,
|
|
307
|
-
keepTurns: 4,
|
|
308
|
-
keepTokens: 10_000_000,
|
|
309
|
-
recentWriteWindowMs: 0,
|
|
310
|
-
});
|
|
311
|
-
assert(result.applied === true, `truncation did not apply: ${result.status}`);
|
|
312
|
-
const after = parseSession(fs.readFileSync(file));
|
|
313
|
-
assert(after.header.isSeeded === true, 'visible truncation cleared isSeeded');
|
|
314
|
-
assert(!('inheritedEventCount' in after.header),
|
|
315
|
-
'header must not carry inheritedEventCount (the persistence header line rejects unknown keys)');
|
|
316
|
-
const markers = seedMarkers(after.events);
|
|
317
|
-
assert(markers.length === 1, `expected exactly one inherited marker, got ${markers.length}`);
|
|
318
|
-
assert(markers[0].seq === 0, `expected the inherited marker at seq 0, got ${markers[0].seq}`);
|
|
319
|
-
assert(markers[0].data.inherited === true, 'marker lost data.inherited === true');
|
|
320
|
-
assert(result.seedMarker?.inheritedEventCount === 0,
|
|
321
|
-
`result.seedMarker should report the cut, got ${JSON.stringify(result.seedMarker)}`);
|
|
322
|
-
assertContiguous(after.events);
|
|
323
|
-
return `${result.before.events} -> ${result.after.events} events, isSeeded kept, inherited marker at seq 0`;
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
runCase('S2', 'seeded 会话日志截断:同样保留 isSeeded 并在 index 0 写一个 inherited 标记', () => {
|
|
327
|
-
// Log truncation may only cut an invisible prefix, so the fixture is
|
|
328
|
-
// compacted at turn 12 and cut inside that shadowed span; markers exist on
|
|
329
|
-
// both sides of the cut and every one of them must be replaced by the single
|
|
330
|
-
// marker the writer puts at index 0.
|
|
331
|
-
const { file } = writeLog(TMP, 'log', {
|
|
332
|
-
turns: 18,
|
|
333
|
-
markerTurns: [3, 5, 7, 14, 16],
|
|
334
|
-
checkpointAt: 12,
|
|
335
|
-
});
|
|
336
|
-
const result = truncateSession(file, {
|
|
337
|
-
keepEvents: 40,
|
|
338
|
-
dryRun: false,
|
|
339
|
-
confirm: CONFIRM_WORD,
|
|
340
|
-
recentWriteWindowMs: 0,
|
|
341
|
-
});
|
|
342
|
-
assert(result.needed === true, 'log truncation found nothing to cut');
|
|
343
|
-
const after = parseSession(fs.readFileSync(file));
|
|
344
|
-
assert(after.header.isSeeded === true, 'log truncation cleared isSeeded');
|
|
345
|
-
assert(!('inheritedEventCount' in after.header),
|
|
346
|
-
'header must not carry inheritedEventCount (the persistence header line rejects unknown keys)');
|
|
347
|
-
const markers = seedMarkers(after.events);
|
|
348
|
-
assert(markers.length === 1, `expected exactly one inherited marker, got ${markers.length}`);
|
|
349
|
-
assert(markers[0].seq === 0, `expected the inherited marker at seq 0, got ${markers[0].seq}`);
|
|
350
|
-
assert(markers[0].data.inherited === true, 'marker lost data.inherited === true');
|
|
351
|
-
assertContiguous(after.events);
|
|
352
|
-
return `${result.beforeEvents} -> ${after.events.length} events, inherited marker at seq 0`;
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
runCase('S3', 'unseeded 会话截断:不写任何 inherited 标记,isSeeded 保持 false', () => {
|
|
356
|
-
const { file } = writeLog(TMP, 'unseeded', { turns: 12, seeded: false });
|
|
357
|
-
truncateVisibleSession(file, {
|
|
358
|
-
dryRun: false,
|
|
359
|
-
confirm: VISIBLE_CONFIRM_WORD,
|
|
360
|
-
keepTurns: 3,
|
|
361
|
-
keepTokens: 10_000_000,
|
|
362
|
-
recentWriteWindowMs: 0,
|
|
363
|
-
});
|
|
364
|
-
const after = parseSession(fs.readFileSync(file));
|
|
365
|
-
assert(after.header.isSeeded !== true, 'unseeded fixture came back seeded');
|
|
366
|
-
assert(seedMarkers(after.events).length === 0, 'unseeded log gained an inherited marker');
|
|
367
|
-
return 'unseeded truncation writes no inherited marker';
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
hostCase('S4', '真实宿主加载:截断后的 seeded 会话可读取(可见截断)', () => {
|
|
371
|
-
const { file } = writeLog(TMP, 'real-visible', { turns: 20, markerTurns: [3, 5, 7, 9] });
|
|
372
|
-
const result = truncateVisibleSession(file, {
|
|
373
|
-
dryRun: false,
|
|
374
|
-
confirm: VISIBLE_CONFIRM_WORD,
|
|
375
|
-
keepTurns: 5,
|
|
376
|
-
keepTokens: 10_000_000,
|
|
377
|
-
recentWriteWindowMs: 0,
|
|
378
|
-
});
|
|
379
|
-
const load = realLoad(TMP, file);
|
|
380
|
-
assert(!load.fail, load.fail);
|
|
381
|
-
assert(load.result.ok === true,
|
|
382
|
-
`real host refused the truncated log: ${load.result.name}: ${load.result.error}`);
|
|
383
|
-
assert(load.result.isSeeded === true, 'host saw isSeeded false after truncating a seeded log');
|
|
384
|
-
assert(load.result.inheritedEventCount === 0,
|
|
385
|
-
`host derived inheritedEventCount ${load.result.inheritedEventCount}, expected 0`);
|
|
386
|
-
assert(load.result.status === 'current', `host status ${load.result.status}`);
|
|
387
|
-
assert(load.result.events === result.after.events,
|
|
388
|
-
`host read ${load.result.events} events, truncation wrote ${result.after.events}`);
|
|
389
|
-
return `host loaded ${load.result.events} events, isSeeded kept, inheritedEventCount 0, ${load.result.messages} messages`;
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
hostCase('S5', '真实宿主加载:截断后的 seeded 会话可读取(日志截断)', () => {
|
|
393
|
-
const { file } = writeLog(TMP, 'real-log', {
|
|
394
|
-
turns: 18,
|
|
395
|
-
markerTurns: [3, 5, 7, 14, 16],
|
|
396
|
-
checkpointAt: 12,
|
|
397
|
-
});
|
|
398
|
-
truncateSession(file, {
|
|
399
|
-
keepEvents: 40,
|
|
400
|
-
dryRun: false,
|
|
401
|
-
confirm: CONFIRM_WORD,
|
|
402
|
-
recentWriteWindowMs: 0,
|
|
403
|
-
});
|
|
404
|
-
const load = realLoad(TMP, file);
|
|
405
|
-
assert(!load.fail, load.fail);
|
|
406
|
-
assert(load.result.ok === true,
|
|
407
|
-
`real host refused the truncated log: ${load.result.name}: ${load.result.error}`);
|
|
408
|
-
assert(load.result.inheritedEventCount === 0,
|
|
409
|
-
`host derived inheritedEventCount ${load.result.inheritedEventCount}, expected 0`);
|
|
410
|
-
return `host loaded ${load.result.events} events after a log cut`;
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
hostCase('S6', '0.7.4 形状(seeded 无标记):真实宿主必须拒绝,错误串与 VM 一致', () => {
|
|
414
|
-
const { file } = writeLog(TMP, 'legacy-shape', { turns: 12, markerTurns: [3, 5] });
|
|
415
|
-
truncateVisibleSession(file, {
|
|
416
|
-
dryRun: false,
|
|
417
|
-
confirm: VISIBLE_CONFIRM_WORD,
|
|
418
|
-
keepTurns: 3,
|
|
419
|
-
keepTokens: 10_000_000,
|
|
420
|
-
recentWriteWindowMs: 0,
|
|
421
|
-
});
|
|
422
|
-
stripMarkers(file);
|
|
423
|
-
const load = realLoad(TMP, file);
|
|
424
|
-
assert(!load.fail, load.fail);
|
|
425
|
-
assert(load.result.ok === false,
|
|
426
|
-
'the host loaded a seeded log with no inherited marker; the regression this suite guards is not reproducible');
|
|
427
|
-
assert(load.result.name === 'SessionPersistenceCorruptionError',
|
|
428
|
-
`expected SessionPersistenceCorruptionError, got ${load.result.name}`);
|
|
429
|
-
assert(String(load.result.error).includes('lacks an inherited end-seed marker')
|
|
430
|
-
|| String(load.result.cause).includes('lacks an inherited end-seed marker'),
|
|
431
|
-
`missing the decoder message: ${load.result.error} / ${load.result.cause}`);
|
|
432
|
-
return 'the old shape is still rejected by the host (SessionFormatError inside SessionPersistenceCorruptionError)';
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
export const SEEDED_LOAD_CASES = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6'];
|