@modusensus/dsh-mneme 0.8.14 → 0.8.15
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 -21
- package/README.md +655 -654
- package/assets/icon.svg +3 -3
- package/bin/cli.mjs +689 -689
- package/bin/dsh-mneme-mcp.mjs +510 -510
- package/bin/dsh-mneme-serve.mjs +151 -151
- package/cordis.patch.yml +21 -21
- package/docs/CONFIGURATION.md +263 -0
- package/docs/CONTINUITY.md +124 -0
- package/docs/DAEMON.md +46 -0
- package/docs/ENTITIES.md +245 -0
- package/docs/LOCAL_MODEL.md +222 -0
- package/docs/SEMANTIC.md +256 -0
- package/docs/SLEEP.md +164 -0
- package/docs/STORAGE.md +89 -0
- package/lib/api-standalone.js +673 -673
- package/lib/api.js +1437 -1433
- package/lib/bootstrap.js +211 -211
- package/lib/client.js +5444 -5295
- package/lib/commands.js +95 -95
- package/lib/config.js +880 -843
- package/lib/content-hash.js +54 -54
- package/lib/continuity.js +220 -220
- package/lib/document-index.js +94 -94
- package/lib/document.js +303 -303
- package/lib/dream/clustering.js +118 -118
- package/lib/dream/decisions.js +674 -674
- package/lib/dream/narratives.js +44 -44
- package/lib/dream/sleep.js +819 -819
- package/lib/dream.js +1501 -1501
- package/lib/embedding.js +177 -177
- package/lib/entities/extractor.js +252 -252
- package/lib/graph/anchoring.js +179 -179
- package/lib/guide.js +74 -74
- package/lib/heat.js +144 -144
- package/lib/hot-memory.js +46 -46
- package/lib/index.js +535 -503
- package/lib/inject.js +464 -450
- package/lib/lang.js +248 -229
- package/lib/local-embedder.js +358 -358
- package/lib/maintenance.js +142 -142
- package/lib/mirror.js +330 -330
- package/lib/organize.js +450 -450
- package/lib/peak-hours.js +117 -117
- package/lib/placement.js +13 -0
- package/lib/pre-inject-gate.js +340 -0
- package/lib/quality-filter.js +126 -126
- package/lib/recall-stats.js +175 -175
- package/lib/reranker.js +269 -269
- package/lib/runtime/adopt.js +176 -176
- package/lib/runtime/closure.js +172 -172
- package/lib/runtime/download.js +247 -247
- package/lib/runtime/layout.js +265 -265
- package/lib/runtime/loader.js +252 -252
- package/lib/runtime/model-fetch.js +361 -361
- package/lib/runtime/provision.js +237 -237
- package/lib/runtime/tarball.js +130 -130
- package/lib/runtime/verify.js +223 -204
- package/lib/scope.js +146 -146
- package/lib/search/adaptive.js +60 -60
- package/lib/search/bm25.js +96 -96
- package/lib/semantic.js +229 -229
- package/lib/sensitive-scan.js +209 -209
- package/lib/serve.js +215 -215
- package/lib/service.js +2663 -2605
- package/lib/settings.js +517 -511
- package/lib/store.js +3007 -3007
- package/lib/summarize.js +891 -856
- package/lib/tools.js +743 -737
- package/lib/vector-index.js +110 -110
- package/lib/version-check.js +122 -122
- package/lib/write-admission.js +402 -402
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/package.json +118 -118
- package/runtime-manifest.json +526 -526
- package/scripts/benchmark-embed.js +201 -201
- package/scripts/benchmark-recall.js +249 -249
- package/scripts/benchmark-rerank.js +166 -166
- package/scripts/build-runtime-manifest.mjs +224 -224
- package/scripts/changelog-prep.mjs +36 -36
- package/scripts/check-sync.js +42 -42
- package/scripts/e2e-dsh.js +220 -220
- package/scripts/mneme-runtime.mjs +277 -277
- package/scripts/stress-dsh.js +255 -255
- package/scripts/sync-lib.js +47 -47
- package/scripts/sync-test-badge.mjs +69 -69
- package/scripts/test-count-sync.mjs +44 -44
- package/src/api-standalone.js +673 -673
- package/src/api.js +1437 -1433
- package/src/bootstrap.js +211 -211
- package/src/commands.js +95 -95
- package/src/config.js +880 -843
- package/src/content-hash.js +54 -54
- package/src/continuity.js +220 -220
- package/src/document-index.js +94 -94
- package/src/document.js +303 -303
- package/src/dream/clustering.js +118 -118
- package/src/dream/decisions.js +674 -674
- package/src/dream/narratives.js +44 -44
- package/src/dream/sleep.js +819 -819
- package/src/dream.js +1501 -1501
- package/src/embedding.js +177 -177
- package/src/entities/extractor.js +252 -252
- package/src/graph/anchoring.js +179 -179
- package/src/guide.js +74 -74
- package/src/heat.js +144 -144
- package/src/hot-memory.js +46 -46
- package/src/index.js +535 -503
- package/src/inject.js +464 -450
- package/src/lang.js +248 -229
- package/src/local-embedder.js +358 -358
- package/src/maintenance.js +142 -142
- package/src/mirror.js +330 -330
- package/src/organize.js +450 -450
- package/src/peak-hours.js +117 -117
- package/src/placement.js +13 -0
- package/src/pre-inject-gate.js +340 -0
- package/src/quality-filter.js +126 -126
- package/src/recall-stats.js +175 -175
- package/src/reranker.js +269 -269
- package/src/runtime/adopt.js +176 -176
- package/src/runtime/closure.js +172 -172
- package/src/runtime/download.js +247 -247
- package/src/runtime/layout.js +265 -265
- package/src/runtime/loader.js +252 -252
- package/src/runtime/model-fetch.js +361 -361
- package/src/runtime/provision.js +237 -237
- package/src/runtime/tarball.js +130 -130
- package/src/runtime/verify.js +223 -204
- package/src/scope.js +146 -146
- package/src/search/adaptive.js +60 -60
- package/src/search/bm25.js +96 -96
- package/src/semantic.js +229 -229
- package/src/sensitive-scan.js +209 -209
- package/src/serve.js +215 -215
- package/src/service.js +2663 -2605
- package/src/settings.js +517 -511
- package/src/store.js +3007 -3007
- package/src/summarize.js +891 -856
- package/src/tools.js +743 -737
- package/src/vector-index.js +110 -110
- package/src/version-check.js +122 -122
- package/src/write-admission.js +402 -402
- package/test/adaptive-inject-budget.test.js +85 -85
- package/test/api-routes-gaps.test.js +218 -218
- package/test/api.test.js +1702 -1690
- package/test/audit.test.js +448 -448
- package/test/baseline-persist.test.js +248 -248
- package/test/benchmark.test.js +94 -94
- package/test/bootstrap.test.js +220 -220
- package/test/changelog-prep.test.js +60 -60
- package/test/client.test.js +1230 -1169
- package/test/clustering.test.js +100 -100
- package/test/commands.test.js +106 -106
- package/test/config.test.js +66 -66
- package/test/conflict-freeze.test.js +300 -300
- package/test/content-hash.test.js +204 -204
- package/test/continuity.test.js +333 -333
- package/test/document-dir.test.js +233 -233
- package/test/document.test.js +671 -671
- package/test/dream-archive-guardrail.test.js +116 -116
- package/test/dream-candidate-hybrid.test.js +281 -281
- package/test/dream-coverage-degrade.test.js +86 -86
- package/test/dream-failure-backoff.test.js +173 -173
- package/test/dream-peak-hours.test.js +194 -194
- package/test/dream.test.js +1385 -1383
- package/test/embedding-ready.test.js +196 -196
- package/test/entities.test.js +627 -547
- package/test/entity-recall.test.js +179 -179
- package/test/epistemic.test.js +325 -325
- package/test/fnew-0112.test.js +311 -311
- package/test/fnew-03.test.js +422 -422
- package/test/graph-anchoring.test.js +184 -184
- package/test/graph-api.test.js +175 -175
- package/test/graph-inject-budget.test.js +103 -103
- package/test/graph-passive-confirm.test.js +91 -91
- package/test/graph-weight-evolution.test.js +104 -104
- package/test/heat.test.js +175 -175
- package/test/helpers/dream-mock.js +82 -82
- package/test/helpers/peer-worker.mjs +25 -25
- package/test/helpers/runtime-source.js +60 -60
- package/test/helpers/tar-builder.js +80 -80
- package/test/helpers/write-admission-samples.js +308 -308
- package/test/hot-memory.test.js +145 -145
- package/test/inject-content-cap.test.js +91 -91
- package/test/inject-first-round-bm25.test.js +89 -89
- package/test/inject-heat.test.js +77 -77
- package/test/inject-parent-gate.test.js +106 -106
- package/test/inject-pools.test.js +194 -194
- package/test/inject-recall.test.js +105 -105
- package/test/inject-rotation.test.js +161 -161
- package/test/inject.test.js +420 -420
- package/test/lang.test.js +87 -87
- package/test/lastrunat-persist.test.js +101 -101
- package/test/lib-smoke.test.js +96 -96
- package/test/llm-audit.test.js +598 -598
- package/test/llm-message-source.test.js +207 -207
- package/test/local-embedder.test.js +292 -292
- package/test/maintenance.test.js +391 -391
- package/test/mcp-stdio.test.js +385 -385
- package/test/mirror-dirty.test.js +424 -424
- package/test/mirror-edit-digest.test.js +187 -187
- package/test/mirror-generation.test.js +499 -499
- package/test/mirror-types.test.js +208 -208
- package/test/mirror.test.js +249 -249
- package/test/narrative-bars.test.js +162 -162
- package/test/organize.test.js +418 -418
- package/test/peer-blockers.test.js +193 -193
- package/test/placement.test.js +36 -0
- package/test/policy-epoch.test.js +259 -259
- package/test/pre-inject-gate.test.js +434 -0
- package/test/quality-filter.test.js +186 -186
- package/test/reasoning-effort.test.js +752 -752
- package/test/recall-anti-update.test.js +82 -82
- package/test/recall-evals.test.js +253 -253
- package/test/recall-layer.test.js +326 -326
- package/test/recall-stats.test.js +189 -189
- package/test/receipt-chain.test.js +451 -451
- package/test/reflection.test.js +226 -226
- package/test/reindex-backfill.test.js +62 -62
- package/test/reranker-single-logit.test.js +73 -73
- package/test/reranker.test.js +197 -197
- package/test/resident-status.test.js +83 -83
- package/test/runtime-adopt.test.js +206 -206
- package/test/runtime-cli.test.js +89 -89
- package/test/runtime-closure.test.js +193 -193
- package/test/runtime-download.test.js +302 -302
- package/test/runtime-layout.test.js +163 -163
- package/test/runtime-loader.test.js +255 -255
- package/test/runtime-manifest.test.js +159 -159
- package/test/runtime-model-fetch.test.js +348 -348
- package/test/runtime-provision.test.js +101 -101
- package/test/runtime-tarball.test.js +81 -81
- package/test/runtime-verify.test.js +319 -279
- package/test/scope-candidates.test.js +239 -239
- package/test/scope-explicit.test.js +452 -452
- package/test/scope-inject-soft.test.js +106 -106
- package/test/scope-retrieval.test.js +197 -197
- package/test/scope-storage.test.js +255 -255
- package/test/scope-strict.test.js +367 -367
- package/test/search-fusion.test.js +90 -90
- package/test/semantic.test.js +124 -124
- package/test/sensitive-scan.test.js +207 -207
- package/test/serve-bin.test.js +121 -121
- package/test/serve.test.js +196 -196
- package/test/service-search.test.js +174 -174
- package/test/service.test.js +405 -405
- package/test/settings.test.js +261 -261
- package/test/skip-invalid-restore.test.js +262 -262
- package/test/sleep-action-set.test.js +422 -422
- package/test/sleep-heat.test.js +126 -126
- package/test/sleep-scheduler-rearm.test.js +89 -89
- package/test/sleep.test.js +527 -527
- package/test/standalone-api.test.js +751 -751
- package/test/store-vector-cache.test.js +98 -98
- package/test/store.test.js +396 -396
- package/test/stress.test.js +209 -209
- package/test/summarize-occurred-at.test.js +127 -0
- package/test/summarize-reasoning-effort.test.js +189 -189
- package/test/summarize.test.js +1465 -1465
- package/test/supersede-state-tracking.test.js +394 -0
- package/test/test-count-sync.test.js +60 -60
- package/test/tools-dto-schema-matrix.test.js +325 -325
- package/test/tools-memory-get-schema.test.js +65 -65
- package/test/tools.test.js +428 -374
- package/test/updated-at-semantics.test.js +113 -113
- package/test/vector-index.test.js +221 -221
- package/test/version-check.test.js +152 -152
- package/test/webServer-optional.test.js +82 -82
- package/test/write-admission.test.js +668 -668
package/test/tools.test.js
CHANGED
|
@@ -1,374 +1,428 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { assertSupportedJsonSchema, validateJsonSchemaValue } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import { createStore } from "../src/store.js";
|
|
5
|
-
import { createService } from "../src/service.js";
|
|
6
|
-
import { existsSync, mkdtempSync, readdirSync } from "node:fs";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { createTools } from "../src/tools.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (typeof node
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
assert.match(search.description, /
|
|
86
|
-
assert.match(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
assertSupportedJsonSchema(tool.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
walkSchema(tool.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
assert.equal(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
assert.equal(
|
|
117
|
-
assert.equal(
|
|
118
|
-
assert.equal(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
assert.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const {
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
assert.equal(res.memory.
|
|
141
|
-
assert.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
assert.ok(text.includes(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
service.saveWithDedupe({ type: "
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
assert.
|
|
165
|
-
assert.ok(text.includes("
|
|
166
|
-
assert.ok(text.includes("
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
service.saveWithDedupe({ type: "
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
assert.
|
|
178
|
-
assert.ok(text.includes("
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
service.saveWithDedupe({ type: "
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
assert.equal(result.items
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
service.saveWithDedupe({ type: "preference", title: "
|
|
195
|
-
service.saveWithDedupe({ type: "
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const {
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const {
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
assert.equal(
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
assert.equal(res.items
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const {
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
assert.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
assert.
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const {
|
|
339
|
-
service.
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
assert.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
assert.
|
|
365
|
-
assert.
|
|
366
|
-
assert.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
assert.
|
|
372
|
-
assert.
|
|
373
|
-
assert.
|
|
374
|
-
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { assertSupportedJsonSchema, validateJsonSchemaValue } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import { createStore } from "../src/store.js";
|
|
5
|
+
import { createService } from "../src/service.js";
|
|
6
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { createTools } from "../src/tools.js";
|
|
10
|
+
import { TRANSFORMERS_ENTRY, defaultModelCacheDir, payloadDir, payloadId } from "../src/runtime/layout.js";
|
|
11
|
+
|
|
12
|
+
function setup(embedder, config = {}) {
|
|
13
|
+
const store = createStore(":memory:");
|
|
14
|
+
const service = createService({ store, mirror: null, config: {} });
|
|
15
|
+
const registered = [];
|
|
16
|
+
const ctx = {
|
|
17
|
+
tools: {
|
|
18
|
+
register(def) {
|
|
19
|
+
registered.push(def);
|
|
20
|
+
return () => {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const tools = createTools(ctx, service, config, embedder);
|
|
25
|
+
return { store, service, tools, registered };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Collect authoring-DSL regressions in a compiled schema: property-level
|
|
29
|
+
// `required: true` (must be projected to a top-level required array by
|
|
30
|
+
// defineTool) and `minimum`/`maximum` (outside the enforced subset) are
|
|
31
|
+
// rejected by the real harness, so they must never appear post-compilation.
|
|
32
|
+
function walkSchema(node, path, problems) {
|
|
33
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) return;
|
|
34
|
+
if (typeof node.required === "boolean") {
|
|
35
|
+
problems.push(`${path}.required must be an array (property-level required leaks through)`);
|
|
36
|
+
}
|
|
37
|
+
if (Object.hasOwn(node, "minimum") || Object.hasOwn(node, "maximum")) {
|
|
38
|
+
problems.push(`${path} uses minimum/maximum, which the enforced JSON Schema subset rejects`);
|
|
39
|
+
}
|
|
40
|
+
if (node.properties && typeof node.properties === "object") {
|
|
41
|
+
for (const [key, value] of Object.entries(node.properties)) {
|
|
42
|
+
walkSchema(value, `${path}.properties.${key}`, problems);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (node.items) walkSchema(node.items, `${path}.items`, problems);
|
|
46
|
+
if (Array.isArray(node.oneOf)) {
|
|
47
|
+
node.oneOf.forEach((branch, index) => walkSchema(branch, `${path}.oneOf[${index}]`, problems));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
test("registers ten tools with correct names", () => {
|
|
52
|
+
const { registered } = setup();
|
|
53
|
+
const names = registered.map((t) => t.name).sort();
|
|
54
|
+
// #230 新增 memory_register_document(agent 产长文档的指针行铸造口)。
|
|
55
|
+
assert.deepEqual(names, ["memory_archive", "memory_delete", "memory_forget", "memory_get", "memory_list", "memory_register_document", "memory_runtime", "memory_save", "memory_search", "memory_update"]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// v0.8.5 tool-exposure gate: disabling a tool hides it from the model entirely
|
|
59
|
+
// (it is not registered), which is the reliable lever against over-calling on
|
|
60
|
+
// slow/lightweight models — the injected memory block already covers recall.
|
|
61
|
+
test("disableMemorySearch hides only memory_search", () => {
|
|
62
|
+
const { registered } = setup({}, { disableMemorySearch: true });
|
|
63
|
+
const names = registered.map((t) => t.name).sort();
|
|
64
|
+
assert.deepEqual(names, ["memory_archive", "memory_delete", "memory_forget", "memory_get", "memory_list", "memory_register_document", "memory_runtime", "memory_save", "memory_update"]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("disableMemoryArchive hides only memory_archive", () => {
|
|
68
|
+
const { registered } = setup({}, { disableMemoryArchive: true });
|
|
69
|
+
const names = registered.map((t) => t.name).sort();
|
|
70
|
+
assert.deepEqual(names, ["memory_delete", "memory_forget", "memory_get", "memory_list", "memory_register_document", "memory_runtime", "memory_save", "memory_search", "memory_update"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("both disable flags hide both tools", () => {
|
|
74
|
+
const { registered } = setup({}, { disableMemorySearch: true, disableMemoryArchive: true });
|
|
75
|
+
const names = registered.map((t) => t.name).sort();
|
|
76
|
+
assert.deepEqual(names, ["memory_delete", "memory_forget", "memory_get", "memory_list", "memory_register_document", "memory_runtime", "memory_save", "memory_update"]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Description discipline: with all tools exposed, the descriptions must steer a
|
|
80
|
+
// weak model away from calling them every turn.
|
|
81
|
+
test("memory_search/archive descriptions carry tool-use discipline", () => {
|
|
82
|
+
const { registered } = setup();
|
|
83
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
84
|
+
const archive = registered.find((t) => t.name === "memory_archive");
|
|
85
|
+
assert.match(search.description, /already injected into your context every turn/i);
|
|
86
|
+
assert.match(search.description, /only call this when/i);
|
|
87
|
+
assert.match(archive.description, /do not archive proactively mid-session/i);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("compiled schemas pass the enforced DSH subset (defineTool projection)", () => {
|
|
91
|
+
const { registered } = setup();
|
|
92
|
+
assert.equal(registered.length, 10);
|
|
93
|
+
for (const tool of registered) {
|
|
94
|
+
assertSupportedJsonSchema(tool.parameters);
|
|
95
|
+
assertSupportedJsonSchema(tool.output.schema);
|
|
96
|
+
const problems = [];
|
|
97
|
+
walkSchema(tool.parameters, `parameters(${tool.name})`, problems);
|
|
98
|
+
walkSchema(tool.output.schema, `output.schema(${tool.name})`, problems);
|
|
99
|
+
assert.deepEqual(problems, []);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("memory_save executes and stores", async () => {
|
|
104
|
+
const { registered, store } = setup();
|
|
105
|
+
const save = registered.find((t) => t.name === "memory_save");
|
|
106
|
+
const result = await save.execute({ type: "preference", title: "语言", content: "中文", importance: 4 });
|
|
107
|
+
assert.equal(result.action, "created");
|
|
108
|
+
assert.equal(store.count(), 1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("memory_save merges on matching title within type", async () => {
|
|
112
|
+
const { registered, store } = setup();
|
|
113
|
+
const save = registered.find((t) => t.name === "memory_save");
|
|
114
|
+
const first = await save.execute({ type: "preference", title: "语言", content: "中文" });
|
|
115
|
+
const second = await save.execute({ type: "preference", title: "语言", content: "简体中文" });
|
|
116
|
+
assert.equal(first.action, "created");
|
|
117
|
+
assert.equal(second.action, "merged");
|
|
118
|
+
assert.equal(first.id, second.id);
|
|
119
|
+
assert.equal(store.count(), 1);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("memory_search finds by CJK substring", async () => {
|
|
123
|
+
const { registered, store, service } = setup();
|
|
124
|
+
service.saveWithDedupe({ type: "project", title: "记忆插件", content: "SQLite 存储中文记忆", importance: 3 });
|
|
125
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
126
|
+
const result = await search.execute({ query: "中文" });
|
|
127
|
+
assert.ok(result.items.length >= 1);
|
|
128
|
+
assert.equal(result.items[0].title, "记忆插件");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Regression: memory_get.execute must live on the defineTool options (top
|
|
132
|
+
// level), NOT nested inside output — a misplaced execute silently becomes
|
|
133
|
+
// options.execute === undefined and every call throws "userExecute is not a
|
|
134
|
+
// function" while tests that only count tool names still pass.
|
|
135
|
+
test("memory_get returns the full body via execute and render", async () => {
|
|
136
|
+
const { registered, service } = setup();
|
|
137
|
+
const { memory } = service.saveWithDedupe({ type: "decision", title: "t", content: "完整正文内容" });
|
|
138
|
+
const get = registered.find((t) => t.name === "memory_get");
|
|
139
|
+
const res = await get.execute({ id: memory.id });
|
|
140
|
+
assert.equal(res.memory.id, memory.id);
|
|
141
|
+
assert.equal(res.memory.content, "完整正文内容");
|
|
142
|
+
assert.deepEqual(validateJsonSchemaValue(get.output.schema, res), []);
|
|
143
|
+
const text = get.output.render({}, res)[0].text;
|
|
144
|
+
assert.ok(text.includes("完整正文内容"), "full body in render");
|
|
145
|
+
assert.ok(text.includes(memory.id) && text.includes("t"), "id + title in render");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("memory_get on missing id rejects", async () => {
|
|
149
|
+
const { registered } = setup();
|
|
150
|
+
const get = registered.find((t) => t.name === "memory_get");
|
|
151
|
+
await assert.rejects(() => get.execute({ id: "missing" }), /memory not found/);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Render output is what hosts surface to the model (not the structured JSON),
|
|
155
|
+
// so it must embed titles + body previews, not just a hit count.
|
|
156
|
+
test("memory_search render embeds titles and body previews, not just a count", async () => {
|
|
157
|
+
const { registered, service } = setup();
|
|
158
|
+
service.saveWithDedupe({ type: "history", title: "旅行计划", content: "用户当前最苦恼时间安排与伦敦行程" });
|
|
159
|
+
service.saveWithDedupe({ type: "project", title: "插件定位", content: "dsh-mneme 插件做记忆沉淀" });
|
|
160
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
161
|
+
const res = await search.execute({ query: "时间" });
|
|
162
|
+
assert.ok(res.items.length >= 1, "search hit exists");
|
|
163
|
+
const text = search.output.render({}, res)[0].text;
|
|
164
|
+
assert.match(text, /Found \d+ memory entr/);
|
|
165
|
+
assert.ok(text.includes("旅行计划"), "title embedded in render");
|
|
166
|
+
assert.ok(text.includes("伦敦行程"), "body preview embedded in render");
|
|
167
|
+
assert.ok(text.includes("ID: "), "id embedded");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("memory_list render embeds titles and ids, not just counts", async () => {
|
|
171
|
+
const { registered, service } = setup();
|
|
172
|
+
service.saveWithDedupe({ type: "preference", title: "昵称", content: "桉桉" });
|
|
173
|
+
service.saveWithDedupe({ type: "project", title: "博客", content: "modusensus" });
|
|
174
|
+
const list = registered.find((t) => t.name === "memory_list");
|
|
175
|
+
const res = await list.execute({});
|
|
176
|
+
const text = list.output.render({}, res)[0].text;
|
|
177
|
+
assert.match(text, /\d+ memory entries \(of \d+\):/);
|
|
178
|
+
assert.ok(text.includes("昵称") && text.includes("博客"), "titles embedded");
|
|
179
|
+
assert.ok(text.includes("ID: "), "ids embedded");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("memory_list filters by type", async () => {
|
|
183
|
+
const { registered, service } = setup();
|
|
184
|
+
service.saveWithDedupe({ type: "preference", title: "a", content: "x" });
|
|
185
|
+
service.saveWithDedupe({ type: "project", title: "b", content: "y" });
|
|
186
|
+
const list = registered.find((t) => t.name === "memory_list");
|
|
187
|
+
const result = await list.execute({ type: "project" });
|
|
188
|
+
assert.equal(result.items.length, 1);
|
|
189
|
+
assert.equal(result.items[0].title, "b");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("memory_list total reflects the type filter", async () => {
|
|
193
|
+
const { registered, service } = setup();
|
|
194
|
+
service.saveWithDedupe({ type: "preference", title: "a", content: "x" });
|
|
195
|
+
service.saveWithDedupe({ type: "preference", title: "b", content: "y" });
|
|
196
|
+
service.saveWithDedupe({ type: "project", title: "c", content: "z" });
|
|
197
|
+
const list = registered.find((t) => t.name === "memory_list");
|
|
198
|
+
const projectRes = await list.execute({ type: "project" });
|
|
199
|
+
assert.equal(projectRes.total, 1);
|
|
200
|
+
const allRes = await list.execute({});
|
|
201
|
+
assert.equal(allRes.total, 3);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("memory_update modifies an entry", async () => {
|
|
205
|
+
const { registered, service } = setup();
|
|
206
|
+
const { memory } = service.saveWithDedupe({ type: "decision", title: "t", content: "c" });
|
|
207
|
+
const update = registered.find((t) => t.name === "memory_update");
|
|
208
|
+
const result = await update.execute({ id: memory.id, content: "updated" });
|
|
209
|
+
assert.equal(result.memory.content, "updated");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("memory_update on missing id rejects", async () => {
|
|
213
|
+
const { registered } = setup();
|
|
214
|
+
const update = registered.find((t) => t.name === "memory_update");
|
|
215
|
+
await assert.rejects(() => update.execute({ id: "missing", content: "x" }), /memory not found/);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("memory_delete removes an entry", async () => {
|
|
219
|
+
const { registered, service, store } = setup();
|
|
220
|
+
const { memory } = service.saveWithDedupe({ type: "decision", title: "t", content: "c" });
|
|
221
|
+
const del = registered.find((t) => t.name === "memory_delete");
|
|
222
|
+
await del.execute({ id: memory.id });
|
|
223
|
+
assert.equal(store.count(), 0);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("memory_delete on missing id returns deleted:false", async () => {
|
|
227
|
+
const { registered } = setup();
|
|
228
|
+
const del = registered.find((t) => t.name === "memory_delete");
|
|
229
|
+
const result = await del.execute({ id: "missing" });
|
|
230
|
+
assert.equal(result.deleted, false);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("memory_forget suppresses injection without deleting", async () => {
|
|
234
|
+
const { registered, service, store } = setup();
|
|
235
|
+
const { memory } = service.saveWithDedupe({ type: "project", title: "t", content: "c", importance: 5 });
|
|
236
|
+
const forget = registered.find((t) => t.name === "memory_forget");
|
|
237
|
+
const result = await forget.execute({ id: memory.id });
|
|
238
|
+
assert.equal(result.memory.forgotten, true);
|
|
239
|
+
assert.equal(store.count(undefined, { includeForgotten: true }), 1, "still stored but suppressed");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("memory_forget on missing id rejects", async () => {
|
|
243
|
+
const { registered } = setup();
|
|
244
|
+
const forget = registered.find((t) => t.name === "memory_forget");
|
|
245
|
+
await assert.rejects(() => forget.execute({ id: "missing" }), /memory not found/);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("memory_forget restores with forgotten:false", async () => {
|
|
249
|
+
const { registered, service } = setup();
|
|
250
|
+
const { memory } = service.saveWithDedupe({ type: "project", title: "t", content: "c", importance: 5 });
|
|
251
|
+
const forget = registered.find((t) => t.name === "memory_forget");
|
|
252
|
+
await forget.execute({ id: memory.id });
|
|
253
|
+
const restored = await forget.execute({ id: memory.id, forgotten: false });
|
|
254
|
+
assert.equal(restored.memory.forgotten, false);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("execution results validate against their declared output schemas", async () => {
|
|
258
|
+
const { registered, service } = setup();
|
|
259
|
+
const byName = (n) => registered.find((t) => t.name === n);
|
|
260
|
+
|
|
261
|
+
const saved = await byName("memory_save").execute({ type: "decision", title: "x", content: "y", tags: ["k"], source: "test" });
|
|
262
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_save").output.schema, saved), []);
|
|
263
|
+
|
|
264
|
+
service.saveWithDedupe({ type: "project", title: "p", content: "q" });
|
|
265
|
+
const searchRes = await byName("memory_search").execute({ query: "q" });
|
|
266
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_search").output.schema, searchRes), []);
|
|
267
|
+
|
|
268
|
+
const listRes = await byName("memory_list").execute({});
|
|
269
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_list").output.schema, listRes), []);
|
|
270
|
+
|
|
271
|
+
const updRes = await byName("memory_update").execute({ id: saved.id, content: "z" });
|
|
272
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_update").output.schema, updRes), []);
|
|
273
|
+
|
|
274
|
+
const forgetRes = await byName("memory_forget").execute({ id: saved.id });
|
|
275
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_forget").output.schema, forgetRes), []);
|
|
276
|
+
|
|
277
|
+
const delRes = await byName("memory_delete").execute({ id: saved.id });
|
|
278
|
+
assert.deepEqual(validateJsonSchemaValue(byName("memory_delete").output.schema, delRes), []);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("memory_search semantic mode merges vector recalls", async () => {
|
|
282
|
+
const store = createStore(":memory:");
|
|
283
|
+
const service = createService({ store, mirror: null, config: {} });
|
|
284
|
+
const registered = [];
|
|
285
|
+
const ctx = { tools: { register(def) { registered.push(def); return () => {}; } } };
|
|
286
|
+
const embedder = { embed: async () => [1, 0, 0] };
|
|
287
|
+
createTools(ctx, service, {}, embedder);
|
|
288
|
+
|
|
289
|
+
const v = service.saveWithDedupe({ type: "preference", title: "猫", content: "喜欢猫" });
|
|
290
|
+
store.setEmbedding(v.memory.id, [1, 0, 0]);
|
|
291
|
+
service.saveWithDedupe({ type: "preference", title: "狗", content: "喜欢狗" });
|
|
292
|
+
|
|
293
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
294
|
+
// literal query matches only 猫; vector recall also surfaces it via embedding
|
|
295
|
+
const res = await search.execute({ query: "猫", semantic: true });
|
|
296
|
+
assert.ok(res.items.some((m) => m.title === "猫"), "vector + keyword merged result contains the hit");
|
|
297
|
+
// mode=vector keeps keyword items too (dedup merge)
|
|
298
|
+
const res2 = await search.execute({ query: "猫", mode: "vector" });
|
|
299
|
+
assert.ok(res2.items.some((m) => m.title === "猫"));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("memory_search falls back to keyword when embedder unavailable or returns null", async () => {
|
|
303
|
+
// No embedder passed → plain keyword search still works.
|
|
304
|
+
const { registered, service } = setup();
|
|
305
|
+
service.saveWithDedupe({ type: "preference", title: "语言", content: "中文交流" });
|
|
306
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
307
|
+
const res = await search.execute({ query: "中文", semantic: true });
|
|
308
|
+
assert.equal(res.items.length, 1);
|
|
309
|
+
assert.equal(res.items[0].title, "语言");
|
|
310
|
+
|
|
311
|
+
// Embedder that resolves null (provider disabled) → keyword fallback.
|
|
312
|
+
const store = createStore(":memory:");
|
|
313
|
+
const service2 = createService({ store, mirror: null, config: {} });
|
|
314
|
+
const registered2 = [];
|
|
315
|
+
const ctx = { tools: { register(def) { registered2.push(def); return () => {}; } } };
|
|
316
|
+
createTools(ctx, service2, {}, { embed: async () => null });
|
|
317
|
+
service2.saveWithDedupe({ type: "preference", title: "语言", content: "中文交流" });
|
|
318
|
+
const search2 = registered2.find((t) => t.name === "memory_search");
|
|
319
|
+
const res2 = await search2.execute({ query: "中文", semantic: true });
|
|
320
|
+
assert.equal(res2.items.length, 1);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// --- memory_archive (item ⑤: archive + verifiable recovery) ----------------
|
|
324
|
+
|
|
325
|
+
test("memory_archive hides an entry and memory_unarchive restores it", async () => {
|
|
326
|
+
const { registered, service } = setup();
|
|
327
|
+
const { memory: m } = service.saveWithDedupe({ type: "project", title: "t", content: "c" });
|
|
328
|
+
const archive = registered.find((t) => t.name === "memory_archive");
|
|
329
|
+
const archived = await archive.execute({ id: m.id });
|
|
330
|
+
assert.equal(archived.memory.archived, true);
|
|
331
|
+
assert.ok(!service.list({ type: "project" }).some((x) => x.id === m.id), "archived hidden from default list");
|
|
332
|
+
const restored = await archive.execute({ id: m.id, archived: false });
|
|
333
|
+
assert.equal(restored.memory.archived, false);
|
|
334
|
+
assert.ok(service.list({ type: "project" }).some((x) => x.id === m.id), "restored entry visible again");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("memory_list include_archived lists hidden entries so they can be restored", async () => {
|
|
338
|
+
const { registered, service } = setup();
|
|
339
|
+
const { memory: m } = service.saveWithDedupe({ type: "preference", title: "a", content: "x" });
|
|
340
|
+
service.setArchived(m.id, true);
|
|
341
|
+
const list = registered.find((t) => t.name === "memory_list");
|
|
342
|
+
const hidden = await list.execute({ type: "preference", include_archived: true });
|
|
343
|
+
assert.ok(hidden.items.some((x) => x.id === m.id), "archived entry discoverable");
|
|
344
|
+
assert.equal(hidden.total, 1, "total counts the archived entry");
|
|
345
|
+
const visible = await list.execute({ type: "preference" });
|
|
346
|
+
assert.ok(!visible.items.some((x) => x.id === m.id), "archived entry hidden by default");
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("memory_archive on missing id rejects", async () => {
|
|
350
|
+
const { registered } = setup();
|
|
351
|
+
const archive = registered.find((t) => t.name === "memory_archive");
|
|
352
|
+
await assert.rejects(() => archive.execute({ id: "missing" }), /memory not found/);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test("memory_runtime:status 只读且带代价说明;两条来源都不可用时如实回报(不联网)", async () => {
|
|
356
|
+
const runtimeDir = mkdtempSync(join(tmpdir(), "mneme-tool-rt-"));
|
|
357
|
+
// 与 api 路由测试同一做法:镜像钉到必然拒绝连接的本地端口,避免测试真的去 registry 拉整套闭包。
|
|
358
|
+
const { registered } = setup(undefined, { runtimeDir, runtimeMirror: "http://127.0.0.1:1/" });
|
|
359
|
+
const tool = registered.find((t) => t.name === "memory_runtime");
|
|
360
|
+
assert.ok(tool, "应当注册 memory_runtime");
|
|
361
|
+
|
|
362
|
+
// status 是 agent 的入口:只读,而且必须带上代价,否则 agent 没法先告诉用户再动手。
|
|
363
|
+
const status = await tool.execute({ action: "status" });
|
|
364
|
+
assert.deepEqual(validateJsonSchemaValue(tool.output.schema, status), []);
|
|
365
|
+
assert.equal(status.status, "missing", "临时目录里没有 payload");
|
|
366
|
+
assert.match(status.cost, /hundreds of MB/, "代价说明要带上体积量级(刻意不写死具体数值:各平台不同、也会漂移)");
|
|
367
|
+
assert.ok(status.summary.length > 0);
|
|
368
|
+
|
|
369
|
+
// provision:仓库布局下推导出的源不是 node_modules,下载又被钉死 —— 如实回报,不抛异常。
|
|
370
|
+
const provision = await tool.execute({ action: "provision" });
|
|
371
|
+
assert.deepEqual(validateJsonSchemaValue(tool.output.schema, provision), []);
|
|
372
|
+
assert.equal(provision.status, "failed");
|
|
373
|
+
assert.match(provision.reason, /收编失败|下载失败/);
|
|
374
|
+
assert.equal(existsSync(runtimeDir) ? readdirSync(runtimeDir).length : 0, 0, "失败后不该留下半份 payload");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 造一份「结构合法、入口是可记录的假 transformers」的 payload:
|
|
379
|
+
* 让 memory_runtime 的 verify 分支能整条跑通而不真加载原生运行时。
|
|
380
|
+
* 形状照 test/runtime-loader.test.js 的 makePayload,只是入口换成会把自己收到的参数写进
|
|
381
|
+
* globalThis 的假模块 —— 面板验证的失败现场(#387)正是「它到底拿哪份模型、去哪个目录找」。
|
|
382
|
+
*/
|
|
383
|
+
function makePayloadWithFakeEntry(runtimeDir, { version = "4.2.0" } = {}) {
|
|
384
|
+
const platform = process.platform;
|
|
385
|
+
const arch = process.arch;
|
|
386
|
+
const dir = payloadDir(runtimeDir, payloadId({ version, platform, arch }));
|
|
387
|
+
const write = (rel, body) => {
|
|
388
|
+
const full = join(dir, rel);
|
|
389
|
+
mkdirSync(join(full, ".."), { recursive: true });
|
|
390
|
+
writeFileSync(full, body);
|
|
391
|
+
};
|
|
392
|
+
for (const name of ["@huggingface/transformers", "onnxruntime-node", "sharp"]) {
|
|
393
|
+
write(join("node_modules", name, "package.json"), JSON.stringify({ name, version: name === "@huggingface/transformers" ? version : "1.0.0" }));
|
|
394
|
+
}
|
|
395
|
+
// 两行归一化且不共线的向量:verifyFunctional 会验模长与退化余弦,假 engine 也得满足契约,
|
|
396
|
+
// 否则这条用例会因为「假数据不合格」而失败,锁不住接线。
|
|
397
|
+
write(TRANSFORMERS_ENTRY, `
|
|
398
|
+
export const env = {};
|
|
399
|
+
export async function pipeline(kind, model, opts) {
|
|
400
|
+
globalThis.__engineSeen = { kind, model, opts, cacheDir: env.cacheDir, remote: env.allowRemoteModels };
|
|
401
|
+
const data = Float32Array.from([0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5]);
|
|
402
|
+
return async () => ({ dims: [2, 4], data });
|
|
403
|
+
}
|
|
404
|
+
`);
|
|
405
|
+
mkdirSync(join(dir, "node_modules", "onnxruntime-node", "bin", "napi-v6", platform, arch), { recursive: true });
|
|
406
|
+
return dir;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
test("memory_runtime verify:用配置里的模型与用户级缓存目录去验(issue #387 的复现面)", async () => {
|
|
410
|
+
// #387 现场:embedModelCacheDir 默认空串 → 交给 transformers.js 时等于「不设 env.cacheDir」,
|
|
411
|
+
// 它转去找包内相对路径,于是真实嵌入好好的、面板 verify 却报 functional: false。
|
|
412
|
+
// 这条用例走的就是面板那条路(tool → verifyPayload → defaultEngine),且刻意不设
|
|
413
|
+
// embedModelCacheDir、把 localEmbedModel 设成非默认值:两只参数都必须真的走到 engine。
|
|
414
|
+
delete globalThis.__engineSeen;
|
|
415
|
+
const runtimeDir = mkdtempSync(join(tmpdir(), "mneme-tool-verify-"));
|
|
416
|
+
makePayloadWithFakeEntry(runtimeDir);
|
|
417
|
+
const { registered } = setup(undefined, { runtimeDir, localEmbedModel: "Xenova/bge-m3" });
|
|
418
|
+
const tool = registered.find((t) => t.name === "memory_runtime");
|
|
419
|
+
|
|
420
|
+
const result = await tool.execute({ action: "verify" });
|
|
421
|
+
assert.equal(result.status, "verified", result.reason ?? result.summary);
|
|
422
|
+
assert.match(result.summary, /Runtime verified/);
|
|
423
|
+
assert.equal(globalThis.__engineSeen.cacheDir, defaultModelCacheDir(), "不填 embedModelCacheDir 时该去用户级默认目录");
|
|
424
|
+
assert.equal(globalThis.__engineSeen.opts.cache_dir, defaultModelCacheDir());
|
|
425
|
+
assert.equal(globalThis.__engineSeen.model, "Xenova/bge-m3", "验的必须是配置里那个嵌入模型");
|
|
426
|
+
assert.equal(globalThis.__engineSeen.remote, false, "验证过程不许触网");
|
|
427
|
+
delete globalThis.__engineSeen;
|
|
428
|
+
});
|