dsh-cross-memory 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +247 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1550 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4475 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +112 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +455 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +314 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +140 -0
- package/lib/test/persona.test.js +73 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +227 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +43 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +233 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the store's git transport.
|
|
3
|
+
*
|
|
4
|
+
* The interesting behaviour is not "does git run" but the arbitration rules:
|
|
5
|
+
* what stays out of the repository, which conflicts the module is allowed to
|
|
6
|
+
* decide, and what happens when the AI resolver declines.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-cross-memory/test/sync.test
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { execFileSync } from 'node:child_process';
|
|
12
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { hostname, tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
import { MemorySync, STORE_GITIGNORE, entryStamp, isEntryPath, isHostDescriptorPath, isSessionNotePath, mergeLoopLedgers, newerEntry, newerHostDescriptor, newerSessionNote, nextClockDelay } from '../sync.js';
|
|
17
|
+
import { applyConflictPlan, isArchivedEntryPath, projectRootOf } from '../sync-runtime.js';
|
|
18
|
+
import { slugify } from '../storage.js';
|
|
19
|
+
/** A logger that swallows everything; tests assert on git state, not log text. */
|
|
20
|
+
const quietLog = { info: () => undefined, warn: () => undefined, decision: () => undefined };
|
|
21
|
+
/** Run one git command in a fixture directory. */
|
|
22
|
+
function git(dir, ...args) {
|
|
23
|
+
return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8' });
|
|
24
|
+
}
|
|
25
|
+
/** Give one fixture repository an identity so commits do not need a global one. */
|
|
26
|
+
function identify(dir) {
|
|
27
|
+
git(dir, 'config', 'user.email', 'memories@test');
|
|
28
|
+
git(dir, 'config', 'user.name', 'Memories Test');
|
|
29
|
+
}
|
|
30
|
+
/** One entry file body with the given id and revision. */
|
|
31
|
+
function entryText(id, body, updated) {
|
|
32
|
+
return [
|
|
33
|
+
'---',
|
|
34
|
+
'id: ' + id,
|
|
35
|
+
'scope: global',
|
|
36
|
+
'kind: fact',
|
|
37
|
+
'title: ' + id,
|
|
38
|
+
'tags:',
|
|
39
|
+
'created: 2026-01-01T00:00:00.000Z',
|
|
40
|
+
'updated: ' + updated,
|
|
41
|
+
'---',
|
|
42
|
+
'',
|
|
43
|
+
body,
|
|
44
|
+
'',
|
|
45
|
+
].join('\n');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Two clones of one bare remote, each with a store the module can drive.
|
|
49
|
+
*
|
|
50
|
+
* Returned rather than built inside each test because the conflict tests need
|
|
51
|
+
* both sides to have pushed before they diverge.
|
|
52
|
+
*/
|
|
53
|
+
async function twoWayFixture() {
|
|
54
|
+
const base = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-sync-'));
|
|
55
|
+
const remote = join(base, 'remote.git');
|
|
56
|
+
execFileSync('git', ['init', '--bare', '--quiet', remote]);
|
|
57
|
+
const left = join(base, 'left');
|
|
58
|
+
const right = join(base, 'right');
|
|
59
|
+
await mkdir(join(left, 'entries'), { recursive: true });
|
|
60
|
+
execFileSync('git', ['init', '--quiet', '-b', 'main', left]);
|
|
61
|
+
identify(left);
|
|
62
|
+
git(left, 'remote', 'add', 'origin', remote);
|
|
63
|
+
const resolver = { calls: [], answer: undefined, run: async (conflict) => { resolver.calls.push(conflict); return resolver.answer; } };
|
|
64
|
+
const makeLeft = new MemorySync({ memoriesDir: left, remote, intervalMs: 0, debounceMs: 0, gitTimeoutMs: 20_000, networkTimeoutMs: 20_000, log: quietLog, host: 'left', resolveConflict: resolver.run });
|
|
65
|
+
await makeLeft.init();
|
|
66
|
+
await writeFile(join(left, 'entries', 'shared.md'), entryText('shared', 'left fact', '2026-02-01T00:00:00.000Z'));
|
|
67
|
+
await makeLeft.run('test');
|
|
68
|
+
execFileSync('git', ['clone', '--quiet', remote, right]);
|
|
69
|
+
identify(right);
|
|
70
|
+
const makeRight = new MemorySync({ memoriesDir: right, remote, intervalMs: 0, debounceMs: 0, gitTimeoutMs: 20_000, networkTimeoutMs: 20_000, log: quietLog, host: 'right', resolveConflict: resolver.run });
|
|
71
|
+
return { remote, left: { dir: left, sync: makeLeft }, right: { dir: right, sync: makeRight }, resolver };
|
|
72
|
+
}
|
|
73
|
+
test('machine state is kept out of the repository', async () => {
|
|
74
|
+
const base = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-ignore-'));
|
|
75
|
+
await mkdir(join(base, 'entries'), { recursive: true });
|
|
76
|
+
await writeFile(join(base, 'state.db'), 'binary');
|
|
77
|
+
await writeFile(join(base, 'index.json'), '{}');
|
|
78
|
+
await writeFile(join(base, 'entries', 'one.md'), entryText('one', 'kept', '2026-02-01T00:00:00.000Z'));
|
|
79
|
+
const sync = new MemorySync({ memoriesDir: base, remote: '', intervalMs: 0, debounceMs: 0, gitTimeoutMs: 20_000, networkTimeoutMs: 20_000, log: quietLog, host: 'test' });
|
|
80
|
+
await sync.init();
|
|
81
|
+
const tracked = git(base, 'ls-files').split('\n');
|
|
82
|
+
assert.ok(tracked.includes('entries/one.md'), 'an entry is tracked');
|
|
83
|
+
assert.ok(!tracked.includes('state.db'), 'the database is not tracked');
|
|
84
|
+
assert.ok(!tracked.includes('index.json'), 'the index cache is not tracked');
|
|
85
|
+
assert.equal(await readFile(join(base, '.gitignore'), 'utf8'), STORE_GITIGNORE);
|
|
86
|
+
});
|
|
87
|
+
test('only entry paths are auto-resolved, and the newer revision wins without a resolver', () => {
|
|
88
|
+
assert.equal(isEntryPath('entries/shared.md'), true);
|
|
89
|
+
assert.equal(isEntryPath('projects/alpha/entries/shared.md'), true);
|
|
90
|
+
assert.equal(isEntryPath('archive/old-fact.md'), true);
|
|
91
|
+
assert.equal(isEntryPath('projects/alpha/archive/old-fact.md'), true);
|
|
92
|
+
assert.equal(isEntryPath('persona.md'), false);
|
|
93
|
+
assert.equal(isEntryPath('sessions/note.md'), false);
|
|
94
|
+
assert.equal(isEntryPath('projects/alpha/project.json'), false);
|
|
95
|
+
assert.equal(isEntryPath('persona.md'), false);
|
|
96
|
+
const older = entryText('shared', 'old', '2026-01-01T00:00:00.000Z');
|
|
97
|
+
const newer = entryText('shared', 'new', '2026-03-01T00:00:00.000Z');
|
|
98
|
+
assert.ok(entryStamp(newer) > entryStamp(older));
|
|
99
|
+
assert.equal(newerEntry(older, newer).text, newer);
|
|
100
|
+
assert.equal(newerEntry(newer, older).text, newer, 'the order of the two sides does not matter');
|
|
101
|
+
});
|
|
102
|
+
test('a conflicting entry is handed to the resolver and its answer is committed', async () => {
|
|
103
|
+
const { remote, left, right, resolver } = await twoWayFixture();
|
|
104
|
+
// left moves the entry forward and publishes it
|
|
105
|
+
await writeFile(join(left.dir, 'entries', 'shared.md'), entryText('shared', 'left fact v2', '2026-03-01T00:00:00.000Z'));
|
|
106
|
+
await left.sync.run('test');
|
|
107
|
+
// right edits the same entry from the older revision, so the rebase conflicts
|
|
108
|
+
await writeFile(join(right.dir, 'entries', 'shared.md'), entryText('shared', 'right fact', '2026-02-10T00:00:00.000Z'));
|
|
109
|
+
resolver.answer = entryText('shared', 'left fact v2 AND right fact', '2026-03-02T00:00:00.000Z');
|
|
110
|
+
const outcome = await right.sync.run('test');
|
|
111
|
+
assert.equal(resolver.calls.length, 1, 'the resolver saw exactly the one conflict');
|
|
112
|
+
assert.equal(outcome.conflicts, 1);
|
|
113
|
+
assert.equal(outcome.resolvedByResolver, 1);
|
|
114
|
+
assert.match(await readFile(join(right.dir, 'entries', 'shared.md'), 'utf8'), /left fact v2 AND right fact/u);
|
|
115
|
+
assert.match(execFileSync('git', ['-C', remote, 'show', 'main:entries/shared.md'], { encoding: 'utf8' }), /left fact v2 AND right fact/u);
|
|
116
|
+
assert.equal(git(right.dir, 'status', '--porcelain').trim(), '', 'the store is not left mid-rebase');
|
|
117
|
+
});
|
|
118
|
+
test('a resolver that declines falls back to the newer revision', async () => {
|
|
119
|
+
const { left, right, resolver } = await twoWayFixture();
|
|
120
|
+
await writeFile(join(left.dir, 'entries', 'shared.md'), entryText('shared', 'left newer', '2026-03-01T00:00:00.000Z'));
|
|
121
|
+
await left.sync.run('test');
|
|
122
|
+
await writeFile(join(right.dir, 'entries', 'shared.md'), entryText('shared', 'right older', '2026-02-10T00:00:00.000Z'));
|
|
123
|
+
resolver.answer = undefined;
|
|
124
|
+
const outcome = await right.sync.run('test');
|
|
125
|
+
assert.equal(outcome.conflicts, 1);
|
|
126
|
+
assert.equal(outcome.resolvedByResolver, 0);
|
|
127
|
+
assert.equal(outcome.resolvedByTime, 1);
|
|
128
|
+
assert.match(await readFile(join(right.dir, 'entries', 'shared.md'), 'utf8'), /left newer/u);
|
|
129
|
+
});
|
|
130
|
+
test('an unparsable resolver answer is discarded rather than written', async () => {
|
|
131
|
+
const { left, right, resolver } = await twoWayFixture();
|
|
132
|
+
await writeFile(join(left.dir, 'entries', 'shared.md'), entryText('shared', 'left newer', '2026-03-01T00:00:00.000Z'));
|
|
133
|
+
await left.sync.run('test');
|
|
134
|
+
await writeFile(join(right.dir, 'entries', 'shared.md'), entryText('shared', 'right older', '2026-02-10T00:00:00.000Z'));
|
|
135
|
+
resolver.answer = 'not an entry file at all';
|
|
136
|
+
const outcome = await right.sync.run('test');
|
|
137
|
+
assert.equal(outcome.resolvedByTime, 1, 'the timestamp rule took over');
|
|
138
|
+
assert.match(await readFile(join(right.dir, 'entries', 'shared.md'), 'utf8'), /left newer/u);
|
|
139
|
+
});
|
|
140
|
+
/** One loop-ledger body: the same shape `loops.ts` writes. */
|
|
141
|
+
function loopText(...loops) {
|
|
142
|
+
const rows = loops.map((loop) => ({
|
|
143
|
+
id: loop.id,
|
|
144
|
+
text: loop.text,
|
|
145
|
+
openedAt: loop.openedAt,
|
|
146
|
+
state: loop.state ?? 'open',
|
|
147
|
+
...(loop.remindedAt === undefined ? {} : { remindedAt: loop.remindedAt }),
|
|
148
|
+
}));
|
|
149
|
+
return JSON.stringify({ version: 1, loops: rows }, null, 2) + '\n';
|
|
150
|
+
}
|
|
151
|
+
test('the loop ledger merges as a union, and a closure survives a stale copy', () => {
|
|
152
|
+
const ours = loopText({ id: 'loop-a', text: 'call Yoko', openedAt: 1 }, { id: 'loop-b', text: 'send invoice', openedAt: 2, state: 'done' });
|
|
153
|
+
const theirs = loopText({ id: 'loop-a', text: 'call Yoko', openedAt: 1, remindedAt: 9 }, { id: 'loop-c', text: 'book the room', openedAt: 3 });
|
|
154
|
+
const merged = mergeLoopLedgers(ours, theirs);
|
|
155
|
+
assert.ok(merged !== undefined);
|
|
156
|
+
const parsed = JSON.parse(merged);
|
|
157
|
+
assert.deepEqual(parsed.loops.map((loop) => loop.id), ['loop-a', 'loop-b', 'loop-c'], 'both sides keep their loops');
|
|
158
|
+
assert.equal(parsed.loops[0]?.remindedAt, 9, 'the copy that was reminded wins');
|
|
159
|
+
assert.equal(parsed.loops[1]?.state, 'done', 'a closed loop is not reopened by a stale open row');
|
|
160
|
+
assert.equal(mergeLoopLedgers('not json', 'also not'), undefined, 'a non-ledger is still refused');
|
|
161
|
+
});
|
|
162
|
+
test('a committed conflict marker in loops.json is repaired instead of blocking the sync', () => {
|
|
163
|
+
const clean = loopText({ id: 'loop-a', text: 'call Yoko', openedAt: 1 });
|
|
164
|
+
const conflicted = clean.replace(' "state": "open"', '<<<<<<< HEAD\n "state": "open"\n=======\n "state": "done"\n>>>>>>> abc1234 (memory(host-a): 1 个文件)');
|
|
165
|
+
const merged = mergeLoopLedgers(conflicted, loopText({ id: 'loop-b', text: 'second', openedAt: 2 })) ?? '';
|
|
166
|
+
assert.match(merged, /"id": "loop-a"/u);
|
|
167
|
+
assert.match(merged, /"id": "loop-b"/u);
|
|
168
|
+
assert.doesNotMatch(merged, /^\s*(<<<<<<<|=======|>>>>>>>)/mu, 'no marker line survives');
|
|
169
|
+
assert.doesNotThrow(() => JSON.parse(merged), 'the repaired ledger is valid JSON');
|
|
170
|
+
});
|
|
171
|
+
test('two machines opening different loops keep both and leave the store in sync', async () => {
|
|
172
|
+
const { remote, left, right } = await twoWayFixture();
|
|
173
|
+
await writeFile(join(left.dir, 'loops.json'), loopText({ id: 'loop-a', text: 'call Yoko', openedAt: 1 }));
|
|
174
|
+
await left.sync.run('test');
|
|
175
|
+
await writeFile(join(right.dir, 'loops.json'), loopText({ id: 'loop-b', text: 'send invoice', openedAt: 2 }));
|
|
176
|
+
const outcome = await right.sync.run('test');
|
|
177
|
+
assert.equal(outcome.pushed, true, 'the ledger no longer blocks the push');
|
|
178
|
+
assert.equal(outcome.mergedByStructure, 1);
|
|
179
|
+
const merged = JSON.parse(await readFile(join(right.dir, 'loops.json'), 'utf8'));
|
|
180
|
+
assert.deepEqual(merged.loops.map((loop) => loop.id), ['loop-a', 'loop-b']);
|
|
181
|
+
assert.match(execFileSync('git', ['-C', remote, 'show', 'main:loops.json'], { encoding: 'utf8' }), /loop-b/u);
|
|
182
|
+
assert.equal(git(right.dir, 'status', '--porcelain').trim(), '', 'the store is not left mid-rebase');
|
|
183
|
+
});
|
|
184
|
+
/** One session-note body: the shape the extractor writes. */
|
|
185
|
+
function sessionNoteText(at, summary) {
|
|
186
|
+
return ['---', 'session: "session-test"', 'at: ' + at, 'memories: none', '---', '', summary, ''].join('\n');
|
|
187
|
+
}
|
|
188
|
+
test('a conflicting session note keeps the later reading', () => {
|
|
189
|
+
const older = sessionNoteText('2026-11-01T03:13:53.263Z', 'first reading');
|
|
190
|
+
const newer = sessionNoteText('2026-11-01T18:42:56.351Z', 'second reading');
|
|
191
|
+
assert.equal(newerSessionNote(older, newer), newer);
|
|
192
|
+
assert.equal(newerSessionNote(newer, older), newer, 'the order of the two sides does not matter');
|
|
193
|
+
assert.equal(newerSessionNote('no stamps here', 'no stamps here'), undefined, 'an unstamped note is still refused');
|
|
194
|
+
assert.equal(isSessionNotePath('sessions/session-a.md'), true);
|
|
195
|
+
assert.equal(isSessionNotePath('projects/alpha/sessions/session-a.md'), true);
|
|
196
|
+
assert.equal(isSessionNotePath('entries/one.md'), false);
|
|
197
|
+
});
|
|
198
|
+
test('two machines resummarising one session keep the later note and finish the sync', async () => {
|
|
199
|
+
const { remote, left, right } = await twoWayFixture();
|
|
200
|
+
await mkdir(join(left.dir, 'sessions'), { recursive: true });
|
|
201
|
+
await writeFile(join(left.dir, 'sessions', 'session-same.md'), sessionNoteText('2026-11-01T03:13:53.263Z', 'first reading'));
|
|
202
|
+
await left.sync.run('test');
|
|
203
|
+
await mkdir(join(right.dir, 'sessions'), { recursive: true });
|
|
204
|
+
await writeFile(join(right.dir, 'sessions', 'session-same.md'), sessionNoteText('2026-11-01T18:42:56.351Z', 'second reading'));
|
|
205
|
+
const outcome = await right.sync.run('test');
|
|
206
|
+
assert.equal(outcome.pushed, true, 'a session note no longer blocks the push');
|
|
207
|
+
assert.equal(outcome.resolvedByTime, 1);
|
|
208
|
+
const note = await readFile(join(right.dir, 'sessions', 'session-same.md'), 'utf8');
|
|
209
|
+
assert.match(note, /second reading/u, 'the later summary won');
|
|
210
|
+
assert.match(execFileSync('git', ['-C', remote, 'show', 'main:sessions/session-same.md'], { encoding: 'utf8' }), /second reading/u);
|
|
211
|
+
assert.equal(git(right.dir, 'status', '--porcelain').trim(), '', 'the store is not left mid-rebase');
|
|
212
|
+
});
|
|
213
|
+
test('a conflicting host descriptor keeps the newer reading', () => {
|
|
214
|
+
const older = JSON.stringify({ host: 'h', platform: 'darwin', root: '/p', firstSeen: 1, lastSeen: 10 });
|
|
215
|
+
const newer = JSON.stringify({ host: 'h', platform: 'darwin', root: '/p', firstSeen: 1, lastSeen: 20, origin: 'github.com/a/b' });
|
|
216
|
+
assert.equal(newerHostDescriptor(older, newer), newer);
|
|
217
|
+
assert.equal(newerHostDescriptor(newer, older), newer, 'the order of the two sides does not matter');
|
|
218
|
+
const noOrigin = JSON.stringify({ host: 'h', lastSeen: 20 });
|
|
219
|
+
assert.equal(newerHostDescriptor(newer, noOrigin), newer, 'the side that knows the origin wins when lastSeen ties');
|
|
220
|
+
assert.equal(newerHostDescriptor('{}', 'not json'), '{}', 'a side that is not JSON is ignored');
|
|
221
|
+
assert.equal(isHostDescriptorPath('projects/a/hosts/example-host-local.json'), true);
|
|
222
|
+
assert.equal(isHostDescriptorPath('projects/a/project.json'), false);
|
|
223
|
+
assert.equal(isHostDescriptorPath('entries/hosts/note.md'), false);
|
|
224
|
+
});
|
|
225
|
+
test('the clock schedule picks the next local time, and wraps to tomorrow', () => {
|
|
226
|
+
const noon = new Date(2026, 9, 26, 12, 0, 0).getTime();
|
|
227
|
+
assert.equal(nextClockDelay(['12:05'], noon), 5 * 60_000, 'five minutes after noon');
|
|
228
|
+
const past = new Date(2026, 9, 26, 12, 6, 0).getTime();
|
|
229
|
+
assert.equal(nextClockDelay(['12:05'], past), 86_400_000 - 60_000, 'the same time tomorrow');
|
|
230
|
+
const afternoon = new Date(2026, 9, 26, 13, 0, 0).getTime();
|
|
231
|
+
assert.equal(nextClockDelay(['18:05', '12:05'], afternoon), (18 * 60 + 5 - 13 * 60) * 60_000);
|
|
232
|
+
assert.equal(nextClockDelay(['nope'], noon), undefined, 'an unparsable clock arms nothing');
|
|
233
|
+
});
|
|
234
|
+
test('a conflict merge is accepted only through the consolidation plan rules', () => {
|
|
235
|
+
const ours = entryText('shared', 'left fact', '2026-02-01T00:00:00.000Z');
|
|
236
|
+
const theirs = entryText('shared', 'right fact', '2026-03-01T00:00:00.000Z');
|
|
237
|
+
const reply = JSON.stringify({ memories: [{ id: 'shared', scope: 'global', kind: 'fact', title: 'shared', body: 'left fact and right fact', tags: [] }], summary: 'merged both revisions' });
|
|
238
|
+
const applied = applyConflictPlan(reply, ours, theirs);
|
|
239
|
+
assert.ok('merged' in applied, 'the plan was accepted');
|
|
240
|
+
assert.match(applied.text, /left fact and right fact/u);
|
|
241
|
+
assert.match(applied.text, /updated: 2026-03-01/u, 'the newer revision stamps the merge');
|
|
242
|
+
});
|
|
243
|
+
test('a merge that drops an anchor is returned as a dispute instead of written', () => {
|
|
244
|
+
const ours = entryText('shared', 'keeps src/app/main.ts as the anchor', '2026-02-01T00:00:00.000Z');
|
|
245
|
+
const reply = JSON.stringify({ memories: [{ id: 'shared', scope: 'global', kind: 'fact', title: 'shared', body: 'no anchors at all', tags: [] }], summary: '' });
|
|
246
|
+
const applied = applyConflictPlan(reply, ours, ours);
|
|
247
|
+
assert.ok(!('merged' in applied), 'nothing is written');
|
|
248
|
+
assert.ok(applied.disputes.length > 0, 'the loss shows up as a question');
|
|
249
|
+
});
|
|
250
|
+
test('a reply that is not a plan leaves the timestamp rule in charge', () => {
|
|
251
|
+
const ours = entryText('shared', 'x', '2026-02-01T00:00:00.000Z');
|
|
252
|
+
const applied = applyConflictPlan('not json at all', ours, ours);
|
|
253
|
+
assert.ok(!('merged' in applied));
|
|
254
|
+
assert.deepEqual(applied.disputes, []);
|
|
255
|
+
});
|
|
256
|
+
test('a merge keeps the scope of the file it merges even when the reply proposes another', () => {
|
|
257
|
+
const ours = entryText('shared', 'left fact', '2026-02-01T00:00:00.000Z');
|
|
258
|
+
const theirs = entryText('shared', 'right fact', '2026-03-01T00:00:00.000Z');
|
|
259
|
+
// The two revisions are one file: the merge is written back to that path, so
|
|
260
|
+
// the reply's "project" scope is not a decision the merge can take. Honouring
|
|
261
|
+
// it would be a scope move, which is the one edit classifyPlan must ask about.
|
|
262
|
+
const reply = JSON.stringify({ memories: [{ id: 'shared', scope: 'project', kind: 'fact', title: 'shared', body: 'left fact and right fact', tags: [] }], summary: 'merged both revisions' });
|
|
263
|
+
const applied = applyConflictPlan(reply, ours, theirs);
|
|
264
|
+
if (!('merged' in applied))
|
|
265
|
+
assert.fail('a scope guess must not turn a merge into a question');
|
|
266
|
+
assert.match(applied.text, /scope: global/u, 'the merge stays where the file lives');
|
|
267
|
+
assert.doesNotMatch(applied.text, /scope: project/u);
|
|
268
|
+
assert.match(applied.text, /left fact and right fact/u);
|
|
269
|
+
});
|
|
270
|
+
test('a disputed merge still carries the fragment that would apply it', () => {
|
|
271
|
+
const ours = entryText('shared', 'keeps src/app/main.ts as the anchor', '2026-02-01T00:00:00.000Z');
|
|
272
|
+
const reply = JSON.stringify({ memories: [{ id: 'shared', scope: 'project', kind: 'fact', title: 'shared', body: 'no anchors at all', tags: [] }], summary: '' });
|
|
273
|
+
const applied = applyConflictPlan(reply, ours, ours);
|
|
274
|
+
if ('merged' in applied)
|
|
275
|
+
assert.fail('dropping the cited path must not be written');
|
|
276
|
+
assert.ok(applied.disputes.length > 0, 'the loss still shows up as a question');
|
|
277
|
+
const fragment = applied.upserts ?? [];
|
|
278
|
+
assert.equal(fragment.length, 1, 'the row carries the rewrite that would apply it');
|
|
279
|
+
assert.equal(fragment[0]?.scope, 'global', 'the stored fragment keeps the pinned scope');
|
|
280
|
+
assert.equal(fragment[0]?.body, 'no anchors at all');
|
|
281
|
+
});
|
|
282
|
+
test('a project conflict path resolves the local checkout, preferring this host descriptor', async (t) => {
|
|
283
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-root-'));
|
|
284
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
285
|
+
const entry = 'projects/alpha/entries/shared.md';
|
|
286
|
+
// A global entry lives outside `projects/`, so there is no checkout to resolve.
|
|
287
|
+
assert.equal(await projectRootOf(dir, 'entries/shared.md'), undefined);
|
|
288
|
+
const projectDir = join(dir, 'projects', 'alpha');
|
|
289
|
+
const hostFile = join(projectDir, 'hosts', `${slugify(hostname())}.json`);
|
|
290
|
+
await mkdir(join(projectDir, 'hosts'), { recursive: true });
|
|
291
|
+
// `project.json` is rewritten by whichever machine synced last; this machine's
|
|
292
|
+
// host file is its own checkout and must win over it.
|
|
293
|
+
await writeFile(join(projectDir, 'project.json'), JSON.stringify({ root: '/elsewhere/alpha', slug: 'alpha' }));
|
|
294
|
+
await writeFile(hostFile, JSON.stringify({ host: hostname(), root: '/this/machine/alpha' }));
|
|
295
|
+
assert.equal(await projectRootOf(dir, entry), '/this/machine/alpha', 'the host descriptor wins');
|
|
296
|
+
// With no host file the canonical descriptor is the only honest fallback.
|
|
297
|
+
await rm(hostFile);
|
|
298
|
+
assert.equal(await projectRootOf(dir, entry), '/elsewhere/alpha');
|
|
299
|
+
// Nothing recorded, or an unreadable record: no root rather than a guessed one.
|
|
300
|
+
await rm(join(projectDir, 'project.json'));
|
|
301
|
+
assert.equal(await projectRootOf(dir, entry), undefined);
|
|
302
|
+
await writeFile(join(projectDir, 'project.json'), 'not json at all');
|
|
303
|
+
assert.equal(await projectRootOf(dir, entry), undefined);
|
|
304
|
+
});
|
|
305
|
+
test('an archived conflict path is recognised, so it never becomes a waiting row', () => {
|
|
306
|
+
// Applying a row writes into `entries/`; staging an archived file's conflict
|
|
307
|
+
// would let "accept" bring a retired memory back, so the path is filtered out.
|
|
308
|
+
assert.equal(isArchivedEntryPath('archive/shared.md'), true);
|
|
309
|
+
assert.equal(isArchivedEntryPath('projects/alpha/archive/shared.md'), true);
|
|
310
|
+
assert.equal(isArchivedEntryPath('entries/shared.md'), false);
|
|
311
|
+
assert.equal(isArchivedEntryPath('projects/alpha/entries/shared.md'), false);
|
|
312
|
+
// A live entry whose id merely contains the word is not an archive file.
|
|
313
|
+
assert.equal(isArchivedEntryPath('entries/archive-cleanup.md'), false);
|
|
314
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the time channel: resolving a turn's window, and the lift it gives
|
|
3
|
+
* entries that fall inside it.
|
|
4
|
+
*
|
|
5
|
+
* Every expectation is built from local `Date` parts rather than from epoch
|
|
6
|
+
* constants, so the suite means the same thing in Shanghai and in UTC — the
|
|
7
|
+
* feature is defined in local time, and a test that hardcoded a Z timestamp
|
|
8
|
+
* would pass in one timezone and fail in the other.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-cross-memory/test/time.test
|
|
11
|
+
*/
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import test from 'node:test';
|
|
14
|
+
import { cnNumber, parseTimeRange, within } from '../time.js';
|
|
15
|
+
import { relevanceOf, scoreEntry, TIME_CREATED_BOOST, TIME_MEASURED_BOOST, timeBoost } from '../search.js';
|
|
16
|
+
import { rankForSummary } from '../render.js';
|
|
17
|
+
/** Tuesday, 29 September 2026, 19:00 local. */
|
|
18
|
+
const NOW = new Date(2026, 8, 29, 19, 0, 0).getTime();
|
|
19
|
+
const DAY = 86_400_000;
|
|
20
|
+
/** Epoch of a local wall-clock moment. */
|
|
21
|
+
function at(year, month, day, hour = 0) {
|
|
22
|
+
return new Date(year, month - 1, day, hour).getTime();
|
|
23
|
+
}
|
|
24
|
+
/** One corpus entry. */
|
|
25
|
+
function entry(id, extra = {}, kind = 'fact') {
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
scope: 'global',
|
|
29
|
+
kind,
|
|
30
|
+
title: id,
|
|
31
|
+
body: `body of ${id}`,
|
|
32
|
+
tags: [],
|
|
33
|
+
keys: [],
|
|
34
|
+
createdAt: at(2026, 1, 1),
|
|
35
|
+
updatedAt: at(2026, 1, 1),
|
|
36
|
+
uses: 0,
|
|
37
|
+
lastUsedAt: 0,
|
|
38
|
+
lastSurfacedAt: 0,
|
|
39
|
+
source: 'auto',
|
|
40
|
+
...extra,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The window a query resolves to, as `[label, start, end]` or `undefined`. */
|
|
44
|
+
function span(query) {
|
|
45
|
+
const range = parseTimeRange(query, NOW);
|
|
46
|
+
return range === undefined ? undefined : [range.label, range.start, range.end];
|
|
47
|
+
}
|
|
48
|
+
test('cnNumber reads both digit forms dates use', () => {
|
|
49
|
+
assert.equal(cnNumber('3'), 3);
|
|
50
|
+
assert.equal(cnNumber('十'), 10);
|
|
51
|
+
assert.equal(cnNumber('十一'), 11);
|
|
52
|
+
assert.equal(cnNumber('二十'), 20);
|
|
53
|
+
assert.equal(cnNumber('三十一'), 31);
|
|
54
|
+
assert.equal(cnNumber('两'), 2);
|
|
55
|
+
assert.equal(cnNumber('九'), 9);
|
|
56
|
+
assert.equal(cnNumber('很多'), undefined);
|
|
57
|
+
assert.equal(cnNumber(''), undefined);
|
|
58
|
+
});
|
|
59
|
+
test('relative days resolve to the local calendar day', () => {
|
|
60
|
+
assert.deepEqual(span('今天做了什么'), ['今天', at(2026, 9, 29), at(2026, 9, 30)]);
|
|
61
|
+
assert.deepEqual(span('昨天的报错'), ['昨天', at(2026, 9, 28), at(2026, 9, 29)]);
|
|
62
|
+
assert.deepEqual(span('前天那次改动'), ['前天', at(2026, 9, 27), at(2026, 9, 28)]);
|
|
63
|
+
});
|
|
64
|
+
test('weeks start on Monday, the way 上周 is read', () => {
|
|
65
|
+
// 2026-09-29 is a Tuesday, so this week starts on 2026-09-28.
|
|
66
|
+
assert.deepEqual(span('上周做的迁移'), ['上周', at(2026, 9, 21), at(2026, 9, 28)]);
|
|
67
|
+
assert.deepEqual(span('本周的进度'), ['本周', at(2026, 9, 28), at(2026, 10, 5)]);
|
|
68
|
+
});
|
|
69
|
+
test('months and years resolve to whole calendar periods', () => {
|
|
70
|
+
assert.deepEqual(span('上个月的对账单'), ['上个月', at(2026, 8, 1), at(2026, 9, 1)]);
|
|
71
|
+
assert.deepEqual(span('去年定的规矩'), ['去年', at(2025, 1, 1), at(2026, 1, 1)]);
|
|
72
|
+
assert.deepEqual(span('明年的排期'), ['明年', at(2027, 1, 1), at(2028, 1, 1)]);
|
|
73
|
+
});
|
|
74
|
+
test('a season is three months, and winter crosses the year boundary', () => {
|
|
75
|
+
assert.deepEqual(span('去年春天在做什么'), ['去年春天', at(2025, 3, 1), at(2025, 6, 1)]);
|
|
76
|
+
assert.deepEqual(span('今年夏天'), ['今年夏天', at(2026, 6, 1), at(2026, 9, 1)]);
|
|
77
|
+
assert.deepEqual(span('今年冬天'), ['今年冬天', at(2026, 12, 1), at(2027, 3, 1)]);
|
|
78
|
+
assert.deepEqual(span('秋季的复盘'), ['秋季', at(2026, 9, 1), at(2026, 12, 1)]);
|
|
79
|
+
});
|
|
80
|
+
test('counted intervals distinguish "the last N" from "N ago"', () => {
|
|
81
|
+
assert.deepEqual(span('最近三天'), ['最近三天', at(2026, 9, 27), NOW]);
|
|
82
|
+
assert.deepEqual(span('近 3 天'), ['近 3 天', at(2026, 9, 27), NOW]);
|
|
83
|
+
assert.deepEqual(span('过去两个月'), ['过去两个月', at(2026, 8, 1), NOW]);
|
|
84
|
+
assert.deepEqual(span('3 天前'), ['3 天前', at(2026, 9, 26), at(2026, 9, 27)]);
|
|
85
|
+
assert.deepEqual(span('两周前'), ['两周前', at(2026, 9, 14), at(2026, 9, 21)]);
|
|
86
|
+
assert.deepEqual(span('5 个月前'), ['5 个月前', at(2026, 4, 1), at(2026, 5, 1)]);
|
|
87
|
+
});
|
|
88
|
+
test('absolute dates win over the looser rules', () => {
|
|
89
|
+
assert.deepEqual(span('2026-09-20 那次事故'), ['2026-9-20', at(2026, 9, 20), at(2026, 9, 21)]);
|
|
90
|
+
assert.deepEqual(span('2026年9月20日'), ['2026-9-20', at(2026, 9, 20), at(2026, 9, 21)]);
|
|
91
|
+
assert.deepEqual(span('2026年9月'), ['2026-9', at(2026, 9, 1), at(2026, 10, 1)]);
|
|
92
|
+
assert.deepEqual(span('2026年'), ['2026年', at(2026, 1, 1), at(2027, 1, 1)]);
|
|
93
|
+
assert.deepEqual(span('9 月 20 日'), ['9月20日', at(2026, 9, 20), at(2026, 9, 21)]);
|
|
94
|
+
assert.deepEqual(span('去年 9 月'), ['去年9月', at(2025, 9, 1), at(2025, 10, 1)]);
|
|
95
|
+
});
|
|
96
|
+
test('a bare month or season still resolves, a number with no unit does not', () => {
|
|
97
|
+
assert.deepEqual(span('3 月做了什么'), ['3月', at(2026, 3, 1), at(2026, 4, 1)]);
|
|
98
|
+
// The unit is required, so 去年3个问题 is not last March — it is simply 去年.
|
|
99
|
+
assert.deepEqual(span('去年3个问题'), ['去年', at(2025, 1, 1), at(2026, 1, 1)]);
|
|
100
|
+
// 月 as part of a word is not a date; 这个月 is.
|
|
101
|
+
assert.equal(span('月度报告怎么写'), undefined);
|
|
102
|
+
assert.deepEqual(span('这个月度报告'), ['这个月', at(2026, 9, 1), at(2026, 10, 1)]);
|
|
103
|
+
});
|
|
104
|
+
test('turns that name no time resolve to nothing', () => {
|
|
105
|
+
assert.equal(parseTimeRange('把混装的工作区改动拆成两笔提交', NOW), undefined);
|
|
106
|
+
assert.equal(parseTimeRange('dsh-cross-memory 注入摘要的排序是怎么算的', NOW), undefined);
|
|
107
|
+
assert.equal(parseTimeRange('日志在哪里', NOW), undefined);
|
|
108
|
+
assert.equal(parseTimeRange('', NOW), undefined);
|
|
109
|
+
});
|
|
110
|
+
test('within() is half-open and rejects missing timestamps', () => {
|
|
111
|
+
const range = parseTimeRange('昨天', NOW);
|
|
112
|
+
assert.ok(range !== undefined);
|
|
113
|
+
assert.equal(within(at(2026, 9, 28), range), true);
|
|
114
|
+
assert.equal(within(at(2026, 9, 28, 23), range), true);
|
|
115
|
+
assert.equal(within(at(2026, 9, 29), range), false, 'the upper bound is exclusive');
|
|
116
|
+
assert.equal(within(at(2026, 9, 27), range), false);
|
|
117
|
+
assert.equal(within(undefined, range), false);
|
|
118
|
+
assert.equal(within(0, range), false);
|
|
119
|
+
});
|
|
120
|
+
test('timeBoost lifts a measurement above a learning date, and never penalises', () => {
|
|
121
|
+
const range = parseTimeRange('上周', NOW);
|
|
122
|
+
const measured = entry('measured', { asOf: at(2026, 9, 22) });
|
|
123
|
+
const learned = entry('learned', { createdAt: at(2026, 9, 22), updatedAt: at(2026, 9, 22) });
|
|
124
|
+
const older = entry('older', { createdAt: at(2026, 3, 1), updatedAt: at(2026, 3, 1) });
|
|
125
|
+
assert.equal(timeBoost(measured, range), TIME_MEASURED_BOOST);
|
|
126
|
+
assert.equal(timeBoost(learned, range), TIME_CREATED_BOOST);
|
|
127
|
+
assert.equal(timeBoost(older, range), 1, 'outside the window is still returned, just not lifted');
|
|
128
|
+
assert.equal(timeBoost(measured, undefined), 1, 'a turn with no date changes nothing');
|
|
129
|
+
});
|
|
130
|
+
test('the window reorders entries that match the same words', () => {
|
|
131
|
+
const inWindow = entry('alice-spring', {
|
|
132
|
+
title: 'Alice 在做异步改造',
|
|
133
|
+
body: 'Alice 那阵子在改异步数据库调用。',
|
|
134
|
+
createdAt: at(2025, 4, 10),
|
|
135
|
+
updatedAt: at(2025, 4, 10),
|
|
136
|
+
});
|
|
137
|
+
const outOfWindow = entry('alice-winter', {
|
|
138
|
+
title: 'Alice 在做异步改造',
|
|
139
|
+
body: 'Alice 那阵子在改异步数据库调用。',
|
|
140
|
+
createdAt: at(2025, 11, 10),
|
|
141
|
+
updatedAt: at(2025, 11, 10),
|
|
142
|
+
});
|
|
143
|
+
const query = 'Alice 去年春天在做什么';
|
|
144
|
+
assert.equal(relevanceOf(inWindow, query), relevanceOf(outOfWindow, query), 'same lexical evidence');
|
|
145
|
+
const ranked = [outOfWindow, inWindow].sort((a, b) => scoreEntry(b, query, NOW) - scoreEntry(a, query, NOW));
|
|
146
|
+
assert.deepEqual(ranked.map((item) => item.id), ['alice-spring', 'alice-winter']);
|
|
147
|
+
});
|
|
148
|
+
test('a turn with no date leaves the ordering untouched', () => {
|
|
149
|
+
const older = entry('older', { createdAt: at(2026, 6, 1), updatedAt: at(2026, 6, 1) });
|
|
150
|
+
const newer = entry('newer', { createdAt: NOW - DAY, updatedAt: NOW - DAY });
|
|
151
|
+
const query = 'Alice 在做异步改造';
|
|
152
|
+
const withoutDate = [newer, older].sort((a, b) => scoreEntry(b, query, NOW) - scoreEntry(a, query, NOW));
|
|
153
|
+
const withDate = [newer, older].sort((a, b) => scoreEntry(b, `${query} 上周`, NOW) - scoreEntry(a, `${query} 上周`, NOW));
|
|
154
|
+
assert.deepEqual(withoutDate.map((item) => item.id), withDate.map((item) => item.id));
|
|
155
|
+
});
|
|
156
|
+
test('the summary tier orders its in-window entries ahead of equally scored ones', () => {
|
|
157
|
+
const query = '上个月那个发票接口的问题怎么解决的';
|
|
158
|
+
const old = entry('invoice-old', {
|
|
159
|
+
title: '发票接口的问题',
|
|
160
|
+
body: '发票接口返回 500,最后发现是发票号码字段为空。',
|
|
161
|
+
createdAt: at(2026, 3, 1),
|
|
162
|
+
updatedAt: at(2026, 3, 1),
|
|
163
|
+
});
|
|
164
|
+
const recent = entry('invoice-recent', {
|
|
165
|
+
title: '发票接口的问题',
|
|
166
|
+
body: '发票接口返回 500,最后发现是发票号码字段为空。',
|
|
167
|
+
createdAt: at(2026, 8, 20),
|
|
168
|
+
updatedAt: at(2026, 8, 20),
|
|
169
|
+
});
|
|
170
|
+
assert.deepEqual(rankForSummary([old, recent], NOW, query).map((item) => item.id), ['invoice-recent', 'invoice-old']);
|
|
171
|
+
});
|