dsh-lite-memory 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lite-memory",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "On-demand memory for the DeepSeek Harness: nothing in the system prompt, one muted line only when something is saved, hit or suggested.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -26,7 +26,8 @@
26
26
  "icon.svg",
27
27
  "README.md",
28
28
  "TRIGGERS.md",
29
- "LICENSE"
29
+ "LICENSE",
30
+ "test"
30
31
  ],
31
32
  "dsh": {
32
33
  "bundle": {
@@ -0,0 +1,65 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import * as store from '../store.js';
6
+
7
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'lite-memory-'));
8
+ process.env.DSH_HOME = home;
9
+
10
+ const scope = store.scopeOf('/tmp/project-a');
11
+ const other = store.scopeOf('/tmp/project-b');
12
+ const draft = { title: '插件市场条目规范', summary: '市场上传指南的位置与要点', body: '见 UPLOAD-GUIDE.md', kind: 'pointer', tags: ['marketplace'] };
13
+
14
+ const first = store.upsert(scope, draft);
15
+ assert.equal(first.merged, false);
16
+ assert.equal(store.loadIndex(scope).entries.length, 1);
17
+
18
+ const second = store.upsert(scope, { ...draft, summary: '市场上传指南的位置与要点(更新)' });
19
+ assert.equal(second.merged, true);
20
+ assert.equal(second.record.id, first.record.id);
21
+ assert.equal(store.loadIndex(scope).entries.length, 1);
22
+ assert.equal(store.loadIndex(scope).entries[0].merges, 1);
23
+
24
+ assert.deepEqual(store.search(scope, '插件市场').map((item) => item.id), [first.record.id]);
25
+ assert.deepEqual(store.search(scope, '量子力学'), []);
26
+ assert.deepEqual(store.loadIndex(other).entries, []);
27
+
28
+ assert.throws(() => store.upsert(scope, { title: 'x', summary: '你要记得用 tab 缩进' }), /名词短语/);
29
+ assert.throws(() => store.upsert(scope, { title: 'y', summary: '凭据位置', body: 'ghp_abcdefghijklmnopqrstuvwxyz0123456789' }), /凭据/);
30
+
31
+ const read = store.readEntry(scope, first.record.id);
32
+ assert.match(read.body, /UPLOAD-GUIDE/);
33
+ assert.ok(store.loadIndex(scope).entries[0].hits >= 2);
34
+
35
+ assert.equal(store.suggestionGate(scope, '插件市场条目规范').ok, false);
36
+ store.noteSuggestion(scope, '提交前先跑 lint');
37
+ assert.equal(store.suggestionGate(scope, '另一条').ok, false);
38
+ store.upsert(scope, { title: '提交前先跑 lint', summary: '交付前的文案检查步骤' });
39
+ assert.equal(store.suggestionGate(scope, '新的建议').ok, true);
40
+
41
+ const old = store.upsert(scope, { title: '很久没用到的条目', summary: '三个月没命中', body: 'x' });
42
+ const index = store.loadIndex(scope);
43
+ index.entries = index.entries.map((item) =>
44
+ item.id === old.record.id ? { ...item, lastUsed: new Date(Date.now() - 400 * 86400000).toISOString() } : item,
45
+ );
46
+ store.saveIndex(scope, index);
47
+ const stale = store.loadIndex(scope).entries.find((item) => item.id === old.record.id);
48
+ const rendered = store.renderIndex([stale]);
49
+ assert.equal(rendered.text.includes('|'), false);
50
+ assert.ok(rendered.text.includes(old.record.title));
51
+
52
+ const forgotten = store.forget(scope, first.record.id);
53
+ assert.equal(forgotten.title, draft.title);
54
+ assert.equal(store.loadIndex(scope).entries.some((item) => item.id === first.record.id), false);
55
+ assert.ok(fs.existsSync(path.join(scope.dir, 'archive', `${first.record.id}.md`)));
56
+
57
+ for (let i = 0; i < 240; i += 1) {
58
+ store.upsert(scope, { title: `条目 ${i}`, summary: `第 ${i} 条`, body: 'x' });
59
+ }
60
+ const trimmed = store.loadIndex(scope);
61
+ assert.ok(trimmed.entries.length <= store.LIMITS.entries);
62
+ assert.ok(trimmed.totalBytes <= store.LIMITS.totalBytes);
63
+
64
+ fs.rmSync(home, { recursive: true, force: true });
65
+ console.log('store: 16 checks passed');