dsh-cortex-memory 0.4.146 → 0.4.147
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 +2396 -2369
- package/README.md +8 -6
- package/bench/semantic-cn.js +4 -4
- package/bench/synthetic.js +2 -2
- package/bin/copy-db.mjs +1 -1
- package/client.js +1 -1
- package/docs/quota-compaction-design.md +2 -2
- package/icon.svg +12 -2
- package/package.json +1 -1
- package/src/engines/consolidate.js +2 -2
- package/src/engines/health.js +1 -1
- package/src/engines/life.js +2 -2
- package/src/engines/narrative.js +2 -2
- package/src/host/scheduler.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,51 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { rankSummonCards } from '../../src/engines/summon-rank.js';
|
|
4
|
-
|
|
5
|
-
function card(id, side, day, extra = {}) {
|
|
6
|
-
return {
|
|
7
|
-
id,
|
|
8
|
-
side,
|
|
9
|
-
day,
|
|
10
|
-
category: 'decision',
|
|
11
|
-
title: `关于 ${id} 的决定`,
|
|
12
|
-
content: `内容 ${id}`,
|
|
13
|
-
triggers: ['向量回填', id],
|
|
14
|
-
importance: 0.8,
|
|
15
|
-
...extra,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
test('槽位满时补齐左卡:挤掉最弱的一项,而不是把自己裁掉', () => {
|
|
20
|
-
const cards = [
|
|
21
|
-
card('r1', 'right', '2026-11-15'),
|
|
22
|
-
card('r2', 'right', '2026-11-14'),
|
|
23
|
-
card('l1', 'left', '2026-11-15'),
|
|
24
|
-
];
|
|
25
|
-
const dropped = [];
|
|
26
|
-
const picked = rankSummonCards(cards, {
|
|
27
|
-
query: '向量回填 这件事怎么处理',
|
|
28
|
-
maxCards: 2,
|
|
29
|
-
onDrop: (entry) => dropped.push(entry.card.id),
|
|
30
|
-
});
|
|
31
|
-
assert.equal(picked.length, 2, '名额不能超');
|
|
32
|
-
assert.ok(picked.some((entry) => entry.card.side === 'left'), '左卡必须出现在结果里');
|
|
33
|
-
assert.equal(dropped.length, 1, '挤掉的卡要回报,不能悄悄消失');
|
|
34
|
-
assert.equal(dropped[0], 'r1', '应挤掉与左卡同一天、分数较低的那张,保住跨天多样性');
|
|
35
|
-
assert.ok(!picked.some((entry) => entry.card.id === dropped[0]), '被挤掉的卡不该同时在结果里');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('槽位没满时左卡直接补位,不触发丢弃', () => {
|
|
39
|
-
const cards = [
|
|
40
|
-
card('r1', 'right', '2026-11-15'),
|
|
41
|
-
card('l1', 'left', '2026-11-14'),
|
|
42
|
-
];
|
|
43
|
-
const dropped = [];
|
|
44
|
-
const picked = rankSummonCards(cards, {
|
|
45
|
-
query: '向量回填 这件事怎么处理',
|
|
46
|
-
maxCards: 3,
|
|
47
|
-
onDrop: (entry) => dropped.push(entry.card.id),
|
|
48
|
-
});
|
|
49
|
-
assert.equal(picked.length, 2);
|
|
50
|
-
assert.equal(dropped.length, 0);
|
|
51
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { rankSummonCards, renderSummonLines } from '../../src/engines/summon-rank.js';
|
|
4
|
-
|
|
5
|
-
const now = Date.parse('2026-11-15T12:00:00Z');
|
|
6
|
-
|
|
7
|
-
function card(overrides) {
|
|
8
|
-
return {
|
|
9
|
-
id: 'c1', side: 'right', category: 'work', title: '打包 cortex', content: '打包并验证',
|
|
10
|
-
triggers: ['打包'], importance: 0.6, day: '2026-11-15',
|
|
11
|
-
...overrides,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
test('新的那天优先,旧的同类被压下去', () => {
|
|
16
|
-
const cards = [
|
|
17
|
-
card({ id: 'old', day: '2026-11-01', triggers: ['打包'], category: 'work' }),
|
|
18
|
-
card({ id: 'new', day: '2026-11-15', triggers: ['打包'], category: 'work' }),
|
|
19
|
-
];
|
|
20
|
-
const ranked = rankSummonCards(cards, { query: '今天想打包一版', now, maxCards: 1 });
|
|
21
|
-
assert.equal(ranked[0].card.id, 'new');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('同一天只取一张,避免一整屏都是同一天', () => {
|
|
25
|
-
const cards = [
|
|
26
|
-
card({ id: 'a', day: '2026-11-15', triggers: ['打包'], category: 'work' }),
|
|
27
|
-
card({ id: 'b', day: '2026-11-15', triggers: ['打包'], category: 'emotion', side: 'left' }),
|
|
28
|
-
card({ id: 'c', day: '2026-11-14', triggers: ['打包'], category: 'work' }),
|
|
29
|
-
];
|
|
30
|
-
const ranked = rankSummonCards(cards, { query: '打包', now, maxCards: 2 });
|
|
31
|
-
const days = new Set(ranked.map((entry) => entry.card.day));
|
|
32
|
-
assert.equal(ranked.length, 2);
|
|
33
|
-
assert.equal(days.size, 2, '两张卡应该来自不同天');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('同类只取一张,左侧情感卡仍会被补进来', () => {
|
|
37
|
-
const cards = [
|
|
38
|
-
card({ id: 'w1', day: '2026-11-15', category: 'work', triggers: ['打包'] }),
|
|
39
|
-
card({ id: 'w2', day: '2026-11-14', category: 'work', triggers: ['打包'] }),
|
|
40
|
-
card({ id: 'e1', day: '2026-11-13', category: 'emotion', side: 'left', triggers: ['打包'] }),
|
|
41
|
-
];
|
|
42
|
-
const ranked = rankSummonCards(cards, { query: '打包', now, maxCards: 2 });
|
|
43
|
-
assert.equal(ranked.length, 2);
|
|
44
|
-
assert.ok(ranked.some((entry) => entry.card.side === 'left'), '应该有一张左侧情感卡');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('不匹配查询的卡片不出现', () => {
|
|
48
|
-
const ranked = rankSummonCards([card({ triggers: ['米饭'] })], { query: '打包', now });
|
|
49
|
-
assert.equal(ranked.length, 0);
|
|
50
|
-
assert.equal(renderSummonLines(ranked).lines.length, 1);
|
|
51
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { parseTemporal, withinWindow, parseDuration, formatRelative } from '../../src/memory/temporal.js';
|
|
4
|
-
import { degreeCentrality, pageRank, connectedComponents, labelPropagation, summarizeGraph } from '../../src/engines/graph-analytics.js';
|
|
5
|
-
|
|
6
|
-
const NOW = Date.parse('2026-11-11T12:00:00+08:00');
|
|
7
|
-
|
|
8
|
-
test('temporal parser understands relative and absolute windows', () => {
|
|
9
|
-
assert.equal(parseTemporal('今天做了什么', NOW).label, 'today');
|
|
10
|
-
assert.equal(parseTemporal('昨天', NOW).label, 'yesterday');
|
|
11
|
-
assert.equal(parseTemporal('3天前', NOW).label, '3-days-ago');
|
|
12
|
-
assert.equal(parseTemporal('2026-11-05', NOW).label, 'date');
|
|
13
|
-
assert.equal(parseTemporal('没有时间词', NOW), null);
|
|
14
|
-
const window = parseTemporal('今天', NOW);
|
|
15
|
-
assert.equal(withinWindow(new Date(NOW).toISOString(), window), true);
|
|
16
|
-
assert.equal(withinWindow(new Date(NOW - 3 * 86400000).toISOString(), window), false);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('duration and relative formatting work', () => {
|
|
20
|
-
assert.equal(parseDuration('2h'), 7_200_000);
|
|
21
|
-
assert.equal(parseDuration('bad', 42), 42);
|
|
22
|
-
assert.match(formatRelative(new Date(NOW - 5000).toISOString(), NOW), /刚刚/);
|
|
23
|
-
assert.match(formatRelative(new Date(NOW - 2 * 3600000).toISOString(), NOW), /小时前/);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('graph analytics ranks, groups and summarizes', () => {
|
|
27
|
-
const edges = [
|
|
28
|
-
{ fromId: 'a', toId: 'b', weight: 2 },
|
|
29
|
-
{ fromId: 'b', toId: 'c', weight: 1 },
|
|
30
|
-
{ fromId: 'd', toId: 'e', weight: 1 },
|
|
31
|
-
];
|
|
32
|
-
const degree = degreeCentrality(edges);
|
|
33
|
-
assert.ok(degree.b >= degree.a);
|
|
34
|
-
const rank = pageRank(edges);
|
|
35
|
-
assert.ok(rank.b > 0);
|
|
36
|
-
const components = connectedComponents(edges);
|
|
37
|
-
assert.equal(components.length, 2);
|
|
38
|
-
const communities = labelPropagation(edges);
|
|
39
|
-
assert.equal(communities.length, 2);
|
|
40
|
-
const summary = summarizeGraph(edges);
|
|
41
|
-
assert.equal(summary.nodes, 5);
|
|
42
|
-
assert.equal(summary.edges, 3);
|
|
43
|
-
assert.ok(summary.top.length > 0);
|
|
44
|
-
});
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { selectTiers, renderTiers } from '../../src/prompt/tiers.js';
|
|
4
|
-
|
|
5
|
-
function item(overrides = {}) {
|
|
6
|
-
return {
|
|
7
|
-
id: 'trc_1',
|
|
8
|
-
layer: 'L2',
|
|
9
|
-
title: 'cortex 0.4.20 打包完成',
|
|
10
|
-
snippet: '这是一段很长的工程细节,讲述了打包、测试、验证的每一步过程,后面还有很多很多字。第二句继续补充。',
|
|
11
|
-
importance: 0.9,
|
|
12
|
-
utility: 0.9,
|
|
13
|
-
...overrides,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
test('高重要度记忆注入时只给一句 gist,并带省略号', () => {
|
|
18
|
-
const selection = selectTiers([item()], { gistChars: 24 });
|
|
19
|
-
const line = selection.perm[0].render;
|
|
20
|
-
assert.match(line, /打包完成/);
|
|
21
|
-
assert.ok(line.endsWith('…') || line.includes('…'), line);
|
|
22
|
-
assert.ok(line.length < 120, 'gist 应该比原 snippet 短得多');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('短片段原样保留,不加省略号', () => {
|
|
26
|
-
const selection = selectTiers([item({ snippet: '用户说会买米饭' })], { gistChars: 120 });
|
|
27
|
-
const line = selection.perm[0].render;
|
|
28
|
-
assert.match(line, /用户说会买米饭/);
|
|
29
|
-
assert.doesNotMatch(line, /…/);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('标题已经包含在正文开头时,不再重复一遍', () => {
|
|
33
|
-
const title = '2026-11-15 17:35:0.4.60 打包,修 GLOB 陷阱';
|
|
34
|
-
const snippet = `${title}。先备份再改,测试跑两遍。第三句。`;
|
|
35
|
-
const selection = selectTiers([item({ title, snippet })], { gistChars: 120 });
|
|
36
|
-
const line = selection.perm[0].render;
|
|
37
|
-
const occurrences = (line.match(/0\.4\.60 打包/g) ?? []).length;
|
|
38
|
-
assert.equal(occurrences, 1, `标题不该在冒号后再出现一次:${line}`);
|
|
39
|
-
assert.match(line, /先备份再改/);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('正文与标题完全相等时,不留悬空的冒号', () => {
|
|
43
|
-
const title = '正文和标题一模一样的一句话';
|
|
44
|
-
const selection = selectTiers([item({ title, snippet: title })], { gistChars: 120 });
|
|
45
|
-
const line = selection.perm[0].render;
|
|
46
|
-
assert.doesNotMatch(line, /:\s*$/, `不该以冒号结尾:${line}`);
|
|
47
|
-
assert.match(line, /一模一样/);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('cold 层给出「为什么可能值得取回」而不只是目录', () => {
|
|
51
|
-
const selection = selectTiers([item({ importance: 0.2, sources: [{ name: 'recent', rank: 1 }] })]);
|
|
52
|
-
assert.equal(selection.cold.length, 1);
|
|
53
|
-
assert.match(selection.cold[0].render, /命中 recent/);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('低重要度 + 语义命中 → 冷层,且理由写「语义相近」', () => {
|
|
57
|
-
const selection = selectTiers([item({ importance: 0.2, sources: [{ name: 'vector', rank: 1 }] })]);
|
|
58
|
-
assert.equal(selection.cold.length, 1, '低重要度不该占 hot 预算');
|
|
59
|
-
assert.match(selection.cold[0].render, /语义相近/);
|
|
60
|
-
assert.equal(selection.hot.length, 0);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('中等重要度的语义命中仍进热层', () => {
|
|
64
|
-
const selection = selectTiers([item({ importance: 0.55, sources: [{ name: 'vector', rank: 1 }] })]);
|
|
65
|
-
assert.equal(selection.hot.length, 1);
|
|
66
|
-
assert.equal(selection.cold.length, 0);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('真实数据里没有 <0.4 时,仍按相对分位切出冷层', () => {
|
|
70
|
-
// 线上 importance 全在 0.6–1.0:绝对阈值永远够不着,靠排名后 25% 兜底。
|
|
71
|
-
const items = Array.from({ length: 8 }, (_, index) => item({
|
|
72
|
-
id: `r${index}`,
|
|
73
|
-
importance: 0.6,
|
|
74
|
-
utility: 1 - index / 100,
|
|
75
|
-
sources: [{ name: 'fts', rank: index }],
|
|
76
|
-
}));
|
|
77
|
-
const selection = selectTiers(items, { budgets: { perm: 0, hot: 2000, cold: 2000 } });
|
|
78
|
-
assert.equal(selection.cold.length, 2, '8 条里后 25% = 2 条进冷层');
|
|
79
|
-
assert.equal(selection.hot.length, 6);
|
|
80
|
-
assert.match(selection.cold[0].render, /字面命中/);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('候选太少时不做相对切分,避免把仅有的几条都塞进冷层', () => {
|
|
84
|
-
const items = Array.from({ length: 3 }, (_, index) => item({ id: `s${index}`, importance: 0.6, utility: 1 - index / 10 }));
|
|
85
|
-
const selection = selectTiers(items, { budgets: { perm: 0, hot: 2000, cold: 2000 } });
|
|
86
|
-
assert.equal(selection.cold.length, 0);
|
|
87
|
-
assert.equal(selection.hot.length, 3);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('冷层条数按「后 25%」取整,不因 ceil 切少', () => {
|
|
91
|
-
const cases = [[4, 1], [5, 2], [6, 2], [7, 2], [8, 2], [10, 3], [20, 5]];
|
|
92
|
-
for (const [total, expected] of cases) {
|
|
93
|
-
const items = Array.from({ length: total }, (_, index) => item({ id: `n${index}`, importance: 0.6, utility: 1 - index / 100 }));
|
|
94
|
-
const selection = selectTiers(items, { budgets: { perm: 0, hot: 5000, cold: 5000 } });
|
|
95
|
-
assert.equal(selection.cold.length, expected, `${total} 条应有 ${expected} 条进冷层`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('utility 相同时按 importance、id 稳定排序', () => {
|
|
100
|
-
const items = [
|
|
101
|
-
item({ id: 'b', importance: 0.7, utility: 1 }),
|
|
102
|
-
item({ id: 'a', importance: 0.7, utility: 1 }),
|
|
103
|
-
item({ id: 'c', importance: 0.9, utility: 1 }),
|
|
104
|
-
];
|
|
105
|
-
const first = selectTiers(items, { budgets: { perm: 500, hot: 5000, cold: 5000 } });
|
|
106
|
-
const second = selectTiers([...items].reverse(), { budgets: { perm: 500, hot: 5000, cold: 5000 } });
|
|
107
|
-
assert.deepEqual(first.selected, second.selected, '同一批候选两轮顺序应一致');
|
|
108
|
-
assert.equal(first.selected[0], 'c', 'importance 高者在前');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('永久层堆满时,冷层不会吃掉加强层', () => {
|
|
112
|
-
// 豆包的场景:8 条候选里 6 条 importance ≥0.8,若按全体 8 条算 25%,会把仅剩的 2 条 hot 全推去 cold。
|
|
113
|
-
const items = [
|
|
114
|
-
...Array.from({ length: 6 }, (_, index) => item({ id: `p${index}`, importance: 0.9, utility: 1 - index / 1000 })),
|
|
115
|
-
...Array.from({ length: 2 }, (_, index) => item({ id: `h${index}`, importance: 0.6, utility: 0.5 - index / 1000 })),
|
|
116
|
-
];
|
|
117
|
-
const selection = selectTiers(items, { budgets: { perm: 5000, hot: 5000, cold: 5000 } });
|
|
118
|
-
assert.equal(selection.perm.length, 6);
|
|
119
|
-
assert.equal(selection.cold.length, 0, '非 perm 只有 2 条,不做相对切分');
|
|
120
|
-
assert.equal(selection.hot.length, 2);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('非 perm 候选足够多时,冷层按非 perm 条数切分', () => {
|
|
124
|
-
const items = [
|
|
125
|
-
...Array.from({ length: 2 }, (_, index) => item({ id: `p${index}`, importance: 0.9, utility: 1 - index / 1000 })),
|
|
126
|
-
...Array.from({ length: 6 }, (_, index) => item({ id: `h${index}`, importance: 0.6, utility: 0.5 - index / 1000 })),
|
|
127
|
-
];
|
|
128
|
-
const selection = selectTiers(items, { budgets: { perm: 5000, hot: 5000, cold: 5000 } });
|
|
129
|
-
assert.equal(selection.perm.length, 2);
|
|
130
|
-
assert.equal(selection.cold.length, 2, '6 条非 perm 的 25% = 2');
|
|
131
|
-
assert.equal(selection.hot.length, 4);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('cold 层仍是索引行,不带正文', () => {
|
|
135
|
-
const selection = selectTiers([item({ importance: 0.2 })]);
|
|
136
|
-
assert.equal(selection.cold.length, 1);
|
|
137
|
-
assert.match(selection.cold[0].render, /正文按需 cortex_get/);
|
|
138
|
-
const rendered = renderTiers(selection);
|
|
139
|
-
assert.match(rendered, /卸载层/);
|
|
140
|
-
});
|
package/test/unit/tiers.test.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { selectTiers, renderTiers, DEFAULT_TIER_BUDGETS } from '../../src/prompt/tiers.js';
|
|
4
|
-
|
|
5
|
-
function item(id, importance, body = '这是一段正文。') {
|
|
6
|
-
return { id, importance, title: id, layer: 'L2', snippet: body, utility: importance };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
test('tiers classify by importance and respect per-tier budgets', () => {
|
|
10
|
-
const items = [
|
|
11
|
-
item('p1', 0.95, '永久正文'),
|
|
12
|
-
item('h1', 0.55, '加强正文'),
|
|
13
|
-
item('c1', 0.1, '冷正文'),
|
|
14
|
-
];
|
|
15
|
-
const selection = selectTiers(items, { budgets: { perm: 50, hot: 50, cold: 50 } });
|
|
16
|
-
assert.equal(selection.perm.length, 1);
|
|
17
|
-
assert.equal(selection.hot.length, 1);
|
|
18
|
-
assert.equal(selection.cold.length, 1);
|
|
19
|
-
assert.match(selection.cold[0].render, /正文按需 cortex_get/);
|
|
20
|
-
assert.doesNotMatch(selection.cold[0].render, /冷正文/);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('tiers emit an omitted count and never overflow a bucket', () => {
|
|
24
|
-
const items = Array.from({ length: 20 }, (_, index) => item(`h${index}`, 0.5, '很长的一段正文'.repeat(20)));
|
|
25
|
-
const selection = selectTiers(items, { budgets: { perm: 20, hot: 200, cold: 20 } });
|
|
26
|
-
assert.ok(selection.omitted > 0);
|
|
27
|
-
assert.ok(selection.used.hot <= 200);
|
|
28
|
-
const text = renderTiers(selection);
|
|
29
|
-
assert.match(text, /加强层/);
|
|
30
|
-
assert.match(text, /预算省略/);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('tiers render only non-empty sections and expose defaults', () => {
|
|
34
|
-
assert.deepEqual(DEFAULT_TIER_BUDGETS, { perm: 700, hot: 900, cold: 400 });
|
|
35
|
-
const selection = selectTiers([item('p1', 0.9, '正文')]);
|
|
36
|
-
const text = renderTiers(selection);
|
|
37
|
-
assert.match(text, /永久层/);
|
|
38
|
-
assert.doesNotMatch(text, /卸载层/);
|
|
39
|
-
});
|
|
@@ -1,35 +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 { ftsText, buildMatchQuery } from '../../src/memory/tokenizer.js';
|
|
7
|
-
import { createCortex } from '../../src/service/cortex.js';
|
|
8
|
-
|
|
9
|
-
test('CJK soft FTS keeps bigrams and adds non-stop single characters', () => {
|
|
10
|
-
const exact = ftsText('米饭 记忆引擎');
|
|
11
|
-
assert.equal(exact, '米饭 记忆 忆引 引擎 记忆引擎');
|
|
12
|
-
const indexed = ftsText('米饭 记忆引擎', { soft: true });
|
|
13
|
-
assert.ok(indexed.includes('米饭'));
|
|
14
|
-
assert.ok(indexed.includes('饭'));
|
|
15
|
-
assert.ok(indexed.includes('记忆引擎'));
|
|
16
|
-
assert.ok(indexed.includes('记'));
|
|
17
|
-
const query = buildMatchQuery('米饭', { soft: true });
|
|
18
|
-
assert.ok(query.includes('米饭'));
|
|
19
|
-
assert.ok(query.includes('米'));
|
|
20
|
-
assert.ok(query.includes('饭'));
|
|
21
|
-
assert.equal(buildMatchQuery('米饭'), '"米饭"');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('a shared-character paraphrase can fall back to FTS', () => {
|
|
25
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-char-fts-'));
|
|
26
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
27
|
-
try {
|
|
28
|
-
cortex.write({ text: '米饭', explicit: true });
|
|
29
|
-
const result = cortex.search('米饭', { limit: 10 });
|
|
30
|
-
assert.ok(result.items.some((item) => item.snippet?.includes('米饭')));
|
|
31
|
-
} finally {
|
|
32
|
-
cortex.close();
|
|
33
|
-
rmSync(dir, { recursive: true, force: true });
|
|
34
|
-
}
|
|
35
|
-
});
|
package/test/unit/tools.test.js
DELETED
|
@@ -1,122 +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
|
-
import { createToolDefinitions } from '../../src/tools/definitions.js';
|
|
8
|
-
|
|
9
|
-
function setup() {
|
|
10
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-tools-'));
|
|
11
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), scope: 'global' } });
|
|
12
|
-
const tools = Object.fromEntries(createToolDefinitions(cortex).map((tool) => [tool.name, tool]));
|
|
13
|
-
return { dir, cortex, tools };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
test('all tools are present and have text output', () => {
|
|
17
|
-
const { dir, cortex, tools } = setup();
|
|
18
|
-
try {
|
|
19
|
-
const names = Object.keys(tools).sort();
|
|
20
|
-
assert.deepEqual(names, [
|
|
21
|
-
'cortex_as_of', 'cortex_compress', 'cortex_consolidate', 'cortex_digest', 'cortex_emotion', 'cortex_evolve', 'cortex_feedback', 'cortex_forget', 'cortex_get', 'cortex_goal', 'cortex_guard', 'cortex_health', 'cortex_inhibition',
|
|
22
|
-
'cortex_life', 'cortex_playbook', 'cortex_reflect', 'cortex_search', 'cortex_self', 'cortex_tick', 'cortex_timeline', 'cortex_working', 'cortex_write',
|
|
23
|
-
]);
|
|
24
|
-
for (const tool of Object.values(tools)) {
|
|
25
|
-
assert.equal(tool.output.schema.required[0], 'text');
|
|
26
|
-
}
|
|
27
|
-
} finally {
|
|
28
|
-
cortex.close();
|
|
29
|
-
rmSync(dir, { recursive: true, force: true });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('tools reject by-id writes into a read-only shared scope', async () => {
|
|
34
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-tools-readonly-'));
|
|
35
|
-
const seed = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite') } });
|
|
36
|
-
const sharedWorking = seed.working.add({ scopeId: 'shared', text: '共享工作项' });
|
|
37
|
-
const sharedGoal = seed.goals.add({ scopeId: 'shared', title: '共享目标' });
|
|
38
|
-
const sharedRule = seed.playbook.add({ scopeId: 'shared', title: '共享准则', body: '只在共享 scope 生效的准则内容。' });
|
|
39
|
-
const sharedTrace = seed.write({ scopeId: 'shared', text: '共享 scope 的记忆不应被外部删除。', explicit: true });
|
|
40
|
-
seed.close();
|
|
41
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), readOnlyScopes: ['shared'] } });
|
|
42
|
-
const tools = Object.fromEntries(createToolDefinitions(cortex).map((tool) => [tool.name, tool]));
|
|
43
|
-
try {
|
|
44
|
-
const working = await tools.cortex_working.execute({ action: 'pin', id: sharedWorking.id, pinned: true });
|
|
45
|
-
assert.match(working.text, /只读共享/);
|
|
46
|
-
const goal = await tools.cortex_goal.execute({ action: 'complete', id: sharedGoal.id });
|
|
47
|
-
assert.match(goal.text, /只读共享/);
|
|
48
|
-
const rule = await tools.cortex_playbook.execute({ action: 'retire', id: sharedRule.id });
|
|
49
|
-
assert.match(rule.text, /只读共享/);
|
|
50
|
-
const forget = await tools.cortex_forget.execute({ id: sharedTrace.trace.id, mode: 'archive' });
|
|
51
|
-
assert.match(forget.text, /只读共享/);
|
|
52
|
-
} finally {
|
|
53
|
-
cortex.close();
|
|
54
|
-
rmSync(dir, { recursive: true, force: true });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('tools reject life and emotion writes when the default scope is read-only', async () => {
|
|
59
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-tools-readonly-default-'));
|
|
60
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), readOnlyScopes: ['global'] } });
|
|
61
|
-
const tools = Object.fromEntries(createToolDefinitions(cortex).map((tool) => [tool.name, tool]));
|
|
62
|
-
try {
|
|
63
|
-
const diary = await tools.cortex_life.execute({ action: 'diary-write', text: '不该写进去的日记' });
|
|
64
|
-
assert.match(diary.text, /只读共享/);
|
|
65
|
-
const emotion = await tools.cortex_emotion.execute({ action: 'record', text: '用户有点担心', target: '用户' });
|
|
66
|
-
assert.match(emotion.text, /只读共享/);
|
|
67
|
-
const compress = await tools.cortex_compress.execute({ action: 'compress', limit: 1 });
|
|
68
|
-
assert.match(compress.text, /只读共享/);
|
|
69
|
-
const sync = await tools.cortex_guard.execute({ action: 'sync', dir: path.join(dir, 'vault') });
|
|
70
|
-
assert.match(sync.text, /只读共享/);
|
|
71
|
-
} finally {
|
|
72
|
-
cortex.close();
|
|
73
|
-
rmSync(dir, { recursive: true, force: true });
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('write/search/get/self/health return readable text', async () => {
|
|
78
|
-
const { dir, cortex, tools } = setup();
|
|
79
|
-
try {
|
|
80
|
-
const write = await tools.cortex_write.execute({
|
|
81
|
-
text: '用户说会买米饭,助手会一直等。',
|
|
82
|
-
explicit: true,
|
|
83
|
-
facts: [{ subject: '用户', predicate: 'likes', object: '米饭' }],
|
|
84
|
-
});
|
|
85
|
-
assert.match(write.text, /已写入/);
|
|
86
|
-
const id = write.text.match(/trc_[a-z0-9]+/)?.[0];
|
|
87
|
-
assert.ok(id);
|
|
88
|
-
const search = await tools.cortex_search.execute({ query: '米饭' });
|
|
89
|
-
assert.match(search.text, /意图/);
|
|
90
|
-
const get = await tools.cortex_get.execute({ id });
|
|
91
|
-
assert.match(get.text, /米饭/);
|
|
92
|
-
const self = await tools.cortex_self.execute({});
|
|
93
|
-
assert.match(self.text, /驱力/);
|
|
94
|
-
const health = await tools.cortex_health.execute({});
|
|
95
|
-
assert.match(health.text, /健康分/);
|
|
96
|
-
const guard = await tools.cortex_guard.execute({ action: 'check' });
|
|
97
|
-
assert.match(guard.text, /自检/);
|
|
98
|
-
const timeline = await tools.cortex_timeline.execute({ aroundId: id });
|
|
99
|
-
assert.match(timeline.text, /锚点/);
|
|
100
|
-
} finally {
|
|
101
|
-
cortex.close();
|
|
102
|
-
rmSync(dir, { recursive: true, force: true });
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('feedback/forget/reflect tool actions are callable', async () => {
|
|
107
|
-
const { dir, cortex, tools } = setup();
|
|
108
|
-
try {
|
|
109
|
-
const write = await tools.cortex_write.execute({ text: '第一条测试。', explicit: true });
|
|
110
|
-
const id = write.text.match(/trc_[a-z0-9]+/)?.[0];
|
|
111
|
-
const feedback = await tools.cortex_feedback.execute({ id, signal: 'helpful', predicted: 0.8 });
|
|
112
|
-
assert.match(feedback.text, /反馈已记/);
|
|
113
|
-
await tools.cortex_write.execute({ text: '第二条测试。', explicit: true });
|
|
114
|
-
const reflect = await tools.cortex_reflect.execute({ windowDays: 1, force: true });
|
|
115
|
-
assert.match(reflect.text, /来源/);
|
|
116
|
-
const forget = await tools.cortex_forget.execute({ id, mode: 'archive' });
|
|
117
|
-
assert.match(forget.text, /已归档/);
|
|
118
|
-
} finally {
|
|
119
|
-
cortex.close();
|
|
120
|
-
rmSync(dir, { recursive: true, force: true });
|
|
121
|
-
}
|
|
122
|
-
});
|
|
@@ -1,104 +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
|
-
import { createHostRuntime } from '../../src/host/runtime.js';
|
|
8
|
-
|
|
9
|
-
function setup(extra = {}) {
|
|
10
|
-
const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-0412-'));
|
|
11
|
-
const cortex = createCortex({ config: { dataRoot: dir, dbFile: path.join(dir, 'cortex.sqlite'), ...extra } });
|
|
12
|
-
return { dir, cortex };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function teardown({ dir, cortex }) {
|
|
16
|
-
cortex.close();
|
|
17
|
-
rmSync(dir, { recursive: true, force: true });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
test('search keeps full memory while prompt injection gates weak matches', () => {
|
|
21
|
-
const ctx = setup();
|
|
22
|
-
try {
|
|
23
|
-
ctx.cortex.write({ text: '用户说会买米饭,这是一条承诺。', title: '米饭承诺', importance: 0.5, explicit: true });
|
|
24
|
-
ctx.cortex.write({ text: '今天颈椎有点疼,和吃饭无关。', title: '颈椎', importance: 0.5, explicit: true });
|
|
25
|
-
ctx.cortex.write({ text: '插件更新了一条无关的日志。', title: '日志', importance: 0.5, explicit: true });
|
|
26
|
-
|
|
27
|
-
const full = ctx.cortex.search('米饭 承诺', { limit: 5 });
|
|
28
|
-
assert.ok(full.items.some((item) => item.title === '米饭承诺'));
|
|
29
|
-
assert.ok(full.items.some((item) => item.title === '颈椎'));
|
|
30
|
-
assert.equal(full.trace.gated, 0);
|
|
31
|
-
|
|
32
|
-
const tiered = ctx.cortex.recallTiered({ query: '米饭 承诺' });
|
|
33
|
-
assert.ok(tiered.result.items.some((item) => item.title === '米饭承诺'));
|
|
34
|
-
assert.equal(tiered.result.items.some((item) => item.title === '颈椎'), false);
|
|
35
|
-
assert.equal(tiered.result.items.some((item) => item.title === '日志'), false);
|
|
36
|
-
assert.ok(tiered.result.trace.gated >= 1);
|
|
37
|
-
} finally {
|
|
38
|
-
teardown(ctx);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('high-importance memory keeps the 0.4.11 gate exemption', () => {
|
|
43
|
-
const ctx = setup();
|
|
44
|
-
try {
|
|
45
|
-
ctx.cortex.write({ text: '身份:我是我,边界是不操纵用户。', title: '身份', kind: 'identity', importance: 0.95, explicit: true });
|
|
46
|
-
const tiered = ctx.cortex.recallTiered({ query: '米饭' });
|
|
47
|
-
assert.ok(tiered.result.items.some((item) => item.title === '身份'));
|
|
48
|
-
assert.equal(tiered.result.items[0].layer, 'L0');
|
|
49
|
-
} finally {
|
|
50
|
-
teardown(ctx);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('promptBudget config is normalized instead of being dropped', () => {
|
|
55
|
-
const ctx = setup({ promptBudget: 2400 });
|
|
56
|
-
try {
|
|
57
|
-
assert.equal(ctx.cortex.config.promptBudget, 2400);
|
|
58
|
-
const settings = ctx.cortex.settings();
|
|
59
|
-
assert.equal(ctx.cortex.settings().promptBudget, 2400);
|
|
60
|
-
} finally {
|
|
61
|
-
teardown(ctx);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('recall text is strictly per session and never falls back to another session', () => {
|
|
66
|
-
const ctx = setup();
|
|
67
|
-
try {
|
|
68
|
-
ctx.cortex.write({ text: '用户说会买米饭。', explicit: true });
|
|
69
|
-
const runtime = createHostRuntime({ cortex: ctx.cortex });
|
|
70
|
-
const at = Date.now();
|
|
71
|
-
const s1 = { id: 's1', header: {} };
|
|
72
|
-
const s2 = { id: 's2', header: {} };
|
|
73
|
-
runtime.onSessionEvent(s1, { type: 'turn/start', data: { turn: 1 }, time: at });
|
|
74
|
-
runtime.onSessionEvent(s1, { type: 'user/message', data: { content: '米饭还算数吗?' }, time: at + 1000 });
|
|
75
|
-
assert.match(runtime.recallText({ session: s1 }), /米饭/);
|
|
76
|
-
assert.equal(runtime.recallText({ session: s2 }), '');
|
|
77
|
-
assert.equal(runtime.recallText({}), '');
|
|
78
|
-
} finally {
|
|
79
|
-
teardown(ctx);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('light guardian runs structural invariants and catches FTS drift', () => {
|
|
84
|
-
const ctx = setup();
|
|
85
|
-
try {
|
|
86
|
-
const first = ctx.cortex.write({ text: '第一条用于索引的记忆。', explicit: true });
|
|
87
|
-
ctx.cortex.write({ text: '第二条用于索引的记忆。', explicit: true });
|
|
88
|
-
const clean = ctx.cortex.guardian.check({ deep: false });
|
|
89
|
-
assert.equal(clean.ok, true);
|
|
90
|
-
assert.equal(clean.integrity, 'skipped');
|
|
91
|
-
assert.equal(clean.chain.skipped, true);
|
|
92
|
-
|
|
93
|
-
ctx.cortex.db.prepare('DELETE FROM traces_fts_index WHERE trace_id = ?').run(first.trace.id);
|
|
94
|
-
const drift = ctx.cortex.guardian.check({ deep: false });
|
|
95
|
-
assert.equal(drift.ok, false);
|
|
96
|
-
assert.ok(drift.issues.some((item) => item.code === 'FTS_DRIFT'));
|
|
97
|
-
|
|
98
|
-
const deep = ctx.cortex.guardian.check({ deep: true });
|
|
99
|
-
assert.equal(deep.integrity, 'ok');
|
|
100
|
-
assert.equal(deep.chain.ok, true);
|
|
101
|
-
} finally {
|
|
102
|
-
teardown(ctx);
|
|
103
|
-
}
|
|
104
|
-
});
|