dsh-memu-memory 1.4.1 → 1.4.3

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.
Files changed (389) hide show
  1. package/AGENTS.md +108 -108
  2. package/CHANGELOG.md +169 -848
  3. package/LICENSE +21 -21
  4. package/README.md +368 -374
  5. package/README.zh.md +354 -360
  6. package/assets/icon.svg +7 -7
  7. package/cordis.patch.yml +8 -8
  8. package/docs/active-memory-ab.md +279 -385
  9. package/docs/binding-lifecycle.md +99 -99
  10. package/docs/client-conventions.md +75 -72
  11. package/docs/contributing.md +217 -217
  12. package/docs/emotion-model-spec.md +247 -281
  13. package/docs/env-and-commands.md +149 -152
  14. package/docs/host-adaptation.md +339 -360
  15. package/docs/host-api.md +131 -137
  16. package/docs/host-versions.md +117 -120
  17. package/docs/mcp-porting.md +146 -0
  18. package/docs/memory-semantics.md +271 -259
  19. package/docs/pending-work.md +44 -51
  20. package/docs/troubleshooting.md +909 -840
  21. package/lib/active-memory.js +160 -165
  22. package/lib/activity-log.js +207 -207
  23. package/lib/auto-link/apply.js +248 -249
  24. package/lib/auto-link/candidates.js +163 -163
  25. package/lib/auto-link/decide.js +300 -300
  26. package/lib/auto-link/normalize.js +99 -99
  27. package/lib/auto-link/policy.js +42 -42
  28. package/lib/auto-link/suppression.js +101 -101
  29. package/lib/auto-link/terminology.js +311 -311
  30. package/lib/backup.js +1254 -1254
  31. package/lib/binding-diagnostics.js +634 -634
  32. package/lib/budget.js +118 -118
  33. package/lib/client.js +9820 -9648
  34. package/lib/commitment.js +178 -138
  35. package/lib/consolidation-ledger.js +434 -438
  36. package/lib/consolidation-receipt.js +386 -387
  37. package/lib/consolidation-snapshot.js +420 -405
  38. package/lib/consolidation-worker.js +240 -241
  39. package/lib/context.js +33 -33
  40. package/lib/curator-evidence.js +131 -131
  41. package/lib/curator-policy.js +198 -202
  42. package/lib/curator.js +1813 -1811
  43. package/lib/cycle.js +524 -513
  44. package/lib/diagnostics.js +524 -524
  45. package/lib/embedding-catalog.js +1051 -1055
  46. package/lib/embedding-download.js +637 -607
  47. package/lib/embedding-runtime.js +946 -946
  48. package/lib/engine.js +1103 -1035
  49. package/lib/entity-repair.js +285 -285
  50. package/lib/environment-check.js +394 -394
  51. package/lib/fork-model.js +312 -312
  52. package/lib/freshness.js +128 -121
  53. package/lib/global-graph.js +389 -389
  54. package/lib/graph.js +1193 -1193
  55. package/lib/host-surface.js +30 -30
  56. package/lib/inbound.js +284 -281
  57. package/lib/index.js +506 -511
  58. package/lib/inject.js +2639 -2619
  59. package/lib/lexicon-scope.js +143 -143
  60. package/lib/lexicon.js +1183 -1192
  61. package/lib/lifecycle-audit.js +37 -0
  62. package/lib/local-embedding-entry.js +145 -145
  63. package/lib/local-embedding-manager.js +306 -306
  64. package/lib/local-embedding-protocol.js +210 -210
  65. package/lib/local-embedding-worker.js +682 -682
  66. package/lib/local-vector-service.js +506 -453
  67. package/lib/maintenance-ledger.js +138 -0
  68. package/lib/maintenance-review.js +103 -0
  69. package/lib/maintenance-runner.js +267 -0
  70. package/lib/managed-runtime.js +118 -118
  71. package/lib/media.js +607 -513
  72. package/lib/memory.js +5035 -4911
  73. package/lib/memu-config.js +213 -213
  74. package/lib/memu.js +565 -565
  75. package/lib/migrate.js +200 -200
  76. package/lib/mood.js +300 -300
  77. package/lib/paths.js +453 -457
  78. package/lib/port-surface.js +82 -0
  79. package/lib/preset-mount.js +79 -0
  80. package/lib/preset-scope.js +126 -126
  81. package/lib/private-links.js +567 -567
  82. package/lib/private.js +2198 -2209
  83. package/lib/prompts/global-curator.md +135 -135
  84. package/lib/prompts/image-caption.md +1 -1
  85. package/lib/prompts/private-consolidation.coding.md +39 -39
  86. package/lib/prompts/private-consolidation.md +32 -32
  87. package/lib/prompts/private-consolidation.mixed.md +37 -37
  88. package/lib/prompts/private-consolidation.rp.md +47 -47
  89. package/lib/prompts/private-policy.coding.md +35 -35
  90. package/lib/prompts/private-policy.md +36 -36
  91. package/lib/prompts/private-policy.mixed.md +29 -29
  92. package/lib/prompts/private-policy.rp.md +43 -43
  93. package/lib/prompts/system-guide.coding.md +20 -20
  94. package/lib/prompts/system-guide.md +25 -25
  95. package/lib/prompts/system-guide.mixed.md +22 -22
  96. package/lib/prompts/system-guide.rp.md +23 -23
  97. package/lib/prompts.js +331 -331
  98. package/lib/recall-cache.js +212 -212
  99. package/lib/remote-summary.js +123 -123
  100. package/lib/rpc.js +2531 -2518
  101. package/lib/salient-wake.js +438 -438
  102. package/lib/snippet.js +125 -125
  103. package/lib/state.js +1948 -1928
  104. package/lib/stats.js +236 -236
  105. package/lib/temporal.js +345 -348
  106. package/lib/text-retrieval.js +992 -1001
  107. package/lib/text-similarity.js +305 -305
  108. package/lib/tokenizer-v2.js +271 -271
  109. package/lib/tools.js +1098 -1066
  110. package/lib/turn-log.js +545 -545
  111. package/lib/vector-migration.js +928 -930
  112. package/lib/vector-profile.js +1353 -1359
  113. package/lib/visibility.js +59 -59
  114. package/lib/webui/graph-LICENSE.txt +1 -1
  115. package/lib/webui/graph-view.bundle.js +2 -2
  116. package/lib/webui/graph-view.js +1171 -1175
  117. package/lib/webui/mark.svg +7 -7
  118. package/lib/webui/standalone.css +1178 -1178
  119. package/lib/webui/standalone.js +238 -238
  120. package/lib/webui.js +136 -136
  121. package/lib/worker-pool.js +1015 -979
  122. package/package.json +153 -152
  123. package/requirements.lock +34 -34
  124. package/scripts/acceptance-local.mjs +946 -946
  125. package/scripts/active-memory-ab-live.mjs +653 -655
  126. package/scripts/active-memory-ab.mjs +1302 -1302
  127. package/scripts/audit-memory-lifecycle.mjs +55 -0
  128. package/scripts/bench-recall.mjs +142 -142
  129. package/scripts/build-graph.mjs +44 -45
  130. package/scripts/chain-matrix.mjs +541 -541
  131. package/scripts/check-all.mjs +68 -74
  132. package/scripts/check-doc-drift.mjs +547 -547
  133. package/scripts/check-graph-browser.mjs +261 -261
  134. package/scripts/check-i18n.mjs +81 -83
  135. package/scripts/check-idle-compositing.mjs +61 -61
  136. package/scripts/check-seed-compat.mjs +115 -118
  137. package/scripts/check-text-format.mjs +55 -0
  138. package/scripts/curator-pair-calibrate.mjs +259 -259
  139. package/scripts/diagnose-bindings.mjs +176 -176
  140. package/scripts/drive-session.mjs +863 -864
  141. package/scripts/engine-smoke.mjs +69 -69
  142. package/scripts/entity-dedupe.mjs +110 -110
  143. package/scripts/lexicon-calibrate.mjs +230 -230
  144. package/scripts/lexicon-dedupe.mjs +318 -318
  145. package/scripts/local-runtime-install.mjs +142 -142
  146. package/scripts/local-runtime-verify.mjs +56 -56
  147. package/scripts/local-vector-verify.mjs +93 -93
  148. package/scripts/make-readme-shots.mjs +59 -59
  149. package/scripts/migrate-visibility.mjs +94 -94
  150. package/scripts/mock-llm.mjs +938 -903
  151. package/scripts/preview.mjs +58 -58
  152. package/scripts/prune-sessions.mjs +31 -34
  153. package/scripts/prune-turnlogs.mjs +29 -30
  154. package/scripts/prune-vectors.mjs +24 -24
  155. package/scripts/rebuild-auto-links.mjs +252 -252
  156. package/scripts/recall-bench.mjs +820 -820
  157. package/scripts/repetition-ab-scenarios.mjs +93 -93
  158. package/scripts/repetition-detector-snapshot.mjs +314 -314
  159. package/scripts/repetition-eval-live.mjs +360 -360
  160. package/scripts/repetition-eval.mjs +702 -702
  161. package/scripts/replay.mjs +705 -575
  162. package/scripts/setup.mjs +46 -46
  163. package/scripts/simulate-injection.mjs +299 -301
  164. package/tests/absorb-review.test.mjs +354 -354
  165. package/tests/activation.test.mjs +89 -89
  166. package/tests/active-memory-ab.test.mjs +745 -745
  167. package/tests/active-memory.test.mjs +129 -129
  168. package/tests/activity-log.test.mjs +126 -126
  169. package/tests/activity-wiring.test.mjs +155 -155
  170. package/tests/appendix-b.test.mjs +217 -217
  171. package/tests/appendix-b2.test.mjs +166 -166
  172. package/tests/audit-batch3.test.mjs +247 -247
  173. package/tests/audit-regression.test.mjs +275 -275
  174. package/tests/audit-safety.test.mjs +227 -227
  175. package/tests/auto-link-candidates.test.mjs +245 -245
  176. package/tests/auto-link-decide.test.mjs +512 -512
  177. package/tests/auto-link-migration.test.mjs +133 -133
  178. package/tests/backend-compensation.test.mjs +272 -272
  179. package/tests/backup.test.mjs +793 -793
  180. package/tests/binding-diagnostics.test.mjs +720 -720
  181. package/tests/browser.test.mjs +476 -455
  182. package/tests/client-export.test.mjs +521 -520
  183. package/tests/client-render.test.mjs +2008 -1727
  184. package/tests/coalesce.test.mjs +113 -113
  185. package/tests/commitment.test.mjs +243 -144
  186. package/tests/config.test.mjs +159 -159
  187. package/tests/consolidation-credential.test.mjs +330 -330
  188. package/tests/consolidation-feed.test.mjs +122 -122
  189. package/tests/consolidation-fork.test.mjs +1586 -1539
  190. package/tests/consolidation-ledger.test.mjs +389 -389
  191. package/tests/consolidation-snapshot.test.mjs +567 -505
  192. package/tests/consolidation-value.test.mjs +89 -89
  193. package/tests/context-scope.test.mjs +40 -40
  194. package/tests/cross-library-recall.test.mjs +269 -269
  195. package/tests/cue.test.mjs +58 -58
  196. package/tests/curator-absorb.test.mjs +444 -444
  197. package/tests/curator-calibrate.test.mjs +173 -173
  198. package/tests/curator-clusters.test.mjs +306 -306
  199. package/tests/curator-commit.test.mjs +325 -325
  200. package/tests/curator-contract.test.mjs +191 -191
  201. package/tests/curator-evidence.test.mjs +102 -102
  202. package/tests/curator-link.test.mjs +317 -317
  203. package/tests/curator-pairing.test.mjs +339 -339
  204. package/tests/curator-probe.test.mjs +490 -490
  205. package/tests/curator-review-mode.test.mjs +315 -315
  206. package/tests/curator.test.mjs +152 -152
  207. package/tests/cycle.test.mjs +567 -568
  208. package/tests/diagnostics.test.mjs +278 -278
  209. package/tests/disclosure.test.mjs +249 -249
  210. package/tests/doc-drift.test.mjs +342 -342
  211. package/tests/drive-session.test.mjs +152 -152
  212. package/tests/dynamic-rrf.test.mjs +182 -182
  213. package/tests/dynamic-threshold.test.mjs +52 -52
  214. package/tests/embedding-catalog.test.mjs +374 -374
  215. package/tests/embedding-download.test.mjs +529 -486
  216. package/tests/embedding-runtime.test.mjs +449 -449
  217. package/tests/emotion-chain.test.mjs +84 -84
  218. package/tests/emotion-contract.test.mjs +445 -445
  219. package/tests/engine.test.mjs +108 -48
  220. package/tests/entity-merge.test.mjs +278 -278
  221. package/tests/environment-check.test.mjs +187 -187
  222. package/tests/fact-version.test.mjs +146 -146
  223. package/tests/fixtures/active-memory-ab/README.md +56 -56
  224. package/tests/fixtures/active-memory-ab/cases/01-clean-dense-turn.json +351 -351
  225. package/tests/fixtures/active-memory-ab/cases/02-clean-thin-turn.json +122 -122
  226. package/tests/fixtures/active-memory-ab/cases/03-clean-starved-small.json +125 -125
  227. package/tests/fixtures/active-memory-ab/cases/04-clean-large-thin.json +137 -137
  228. package/tests/fixtures/active-memory-ab/cases/05-clean-half-step.json +166 -166
  229. package/tests/fixtures/active-memory-ab/cases/06-clean-duplicate-reread.json +197 -197
  230. package/tests/fixtures/active-memory-ab/cases/07-clean-recent-recall.json +125 -125
  231. package/tests/fixtures/active-memory-ab/cases/08-global-relevant.json +111 -111
  232. package/tests/fixtures/active-memory-ab/cases/09-global-irrelevant-conflict.json +158 -158
  233. package/tests/fixtures/active-memory-ab/cases/10-no-human-turn.json +97 -97
  234. package/tests/fixtures/active-memory-ab/cases/11-clean-scale-100.json +137 -137
  235. package/tests/fixtures/active-memory-ab/cases/12-clean-scale-1000.json +137 -137
  236. package/tests/fixtures/active-memory-ab/cases/13-clean-scale-5000.json +137 -137
  237. package/tests/fixtures/active-memory-ab/cases/14-clean-scale-20000.json +137 -137
  238. package/tests/fixtures/active-memory-ab/lead-ai-reviewed-reference.json +191 -191
  239. package/tests/fixtures/active-memory-ab/manifest.json +199 -199
  240. package/tests/fixtures/curator-pairs/labeled.v1.jsonl +90 -90
  241. package/tests/fixtures/lexicon-stub-hooks.mjs +15 -15
  242. package/tests/fixtures/lexicon-stub.mjs +284 -284
  243. package/tests/fixtures/mock-llm/reply.txt +1 -1
  244. package/tests/fixtures/recall-bench/01-paraphrase.json +183 -183
  245. package/tests/fixtures/recall-bench/02-exact.json +152 -152
  246. package/tests/fixtures/recall-bench/03-negation.json +172 -172
  247. package/tests/fixtures/recall-bench/04-no-answer.json +161 -161
  248. package/tests/fixtures/recall-bench/05-conflict.json +193 -193
  249. package/tests/fixtures/recall-bench/06-boundary.json +272 -272
  250. package/tests/fixtures/recall-bench/07-secret.json +190 -190
  251. package/tests/fixtures/recall-bench/08-coding.json +163 -163
  252. package/tests/fixtures/recall-bench-gold-candidates/01-paraphrase.json +193 -193
  253. package/tests/fixtures/recall-bench-gold-candidates/02-exact.json +197 -197
  254. package/tests/fixtures/recall-bench-gold-candidates/03-negation.json +244 -244
  255. package/tests/fixtures/recall-bench-gold-candidates/04-no-answer.json +189 -189
  256. package/tests/fixtures/recall-bench-gold-candidates/05-conflict.json +245 -245
  257. package/tests/fixtures/recall-bench-gold-candidates/06-boundary.json +279 -279
  258. package/tests/fixtures/recall-bench-gold-candidates/07-secret.json +224 -224
  259. package/tests/fixtures/recall-bench-gold-candidates/08-coding.json +218 -218
  260. package/tests/fixtures/repetition-eval/01-zh-rp.json +92 -92
  261. package/tests/fixtures/repetition-eval/02-en.json +96 -96
  262. package/tests/fixtures/repetition-eval/03-code.json +90 -90
  263. package/tests/fixtures/repetition-eval/04-names.json +115 -115
  264. package/tests/fixtures/repetition-eval/05-user-quote.json +95 -95
  265. package/tests/fixtures/repetition-eval/06-agreement.json +85 -85
  266. package/tests/fixtures/tokenizer-cases.mjs +27 -27
  267. package/tests/fork-model.test.mjs +345 -345
  268. package/tests/freshness.test.mjs +140 -140
  269. package/tests/global-graph.test.mjs +106 -106
  270. package/tests/global-lifecycle.test.mjs +149 -149
  271. package/tests/graph-cascade.test.mjs +363 -363
  272. package/tests/graph-view.test.mjs +414 -414
  273. package/tests/graph.test.mjs +371 -371
  274. package/tests/help-page.test.mjs +416 -415
  275. package/tests/hook-order.test.mjs +72 -72
  276. package/tests/humanlike.test.mjs +232 -232
  277. package/tests/hybrid-recall.test.mjs +610 -610
  278. package/tests/inbound.test.mjs +441 -441
  279. package/tests/inject-conflict.test.mjs +173 -173
  280. package/tests/inject-guide.test.mjs +513 -513
  281. package/tests/inject.test.mjs +384 -384
  282. package/tests/injection-budget-settings.test.mjs +35 -35
  283. package/tests/injection-budget.test.mjs +165 -165
  284. package/tests/injection-chain.test.mjs +442 -442
  285. package/tests/injection-intent-budget.test.mjs +92 -92
  286. package/tests/injection-rollback.test.mjs +428 -428
  287. package/tests/issue2-chain.test.mjs +169 -169
  288. package/tests/lexical-bm25.test.mjs +171 -171
  289. package/tests/lexicon-calibrate.test.mjs +48 -48
  290. package/tests/lexicon-dedupe.test.mjs +171 -171
  291. package/tests/lexicon-frequency.test.mjs +195 -195
  292. package/tests/lexicon-inject.test.mjs +459 -459
  293. package/tests/lexicon-perf.test.mjs +464 -464
  294. package/tests/lexicon-scope.test.mjs +256 -256
  295. package/tests/lexicon-ui.test.mjs +667 -667
  296. package/tests/lexicon.test.mjs +922 -922
  297. package/tests/lifecycle-audit.test.mjs +56 -0
  298. package/tests/loader-register.mjs +3 -3
  299. package/tests/loader.mjs +17 -17
  300. package/tests/local-embedding-entry.test.mjs +95 -95
  301. package/tests/local-embedding-env.test.mjs +51 -51
  302. package/tests/local-embedding-manager.test.mjs +494 -494
  303. package/tests/local-embedding-protocol.test.mjs +121 -121
  304. package/tests/local-embedding-worker.test.mjs +440 -440
  305. package/tests/local-vector-service.test.mjs +41 -0
  306. package/tests/maintenance-status.test.mjs +77 -0
  307. package/tests/maintenance.test.mjs +438 -0
  308. package/tests/managed-memory.test.mjs +1234 -1234
  309. package/tests/managed-runtime.test.mjs +72 -72
  310. package/tests/media-injection.test.mjs +225 -0
  311. package/tests/media.test.mjs +135 -135
  312. package/tests/memory-chain.test.mjs +169 -169
  313. package/tests/memory-fields.test.mjs +134 -134
  314. package/tests/memu-resident-route.test.mjs +130 -130
  315. package/tests/memu-resident.test.mjs +33 -33
  316. package/tests/migration-payload.test.mjs +40 -42
  317. package/tests/mock-llm.test.mjs +263 -225
  318. package/tests/mood.test.mjs +109 -109
  319. package/tests/multiprocess.test.mjs +29 -29
  320. package/tests/negation-polarity.test.mjs +135 -135
  321. package/tests/new-session-gate.test.mjs +617 -616
  322. package/tests/open-loop-date.test.mjs +416 -416
  323. package/tests/ops-hardening.test.mjs +209 -209
  324. package/tests/package-shipping.test.mjs +88 -88
  325. package/tests/pending-injection.test.mjs +107 -107
  326. package/tests/port-surface.test.mjs +138 -0
  327. package/tests/preset-mount.test.mjs +124 -0
  328. package/tests/preset-scope.test.mjs +212 -212
  329. package/tests/private-links.test.mjs +493 -493
  330. package/tests/prompt-semantics.test.mjs +51 -51
  331. package/tests/prompts.test.mjs +315 -315
  332. package/tests/query-decompose.test.mjs +62 -62
  333. package/tests/react-snapshot.test.mjs +24 -23
  334. package/tests/recall-bench.test.mjs +317 -317
  335. package/tests/recall-cache.test.mjs +292 -292
  336. package/tests/recall-corpus-eligibility.test.mjs +51 -51
  337. package/tests/recall-dedup.test.mjs +446 -446
  338. package/tests/recall-intent.test.mjs +172 -172
  339. package/tests/regression-sweep.test.mjs +311 -311
  340. package/tests/reminder-fairness.test.mjs +55 -0
  341. package/tests/remote.test.mjs +140 -140
  342. package/tests/rename.test.mjs +30 -30
  343. package/tests/repetition-detector-snapshot.test.mjs +231 -231
  344. package/tests/repetition-eval-live.test.mjs +177 -177
  345. package/tests/repetition-eval.test.mjs +373 -373
  346. package/tests/salience-domain.test.mjs +173 -173
  347. package/tests/salient-date.test.mjs +142 -142
  348. package/tests/salient-wake.test.mjs +389 -389
  349. package/tests/settings-beat.test.mjs +222 -221
  350. package/tests/settings-coverage.test.mjs +97 -97
  351. package/tests/settings-plumbing.test.mjs +79 -79
  352. package/tests/short-term.test.mjs +182 -166
  353. package/tests/sidebar-beat.test.mjs +213 -212
  354. package/tests/sidebar-refresh.test.mjs +123 -123
  355. package/tests/sidebar.test.mjs +102 -74
  356. package/tests/simulate-injection.test.mjs +76 -76
  357. package/tests/slot-similarity.test.mjs +153 -153
  358. package/tests/snippet.test.mjs +79 -79
  359. package/tests/source-kind.test.mjs +52 -52
  360. package/tests/speaker-provenance.test.mjs +120 -120
  361. package/tests/stale-maintenance.test.mjs +206 -131
  362. package/tests/state-gc.test.mjs +34 -34
  363. package/tests/state.test.mjs +155 -155
  364. package/tests/stats.test.mjs +112 -112
  365. package/tests/storage.test.mjs +125 -125
  366. package/tests/stubs/child-process-spy.mjs +14 -14
  367. package/tests/stubs/dsh-llm-pi-ai.js +13 -13
  368. package/tests/stubs/dsh-llm.js +5 -5
  369. package/tests/stubs/dsh-schedule.js +140 -140
  370. package/tests/stubs/dsh-session-query.js +26 -26
  371. package/tests/stubs/dsh-session.js +7 -7
  372. package/tests/stubs/dsh-tools.js +101 -101
  373. package/tests/temporal-repair.test.mjs +78 -0
  374. package/tests/temporal.test.mjs +124 -124
  375. package/tests/text-format.test.mjs +24 -0
  376. package/tests/tokenizer-v2.test.mjs +142 -142
  377. package/tests/tool-schema.test.mjs +126 -126
  378. package/tests/tools.test.mjs +810 -810
  379. package/tests/turn-log.test.mjs +487 -487
  380. package/tests/ui-defaults.test.mjs +57 -57
  381. package/tests/update-fields.test.mjs +138 -138
  382. package/tests/vector-gc.test.mjs +37 -37
  383. package/tests/vector-migration.test.mjs +810 -810
  384. package/tests/vector-profile.test.mjs +449 -449
  385. package/tests/visibility-migration.test.mjs +152 -152
  386. package/tests/webui-auth.test.mjs +963 -963
  387. package/tests/webui.test.mjs +421 -414
  388. package/tests/windows-env.test.mjs +89 -89
  389. package/tests/worker-lifecycle.test.mjs +1521 -1429
@@ -1,520 +1,521 @@
1
- // Package B (spec §6.2): export/import contract + success notices.
2
- //
3
- // The export contract is behavioral: exportLibraryNow/importLibraryNow take an
4
- // options object whose libraryId defaults to the browsed library but must be
5
- // the id that reaches the exportLibrary payload, the fallback download name
6
- // and the ZIP upload URL. The notices are the other half: every browser row
7
- // action answers with its own success message through the page's notice slot
8
- // while failures keep using setError.
9
- //
10
- // Same fake-React harness as tests/client-render.test.mjs, plus two seams the
11
- // old harness never needed: captured createElement nodes (the file input and
12
- // the download anchors) and stubbed fetch/URL.createObjectURL.
13
- import test from 'node:test'
14
- import assert from 'node:assert/strict'
15
-
16
- const createdNodes = []
17
- const fetchCalls = []
18
- const realFetch = globalThis.fetch
19
- const realCreateObjectURL = URL.createObjectURL
20
- const realRevokeObjectURL = URL.revokeObjectURL
21
-
22
- const registrations = []
23
-
24
- function makeElement(type, props, ...children) {
25
- return { type, props: { ...(props || {}), children: children.length <= 1 ? children[0] : children } }
26
- }
27
-
28
- let hooks = []
29
- let cursor = 0
30
- let effects = []
31
- let dirty = false
32
- let forced = null
33
- let generation = 0
34
-
35
- const React = {
36
- createElement: makeElement,
37
- Fragment: Symbol('Fragment'),
38
- useState(initial) {
39
- const index = cursor++
40
- const generation_ = generation
41
- if (hooks[index] === undefined) hooks[index] = typeof initial === 'function' ? initial() : initial
42
- if (forced && forced.index === index) hooks[index] = forced.value
43
- return [hooks[index], (next) => {
44
- if (generation_ !== generation) return
45
- hooks[index] = typeof next === 'function' ? next(hooks[index]) : next
46
- dirty = true
47
- }]
48
- },
49
- useCallback: (fn) => fn,
50
- useMemo: (fn) => fn(),
51
- useEffect(fn, deps) { effects.push({ fn, deps, index: cursor++ }) },
52
- useLayoutEffect() {},
53
- useRef: (value) => ({ current: value }),
54
- useSyncExternalStore: (_subscribe, getSnapshot) => getSnapshot(),
55
- }
56
-
57
- globalThis.window = {
58
- __ModuleLoader__: {
59
- load({ factory }) {
60
- globalThis.__dshMemuExports = factory((name) => {
61
- if (name === 'react') return React
62
- throw new Error(`unexpected require: ${name}`)
63
- })
64
- },
65
- },
66
- addEventListener() {},
67
- removeEventListener() {},
68
- }
69
- globalThis.document = {
70
- createElement: (tag) => {
71
- const node = {
72
- tag,
73
- style: {},
74
- attrs: {},
75
- children: [],
76
- href: '',
77
- download: '',
78
- textContent: '',
79
- setAttribute(name, value) { node.attrs[name] = value },
80
- addEventListener() {},
81
- appendChild(child) { node.children.push(child); return child },
82
- remove() { node.removed = true },
83
- click() { node.clicked = true },
84
- }
85
- createdNodes.push(node)
86
- return node
87
- },
88
- querySelector: () => null,
89
- addEventListener() {},
90
- removeEventListener() {},
91
- head: { appendChild() {} },
92
- body: { appendChild() {} },
93
- }
94
-
95
- // The import ZIP path POSTs to a host route; record instead of hitting nothing.
96
- globalThis.fetch = async (url, options) => {
97
- fetchCalls.push({ url: String(url), options })
98
- return { json: async () => ({ ok: true, value: { imported: 2, counts: {} } }) }
99
- }
100
- URL.createObjectURL = () => 'blob:fixture'
101
- URL.revokeObjectURL = () => {}
102
-
103
- await import('../lib/client.js')
104
-
105
- const EMPTY_STATE = {
106
- engine: { status: 'ready', versions: [], currentVersion: '0.11.0b3', recommendedVersion: '0.11.0b3', installed: true, state: {} },
107
- settings: { autoInject: 'smart', mustRememberCap: 16, unpinBudgetPerSession: 2 },
108
- libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 2 }],
109
- archivedLibraries: [],
110
- memuConfig: { provider: 'openai' },
111
- summaryConfig: {},
112
- binding: null,
113
- privateCount: 2,
114
- pinnedCount: 0,
115
- globalCount: 0,
116
- jobs: [],
117
- }
118
-
119
- const BROWSE_FILES = [
120
- { id: 'mem-live', title: 'live entry', content: 'an active body', layer: 'long_term', status: 'active', decay: 0.9 },
121
- { id: 'mem-gone', title: 'archived entry', content: 'an archived body', layer: 'long_term', status: 'archived', decay: 0.4 },
122
- ]
123
-
124
- const WALL_ITEM = {
125
- id: 'mem-wall', libraryId: 'lib-1', title: 'walled entry', preview: 'a body',
126
- layer: 'long_term', status: 'active', decay: 0.9,
127
- }
128
-
129
- function makeAnswers(over = {}) {
130
- return {
131
- getState: EMPTY_STATE,
132
- getSettingsState: EMPTY_STATE,
133
- listLibraries: { libraries: EMPTY_STATE.libraries },
134
- listSessions: { sessions: [] },
135
- listVersions: { ok: true, versions: [] },
136
- listBackups: { backups: [] },
137
- listFolders: { folders: [] },
138
- getSidebarState: {
139
- binding: null, domain: 'general', folder: null,
140
- effective: { useLibrary: false, useGlobal: false, enabled: false },
141
- private: { items: [], active: 0, pinned: 0, total: 0 },
142
- global: { items: [], active: 0, total: 0 },
143
- domains: [],
144
- },
145
- jobStatus: null,
146
- browseLibrary: { source: 'engine', files: structuredClone(BROWSE_FILES) },
147
- browseWall: { items: [structuredClone(WALL_ITEM)], total: 1, errors: [] },
148
- getMemory: { id: 'mem-wall', libraryId: 'lib-1', entry: { title: 'walled entry', content: 'a body', layer: 'long_term', status: 'active', confidence: 0.8, tags: [] }, attachments: [] },
149
- ...over,
150
- }
151
- }
152
-
153
- function fakeCtx({ answers = {}, rpcCalls = [] } = {}) {
154
- return {
155
- effect: (fn) => { try { fn() } catch {} },
156
- locale: { register: () => () => {}, bind: () => (key) => key, get: () => 'zh' },
157
- connection: {
158
- rpc: {
159
- call: async (path, endpoint, payload) => {
160
- rpcCalls.push({ path, endpoint, payload })
161
- if (typeof answers[endpoint] === 'function') return answers[endpoint](payload)
162
- return { ok: true, value: answers[endpoint] ?? {} }
163
- },
164
- },
165
- },
166
- sessions: { list: { subscribe: () => () => {}, getSnapshot: () => ({ byId: {}, ids: [] }) } },
167
- get: (name) => (name === 'uiSession'
168
- ? { adapter: { current: { getSnapshot: () => ({ key: 'probe-session' }) } } }
169
- : undefined),
170
- slots: {
171
- inject: (_name, callback) => callback(scope),
172
- register: (spec, component) => { registrations.push({ slot: spec.name, id: spec.id, component }); return () => {} },
173
- },
174
- inject: (_deps, callback) => callback({
175
- effect: (fn) => { try { fn() } catch {} },
176
- sidebarRightTabs: { register: () => () => {} },
177
- get: () => undefined,
178
- }),
179
- }
180
- }
181
-
182
- const scope = {
183
- effect: (fn) => { try { fn() } catch {} },
184
- register: (spec, component) => { registrations.push({ slot: spec.name, id: spec.id, component }); return () => {} },
185
- inject: (_deps, callback) => callback(scope),
186
- }
187
-
188
- async function renderPage(component, props, pageValue, { remount = false } = {}) {
189
- if (remount) { hooks = []; generation++ }
190
- effects = []
191
- cursor = 0
192
- forced = pageValue === undefined ? null : { index: pageHookIndex, value: pageValue }
193
- const tree = component(props)
194
- assert.ok(tree, 'component rendered nothing')
195
- return { tree, effects }
196
- }
197
-
198
- let pageHookIndex = -1
199
-
200
- function collectPageHook() {
201
- const zeroes = hooks.map((value, index) => (value === 0 ? index : -1)).filter((index) => index >= 0)
202
- assert.equal(zeroes.length, 1, 'expected exactly one numeric-zero state (the page index)')
203
- pageHookIndex = zeroes[0]
204
- }
205
-
206
- function treeText(node, depth = 0) {
207
- if (node === null || node === undefined || depth > 400) return ''
208
- if (typeof node === 'string' || typeof node === 'number') return String(node)
209
- if (Array.isArray(node)) return node.map((child) => treeText(child, depth + 1)).join(' ')
210
- if (typeof node.type === 'function') return treeText(node.type(node.props), depth + 1)
211
- return `${node.props?.className || ''} ${treeText(node.props?.children, depth + 1)}`
212
- }
213
-
214
- function walkNodes(node, visit, depth = 0) {
215
- if (node === null || node === undefined || depth > 400) return
216
- if (Array.isArray(node)) {
217
- for (const child of node) walkNodes(child, visit, depth + 1)
218
- return
219
- }
220
- if (typeof node !== 'object') return
221
- if (visit(node, depth) === false) return
222
- if (typeof node.type === 'function') {
223
- walkNodes(node.type(node.props), visit, depth + 1)
224
- return
225
- }
226
- walkNodes(node.props?.children, visit, depth + 1)
227
- }
228
-
229
- const settle = () => new Promise((resolve) => setTimeout(resolve, 0))
230
-
231
- // Renders the settings page, waits for the mount fetches, jumps to the browser
232
- // page (5), selects lib-1 in the picker and (optionally) presses reload so the
233
- // rows are painted. Returns render/rerender helpers plus the collected calls.
234
- async function openBrowserPage(t, { reload = true, answers = {} } = {}) {
235
- const rpcCalls = []
236
- const ctx = fakeCtx({ answers: makeAnswers(answers), rpcCalls })
237
- globalThis.__dshMemuExports.apply(ctx)
238
- const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
239
- assert.ok(settings?.component, 'settings.section was not registered')
240
- const props = { ctx, t: (key) => key }
241
- const first = await renderPage(settings.component, props, undefined, { remount: true })
242
- collectPageHook()
243
- const cleanups = []
244
- t.after(() => { for (const cleanup of cleanups.reverse()) cleanup() })
245
- for (const effect of first.effects) {
246
- const cleanup = effect.fn()
247
- if (typeof cleanup === 'function') cleanups.push(cleanup)
248
- }
249
- await settle()
250
- await settle()
251
-
252
- let tree = (await renderPage(settings.component, props, 5)).tree
253
- let picker = []
254
- walkNodes(tree, (node) => {
255
- const options = Array.isArray(node.props?.children) ? node.props.children : []
256
- if (node.type === 'select' && options.some((option) => option?.props?.value === 'lib-1')) picker.push(node)
257
- })
258
- assert.equal(picker.length, 1, 'the library picker did not render')
259
- picker[0].props.onChange({ target: { value: 'lib-1' } })
260
-
261
- const rerender = async () => {
262
- const { tree, effects } = await renderPage(settings.component, props, 5)
263
- const nodes = []
264
- walkNodes(tree, (node) => { nodes.push(node) })
265
- return { tree, nodes, text: treeText(tree), effects }
266
- }
267
- let view = await rerender()
268
-
269
- if (reload) {
270
- const reloadButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'reload')
271
- assert.equal(reloadButtons.length, 1, 'the reload button did not render')
272
- reloadButtons[0].props.onClick()
273
- await settle()
274
- await settle()
275
- view = await rerender()
276
- }
277
- const findButtons = (label) => view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === label)
278
- return { ctx, rpcCalls, rerender, view, findButtons }
279
- }
280
-
281
- test.after(() => {
282
- globalThis.fetch = realFetch
283
- URL.createObjectURL = realCreateObjectURL
284
- URL.revokeObjectURL = realRevokeObjectURL
285
- })
286
-
287
- test('the JSON export sends the browsed libraryId and reports exportStarted with the filename', async (t) => {
288
- createdNodes.length = 0
289
- const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, {
290
- reload: false,
291
- answers: { exportLibrary: { filename: 'lib-1.json', base64: Buffer.from('hello').toString('base64') } },
292
- })
293
- const exportButtons = findButtons('export')
294
- assert.equal(exportButtons.length, 1, 'the JSON export button did not render')
295
- exportButtons[0].props.onClick()
296
- await settle()
297
- await settle()
298
-
299
- const call = rpcCalls.find((entry) => entry.endpoint === 'exportLibrary')
300
- assert.ok(call, 'exportLibrary was not called')
301
- assert.equal(call.payload.libraryId, 'lib-1', 'the payload must carry the selected library id')
302
- assert.equal(call.payload.includeAttachments, false)
303
- assert.equal(call.payload.delivery, undefined)
304
- const anchor = createdNodes.find((node) => node.tag === 'a' && node.clicked)
305
- assert.ok(anchor, 'the download anchor was created and clicked')
306
- assert.equal(anchor.href, 'blob:fixture')
307
- assert.equal(anchor.download, 'lib-1.json', 'the fallback download name uses the served filename')
308
- const { text } = await rerender()
309
- assert.ok(text.includes('exportStarted'), 'the export notice did not appear')
310
- assert.ok(!text.includes('exportImages'), 'the renamed copy key leaked back in')
311
- })
312
-
313
- test('the ZIP export passes includeAttachments with delivery download and offers the served URL', async (t) => {
314
- createdNodes.length = 0
315
- const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, {
316
- reload: false,
317
- answers: { exportLibrary: { filename: 'lib-1-with-attachments.zip', downloadUrl: 'http://host/exports/lib-1-with-attachments.zip' } },
318
- })
319
- const zipButtons = findButtons('exportZip')
320
- assert.equal(zipButtons.length, 1, 'the ZIP export button did not render')
321
- zipButtons[0].props.onClick()
322
- await settle()
323
- await settle()
324
-
325
- const call = rpcCalls.find((entry) => entry.endpoint === 'exportLibrary')
326
- assert.equal(call.payload.includeAttachments, true, 'the ZIP button must request attachments')
327
- assert.equal(call.payload.delivery, 'download')
328
- assert.equal(call.payload.libraryId, 'lib-1')
329
- const anchor = createdNodes.find((node) => node.tag === 'a' && node.clicked)
330
- assert.ok(anchor, 'the downloadUrl branch still downloads through an anchor')
331
- assert.equal(anchor.href, 'http://host/exports/lib-1-with-attachments.zip')
332
- const { text } = await rerender()
333
- assert.ok(text.includes('exportStarted'), 'a served URL export also reports exportStarted')
334
- })
335
-
336
- test('the ZIP import posts to the selected library id and lands back in that library', async (t) => {
337
- createdNodes.length = 0
338
- fetchCalls.length = 0
339
- const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, { reload: false })
340
- const importButtons = findButtons('importJson')
341
- assert.equal(importButtons.length, 1, 'the import button did not render')
342
- importButtons[0].props.onClick()
343
- const input = createdNodes.find((node) => node.tag === 'input' && node.type === 'file')
344
- assert.ok(input, 'the import file picker was created')
345
- input.files = [{ name: 'lib-1.zip' }]
346
- await input.onchange()
347
- await settle()
348
- await settle()
349
-
350
- assert.equal(fetchCalls.length, 1, 'the ZIP import must go through the host route')
351
- assert.ok(
352
- fetchCalls[0].url.startsWith('/dsh-memu-memory/import/lib-1.zip'),
353
- `the ZIP URL must use the selected library id, got ${fetchCalls[0].url}`,
354
- )
355
- const { text } = await rerender()
356
- assert.ok(text.includes('importDone'), 'the import success notice did not appear')
357
- // After a successful import the browser reloads the same library.
358
- const browsed = rpcCalls.filter((entry) => entry.endpoint === 'browseLibrary')
359
- assert.ok(browsed.some((entry) => entry.payload.libraryId === 'lib-1'), 'the browser reloaded the imported library')
360
- })
361
-
362
- test('each browser row action answers with its own success notice', async (t) => {
363
- createdNodes.length = 0
364
- // A server with state: the row actions mutate the served inventory, so the
365
- // archived tab really gains/loses rows as the test drives it. Function
366
- // answers must hand back the full RPC envelope (ok/value) themselves.
367
- const files = structuredClone(BROWSE_FILES)
368
- const { rpcCalls, rerender, view, findButtons } = await openBrowserPage(t, {
369
- reload: true,
370
- answers: {
371
- browseLibrary: () => ({ ok: true, value: { source: 'engine', files: structuredClone(files) } }),
372
- addMemory: async () => ({ ok: true, value: { id: 'mem-added' } }),
373
- updateMemory: async (payload) => {
374
- const row = files.find((file) => file.id === payload.id)
375
- if (row) Object.assign(row, payload.patch)
376
- return { ok: true, value: {} }
377
- },
378
- archiveMemory: async (payload) => {
379
- const row = files.find((file) => file.id === payload.id)
380
- if (row) row.status = 'archived'
381
- return { ok: true, value: {} }
382
- },
383
- deleteMemory: async (payload) => {
384
- const at = files.findIndex((file) => file.id === payload.id)
385
- if (at >= 0) files.splice(at, 1)
386
- return { ok: true, value: {} }
387
- },
388
- },
389
- })
390
-
391
- // addMemory → memorySaved
392
- const contentBox = view.nodes.find((node) => node.type === 'textarea' && node.props?.placeholder === 'memoryContent')
393
- assert.ok(contentBox, 'the new-memory form did not render')
394
- contentBox.props.onChange({ target: { value: 'a fresh fact worth keeping' } })
395
- let next = await rerender()
396
- const addButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'add')
397
- assert.equal(addButtons.length, 1)
398
- addButtons[0].props.onClick()
399
- await settle(); await settle()
400
- next = await rerender()
401
- assert.ok(next.text.includes('memorySaved'), 'addMemory did not report memorySaved')
402
- assert.ok(rpcCalls.some((call) => call.endpoint === 'addMemory' && call.payload.libraryId === 'lib-1'))
403
-
404
- // saveMemory → memorySaved (the row editor needs a non-empty draft first)
405
- const titleInput = next.nodes.find((node) => node.type === 'input' && node.props?.placeholder === 'name')
406
- assert.ok(titleInput, 'the row editor did not render')
407
- titleInput.props.onChange({ target: { value: 'renamed entry' } })
408
- next = await rerender()
409
- const saveButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'save')
410
- assert.equal(saveButtons.length, 1, 'the row save button did not render')
411
- saveButtons[0].props.onClick()
412
- await settle(); await settle()
413
- next = await rerender()
414
- assert.ok(next.text.includes('memorySaved'), 'saveMemory did not report memorySaved')
415
- assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-live'))
416
-
417
- // archiveMemory → memoryArchived (the active row's archive button)
418
- const archiveButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive')
419
- assert.equal(archiveButtons.length, 1, 'the active row archive button did not render')
420
- archiveButtons[0].props.onClick()
421
- await settle(); await settle()
422
- next = await rerender()
423
- assert.ok(next.text.includes('memoryArchived'), 'archiveMemory did not report memoryArchived')
424
- assert.ok(rpcCalls.some((call) => call.endpoint === 'archiveMemory' && call.payload.id === 'mem-live'))
425
-
426
- // The archived tab now holds both rows; restore → memoryRestored.
427
- const archivedTab = next.nodes.filter((node) => node.props?.role === 'tab'
428
- && String(node.props?.children || '').startsWith('browseArchivedTab'))
429
- assert.equal(archivedTab.length, 1)
430
- archivedTab[0].props.onClick()
431
- next = await rerender()
432
- const restoreButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'restore')
433
- assert.equal(restoreButtons.length, 2, 'both archived rows offer restore')
434
- restoreButtons[1].props.onClick()
435
- await settle(); await settle()
436
- next = await rerender()
437
- assert.ok(next.text.includes('memoryRestored'), 'restoreMemory did not report memoryRestored')
438
- assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-gone' && call.payload.patch.status === 'active'))
439
-
440
- // deleteMemoryForever → memoryDeleted (two-step confirm on the last archived row)
441
- const armButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'deleteForever')
442
- assert.ok(armButtons.length >= 1, 'the archived delete button did not render')
443
- armButtons[0].props.onClick()
444
- next = await rerender()
445
- const confirmButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'confirmDelete')
446
- assert.equal(confirmButtons.length, 1, 'the armed confirm did not render')
447
- confirmButtons[0].props.onClick()
448
- await settle(); await settle()
449
- next = await rerender()
450
- assert.ok(next.text.includes('memoryDeleted'), 'deleteMemoryForever did not report memoryDeleted')
451
- assert.ok(rpcCalls.some((call) => call.endpoint === 'deleteMemory' && call.payload.id === 'mem-live'))
452
- })
453
-
454
- test('the memory wall reports save, archive and bulk outcomes through onNotice', async (t) => {
455
- createdNodes.length = 0
456
- const rpcCalls = []
457
- const ctx = fakeCtx({ answers: makeAnswers(), rpcCalls })
458
- globalThis.__dshMemuExports.apply(ctx)
459
- const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
460
- const props = { ctx, t: (key) => key }
461
- const first = await renderPage(settings.component, props, undefined, { remount: true })
462
- collectPageHook()
463
- for (const effect of first.effects) effect.fn()
464
- await settle(); await settle()
465
-
466
- const rerenderAt = async (page) => {
467
- const { tree, effects } = await renderPage(settings.component, props, page)
468
- const nodes = []
469
- walkNodes(tree, (node) => { nodes.push(node) })
470
- return { tree, nodes, text: treeText(tree), effects }
471
- }
472
- // Jump to the wall page and let its own effects fetch; browseWall is
473
- // effect-driven, unlike the browser page's handler-driven reload.
474
- let view = await rerenderAt(9)
475
- for (const effect of view.effects) effect.fn()
476
- await settle(); await settle()
477
- view = await rerenderAt(9)
478
- const wallItems = view.nodes.filter((node) => node.type === 'button' && String(node.props?.className || '').includes('dshm-wall-item'))
479
- assert.equal(wallItems.length, 1, 'the wall item did not render')
480
- wallItems[0].props.onClick()
481
- await settle(); await settle()
482
- view = await rerenderAt(9)
483
-
484
- // The drawer is open and editable: save → memorySaved.
485
- const saveButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'save')
486
- assert.equal(saveButtons.length, 1, 'the drawer save button did not render')
487
- saveButtons[0].props.onClick()
488
- await settle(); await settle()
489
- view = await rerenderAt(9)
490
- assert.ok(view.text.includes('memorySaved'), 'the wall save did not reach the page notice')
491
-
492
- // Archive from the drawer → memoryArchived.
493
- const archiveButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive')
494
- assert.equal(archiveButtons.length, 1, 'the drawer archive button did not render')
495
- archiveButtons[0].props.onClick()
496
- await settle(); await settle()
497
- view = await rerenderAt(9)
498
- assert.ok(view.text.includes('memoryArchived'), 'the wall archive did not reach the page notice')
499
-
500
- // Close the drawer, enter multi-select, select all, bulk archive → bulkDone.
501
- const closeButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'close')
502
- assert.ok(closeButtons.length >= 1)
503
- closeButtons[closeButtons.length - 1].props.onClick()
504
- view = await rerenderAt(9)
505
- const multiButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'multiSelect')
506
- assert.equal(multiButtons.length, 1, 'the multi-select entry did not render')
507
- multiButtons[0].props.onClick()
508
- view = await rerenderAt(9)
509
- const selectAll = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'wallSelectAll')
510
- assert.equal(selectAll.length, 1)
511
- selectAll[0].props.onClick()
512
- view = await rerenderAt(9)
513
- const bulkArchive = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive (1)')
514
- assert.equal(bulkArchive.length, 1, 'the bulk archive button did not render')
515
- bulkArchive[0].props.onClick()
516
- await settle(); await settle()
517
- view = await rerenderAt(9)
518
- assert.ok(view.text.includes('bulkDone'), 'the bulk success notice did not appear')
519
- assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-wall' && call.payload.patch.status === 'archived'))
520
- })
1
+ // Package B (spec §6.2): export/import contract + success notices.
2
+ //
3
+ // The export contract is behavioral: exportLibraryNow/importLibraryNow take an
4
+ // options object whose libraryId defaults to the browsed library but must be
5
+ // the id that reaches the exportLibrary payload, the fallback download name
6
+ // and the ZIP upload URL. The notices are the other half: every browser row
7
+ // action answers with its own success message through the page's notice slot
8
+ // while failures keep using setError.
9
+ //
10
+ // Same fake-React harness as tests/client-render.test.mjs, plus two seams the
11
+ // old harness never needed: captured createElement nodes (the file input and
12
+ // the download anchors) and stubbed fetch/URL.createObjectURL.
13
+ import test from 'node:test'
14
+ import assert from 'node:assert/strict'
15
+
16
+ const createdNodes = []
17
+ const fetchCalls = []
18
+ const realFetch = globalThis.fetch
19
+ const realCreateObjectURL = URL.createObjectURL
20
+ const realRevokeObjectURL = URL.revokeObjectURL
21
+
22
+ const registrations = []
23
+
24
+ function makeElement(type, props, ...children) {
25
+ return { type, props: { ...(props || {}), children: children.length <= 1 ? children[0] : children } }
26
+ }
27
+
28
+ let hooks = []
29
+ let cursor = 0
30
+ let effects = []
31
+ let dirty = false
32
+ let forced = null
33
+ let generation = 0
34
+
35
+ const React = {
36
+ createElement: makeElement,
37
+ Fragment: Symbol('Fragment'),
38
+ useState(initial) {
39
+ const index = cursor++
40
+ const generation_ = generation
41
+ if (hooks[index] === undefined) hooks[index] = typeof initial === 'function' ? initial() : initial
42
+ if (forced && forced.index === index) hooks[index] = forced.value
43
+ return [hooks[index], (next) => {
44
+ if (generation_ !== generation) return
45
+ hooks[index] = typeof next === 'function' ? next(hooks[index]) : next
46
+ dirty = true
47
+ }]
48
+ },
49
+ memo: (component) => component,
50
+ useCallback: (fn) => fn,
51
+ useMemo: (fn) => fn(),
52
+ useEffect(fn, deps) { effects.push({ fn, deps, index: cursor++ }) },
53
+ useLayoutEffect() {},
54
+ useRef: (value) => ({ current: value }),
55
+ useSyncExternalStore: (_subscribe, getSnapshot) => getSnapshot(),
56
+ }
57
+
58
+ globalThis.window = {
59
+ __ModuleLoader__: {
60
+ load({ factory }) {
61
+ globalThis.__dshMemuExports = factory((name) => {
62
+ if (name === 'react') return React
63
+ throw new Error(`unexpected require: ${name}`)
64
+ })
65
+ },
66
+ },
67
+ addEventListener() {},
68
+ removeEventListener() {},
69
+ }
70
+ globalThis.document = {
71
+ createElement: (tag) => {
72
+ const node = {
73
+ tag,
74
+ style: {},
75
+ attrs: {},
76
+ children: [],
77
+ href: '',
78
+ download: '',
79
+ textContent: '',
80
+ setAttribute(name, value) { node.attrs[name] = value },
81
+ addEventListener() {},
82
+ appendChild(child) { node.children.push(child); return child },
83
+ remove() { node.removed = true },
84
+ click() { node.clicked = true },
85
+ }
86
+ createdNodes.push(node)
87
+ return node
88
+ },
89
+ querySelector: () => null,
90
+ addEventListener() {},
91
+ removeEventListener() {},
92
+ head: { appendChild() {} },
93
+ body: { appendChild() {} },
94
+ }
95
+
96
+ // The import ZIP path POSTs to a host route; record instead of hitting nothing.
97
+ globalThis.fetch = async (url, options) => {
98
+ fetchCalls.push({ url: String(url), options })
99
+ return { json: async () => ({ ok: true, value: { imported: 2, counts: {} } }) }
100
+ }
101
+ URL.createObjectURL = () => 'blob:fixture'
102
+ URL.revokeObjectURL = () => {}
103
+
104
+ await import('../lib/client.js')
105
+
106
+ const EMPTY_STATE = {
107
+ engine: { status: 'ready', versions: [], currentVersion: '0.11.0b3', recommendedVersion: '0.11.0b3', installed: true, state: {} },
108
+ settings: { autoInject: 'smart', mustRememberCap: 16, unpinBudgetPerSession: 2 },
109
+ libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 2 }],
110
+ archivedLibraries: [],
111
+ memuConfig: { provider: 'openai' },
112
+ summaryConfig: {},
113
+ binding: null,
114
+ privateCount: 2,
115
+ pinnedCount: 0,
116
+ globalCount: 0,
117
+ jobs: [],
118
+ }
119
+
120
+ const BROWSE_FILES = [
121
+ { id: 'mem-live', title: 'live entry', content: 'an active body', layer: 'long_term', status: 'active', decay: 0.9 },
122
+ { id: 'mem-gone', title: 'archived entry', content: 'an archived body', layer: 'long_term', status: 'archived', decay: 0.4 },
123
+ ]
124
+
125
+ const WALL_ITEM = {
126
+ id: 'mem-wall', libraryId: 'lib-1', title: 'walled entry', preview: 'a body',
127
+ layer: 'long_term', status: 'active', decay: 0.9,
128
+ }
129
+
130
+ function makeAnswers(over = {}) {
131
+ return {
132
+ getState: EMPTY_STATE,
133
+ getSettingsState: EMPTY_STATE,
134
+ listLibraries: { libraries: EMPTY_STATE.libraries },
135
+ listSessions: { sessions: [] },
136
+ listVersions: { ok: true, versions: [] },
137
+ listBackups: { backups: [] },
138
+ listFolders: { folders: [] },
139
+ getSidebarState: {
140
+ binding: null, domain: 'general', folder: null,
141
+ effective: { useLibrary: false, useGlobal: false, enabled: false },
142
+ private: { items: [], active: 0, pinned: 0, total: 0 },
143
+ global: { items: [], active: 0, total: 0 },
144
+ domains: [],
145
+ },
146
+ jobStatus: null,
147
+ browseLibrary: { source: 'engine', files: structuredClone(BROWSE_FILES) },
148
+ browseWall: { items: [structuredClone(WALL_ITEM)], total: 1, errors: [] },
149
+ getMemory: { id: 'mem-wall', libraryId: 'lib-1', entry: { title: 'walled entry', content: 'a body', layer: 'long_term', status: 'active', confidence: 0.8, tags: [] }, attachments: [] },
150
+ ...over,
151
+ }
152
+ }
153
+
154
+ function fakeCtx({ answers = {}, rpcCalls = [] } = {}) {
155
+ return {
156
+ effect: (fn) => { try { fn() } catch {} },
157
+ locale: { register: () => () => {}, bind: () => (key) => key, get: () => 'zh' },
158
+ connection: {
159
+ rpc: {
160
+ call: async (path, endpoint, payload) => {
161
+ rpcCalls.push({ path, endpoint, payload })
162
+ if (typeof answers[endpoint] === 'function') return answers[endpoint](payload)
163
+ return { ok: true, value: answers[endpoint] ?? {} }
164
+ },
165
+ },
166
+ },
167
+ sessions: { list: { subscribe: () => () => {}, getSnapshot: () => ({ byId: {}, ids: [] }) } },
168
+ get: (name) => (name === 'uiSession'
169
+ ? { adapter: { current: { getSnapshot: () => ({ key: 'probe-session' }) } } }
170
+ : undefined),
171
+ slots: {
172
+ inject: (_name, callback) => callback(scope),
173
+ register: (spec, component) => { registrations.push({ slot: spec.name, id: spec.id, component }); return () => {} },
174
+ },
175
+ inject: (_deps, callback) => callback({
176
+ effect: (fn) => { try { fn() } catch {} },
177
+ sidebarRightTabs: { register: () => () => {} },
178
+ get: () => undefined,
179
+ }),
180
+ }
181
+ }
182
+
183
+ const scope = {
184
+ effect: (fn) => { try { fn() } catch {} },
185
+ register: (spec, component) => { registrations.push({ slot: spec.name, id: spec.id, component }); return () => {} },
186
+ inject: (_deps, callback) => callback(scope),
187
+ }
188
+
189
+ async function renderPage(component, props, pageValue, { remount = false } = {}) {
190
+ if (remount) { hooks = []; generation++ }
191
+ effects = []
192
+ cursor = 0
193
+ forced = pageValue === undefined ? null : { index: pageHookIndex, value: pageValue }
194
+ const tree = component(props)
195
+ assert.ok(tree, 'component rendered nothing')
196
+ return { tree, effects }
197
+ }
198
+
199
+ let pageHookIndex = -1
200
+
201
+ function collectPageHook() {
202
+ const zeroes = hooks.map((value, index) => (value === 0 ? index : -1)).filter((index) => index >= 0)
203
+ assert.equal(zeroes.length, 1, 'expected exactly one numeric-zero state (the page index)')
204
+ pageHookIndex = zeroes[0]
205
+ }
206
+
207
+ function treeText(node, depth = 0) {
208
+ if (node === null || node === undefined || depth > 400) return ''
209
+ if (typeof node === 'string' || typeof node === 'number') return String(node)
210
+ if (Array.isArray(node)) return node.map((child) => treeText(child, depth + 1)).join(' ')
211
+ if (typeof node.type === 'function') return treeText(node.type(node.props), depth + 1)
212
+ return `${node.props?.className || ''} ${treeText(node.props?.children, depth + 1)}`
213
+ }
214
+
215
+ function walkNodes(node, visit, depth = 0) {
216
+ if (node === null || node === undefined || depth > 400) return
217
+ if (Array.isArray(node)) {
218
+ for (const child of node) walkNodes(child, visit, depth + 1)
219
+ return
220
+ }
221
+ if (typeof node !== 'object') return
222
+ if (visit(node, depth) === false) return
223
+ if (typeof node.type === 'function') {
224
+ walkNodes(node.type(node.props), visit, depth + 1)
225
+ return
226
+ }
227
+ walkNodes(node.props?.children, visit, depth + 1)
228
+ }
229
+
230
+ const settle = () => new Promise((resolve) => setTimeout(resolve, 0))
231
+
232
+ // Renders the settings page, waits for the mount fetches, jumps to the browser
233
+ // page (5), selects lib-1 in the picker and (optionally) presses reload so the
234
+ // rows are painted. Returns render/rerender helpers plus the collected calls.
235
+ async function openBrowserPage(t, { reload = true, answers = {} } = {}) {
236
+ const rpcCalls = []
237
+ const ctx = fakeCtx({ answers: makeAnswers(answers), rpcCalls })
238
+ globalThis.__dshMemuExports.apply(ctx)
239
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
240
+ assert.ok(settings?.component, 'settings.section was not registered')
241
+ const props = { ctx, t: (key) => key }
242
+ const first = await renderPage(settings.component, props, undefined, { remount: true })
243
+ collectPageHook()
244
+ const cleanups = []
245
+ t.after(() => { for (const cleanup of cleanups.reverse()) cleanup() })
246
+ for (const effect of first.effects) {
247
+ const cleanup = effect.fn()
248
+ if (typeof cleanup === 'function') cleanups.push(cleanup)
249
+ }
250
+ await settle()
251
+ await settle()
252
+
253
+ let tree = (await renderPage(settings.component, props, 5)).tree
254
+ let picker = []
255
+ walkNodes(tree, (node) => {
256
+ const options = Array.isArray(node.props?.children) ? node.props.children : []
257
+ if (node.type === 'select' && options.some((option) => option?.props?.value === 'lib-1')) picker.push(node)
258
+ })
259
+ assert.equal(picker.length, 1, 'the library picker did not render')
260
+ picker[0].props.onChange({ target: { value: 'lib-1' } })
261
+
262
+ const rerender = async () => {
263
+ const { tree, effects } = await renderPage(settings.component, props, 5)
264
+ const nodes = []
265
+ walkNodes(tree, (node) => { nodes.push(node) })
266
+ return { tree, nodes, text: treeText(tree), effects }
267
+ }
268
+ let view = await rerender()
269
+
270
+ if (reload) {
271
+ const reloadButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'reload')
272
+ assert.equal(reloadButtons.length, 1, 'the reload button did not render')
273
+ reloadButtons[0].props.onClick()
274
+ await settle()
275
+ await settle()
276
+ view = await rerender()
277
+ }
278
+ const findButtons = (label) => view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === label)
279
+ return { ctx, rpcCalls, rerender, view, findButtons }
280
+ }
281
+
282
+ test.after(() => {
283
+ globalThis.fetch = realFetch
284
+ URL.createObjectURL = realCreateObjectURL
285
+ URL.revokeObjectURL = realRevokeObjectURL
286
+ })
287
+
288
+ test('the JSON export sends the browsed libraryId and reports exportStarted with the filename', async (t) => {
289
+ createdNodes.length = 0
290
+ const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, {
291
+ reload: false,
292
+ answers: { exportLibrary: { filename: 'lib-1.json', base64: Buffer.from('hello').toString('base64') } },
293
+ })
294
+ const exportButtons = findButtons('export')
295
+ assert.equal(exportButtons.length, 1, 'the JSON export button did not render')
296
+ exportButtons[0].props.onClick()
297
+ await settle()
298
+ await settle()
299
+
300
+ const call = rpcCalls.find((entry) => entry.endpoint === 'exportLibrary')
301
+ assert.ok(call, 'exportLibrary was not called')
302
+ assert.equal(call.payload.libraryId, 'lib-1', 'the payload must carry the selected library id')
303
+ assert.equal(call.payload.includeAttachments, false)
304
+ assert.equal(call.payload.delivery, undefined)
305
+ const anchor = createdNodes.find((node) => node.tag === 'a' && node.clicked)
306
+ assert.ok(anchor, 'the download anchor was created and clicked')
307
+ assert.equal(anchor.href, 'blob:fixture')
308
+ assert.equal(anchor.download, 'lib-1.json', 'the fallback download name uses the served filename')
309
+ const { text } = await rerender()
310
+ assert.ok(text.includes('exportStarted'), 'the export notice did not appear')
311
+ assert.ok(!text.includes('exportImages'), 'the renamed copy key leaked back in')
312
+ })
313
+
314
+ test('the ZIP export passes includeAttachments with delivery download and offers the served URL', async (t) => {
315
+ createdNodes.length = 0
316
+ const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, {
317
+ reload: false,
318
+ answers: { exportLibrary: { filename: 'lib-1-with-attachments.zip', downloadUrl: 'http://host/exports/lib-1-with-attachments.zip' } },
319
+ })
320
+ const zipButtons = findButtons('exportZip')
321
+ assert.equal(zipButtons.length, 1, 'the ZIP export button did not render')
322
+ zipButtons[0].props.onClick()
323
+ await settle()
324
+ await settle()
325
+
326
+ const call = rpcCalls.find((entry) => entry.endpoint === 'exportLibrary')
327
+ assert.equal(call.payload.includeAttachments, true, 'the ZIP button must request attachments')
328
+ assert.equal(call.payload.delivery, 'download')
329
+ assert.equal(call.payload.libraryId, 'lib-1')
330
+ const anchor = createdNodes.find((node) => node.tag === 'a' && node.clicked)
331
+ assert.ok(anchor, 'the downloadUrl branch still downloads through an anchor')
332
+ assert.equal(anchor.href, 'http://host/exports/lib-1-with-attachments.zip')
333
+ const { text } = await rerender()
334
+ assert.ok(text.includes('exportStarted'), 'a served URL export also reports exportStarted')
335
+ })
336
+
337
+ test('the ZIP import posts to the selected library id and lands back in that library', async (t) => {
338
+ createdNodes.length = 0
339
+ fetchCalls.length = 0
340
+ const { rpcCalls, rerender, findButtons } = await openBrowserPage(t, { reload: false })
341
+ const importButtons = findButtons('importJson')
342
+ assert.equal(importButtons.length, 1, 'the import button did not render')
343
+ importButtons[0].props.onClick()
344
+ const input = createdNodes.find((node) => node.tag === 'input' && node.type === 'file')
345
+ assert.ok(input, 'the import file picker was created')
346
+ input.files = [{ name: 'lib-1.zip' }]
347
+ await input.onchange()
348
+ await settle()
349
+ await settle()
350
+
351
+ assert.equal(fetchCalls.length, 1, 'the ZIP import must go through the host route')
352
+ assert.ok(
353
+ fetchCalls[0].url.startsWith('/dsh-memu-memory/import/lib-1.zip'),
354
+ `the ZIP URL must use the selected library id, got ${fetchCalls[0].url}`,
355
+ )
356
+ const { text } = await rerender()
357
+ assert.ok(text.includes('importDone'), 'the import success notice did not appear')
358
+ // After a successful import the browser reloads the same library.
359
+ const browsed = rpcCalls.filter((entry) => entry.endpoint === 'browseLibrary')
360
+ assert.ok(browsed.some((entry) => entry.payload.libraryId === 'lib-1'), 'the browser reloaded the imported library')
361
+ })
362
+
363
+ test('each browser row action answers with its own success notice', async (t) => {
364
+ createdNodes.length = 0
365
+ // A server with state: the row actions mutate the served inventory, so the
366
+ // archived tab really gains/loses rows as the test drives it. Function
367
+ // answers must hand back the full RPC envelope (ok/value) themselves.
368
+ const files = structuredClone(BROWSE_FILES)
369
+ const { rpcCalls, rerender, view, findButtons } = await openBrowserPage(t, {
370
+ reload: true,
371
+ answers: {
372
+ browseLibrary: () => ({ ok: true, value: { source: 'engine', files: structuredClone(files) } }),
373
+ addMemory: async () => ({ ok: true, value: { id: 'mem-added' } }),
374
+ updateMemory: async (payload) => {
375
+ const row = files.find((file) => file.id === payload.id)
376
+ if (row) Object.assign(row, payload.patch)
377
+ return { ok: true, value: {} }
378
+ },
379
+ archiveMemory: async (payload) => {
380
+ const row = files.find((file) => file.id === payload.id)
381
+ if (row) row.status = 'archived'
382
+ return { ok: true, value: {} }
383
+ },
384
+ deleteMemory: async (payload) => {
385
+ const at = files.findIndex((file) => file.id === payload.id)
386
+ if (at >= 0) files.splice(at, 1)
387
+ return { ok: true, value: {} }
388
+ },
389
+ },
390
+ })
391
+
392
+ // addMemory → memorySaved
393
+ const contentBox = view.nodes.find((node) => node.type === 'textarea' && node.props?.placeholder === 'memoryContent')
394
+ assert.ok(contentBox, 'the new-memory form did not render')
395
+ contentBox.props.onChange({ target: { value: 'a fresh fact worth keeping' } })
396
+ let next = await rerender()
397
+ const addButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'add')
398
+ assert.equal(addButtons.length, 1)
399
+ addButtons[0].props.onClick()
400
+ await settle(); await settle()
401
+ next = await rerender()
402
+ assert.ok(next.text.includes('memorySaved'), 'addMemory did not report memorySaved')
403
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'addMemory' && call.payload.libraryId === 'lib-1'))
404
+
405
+ // saveMemory → memorySaved (the row editor needs a non-empty draft first)
406
+ const titleInput = next.nodes.find((node) => node.type === 'input' && node.props?.placeholder === 'name')
407
+ assert.ok(titleInput, 'the row editor did not render')
408
+ titleInput.props.onChange({ target: { value: 'renamed entry' } })
409
+ next = await rerender()
410
+ const saveButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'save')
411
+ assert.equal(saveButtons.length, 1, 'the row save button did not render')
412
+ saveButtons[0].props.onClick()
413
+ await settle(); await settle()
414
+ next = await rerender()
415
+ assert.ok(next.text.includes('memorySaved'), 'saveMemory did not report memorySaved')
416
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-live'))
417
+
418
+ // archiveMemory → memoryArchived (the active row's archive button)
419
+ const archiveButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive')
420
+ assert.equal(archiveButtons.length, 1, 'the active row archive button did not render')
421
+ archiveButtons[0].props.onClick()
422
+ await settle(); await settle()
423
+ next = await rerender()
424
+ assert.ok(next.text.includes('memoryArchived'), 'archiveMemory did not report memoryArchived')
425
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'archiveMemory' && call.payload.id === 'mem-live'))
426
+
427
+ // The archived tab now holds both rows; restore → memoryRestored.
428
+ const archivedTab = next.nodes.filter((node) => node.props?.role === 'tab'
429
+ && String(node.props?.children || '').startsWith('browseArchivedTab'))
430
+ assert.equal(archivedTab.length, 1)
431
+ archivedTab[0].props.onClick()
432
+ next = await rerender()
433
+ const restoreButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'restore')
434
+ assert.equal(restoreButtons.length, 2, 'both archived rows offer restore')
435
+ restoreButtons[1].props.onClick()
436
+ await settle(); await settle()
437
+ next = await rerender()
438
+ assert.ok(next.text.includes('memoryRestored'), 'restoreMemory did not report memoryRestored')
439
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-gone' && call.payload.patch.status === 'active'))
440
+
441
+ // deleteMemoryForever → memoryDeleted (two-step confirm on the last archived row)
442
+ const armButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'deleteForever')
443
+ assert.ok(armButtons.length >= 1, 'the archived delete button did not render')
444
+ armButtons[0].props.onClick()
445
+ next = await rerender()
446
+ const confirmButtons = next.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'confirmDelete')
447
+ assert.equal(confirmButtons.length, 1, 'the armed confirm did not render')
448
+ confirmButtons[0].props.onClick()
449
+ await settle(); await settle()
450
+ next = await rerender()
451
+ assert.ok(next.text.includes('memoryDeleted'), 'deleteMemoryForever did not report memoryDeleted')
452
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'deleteMemory' && call.payload.id === 'mem-live'))
453
+ })
454
+
455
+ test('the memory wall reports save, archive and bulk outcomes through onNotice', async (t) => {
456
+ createdNodes.length = 0
457
+ const rpcCalls = []
458
+ const ctx = fakeCtx({ answers: makeAnswers(), rpcCalls })
459
+ globalThis.__dshMemuExports.apply(ctx)
460
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
461
+ const props = { ctx, t: (key) => key }
462
+ const first = await renderPage(settings.component, props, undefined, { remount: true })
463
+ collectPageHook()
464
+ for (const effect of first.effects) effect.fn()
465
+ await settle(); await settle()
466
+
467
+ const rerenderAt = async (page) => {
468
+ const { tree, effects } = await renderPage(settings.component, props, page)
469
+ const nodes = []
470
+ walkNodes(tree, (node) => { nodes.push(node) })
471
+ return { tree, nodes, text: treeText(tree), effects }
472
+ }
473
+ // Jump to the wall page and let its own effects fetch; browseWall is
474
+ // effect-driven, unlike the browser page's handler-driven reload.
475
+ let view = await rerenderAt(9)
476
+ for (const effect of view.effects) effect.fn()
477
+ await settle(); await settle()
478
+ view = await rerenderAt(9)
479
+ const wallItems = view.nodes.filter((node) => node.type === 'button' && String(node.props?.className || '').includes('dshm-wall-item'))
480
+ assert.equal(wallItems.length, 1, 'the wall item did not render')
481
+ wallItems[0].props.onClick()
482
+ await settle(); await settle()
483
+ view = await rerenderAt(9)
484
+
485
+ // The drawer is open and editable: save → memorySaved.
486
+ const saveButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'save')
487
+ assert.equal(saveButtons.length, 1, 'the drawer save button did not render')
488
+ saveButtons[0].props.onClick()
489
+ await settle(); await settle()
490
+ view = await rerenderAt(9)
491
+ assert.ok(view.text.includes('memorySaved'), 'the wall save did not reach the page notice')
492
+
493
+ // Archive from the drawer → memoryArchived.
494
+ const archiveButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive')
495
+ assert.equal(archiveButtons.length, 1, 'the drawer archive button did not render')
496
+ archiveButtons[0].props.onClick()
497
+ await settle(); await settle()
498
+ view = await rerenderAt(9)
499
+ assert.ok(view.text.includes('memoryArchived'), 'the wall archive did not reach the page notice')
500
+
501
+ // Close the drawer, enter multi-select, select all, bulk archive → bulkDone.
502
+ const closeButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'close')
503
+ assert.ok(closeButtons.length >= 1)
504
+ closeButtons[closeButtons.length - 1].props.onClick()
505
+ view = await rerenderAt(9)
506
+ const multiButtons = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'multiSelect')
507
+ assert.equal(multiButtons.length, 1, 'the multi-select entry did not render')
508
+ multiButtons[0].props.onClick()
509
+ view = await rerenderAt(9)
510
+ const selectAll = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'wallSelectAll')
511
+ assert.equal(selectAll.length, 1)
512
+ selectAll[0].props.onClick()
513
+ view = await rerenderAt(9)
514
+ const bulkArchive = view.nodes.filter((node) => typeof node.type === 'function' && node.props?.children === 'archive (1)')
515
+ assert.equal(bulkArchive.length, 1, 'the bulk archive button did not render')
516
+ bulkArchive[0].props.onClick()
517
+ await settle(); await settle()
518
+ view = await rerenderAt(9)
519
+ assert.ok(view.text.includes('bulkDone'), 'the bulk success notice did not appear')
520
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'updateMemory' && call.payload.id === 'mem-wall' && call.payload.patch.status === 'archived'))
521
+ })