dsh-cortex-memory 0.4.146 → 0.4.148
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 +2423 -2369
- package/README.md +8 -8
- package/bench/governance.mjs +265 -0
- package/bench/migration-bench.mjs +1 -1
- package/bench/semantic-cn.js +4 -4
- package/bench/synthetic.js +3 -3
- package/bin/copy-db.mjs +1 -1
- package/bin/repair.mjs +7 -7
- package/client.js +1 -1
- package/docs/install-windows.md +2 -2
- package/docs/models.md +1 -1
- package/docs/quota-compaction-design.md +3 -3
- package/icon.svg +12 -2
- package/index.js +5 -6
- package/package.json +7 -8
- package/src/adapters/shiori.js +1 -1
- package/src/engines/compression.js +8 -3
- package/src/engines/consolidate.js +1 -1
- package/src/engines/encode.js +3 -3
- package/src/engines/extract.js +1 -1
- package/src/engines/health.js +1 -1
- package/src/engines/life.js +2 -2
- package/src/engines/narrative.js +4 -8
- package/src/engines/retrieve.js +41 -4
- package/src/host/scheduler.js +5 -4
- package/src/memory/tokenizer.js +1 -1
- package/src/self/alias.js +4 -5
- package/src/self/memory-policy.js +59 -0
- package/src/service/cortex.js +20 -2
- package/src/store/repositories/facts.js +1 -1
- package/src/store/repositories/traces.js +1 -1
- package/test/integration/_helpers.js +0 -128
- package/test/integration/acceptance.test.js +0 -803
- package/test/integration/ann-load.test.js +0 -61
- package/test/integration/api-contract.test.js +0 -1476
- package/test/integration/backup-privacy.test.js +0 -214
- package/test/integration/consolidate.test.js +0 -79
- package/test/integration/edge-cases.test.js +0 -1089
- package/test/integration/exchange.test.js +0 -326
- package/test/integration/life-loop.test.js +0 -189
- package/test/integration/load.test.js +0 -751
- package/test/integration/markdown-sync.test.js +0 -35
- package/test/integration/policy-query-api.test.js +0 -306
- package/test/integration/resilience-writes.test.js +0 -241
- package/test/integration/tools-contract.test.js +0 -1324
- package/test/unit/alias.test.js +0 -87
- package/test/unit/ann-edge.test.js +0 -102
- package/test/unit/ann.test.js +0 -77
- package/test/unit/api-client.test.js +0 -576
- package/test/unit/api-validate.test.js +0 -19
- package/test/unit/api.test.js +0 -555
- package/test/unit/appraisal.test.js +0 -48
- package/test/unit/attachments.test.js +0 -33
- package/test/unit/auto-reflect.test.js +0 -141
- package/test/unit/autonomy.test.js +0 -53
- package/test/unit/batch.test.js +0 -46
- package/test/unit/bench.test.js +0 -40
- package/test/unit/benchmark-synthetic.test.js +0 -52
- package/test/unit/capture-filter.test.js +0 -296
- package/test/unit/cli-default-root.test.js +0 -21
- package/test/unit/client-contract.test.js +0 -32
- package/test/unit/compaction-preview.test.js +0 -91
- package/test/unit/compression.test.js +0 -76
- package/test/unit/consolidate-dedupe.test.js +0 -174
- package/test/unit/consolidate-errors.test.js +0 -63
- package/test/unit/consolidate-gate.test.js +0 -26
- package/test/unit/consolidate-preview.test.js +0 -168
- package/test/unit/consolidate-protection.test.js +0 -156
- package/test/unit/consolidate-reason.test.js +0 -206
- package/test/unit/consolidate-retry.test.js +0 -91
- package/test/unit/consolidate-selection.test.js +0 -103
- package/test/unit/core.test.js +0 -77
- package/test/unit/coverage-rewrite.test.js +0 -38
- package/test/unit/dedupe-episodes.test.js +0 -34
- package/test/unit/dedupe-threshold.test.js +0 -14
- package/test/unit/develop.test.js +0 -130
- package/test/unit/development.test.js +0 -68
- package/test/unit/digest.test.js +0 -26
- package/test/unit/dsr.test.js +0 -111
- package/test/unit/edges-candidates.test.js +0 -113
- package/test/unit/emotion.test.js +0 -62
- package/test/unit/encode.test.js +0 -98
- package/test/unit/evolution.test.js +0 -130
- package/test/unit/external-ann-search.test.js +0 -50
- package/test/unit/external-ann.test.js +0 -29
- package/test/unit/extract-question.test.js +0 -41
- package/test/unit/fact-guard.test.js +0 -51
- package/test/unit/fact-noise-llm.test.js +0 -44
- package/test/unit/facts-belief.test.js +0 -32
- package/test/unit/facts-compat.test.js +0 -62
- package/test/unit/facts.test.js +0 -107
- package/test/unit/feature-overrides.test.js +0 -42
- package/test/unit/fts-migration.test.js +0 -42
- package/test/unit/graph.test.js +0 -79
- package/test/unit/growth-reflect.test.js +0 -124
- package/test/unit/guard-runtime.test.js +0 -40
- package/test/unit/guardian.test.js +0 -91
- package/test/unit/health-consolidation.test.js +0 -52
- package/test/unit/health-fts-scope.test.js +0 -33
- package/test/unit/health-privacy.test.js +0 -102
- package/test/unit/health-summaries.test.js +0 -24
- package/test/unit/health-text-maintain.test.js +0 -33
- package/test/unit/health-today.test.js +0 -45
- package/test/unit/hnsw.test.js +0 -35
- package/test/unit/host-runtime.test.js +0 -142
- package/test/unit/host.test.js +0 -58
- package/test/unit/identity.test.js +0 -98
- package/test/unit/induct-evaluate.test.js +0 -41
- package/test/unit/ingest-extracted.test.js +0 -35
- package/test/unit/inhibition.test.js +0 -90
- package/test/unit/initiative.test.js +0 -90
- package/test/unit/jobs.test.js +0 -93
- package/test/unit/json-snapshot.test.js +0 -57
- package/test/unit/label-entities-skip.test.js +0 -18
- package/test/unit/life-consolidate.test.js +0 -34
- package/test/unit/life.test.js +0 -149
- package/test/unit/llm-facts-integration.test.js +0 -27
- package/test/unit/llm-facts.test.js +0 -16
- package/test/unit/llm.test.js +0 -45
- package/test/unit/locomo.test.js +0 -45
- package/test/unit/longmemeval.test.js +0 -56
- package/test/unit/maintain-dispute.test.js +0 -62
- package/test/unit/maintain-duration.test.js +0 -194
- package/test/unit/markdown-import.test.js +0 -44
- package/test/unit/markdown.test.js +0 -34
- package/test/unit/memory-edit.test.js +0 -112
- package/test/unit/metrics.test.js +0 -26
- package/test/unit/migration.test.js +0 -38
- package/test/unit/model-config.test.js +0 -52
- package/test/unit/mood-saturation.test.js +0 -33
- package/test/unit/narrative-weave.test.js +0 -271
- package/test/unit/narrative.test.js +0 -62
- package/test/unit/playbook-consolidate.test.js +0 -24
- package/test/unit/privacy-scope.test.js +0 -39
- package/test/unit/profile-paths.test.js +0 -21
- package/test/unit/profile.test.js +0 -26
- package/test/unit/prompt.test.js +0 -42
- package/test/unit/providers.test.js +0 -42
- package/test/unit/qa.test.js +0 -100
- package/test/unit/query.test.js +0 -53
- package/test/unit/reflect-backfill.test.js +0 -158
- package/test/unit/reflect-coverage.test.js +0 -35
- package/test/unit/reflect-overview.test.js +0 -22
- package/test/unit/reflect-phrasing.test.js +0 -75
- package/test/unit/reflect-sampling.test.js +0 -80
- package/test/unit/reflect-source-budget.test.js +0 -24
- package/test/unit/relationship-dynamics.test.js +0 -29
- package/test/unit/retention.test.js +0 -31
- package/test/unit/retrieval-ranking.test.js +0 -31
- package/test/unit/retrieve.test.js +0 -117
- package/test/unit/revive-on-read.test.js +0 -84
- package/test/unit/rotation.test.js +0 -25
- package/test/unit/scanner.test.js +0 -50
- package/test/unit/scenario.test.js +0 -78
- package/test/unit/scheduler-autoconsolidate.test.js +0 -95
- package/test/unit/scheduler-autodedupe.test.js +0 -52
- package/test/unit/scheduler-autosleep.test.js +0 -50
- package/test/unit/scheduler-cadence.test.js +0 -33
- package/test/unit/scheduler-deep.test.js +0 -62
- package/test/unit/scheduler-tick-gate.test.js +0 -38
- package/test/unit/scheduler.test.js +0 -137
- package/test/unit/self-state.test.js +0 -94
- package/test/unit/service.test.js +0 -72
- package/test/unit/shiori-import.test.js +0 -77
- package/test/unit/skills.test.js +0 -104
- package/test/unit/spacing.test.js +0 -14
- package/test/unit/store.test.js +0 -111
- package/test/unit/summon-left-slot.test.js +0 -51
- package/test/unit/summon-rank.test.js +0 -51
- package/test/unit/temporal-graph.test.js +0 -44
- package/test/unit/tiers-gist.test.js +0 -140
- package/test/unit/tiers.test.js +0 -39
- package/test/unit/tokenizer-fts.test.js +0 -35
- package/test/unit/tools.test.js +0 -122
- package/test/unit/upgrade-0412.test.js +0 -104
- package/test/unit/upgrade-0413.test.js +0 -84
- package/test/unit/upgrade-0414.test.js +0 -101
- package/test/unit/vector-ann.test.js +0 -53
- package/test/unit/vector-async.test.js +0 -69
- package/test/unit/vector-coverage.test.js +0 -34
- package/test/unit/vector-override.test.js +0 -37
- package/test/unit/vector-typed-array.test.js +0 -47
- package/test/unit/vector.test.js +0 -68
- package/test/unit/working.test.js +0 -99
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
|
|
8
|
-
test('maintain 会记录耗时,健康报告能读到(空转走内存回退)', () => {
|
|
9
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-ms-'));
|
|
10
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
11
|
-
try {
|
|
12
|
-
const now = Date.now();
|
|
13
|
-
const report = cortex.maintain({ now });
|
|
14
|
-
assert.ok(Number.isFinite(report.ms) && report.ms >= 0, `maintain 应回报耗时(实际 ${report.ms})`);
|
|
15
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
16
|
-
assert.ok(health.maintain, '健康报告应带上一次维护');
|
|
17
|
-
assert.equal(health.maintain.ms, report.ms, '耗时应通过内存回退传到健康报告');
|
|
18
|
-
} finally {
|
|
19
|
-
cortex.close();
|
|
20
|
-
rmSync(dir, { recursive: true, force: true });
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('真产生变更(写审计行)时,审计行里也有 ms', () => {
|
|
25
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-audit-ms-'));
|
|
26
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
27
|
-
try {
|
|
28
|
-
const now = Date.now();
|
|
29
|
-
// 两条完全相同的摘要会被维护清掉一条 → 一定会写 maintain.run 审计行
|
|
30
|
-
cortex.repos.summaries.insert({ level: 'thread', content: '重复的摘要内容', sourceIds: ['t1'], coverage: 0.2 });
|
|
31
|
-
cortex.repos.summaries.insert({ level: 'thread', content: '重复的摘要内容', sourceIds: ['t1'], coverage: 0.2 });
|
|
32
|
-
const report = cortex.maintain({ now });
|
|
33
|
-
assert.ok(report.summaries >= 1, '应清掉一条重复摘要');
|
|
34
|
-
|
|
35
|
-
const row = cortex.repos.audit.list({ targetType: 'scope', targetId: 'global', limit: 1 })[0];
|
|
36
|
-
assert.ok(row, '应写入 maintain.run 审计行');
|
|
37
|
-
const detail = row.detail ?? {};
|
|
38
|
-
assert.ok(Number.isFinite(detail.ms), `审计 detail 里应该有 ms(实际 ${JSON.stringify(Object.keys(detail))})`);
|
|
39
|
-
|
|
40
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
41
|
-
assert.ok(Number.isFinite(health.maintain?.ms), '有审计行时健康报告也要拿到 ms');
|
|
42
|
-
} finally {
|
|
43
|
-
cortex.close();
|
|
44
|
-
rmSync(dir, { recursive: true, force: true });
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('维护超过阈值的耗时会被报成 SLOW_MAINTAIN,阈值可配', () => {
|
|
49
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-slow-'));
|
|
50
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), maintainSlowMs: 5 } });
|
|
51
|
-
try {
|
|
52
|
-
const now = Date.now();
|
|
53
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: new Date(now).toISOString(), ms: 50 } });
|
|
54
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
55
|
-
const slow = health.issues.find((issue) => issue.code === 'SLOW_MAINTAIN');
|
|
56
|
-
assert.ok(slow, '超过 maintainSlowMs 应提示慢维护');
|
|
57
|
-
assert.equal(slow.detail?.ms, 50);
|
|
58
|
-
} finally {
|
|
59
|
-
cortex.close();
|
|
60
|
-
rmSync(dir, { recursive: true, force: true });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('旧审计行缺 ms 时整条回退到内存快照,不混合两次维护的数字', () => {
|
|
65
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-mixed-'));
|
|
66
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
67
|
-
try {
|
|
68
|
-
const now = Date.now();
|
|
69
|
-
// 升级前留下的 9 键旧行:没有 ms,但 working=7
|
|
70
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: new Date(now - 60000).toISOString(), working: 7, intentions: 3 } });
|
|
71
|
-
const report = cortex.maintain({ now });
|
|
72
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
73
|
-
assert.ok(Number.isFinite(health.maintain?.ms), '应回退到内存快照拿到 ms');
|
|
74
|
-
assert.equal(health.maintain.working, report.working, '条数与耗时必须来自同一次维护');
|
|
75
|
-
assert.notEqual(health.maintain.working, 7, '不应把旧行的 7 与新的耗时混在一起');
|
|
76
|
-
} finally {
|
|
77
|
-
cortex.close();
|
|
78
|
-
rmSync(dir, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('安静的一趟不写审计行时,健康报告同时说清「最近一趟」与「最近一次有变更」', () => {
|
|
83
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-twolines-'));
|
|
84
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
85
|
-
try {
|
|
86
|
-
const now = Date.now();
|
|
87
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: new Date(now - 6 * 3600000).toISOString(), working: 7, intentions: 3 } });
|
|
88
|
-
cortex.maintain({ now });
|
|
89
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
90
|
-
const lines = health.ok.join('\n');
|
|
91
|
-
assert.match(lines, /最近一趟维护/, '应报告最近一趟');
|
|
92
|
-
assert.match(lines, /最近一次有变更的维护/, '旧审计行较旧时应另说一句');
|
|
93
|
-
assert.equal(health.maintainLastChanged?.working, 7, 'maintainLastChanged 应保留旧行数据');
|
|
94
|
-
} finally {
|
|
95
|
-
cortex.close();
|
|
96
|
-
rmSync(dir, { recursive: true, force: true });
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('先变更一趟、再安静一趟:第一行是最近的安静趟,第二行才是那次变更', () => {
|
|
101
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-order-'));
|
|
102
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
103
|
-
try {
|
|
104
|
-
const t1 = Date.now();
|
|
105
|
-
cortex.repos.summaries.insert({ level: 'thread', content: '重复摘要 A', sourceIds: ['t1'], coverage: 0.2 });
|
|
106
|
-
cortex.repos.summaries.insert({ level: 'thread', content: '重复摘要 A', sourceIds: ['t1'], coverage: 0.2 });
|
|
107
|
-
const change = cortex.maintain({ now: t1 });
|
|
108
|
-
assert.ok(change.summaries >= 1, '第一趟应真的产生变更');
|
|
109
|
-
|
|
110
|
-
const t2 = t1 + 60_000;
|
|
111
|
-
const quiet = cortex.maintain({ now: t2 });
|
|
112
|
-
assert.equal(quiet.summaries, 0, '第二趟应无变更');
|
|
113
|
-
|
|
114
|
-
const health = cortex.health({ scopeId: 'global', now: t2 });
|
|
115
|
-
assert.equal(health.maintain.at, quiet.at, '第一行必须是最近那一趟(安静趟)');
|
|
116
|
-
assert.equal(health.maintainLastChanged?.passAt ?? health.maintainLastChanged?.at, change.at, '第二行才是那次有变更的维护');
|
|
117
|
-
assert.notEqual(health.maintain.at, health.maintainLastChanged?.passAt, '两行不能同源');
|
|
118
|
-
} finally {
|
|
119
|
-
cortex.close();
|
|
120
|
-
rmSync(dir, { recursive: true, force: true });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('慢维护被后续安静趟盖住时,仍要报 SLOW_MAINTAIN', () => {
|
|
125
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-masked-'));
|
|
126
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
127
|
-
try {
|
|
128
|
-
const t1 = Date.now() - 60_000;
|
|
129
|
-
// 伪造一次 8.5 秒的慢维护审计行
|
|
130
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: new Date(t1).toISOString(), ms: 8500, working: 2 } });
|
|
131
|
-
// 一分钟后跑一次很快的安静维护,把「最近一趟」顶掉
|
|
132
|
-
const quiet = cortex.maintain({ now: Date.now() });
|
|
133
|
-
assert.ok(quiet.ms < 2000, '安静趟本身不该慢');
|
|
134
|
-
|
|
135
|
-
const health = cortex.health({ scopeId: 'global' });
|
|
136
|
-
const slow = health.issues.find((issue) => issue.code === 'SLOW_MAINTAIN');
|
|
137
|
-
assert.ok(slow, '慢趟不该被后续安静趟遮住');
|
|
138
|
-
assert.equal(slow.detail.ms, 8500);
|
|
139
|
-
assert.match(String(slow.detail.at), /T/, '告警要带上那一趟的时间');
|
|
140
|
-
} finally {
|
|
141
|
-
cortex.close();
|
|
142
|
-
rmSync(dir, { recursive: true, force: true });
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('慢维护即使没有变更也要落审计行(否则护栏永远没样本)', () => {
|
|
147
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-slowrow-'));
|
|
148
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), maintainSlowMs: 0 } });
|
|
149
|
-
try {
|
|
150
|
-
const now = Date.now();
|
|
151
|
-
const report = cortex.maintain({ now });
|
|
152
|
-
assert.ok(report.ms > 0, '阈值设 0 时每趟都算慢');
|
|
153
|
-
const row = cortex.repos.audit.list({ targetType: 'scope', targetId: 'global', limit: 1 })[0];
|
|
154
|
-
assert.ok(row, '慢趟应写审计行');
|
|
155
|
-
assert.ok(Number.isFinite(row.detail?.ms), '审计 detail 应带 ms');
|
|
156
|
-
} finally {
|
|
157
|
-
cortex.close();
|
|
158
|
-
rmSync(dir, { recursive: true, force: true });
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('超过窗口的慢维护不再常驻告警', () => {
|
|
163
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-olderv-'));
|
|
164
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
165
|
-
try {
|
|
166
|
-
const now = Date.now();
|
|
167
|
-
const old = now - 8 * 3600_000;
|
|
168
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: new Date(old).toISOString(), ms: 9000, working: 1 } });
|
|
169
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
170
|
-
const slow = health.issues.find((issue) => issue.code === 'SLOW_MAINTAIN');
|
|
171
|
-
assert.equal(slow, undefined, '8 小时前的慢趟属于历史,不该常驻');
|
|
172
|
-
} finally {
|
|
173
|
-
cortex.close();
|
|
174
|
-
rmSync(dir, { recursive: true, force: true });
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test('时间戳带空格也能正确比较,不被字典序骗到', () => {
|
|
179
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-maintain-spacefmt-'));
|
|
180
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
181
|
-
try {
|
|
182
|
-
const now = Date.now();
|
|
183
|
-
// 同一时刻:审计行写成带空格格式,内存是 ISO
|
|
184
|
-
const iso = new Date(now).toISOString();
|
|
185
|
-
const spaced = iso.replace('T', ' ').replace('Z', '');
|
|
186
|
-
cortex.repos.audit.record({ actor: 'self:maintain', action: 'maintain.run', targetType: 'scope', targetId: 'global', detail: { at: spaced, ms: 3, working: 2 } });
|
|
187
|
-
const report = cortex.maintain({ now });
|
|
188
|
-
const health = cortex.health({ scopeId: 'global', now });
|
|
189
|
-
assert.equal(health.maintain.at, report.at, '同一时刻应判为同一趟,用内存快照');
|
|
190
|
-
} finally {
|
|
191
|
-
cortex.close();
|
|
192
|
-
rmSync(dir, { recursive: true, force: true });
|
|
193
|
-
}
|
|
194
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
import { parseMemoryMarkdown, importMarkdown } from '../../src/adapters/markdown-import.js';
|
|
8
|
-
|
|
9
|
-
test('markdown parser reads frontmatter and body', () => {
|
|
10
|
-
const parsed = parseMemoryMarkdown('---\nid: "t1"\nkind: "fact"\ntitle: "米饭"\ntags: ["米饭", "承诺"]\nattachments: [{"kind":"image","uri":"https://example.test/rice.png"}]\nrecorded_at: "2026-11-05T10:00:00+08:00"\n---\n\n用户喜欢米饭。\n');
|
|
11
|
-
assert.equal(parsed.id, 't1');
|
|
12
|
-
assert.equal(parsed.kind, 'fact');
|
|
13
|
-
assert.deepEqual(parsed.tags, ['米饭', '承诺']);
|
|
14
|
-
assert.equal(parsed.attachments.length, 1);
|
|
15
|
-
assert.equal(parsed.attachments[0].uri, 'https://example.test/rice.png');
|
|
16
|
-
assert.match(parsed.content, /用户喜欢米饭/);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('markdown import writes active files idempotently', () => {
|
|
20
|
-
const dataDir = mkdtempSync(path.join(os.tmpdir(), 'cortex-md-import-'));
|
|
21
|
-
const vault = mkdtempSync(path.join(os.tmpdir(), 'cortex-vault-'));
|
|
22
|
-
const cortex = createCortex({ config: { dataRoot: dataDir, dbFile: path.join(dataDir, 'cortex.sqlite') } });
|
|
23
|
-
try {
|
|
24
|
-
writeFileSync(path.join(vault, 'a.md'), '---\nid: a\nkind: utterance\ntitle: 米饭\ntags: [米饭]\nattachments: [{"kind":"image","uri":"https://example.test/rice.png"}]\n---\n\n用户喜欢米饭。\n', 'utf8');
|
|
25
|
-
writeFileSync(path.join(vault, 'b.md'), '---\nid: b\nstate: archived\n---\n\n不该导入。\n', 'utf8');
|
|
26
|
-
const dry = importMarkdown(cortex, vault, { dryRun: true });
|
|
27
|
-
assert.equal(dry.files, 2);
|
|
28
|
-
assert.equal(cortex.repos.traces.count(), 0);
|
|
29
|
-
const result = importMarkdown(cortex, vault);
|
|
30
|
-
assert.equal(result.imported, 1);
|
|
31
|
-
assert.equal(result.skipped, 1);
|
|
32
|
-
assert.equal(cortex.repos.traces.count(), 1);
|
|
33
|
-
const importedTrace = cortex.repos.traces.list({ scopeId: 'global', limit: 10 })[0];
|
|
34
|
-
assert.equal(importedTrace.metadata.attachments.length, 1);
|
|
35
|
-
assert.equal(importedTrace.metadata.attachments[0].uri, 'https://example.test/rice.png');
|
|
36
|
-
const again = importMarkdown(cortex, vault);
|
|
37
|
-
assert.equal(again.items.find((item) => item.title === '米饭').skipped, true);
|
|
38
|
-
assert.equal(cortex.repos.traces.count(), 1);
|
|
39
|
-
} finally {
|
|
40
|
-
cortex.close();
|
|
41
|
-
rmSync(dataDir, { recursive: true, force: true });
|
|
42
|
-
rmSync(vault, { recursive: true, force: true });
|
|
43
|
-
}
|
|
44
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
import { exportMarkdown } from '../../src/adapters/markdown.js';
|
|
8
|
-
|
|
9
|
-
test('markdown mirror exports readable files and skips secrets', () => {
|
|
10
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-md-'));
|
|
11
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
12
|
-
try {
|
|
13
|
-
cortex.write({ text: '用户说会买米饭。', title: '米饭', explicit: true, facts: [{ subject: '用户', predicate: 'likes', object: '米饭' }], attachments: [{ kind: 'image', uri: 'https://example.test/rice.png', mime: 'image/png' }] });
|
|
14
|
-
cortex.write({ text: '这是一个 secret:sk-abcdefghijklmnopqrstuvwxyz123456', explicit: true });
|
|
15
|
-
cortex.engines.skills.create({ name: '修插件', steps: ['看日志', '改一处', '跑测试'], state: 'active' });
|
|
16
|
-
const result = exportMarkdown(cortex, path.join(dir, 'mirror'));
|
|
17
|
-
assert.equal(result.traces, 1);
|
|
18
|
-
assert.equal(result.skippedSecrets, 1);
|
|
19
|
-
const memory = readFileSync(path.join(dir, 'mirror', 'MEMORY.md'), 'utf8');
|
|
20
|
-
assert.match(memory, /米饭/);
|
|
21
|
-
assert.match(memory, /Attachments \(metadata only\)/);
|
|
22
|
-
assert.match(memory, /https:\/\/example\.test\/rice\.png/);
|
|
23
|
-
assert.doesNotMatch(memory, /sk-abcdefghijklmnop/);
|
|
24
|
-
const self = readFileSync(path.join(dir, 'mirror', 'SELF.md'), 'utf8');
|
|
25
|
-
assert.match(self, /Identity/);
|
|
26
|
-
const facts = readFileSync(path.join(dir, 'mirror', 'FACTS.md'), 'utf8');
|
|
27
|
-
assert.match(facts, /likes/);
|
|
28
|
-
const skills = readFileSync(path.join(dir, 'mirror', 'SKILLS.md'), 'utf8');
|
|
29
|
-
assert.match(skills, /修插件/);
|
|
30
|
-
} finally {
|
|
31
|
-
cortex.close();
|
|
32
|
-
rmSync(dir, { recursive: true, force: true });
|
|
33
|
-
}
|
|
34
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
7
|
-
|
|
8
|
-
function setup() {
|
|
9
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-memory-edit-'));
|
|
10
|
-
const cortex = createCortex({
|
|
11
|
-
config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), features: { autoFacts: false, llmFacts: false } },
|
|
12
|
-
});
|
|
13
|
-
return { dir, cortex };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
test('memory day view groups emotion and work; editing is locked by default', () => {
|
|
17
|
-
const { dir, cortex } = setup();
|
|
18
|
-
try {
|
|
19
|
-
const at = '2026-11-12T03:00:00.000Z';
|
|
20
|
-
const written = cortex.write({ text: '今天完成记忆查询面板。', title: '面板测试', explicit: true, recordedAt: at, importance: 0.8 });
|
|
21
|
-
cortex.emotion.record({ text: '助手觉得安心。', target: '用户', at });
|
|
22
|
-
const day = cortex.memoryDay({ date: '2026-11-12' });
|
|
23
|
-
assert.equal(day.counts.traces, 1);
|
|
24
|
-
assert.equal(day.counts.emotion, 1);
|
|
25
|
-
assert.equal(day.work.traces[0].id, written.trace.id);
|
|
26
|
-
assert.equal(cortex.memoryEditState().enabled, false);
|
|
27
|
-
assert.throws(() => cortex.updateMemoryTrace({ id: written.trace.id, title: '不能改' }), /locked/);
|
|
28
|
-
} finally {
|
|
29
|
-
cortex.close();
|
|
30
|
-
rmSync(dir, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('summon cards are built for left/right brain and can be edited after unlock', () => {
|
|
35
|
-
const { dir, cortex } = setup();
|
|
36
|
-
try {
|
|
37
|
-
const at = '2026-11-12T03:00:00.000Z';
|
|
38
|
-
cortex.write({ text: '今天完成了召唤册。', title: '召唤册', kind: 'decision', explicit: true, recordedAt: at, importance: 0.9 });
|
|
39
|
-
cortex.emotion.record({ text: '助手觉得安心。', target: '用户', at });
|
|
40
|
-
const built = cortex.rebuildSummonBook();
|
|
41
|
-
assert.ok(built.cards >= 2);
|
|
42
|
-
const book = cortex.summonBook({ date: '2026-11-12' });
|
|
43
|
-
assert.ok(book.left.length >= 1);
|
|
44
|
-
assert.ok(book.right.length >= 1);
|
|
45
|
-
assert.ok(book.volumes.length >= 1);
|
|
46
|
-
const card = book.left[0];
|
|
47
|
-
assert.throws(() => cortex.updateSummonCard({ id: card.id, title: '不能改' }), /locked/);
|
|
48
|
-
cortex.setMemoryEdit(true);
|
|
49
|
-
const updated = cortex.updateSummonCard({ id: card.id, title: '改过的召唤卡' });
|
|
50
|
-
assert.equal(updated.title, '改过的召唤卡');
|
|
51
|
-
} finally {
|
|
52
|
-
cortex.close();
|
|
53
|
-
rmSync(dir, { recursive: true, force: true });
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('manual card edits survive a rebuild and cards can be matched by a specific phrase', () => {
|
|
58
|
-
const { dir, cortex } = setup();
|
|
59
|
-
try {
|
|
60
|
-
cortex.write({ text: '米饭约定:以后要一起买米饭。', title: '米饭约定', kind: 'decision', explicit: true, importance: 0.95 });
|
|
61
|
-
cortex.rebuildSummonBook();
|
|
62
|
-
const first = cortex.summonBook({ date: new Date().toLocaleDateString('en-CA') });
|
|
63
|
-
const card = first.right.find((item) => item.title.includes('米饭')) ?? first.right[0];
|
|
64
|
-
assert.ok(card);
|
|
65
|
-
cortex.setMemoryEdit(true);
|
|
66
|
-
cortex.updateSummonCard({ id: card.id, title: '用户改过的米饭卡' });
|
|
67
|
-
cortex.rebuildSummonBook();
|
|
68
|
-
const second = cortex.summonBook({ date: new Date().toLocaleDateString('en-CA') });
|
|
69
|
-
assert.equal(second.right.find((item) => item.id === card.id).title, '用户改过的米饭卡');
|
|
70
|
-
const match = cortex.matchSummonCards({ text: '你还记得米饭约定吗?' });
|
|
71
|
-
assert.ok(match.cards.length >= 1);
|
|
72
|
-
assert.match(match.block, /召唤卡/);
|
|
73
|
-
const feedback = cortex.feedbackSummonCard({ id: card.id, signal: 'helpful' });
|
|
74
|
-
assert.equal(feedback.signal, 'helpful');
|
|
75
|
-
assert.ok(feedback.feedback || feedback.sourceKind !== 'trace');
|
|
76
|
-
} finally {
|
|
77
|
-
cortex.close();
|
|
78
|
-
rmSync(dir, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('reviewIntentions creates a pending intention when none are triggered', () => {
|
|
83
|
-
const { dir, cortex } = setup();
|
|
84
|
-
try {
|
|
85
|
-
const result = cortex.reviewIntentions({ at: Date.now() });
|
|
86
|
-
assert.ok(result.intentions.length >= 1);
|
|
87
|
-
assert.equal(result.intentions[0].kind, 'question');
|
|
88
|
-
assert.ok(cortex.self().intentions.some((item) => item.payload?.topic === '1.5h-review'));
|
|
89
|
-
} finally {
|
|
90
|
-
cortex.close();
|
|
91
|
-
rmSync(dir, { recursive: true, force: true });
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('unlocking memory edit allows trace edits and audits them', () => {
|
|
96
|
-
const { dir, cortex } = setup();
|
|
97
|
-
try {
|
|
98
|
-
const at = '2026-11-12T03:00:00.000Z';
|
|
99
|
-
const written = cortex.write({ text: '旧正文', title: '旧标题', explicit: true, recordedAt: at });
|
|
100
|
-
cortex.setMemoryEdit(true);
|
|
101
|
-
const updated = cortex.updateMemoryTrace({ id: written.trace.id, title: '新标题', content: '新正文', tags: ['手动', '编辑'] });
|
|
102
|
-
assert.equal(updated.title, '新标题');
|
|
103
|
-
assert.equal(updated.content, '新正文');
|
|
104
|
-
assert.deepEqual(updated.tags, ['手动', '编辑']);
|
|
105
|
-
const audit = cortex.repos.audit.list({ limit: 20 });
|
|
106
|
-
assert.ok(audit.some((entry) => entry.action === 'memory.trace.edit'));
|
|
107
|
-
cortex.setMemoryEdit(false);
|
|
108
|
-
} finally {
|
|
109
|
-
cortex.close();
|
|
110
|
-
rmSync(dir, { recursive: true, force: true });
|
|
111
|
-
}
|
|
112
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { createMetrics } from '../../src/observability/metrics.js';
|
|
4
|
-
|
|
5
|
-
test('metrics aggregate counters and percentiles', () => {
|
|
6
|
-
const metrics = createMetrics();
|
|
7
|
-
metrics.inc('writes');
|
|
8
|
-
metrics.inc('writes', 2);
|
|
9
|
-
metrics.observe('search.ms', 10);
|
|
10
|
-
metrics.observe('search.ms', 20);
|
|
11
|
-
metrics.observe('search.ms', 30);
|
|
12
|
-
const snapshot = metrics.snapshot();
|
|
13
|
-
assert.equal(snapshot.counters.writes, 3);
|
|
14
|
-
assert.equal(snapshot.histograms['search.ms'].count, 3);
|
|
15
|
-
assert.equal(snapshot.histograms['search.ms'].p50, 20);
|
|
16
|
-
assert.equal(snapshot.histograms['search.ms'].max, 30);
|
|
17
|
-
metrics.reset();
|
|
18
|
-
assert.equal(metrics.snapshot().counters.writes, undefined);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('metrics ignore non-finite observations', () => {
|
|
22
|
-
const metrics = createMetrics();
|
|
23
|
-
metrics.observe('x', NaN);
|
|
24
|
-
metrics.observe('x', 'bad');
|
|
25
|
-
assert.equal(metrics.snapshot().histograms.x?.count ?? 0, 0);
|
|
26
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
7
|
-
import { migrate } from '../../src/store/database.js';
|
|
8
|
-
|
|
9
|
-
test('migration adds facts.superseded_at and backfills invalidated rows', () => {
|
|
10
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-migrate-'));
|
|
11
|
-
const file = path.join(dir, 'legacy.sqlite');
|
|
12
|
-
const db = new DatabaseSync(file);
|
|
13
|
-
try {
|
|
14
|
-
db.exec(`
|
|
15
|
-
CREATE TABLE meta (key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_at TEXT NOT NULL);
|
|
16
|
-
CREATE TABLE facts (
|
|
17
|
-
id TEXT PRIMARY KEY, scope_id TEXT NOT NULL, subject_id TEXT NOT NULL,
|
|
18
|
-
predicate TEXT NOT NULL, object_id TEXT, object_literal TEXT,
|
|
19
|
-
valid_from TEXT, valid_to TEXT, recorded_at TEXT NOT NULL,
|
|
20
|
-
confidence REAL NOT NULL DEFAULT 0.7, status TEXT NOT NULL DEFAULT 'active',
|
|
21
|
-
source_event_id TEXT, invalidated_by TEXT, evidence_json TEXT NOT NULL DEFAULT '[]',
|
|
22
|
-
hash TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL
|
|
23
|
-
);
|
|
24
|
-
INSERT INTO meta VALUES ('schema_version', '5', '2026-11-01T00:00:00Z');
|
|
25
|
-
INSERT INTO facts VALUES ('f_old','global','e1','喜欢',NULL,'米饭','2026-01-01','2026-02-01','2026-01-02',0.7,'invalidated',NULL,'f_new','[]','h','2026-01-02','2026-02-01');
|
|
26
|
-
`);
|
|
27
|
-
migrate(db);
|
|
28
|
-
const columns = db.prepare('PRAGMA table_info(facts)').all().map((column) => column.name);
|
|
29
|
-
assert.ok(columns.includes('superseded_at'));
|
|
30
|
-
const row = db.prepare('SELECT superseded_at FROM facts WHERE id = ?').get('f_old');
|
|
31
|
-
assert.equal(row.superseded_at, '2026-02-01');
|
|
32
|
-
const version = db.prepare('SELECT value FROM meta WHERE key = ?').get('schema_version');
|
|
33
|
-
assert.equal(version.value, '7');
|
|
34
|
-
} finally {
|
|
35
|
-
db.close();
|
|
36
|
-
rmSync(dir, { recursive: true, force: true });
|
|
37
|
-
}
|
|
38
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { readModelConfig, saveModelConfig, redactedModelConfig } from '../../src/core/model-config.js';
|
|
7
|
-
|
|
8
|
-
test('model config applies local preset and redacts keys', () => {
|
|
9
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-model-config-'));
|
|
10
|
-
try {
|
|
11
|
-
const saved = saveModelConfig(dir, {
|
|
12
|
-
embedding: { mode: 'local', apiKey: 'secret' },
|
|
13
|
-
rerank: { enabled: true, baseUrl: 'http://127.0.0.1:9000/v1', model: 'r', apiKey: 'rerank-secret' },
|
|
14
|
-
}, { confirm: true });
|
|
15
|
-
assert.equal(saved.config.embedding.mode, 'local');
|
|
16
|
-
assert.equal(saved.config.embedding.baseUrl, 'http://127.0.0.1:11434/v1');
|
|
17
|
-
assert.equal(saved.config.embedding.model, 'bge-m3');
|
|
18
|
-
assert.equal(saved.config.embedding.dim, 1024);
|
|
19
|
-
assert.equal(saved.config.embedding.apiKeySet, true);
|
|
20
|
-
assert.equal(saved.config.rerank.apiKeySet, true);
|
|
21
|
-
assert.equal(readModelConfig(dir).embedding.apiKey, 'secret');
|
|
22
|
-
assert.doesNotMatch(JSON.stringify(saved.config), /secret/);
|
|
23
|
-
} finally {
|
|
24
|
-
rmSync(dir, { recursive: true, force: true });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('model config tolerates a UTF-8 BOM from Windows PowerShell', () => {
|
|
29
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-model-config-bom-'));
|
|
30
|
-
try {
|
|
31
|
-
writeFileSync(path.join(dir, 'model-config.json'), '\uFEFF{"embedding":{"mode":"local","baseUrl":"http://127.0.0.1:11434/v1","model":"bge-m3","dim":1024}}', 'utf8');
|
|
32
|
-
const config = readModelConfig(dir);
|
|
33
|
-
assert.equal(config.embedding.mode, 'local');
|
|
34
|
-
assert.equal(config.embedding.model, 'bge-m3');
|
|
35
|
-
assert.equal(config.embedding.dim, 1024);
|
|
36
|
-
} finally {
|
|
37
|
-
rmSync(dir, { recursive: true, force: true });
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('model config rejects missing remote fields and no confirmation', () => {
|
|
42
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-model-config-bad-'));
|
|
43
|
-
try {
|
|
44
|
-
assert.throws(() => saveModelConfig(dir, { rerank: { enabled: true, baseUrl: '', model: '' } }, { confirm: true }), /rerank needs/);
|
|
45
|
-
assert.throws(() => saveModelConfig(dir, { embedding: { mode: 'remote', baseUrl: 'https://api.example/v1', model: 'm' } }, { confirm: true }), /needs apiKey/);
|
|
46
|
-
assert.throws(() => saveModelConfig(dir, { embedding: { mode: 'hash' } }, {}), /confirm/);
|
|
47
|
-
writeFileSync(path.join(dir, 'model-config.json'), '{broken', 'utf8');
|
|
48
|
-
assert.equal(readModelConfig(dir).embedding.mode, 'hash');
|
|
49
|
-
} finally {
|
|
50
|
-
rmSync(dir, { recursive: true, force: true });
|
|
51
|
-
}
|
|
52
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { applyMood } from '../../src/self/state.js';
|
|
4
|
-
|
|
5
|
-
const base = { valence: 0, arousal: 0.2, energy: 0.6 };
|
|
6
|
-
|
|
7
|
-
test('越接近边界,同样的好事推动越小(饱和)', () => {
|
|
8
|
-
const fromNeutral = applyMood({ ...base, valence: 0 }, { valence: 0.8, salience: 0.6 });
|
|
9
|
-
const fromHigh = applyMood({ ...base, valence: 0.9 }, { valence: 0.8, salience: 0.6 });
|
|
10
|
-
const deltaNeutral = fromNeutral.valence - 0;
|
|
11
|
-
const deltaHigh = fromHigh.valence - 0.9;
|
|
12
|
-
assert.ok(deltaHigh < deltaNeutral, `高处应更小:${deltaHigh} < ${deltaNeutral}`);
|
|
13
|
-
assert.ok(deltaHigh > 0, '仍然要往好的方向走');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('反复叠加只会逼近上限,不会一次顶死', () => {
|
|
17
|
-
let mood = { ...base };
|
|
18
|
-
for (let i = 0; i < 3; i += 1) mood = applyMood(mood, { valence: 1, salience: 1, weight: 0.5 });
|
|
19
|
-
assert.ok(mood.valence < 0.99, `不应该顶到 1.0:${mood.valence}`);
|
|
20
|
-
assert.ok(mood.valence > 0.9, `但也该足够高:${mood.valence}`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('负向事件同样饱和,一次不该按到底', () => {
|
|
24
|
-
const mood = applyMood({ ...base, valence: -0.9 }, { valence: -1, salience: 0.9 });
|
|
25
|
-
assert.ok(mood.valence > -1, `一次事件不该把它按到底:${mood.valence}`);
|
|
26
|
-
assert.ok(mood.valence < -0.9, '但确实更低了');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('唤醒度用同样的饱和规则,且不越出 0..1', () => {
|
|
30
|
-
const high = applyMood({ ...base, arousal: 0.95 }, { arousal: 1, salience: 1 });
|
|
31
|
-
assert.ok(high.arousal <= 1);
|
|
32
|
-
assert.ok(high.arousal > 0.95);
|
|
33
|
-
});
|