@fgv/ts-agent-memory 5.1.0-46 → 5.1.0-48

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 (336) hide show
  1. package/README.md +55 -0
  2. package/dist/packlets/ingest/orchestrator.js +115 -20
  3. package/dist/packlets/ingest/orchestrator.js.map +1 -1
  4. package/dist/packlets/observe/memoryObservationStore.js +6 -0
  5. package/dist/packlets/observe/memoryObservationStore.js.map +1 -1
  6. package/dist/packlets/observe/observer.js.map +1 -1
  7. package/dist/packlets/store/fileTreeMemoryStore.js +63 -135
  8. package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
  9. package/dist/packlets/store/vectorMaintenance.js +251 -0
  10. package/dist/packlets/store/vectorMaintenance.js.map +1 -0
  11. package/dist/packlets/vector/inMemoryCosineIndex.js +81 -18
  12. package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  13. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  14. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  15. package/dist/packlets/vector/vectorIndex.js.map +1 -1
  16. package/dist/ts-agent-memory.d.ts +389 -71
  17. package/lib/packlets/ingest/orchestrator.d.ts +62 -5
  18. package/lib/packlets/ingest/orchestrator.d.ts.map +1 -1
  19. package/lib/packlets/ingest/orchestrator.js +115 -20
  20. package/lib/packlets/ingest/orchestrator.js.map +1 -1
  21. package/lib/packlets/observe/memoryObservationStore.d.ts.map +1 -1
  22. package/lib/packlets/observe/memoryObservationStore.js +6 -0
  23. package/lib/packlets/observe/memoryObservationStore.js.map +1 -1
  24. package/lib/packlets/observe/observer.d.ts +61 -0
  25. package/lib/packlets/observe/observer.d.ts.map +1 -1
  26. package/lib/packlets/observe/observer.js.map +1 -1
  27. package/lib/packlets/store/fileTreeMemoryStore.d.ts +97 -60
  28. package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
  29. package/lib/packlets/store/fileTreeMemoryStore.js +63 -135
  30. package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
  31. package/lib/packlets/store/vectorMaintenance.d.ts +149 -0
  32. package/lib/packlets/store/vectorMaintenance.d.ts.map +1 -0
  33. package/lib/packlets/store/vectorMaintenance.js +255 -0
  34. package/lib/packlets/store/vectorMaintenance.js.map +1 -0
  35. package/lib/packlets/vector/inMemoryCosineIndex.d.ts +30 -7
  36. package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -1
  37. package/lib/packlets/vector/inMemoryCosineIndex.js +80 -17
  38. package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  39. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts +7 -0
  40. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts.map +1 -1
  41. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  42. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  43. package/lib/packlets/vector/vectorIndex.d.ts +129 -1
  44. package/lib/packlets/vector/vectorIndex.d.ts.map +1 -1
  45. package/lib/packlets/vector/vectorIndex.js.map +1 -1
  46. package/package.json +17 -7
  47. package/.rush/temp/6e1299d1cebb080772163a532c221cd181b54f9f.tar.log +0 -462
  48. package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +0 -9
  49. package/.rush/temp/operation/build/all.log +0 -9
  50. package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
  51. package/.rush/temp/operation/build/state.json +0 -3
  52. package/.rush/temp/shrinkwrap-deps.json +0 -689
  53. package/config/api-extractor.json +0 -343
  54. package/config/jest.config.json +0 -14
  55. package/config/rig.json +0 -4
  56. package/dist/test/unit/converters/antagonistRoundTrip.test.js +0 -95
  57. package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  58. package/dist/test/unit/converters/bodyConverterRegistry.test.js +0 -72
  59. package/dist/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  60. package/dist/test/unit/converters/envelopeConverter.test.js +0 -313
  61. package/dist/test/unit/converters/envelopeConverter.test.js.map +0 -1
  62. package/dist/test/unit/index/memoryIndex.test.js +0 -214
  63. package/dist/test/unit/index/memoryIndex.test.js.map +0 -1
  64. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +0 -277
  65. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  66. package/dist/test/unit/ingest/cycleGuard.test.js +0 -81
  67. package/dist/test/unit/ingest/cycleGuard.test.js.map +0 -1
  68. package/dist/test/unit/ingest/orchestrator.test.js +0 -1055
  69. package/dist/test/unit/ingest/orchestrator.test.js.map +0 -1
  70. package/dist/test/unit/observe/memoryObservationStore.test.js +0 -118
  71. package/dist/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  72. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -116
  73. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  74. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +0 -257
  75. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  76. package/dist/test/unit/retrieve/retrievers.test.js +0 -768
  77. package/dist/test/unit/retrieve/retrievers.test.js.map +0 -1
  78. package/dist/test/unit/retrieve/temporalRetrievers.test.js +0 -182
  79. package/dist/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  80. package/dist/test/unit/store/antagonistTemporalBoundary.test.js +0 -120
  81. package/dist/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  82. package/dist/test/unit/store/embedOnWrite.test.js +0 -317
  83. package/dist/test/unit/store/embedOnWrite.test.js.map +0 -1
  84. package/dist/test/unit/store/fileTreeMemoryStore.test.js +0 -778
  85. package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  86. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js +0 -255
  87. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  88. package/dist/test/unit/store/indexInjection.test.js +0 -432
  89. package/dist/test/unit/store/indexInjection.test.js.map +0 -1
  90. package/dist/test/unit/store/lenientOpen.test.js +0 -248
  91. package/dist/test/unit/store/lenientOpen.test.js.map +0 -1
  92. package/dist/test/unit/store/listScoped.test.js +0 -109
  93. package/dist/test/unit/store/listScoped.test.js.map +0 -1
  94. package/dist/test/unit/store/observations.test.js +0 -239
  95. package/dist/test/unit/store/observations.test.js.map +0 -1
  96. package/dist/test/unit/store/rankAxis.test.js +0 -254
  97. package/dist/test/unit/store/rankAxis.test.js.map +0 -1
  98. package/dist/test/unit/store/scopeEncoding.test.js +0 -24
  99. package/dist/test/unit/store/scopeEncoding.test.js.map +0 -1
  100. package/dist/test/unit/store/temporalStore.test.js +0 -398
  101. package/dist/test/unit/store/temporalStore.test.js.map +0 -1
  102. package/dist/test/unit/tools/memoryTools.test.js +0 -841
  103. package/dist/test/unit/tools/memoryTools.test.js.map +0 -1
  104. package/dist/test/unit/types/identityCodec.test.js +0 -187
  105. package/dist/test/unit/types/identityCodec.test.js.map +0 -1
  106. package/dist/test/unit/types/ids.test.js +0 -84
  107. package/dist/test/unit/types/ids.test.js.map +0 -1
  108. package/dist/test/unit/types/temporalCodec.test.js +0 -203
  109. package/dist/test/unit/types/temporalCodec.test.js.map +0 -1
  110. package/dist/test/unit/types/temporalPolicy.test.js +0 -83
  111. package/dist/test/unit/types/temporalPolicy.test.js.map +0 -1
  112. package/dist/test/unit/types/writePolicy.test.js +0 -331
  113. package/dist/test/unit/types/writePolicy.test.js.map +0 -1
  114. package/dist/test/unit/vector/fragmentConverters.test.js +0 -58
  115. package/dist/test/unit/vector/fragmentConverters.test.js.map +0 -1
  116. package/dist/test/unit/vector/inMemoryCosineIndex.test.js +0 -252
  117. package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  118. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -362
  119. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  120. package/dist/test/unit/vector/vectorIndex.test.js +0 -51
  121. package/dist/test/unit/vector/vectorIndex.test.js.map +0 -1
  122. package/eslint.config.js +0 -15
  123. package/etc/ts-agent-memory.api.md +0 -938
  124. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts +0 -10
  125. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts.map +0 -1
  126. package/lib/test/unit/converters/antagonistRoundTrip.test.js +0 -97
  127. package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  128. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts +0 -2
  129. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts.map +0 -1
  130. package/lib/test/unit/converters/bodyConverterRegistry.test.js +0 -74
  131. package/lib/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  132. package/lib/test/unit/converters/envelopeConverter.test.d.ts +0 -2
  133. package/lib/test/unit/converters/envelopeConverter.test.d.ts.map +0 -1
  134. package/lib/test/unit/converters/envelopeConverter.test.js +0 -315
  135. package/lib/test/unit/converters/envelopeConverter.test.js.map +0 -1
  136. package/lib/test/unit/index/memoryIndex.test.d.ts +0 -2
  137. package/lib/test/unit/index/memoryIndex.test.d.ts.map +0 -1
  138. package/lib/test/unit/index/memoryIndex.test.js +0 -216
  139. package/lib/test/unit/index/memoryIndex.test.js.map +0 -1
  140. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts +0 -9
  141. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts.map +0 -1
  142. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +0 -279
  143. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  144. package/lib/test/unit/ingest/cycleGuard.test.d.ts +0 -2
  145. package/lib/test/unit/ingest/cycleGuard.test.d.ts.map +0 -1
  146. package/lib/test/unit/ingest/cycleGuard.test.js +0 -83
  147. package/lib/test/unit/ingest/cycleGuard.test.js.map +0 -1
  148. package/lib/test/unit/ingest/orchestrator.test.d.ts +0 -2
  149. package/lib/test/unit/ingest/orchestrator.test.d.ts.map +0 -1
  150. package/lib/test/unit/ingest/orchestrator.test.js +0 -1057
  151. package/lib/test/unit/ingest/orchestrator.test.js.map +0 -1
  152. package/lib/test/unit/observe/memoryObservationStore.test.d.ts +0 -2
  153. package/lib/test/unit/observe/memoryObservationStore.test.d.ts.map +0 -1
  154. package/lib/test/unit/observe/memoryObservationStore.test.js +0 -120
  155. package/lib/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  156. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts +0 -2
  157. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts.map +0 -1
  158. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -118
  159. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  160. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts +0 -2
  161. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts.map +0 -1
  162. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +0 -259
  163. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  164. package/lib/test/unit/retrieve/retrievers.test.d.ts +0 -2
  165. package/lib/test/unit/retrieve/retrievers.test.d.ts.map +0 -1
  166. package/lib/test/unit/retrieve/retrievers.test.js +0 -770
  167. package/lib/test/unit/retrieve/retrievers.test.js.map +0 -1
  168. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts +0 -2
  169. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts.map +0 -1
  170. package/lib/test/unit/retrieve/temporalRetrievers.test.js +0 -184
  171. package/lib/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  172. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts +0 -9
  173. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts.map +0 -1
  174. package/lib/test/unit/store/antagonistTemporalBoundary.test.js +0 -122
  175. package/lib/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  176. package/lib/test/unit/store/embedOnWrite.test.d.ts +0 -2
  177. package/lib/test/unit/store/embedOnWrite.test.d.ts.map +0 -1
  178. package/lib/test/unit/store/embedOnWrite.test.js +0 -319
  179. package/lib/test/unit/store/embedOnWrite.test.js.map +0 -1
  180. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts +0 -2
  181. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts.map +0 -1
  182. package/lib/test/unit/store/fileTreeMemoryStore.test.js +0 -780
  183. package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  184. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts +0 -2
  185. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts.map +0 -1
  186. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js +0 -257
  187. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  188. package/lib/test/unit/store/indexInjection.test.d.ts +0 -2
  189. package/lib/test/unit/store/indexInjection.test.d.ts.map +0 -1
  190. package/lib/test/unit/store/indexInjection.test.js +0 -434
  191. package/lib/test/unit/store/indexInjection.test.js.map +0 -1
  192. package/lib/test/unit/store/lenientOpen.test.d.ts +0 -2
  193. package/lib/test/unit/store/lenientOpen.test.d.ts.map +0 -1
  194. package/lib/test/unit/store/lenientOpen.test.js +0 -250
  195. package/lib/test/unit/store/lenientOpen.test.js.map +0 -1
  196. package/lib/test/unit/store/listScoped.test.d.ts +0 -2
  197. package/lib/test/unit/store/listScoped.test.d.ts.map +0 -1
  198. package/lib/test/unit/store/listScoped.test.js +0 -111
  199. package/lib/test/unit/store/listScoped.test.js.map +0 -1
  200. package/lib/test/unit/store/observations.test.d.ts +0 -2
  201. package/lib/test/unit/store/observations.test.d.ts.map +0 -1
  202. package/lib/test/unit/store/observations.test.js +0 -241
  203. package/lib/test/unit/store/observations.test.js.map +0 -1
  204. package/lib/test/unit/store/rankAxis.test.d.ts +0 -2
  205. package/lib/test/unit/store/rankAxis.test.d.ts.map +0 -1
  206. package/lib/test/unit/store/rankAxis.test.js +0 -256
  207. package/lib/test/unit/store/rankAxis.test.js.map +0 -1
  208. package/lib/test/unit/store/scopeEncoding.test.d.ts +0 -2
  209. package/lib/test/unit/store/scopeEncoding.test.d.ts.map +0 -1
  210. package/lib/test/unit/store/scopeEncoding.test.js +0 -26
  211. package/lib/test/unit/store/scopeEncoding.test.js.map +0 -1
  212. package/lib/test/unit/store/temporalStore.test.d.ts +0 -2
  213. package/lib/test/unit/store/temporalStore.test.d.ts.map +0 -1
  214. package/lib/test/unit/store/temporalStore.test.js +0 -400
  215. package/lib/test/unit/store/temporalStore.test.js.map +0 -1
  216. package/lib/test/unit/tools/memoryTools.test.d.ts +0 -2
  217. package/lib/test/unit/tools/memoryTools.test.d.ts.map +0 -1
  218. package/lib/test/unit/tools/memoryTools.test.js +0 -843
  219. package/lib/test/unit/tools/memoryTools.test.js.map +0 -1
  220. package/lib/test/unit/types/identityCodec.test.d.ts +0 -2
  221. package/lib/test/unit/types/identityCodec.test.d.ts.map +0 -1
  222. package/lib/test/unit/types/identityCodec.test.js +0 -189
  223. package/lib/test/unit/types/identityCodec.test.js.map +0 -1
  224. package/lib/test/unit/types/ids.test.d.ts +0 -2
  225. package/lib/test/unit/types/ids.test.d.ts.map +0 -1
  226. package/lib/test/unit/types/ids.test.js +0 -86
  227. package/lib/test/unit/types/ids.test.js.map +0 -1
  228. package/lib/test/unit/types/temporalCodec.test.d.ts +0 -2
  229. package/lib/test/unit/types/temporalCodec.test.d.ts.map +0 -1
  230. package/lib/test/unit/types/temporalCodec.test.js +0 -205
  231. package/lib/test/unit/types/temporalCodec.test.js.map +0 -1
  232. package/lib/test/unit/types/temporalPolicy.test.d.ts +0 -2
  233. package/lib/test/unit/types/temporalPolicy.test.d.ts.map +0 -1
  234. package/lib/test/unit/types/temporalPolicy.test.js +0 -85
  235. package/lib/test/unit/types/temporalPolicy.test.js.map +0 -1
  236. package/lib/test/unit/types/writePolicy.test.d.ts +0 -2
  237. package/lib/test/unit/types/writePolicy.test.d.ts.map +0 -1
  238. package/lib/test/unit/types/writePolicy.test.js +0 -333
  239. package/lib/test/unit/types/writePolicy.test.js.map +0 -1
  240. package/lib/test/unit/vector/fragmentConverters.test.d.ts +0 -2
  241. package/lib/test/unit/vector/fragmentConverters.test.d.ts.map +0 -1
  242. package/lib/test/unit/vector/fragmentConverters.test.js +0 -60
  243. package/lib/test/unit/vector/fragmentConverters.test.js.map +0 -1
  244. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts +0 -2
  245. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts.map +0 -1
  246. package/lib/test/unit/vector/inMemoryCosineIndex.test.js +0 -254
  247. package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  248. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts +0 -2
  249. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts.map +0 -1
  250. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -364
  251. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  252. package/lib/test/unit/vector/vectorIndex.test.d.ts +0 -2
  253. package/lib/test/unit/vector/vectorIndex.test.d.ts.map +0 -1
  254. package/lib/test/unit/vector/vectorIndex.test.js +0 -53
  255. package/lib/test/unit/vector/vectorIndex.test.js.map +0 -1
  256. package/rush-logs/ts-agent-memory.build.cache.log +0 -3
  257. package/rush-logs/ts-agent-memory.build.log +0 -9
  258. package/src/index.ts +0 -14
  259. package/src/packlets/converters/bodyConverterRegistry.ts +0 -105
  260. package/src/packlets/converters/envelopeConverter.ts +0 -233
  261. package/src/packlets/converters/index.ts +0 -7
  262. package/src/packlets/index/index.ts +0 -6
  263. package/src/packlets/index/memoryIndex.ts +0 -332
  264. package/src/packlets/ingest/cycleGuard.ts +0 -153
  265. package/src/packlets/ingest/hostStages.ts +0 -111
  266. package/src/packlets/ingest/index.ts +0 -9
  267. package/src/packlets/ingest/model.ts +0 -195
  268. package/src/packlets/ingest/orchestrator.ts +0 -873
  269. package/src/packlets/observe/index.ts +0 -7
  270. package/src/packlets/observe/memoryObservationStore.ts +0 -153
  271. package/src/packlets/observe/observer.ts +0 -119
  272. package/src/packlets/retrieve/fragmentSemanticRetriever.ts +0 -138
  273. package/src/packlets/retrieve/hybridRetriever.ts +0 -194
  274. package/src/packlets/retrieve/index.ts +0 -14
  275. package/src/packlets/retrieve/linkTraversalRetriever.ts +0 -158
  276. package/src/packlets/retrieve/recencyRetriever.ts +0 -54
  277. package/src/packlets/retrieve/retriever.ts +0 -291
  278. package/src/packlets/retrieve/semanticRetriever.ts +0 -152
  279. package/src/packlets/retrieve/structuredFilterRetriever.ts +0 -58
  280. package/src/packlets/retrieve/tagRetriever.ts +0 -58
  281. package/src/packlets/retrieve/temporalRetrievers.ts +0 -210
  282. package/src/packlets/store/fileTreeMemoryStore.ts +0 -1834
  283. package/src/packlets/store/index.ts +0 -7
  284. package/src/packlets/store/scopeEncoding.ts +0 -36
  285. package/src/packlets/tools/index.ts +0 -6
  286. package/src/packlets/tools/memoryTools.ts +0 -706
  287. package/src/packlets/types/envelope.ts +0 -196
  288. package/src/packlets/types/filenameSafety.ts +0 -57
  289. package/src/packlets/types/identityCodec.ts +0 -447
  290. package/src/packlets/types/ids.ts +0 -124
  291. package/src/packlets/types/index.ts +0 -11
  292. package/src/packlets/types/temporal.ts +0 -96
  293. package/src/packlets/types/writePolicy.ts +0 -612
  294. package/src/packlets/vector/fragmentConverters.ts +0 -55
  295. package/src/packlets/vector/inMemoryCosineIndex.ts +0 -196
  296. package/src/packlets/vector/inMemoryFragmentCosineIndex.ts +0 -289
  297. package/src/packlets/vector/index.ts +0 -9
  298. package/src/packlets/vector/vectorIndex.ts +0 -273
  299. package/src/test/unit/converters/antagonistRoundTrip.test.ts +0 -110
  300. package/src/test/unit/converters/bodyConverterRegistry.test.ts +0 -89
  301. package/src/test/unit/converters/envelopeConverter.test.ts +0 -418
  302. package/src/test/unit/index/memoryIndex.test.ts +0 -272
  303. package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +0 -367
  304. package/src/test/unit/ingest/cycleGuard.test.ts +0 -110
  305. package/src/test/unit/ingest/orchestrator.test.ts +0 -1351
  306. package/src/test/unit/observe/memoryObservationStore.test.ts +0 -158
  307. package/src/test/unit/retrieve/fragmentSemanticRetriever.test.ts +0 -163
  308. package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +0 -329
  309. package/src/test/unit/retrieve/retrievers.test.ts +0 -1018
  310. package/src/test/unit/retrieve/temporalRetrievers.test.ts +0 -226
  311. package/src/test/unit/store/antagonistTemporalBoundary.test.ts +0 -158
  312. package/src/test/unit/store/embedOnWrite.test.ts +0 -418
  313. package/src/test/unit/store/fileTreeMemoryStore.test.ts +0 -1041
  314. package/src/test/unit/store/fragmentEmbedOnWrite.test.ts +0 -349
  315. package/src/test/unit/store/indexInjection.test.ts +0 -550
  316. package/src/test/unit/store/lenientOpen.test.ts +0 -292
  317. package/src/test/unit/store/listScoped.test.ts +0 -138
  318. package/src/test/unit/store/observations.test.ts +0 -290
  319. package/src/test/unit/store/rankAxis.test.ts +0 -349
  320. package/src/test/unit/store/scopeEncoding.test.ts +0 -37
  321. package/src/test/unit/store/temporalStore.test.ts +0 -469
  322. package/src/test/unit/tools/memoryTools.test.ts +0 -1120
  323. package/src/test/unit/types/identityCodec.test.ts +0 -266
  324. package/src/test/unit/types/ids.test.ts +0 -94
  325. package/src/test/unit/types/temporalCodec.test.ts +0 -259
  326. package/src/test/unit/types/temporalPolicy.test.ts +0 -124
  327. package/src/test/unit/types/writePolicy.test.ts +0 -446
  328. package/src/test/unit/vector/fragmentConverters.test.ts +0 -80
  329. package/src/test/unit/vector/inMemoryCosineIndex.test.ts +0 -318
  330. package/src/test/unit/vector/inMemoryFragmentCosineIndex.test.ts +0 -477
  331. package/src/test/unit/vector/vectorIndex.test.ts +0 -64
  332. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -302
  333. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  334. package/temp/ts-agent-memory.api.json +0 -20933
  335. package/temp/ts-agent-memory.api.md +0 -938
  336. package/tsconfig.json +0 -8
@@ -1 +0,0 @@
1
- {"version":3,"file":"memoryIndex.test.js","sourceRoot":"","sources":["../../../../src/test/unit/index/memoryIndex.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAML,WAAW,EAGX,iBAAiB,EACjB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,iBAAiB,GAAW,WAAW,CAAC;AAE9C,+EAA+E;AAC/E,SAAS,EAAE,CAAC,EAAU;IACpB,OAAO,EAAE,KAAK,EAAE,iBAAmC,EAAE,EAAE,EAAE,EAAc,EAAE,CAAC;AAC5E,CAAC;AAED,qFAAqF;AACrF,SAAS,SAAS,CAAC,OAAmC;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAY,CAAC,CAAC;AAC5C,CAAC;AAaD,SAAS,SAAS,CAAC,IAAiB;;IAClC,MAAM,MAAM,GAA2B;QACrC,QAAQ,EAAE,iBAAiB;aACxB,OAAO,+BACN,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,QAAQ,EAAE,IAAI,CAAC,EAAE,EACjB,IAAI,EAAE,MAAA,IAAI,CAAC,IAAI,mCAAI,WAAW,EAC9B,IAAI,EAAE,MAAA,IAAI,CAAC,IAAI,mCAAI,EAAE,EACrB,KAAK,EAAE,CAAC,MAAA,IAAI,CAAC,KAAK,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBACzC,IAAI,EAAE,KAAK;gBACX,MAAM,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,EAAE,EAAE,MAAM,EAAE;aACjD,CAAC,CAAC,EACH,OAAO,EAAE,CAAC,EACV,OAAO,EAA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AG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACtD,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3D,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAClD,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport '@fgv/ts-utils-jest';\nimport {\n IEdgeTarget,\n IIndexedMemoryRecord,\n IMemoryRecord,\n Kind,\n MemoryId,\n MemoryIndex,\n MemoryScopeKey,\n Tag,\n envelopeConverter,\n rankCompare\n} from '../../../index';\n\n/**\n * The scope every link target in this fixture lives under. Links are authored as\n * bare id strings and resolved to `{ scope: LINK_TARGET_SCOPE, id }`, so the\n * cross-scope source tests can share one target while their sources differ.\n */\nconst LINK_TARGET_SCOPE: string = 'knowledge';\n\n/** A scope-qualified backlink-target query for the fixed link-target scope. */\nfunction bt(id: string): IEdgeTarget {\n return { scope: LINK_TARGET_SCOPE as MemoryScopeKey, id: id as MemoryId };\n}\n\n/** Extract the bare ids from a set of scope-qualified targets (backlink results). */\nfunction targetIds(targets: ReadonlyArray<IEdgeTarget>): string[] {\n return targets.map((t) => t.id as string);\n}\n\ninterface IRecordSpec {\n readonly id: string;\n readonly scope?: string;\n readonly kind?: string;\n readonly tags?: ReadonlyArray<string>;\n readonly links?: ReadonlyArray<string>;\n readonly updated?: number;\n readonly seq?: number;\n readonly rank?: number;\n}\n\nfunction makeEntry(spec: IRecordSpec): IIndexedMemoryRecord {\n const record: IMemoryRecord<unknown> = {\n envelope: envelopeConverter\n .convert({\n id: spec.id,\n entityId: spec.id,\n kind: spec.kind ?? 'knowledge',\n tags: spec.tags ?? [],\n links: (spec.links ?? []).map((target) => ({\n type: 'rel',\n target: { scope: LINK_TARGET_SCOPE, id: target }\n })),\n created: 0,\n updated: spec.updated ?? 0,\n seq: spec.seq ?? 0,\n contentHash: 'h',\n ...(spec.rank !== undefined ? { rank: spec.rank } : {}),\n provenance: { source: 'agent' }\n })\n .orThrow(),\n body: `body-${spec.id}`\n };\n return { scope: (spec.scope ?? 'knowledge') as MemoryScopeKey, record };\n}\n\nfunction ids(records: ReadonlyArray<IMemoryRecord<unknown>>): ReadonlyArray<string> {\n return records.map((r) => r.envelope.id as string);\n}\n\ndescribe('MemoryIndex', () => {\n let index: MemoryIndex;\n\n beforeEach(() => {\n index = MemoryIndex.create().orThrow();\n });\n\n describe('create', () => {\n test('starts empty', () => {\n expect(index.entries()).toHaveLength(0);\n expect(index.byKind('knowledge' as Kind)).toHaveLength(0);\n expect(index.byTag('any' as Tag)).toHaveLength(0);\n expect(index.byRecency()).toHaveLength(0);\n expect(index.backlinks(bt('none'))).toHaveLength(0);\n });\n });\n\n describe('rebuild', () => {\n test('indexes every entry and reports the count', () => {\n const entries = [\n makeEntry({ id: 'a', tags: ['x'], links: ['b'] }),\n makeEntry({ id: 'b', tags: ['x', 'y'] })\n ];\n expect(index.rebuild(entries)).toSucceedWith(2);\n expect(index.entries()).toHaveLength(2);\n expect([...ids(index.byKind('knowledge' as Kind))].sort()).toEqual(['a', 'b']);\n expect([...ids(index.byTag('x' as Tag))].sort()).toEqual(['a', 'b']);\n expect(ids(index.byTag('y' as Tag))).toEqual(['b']);\n expect(targetIds(index.backlinks(bt('b')))).toEqual(['a']);\n });\n\n test('clears prior state', () => {\n index.rebuild([makeEntry({ id: 'a', tags: ['x'] })]).orThrow();\n expect(index.rebuild([makeEntry({ id: 'c', tags: ['z'] })])).toSucceedWith(1);\n expect(ids(index.entries().map((e) => e.record))).toEqual(['c']);\n expect(index.byTag('x' as Tag)).toHaveLength(0);\n });\n });\n\n describe('patch', () => {\n test('put inserts a new entry and returns it', () => {\n const entry = makeEntry({ id: 'a', tags: ['x'], links: ['b'] });\n expect(index.patch('put', entry)).toSucceedWith(entry);\n expect(ids(index.byKind('knowledge' as Kind))).toEqual(['a']);\n expect(targetIds(index.backlinks(bt('b')))).toEqual(['a']);\n });\n\n test('put on an existing key replaces stale associations', () => {\n index.patch('put', makeEntry({ id: 'a', kind: 'knowledge', tags: ['old'], links: ['b'] })).orThrow();\n index.patch('put', makeEntry({ id: 'a', kind: 'note', tags: ['new'], links: ['c'] })).orThrow();\n expect(index.entries()).toHaveLength(1);\n expect(index.byTag('old' as Tag)).toHaveLength(0);\n expect(ids(index.byTag('new' as Tag))).toEqual(['a']);\n expect(index.byKind('knowledge' as Kind)).toHaveLength(0);\n expect(ids(index.byKind('note' as Kind))).toEqual(['a']);\n expect(index.backlinks(bt('b'))).toHaveLength(0);\n expect(targetIds(index.backlinks(bt('c')))).toEqual(['a']);\n });\n\n test('delete removes the entry and its associations', () => {\n const entry = makeEntry({ id: 'a', tags: ['x'], links: ['b'] });\n index.patch('put', entry).orThrow();\n expect(index.patch('delete', entry)).toSucceedWith(entry);\n expect(index.entries()).toHaveLength(0);\n expect(index.byTag('x' as Tag)).toHaveLength(0);\n expect(index.backlinks(bt('b'))).toHaveLength(0);\n });\n\n test('delete of an absent key is a no-op that still succeeds', () => {\n const entry = makeEntry({ id: 'ghost' });\n expect(index.patch('delete', entry)).toSucceedWith(entry);\n expect(index.entries()).toHaveLength(0);\n });\n\n test('distinguishes entries with the same id across scopes', () => {\n index.patch('put', makeEntry({ id: 'turn-0', scope: 'conversations/c1' })).orThrow();\n index.patch('put', makeEntry({ id: 'turn-0', scope: 'conversations/c2' })).orThrow();\n expect(index.entries()).toHaveLength(2);\n });\n });\n\n describe('byRecency', () => {\n test('orders most-recently-updated first, breaking ties by seq', () => {\n index\n .rebuild([\n makeEntry({ id: 'old', updated: 100, seq: 1 }),\n makeEntry({ id: 'newest', updated: 300, seq: 3 }),\n makeEntry({ id: 'tie-lo', updated: 200, seq: 4 }),\n makeEntry({ id: 'tie-hi', updated: 200, seq: 9 })\n ])\n .orThrow();\n expect(ids(index.byRecency())).toEqual(['newest', 'tie-hi', 'tie-lo', 'old']);\n });\n });\n\n describe('byRank', () => {\n test('orders by rank descending, absent-rank records last, recency tiebreak', () => {\n index\n .rebuild([\n makeEntry({ id: 'mid', rank: 5, updated: 100, seq: 1 }),\n makeEntry({ id: 'top', rank: 9, updated: 100, seq: 2 }),\n makeEntry({ id: 'tie-lo', rank: 3, updated: 200, seq: 4 }),\n makeEntry({ id: 'tie-hi', rank: 3, updated: 200, seq: 9 }),\n makeEntry({ id: 'unranked-old', updated: 100, seq: 5 }),\n makeEntry({ id: 'unranked-new', updated: 400, seq: 6 })\n ])\n .orThrow();\n // ranked (desc): top(9), mid(5), tie-hi(3,seq9), tie-lo(3,seq4);\n // then unranked by recency: unranked-new(updated400), unranked-old(updated100).\n expect(ids(index.byRank())).toEqual(['top', 'mid', 'tie-hi', 'tie-lo', 'unranked-new', 'unranked-old']);\n });\n\n test('is empty on an empty index', () => {\n expect(index.byRank()).toHaveLength(0);\n });\n\n test('sorts a ranked record ahead of an earlier-listed absent-rank record', () => {\n // Input lists the absent-rank record first so the sort compares (ranked, absent),\n // exercising the ranked-before-absent direction of the comparator.\n index\n .rebuild([\n makeEntry({ id: 'unranked', updated: 100, seq: 1 }),\n makeEntry({ id: 'ranked', rank: 5, updated: 100, seq: 2 })\n ])\n .orThrow();\n expect(ids(index.byRank())).toEqual(['ranked', 'unranked']);\n });\n\n test('orders two absent-rank records by recency alone', () => {\n index\n .rebuild([makeEntry({ id: 'a', updated: 100, seq: 1 }), makeEntry({ id: 'b', updated: 300, seq: 2 })])\n .orThrow();\n expect(ids(index.byRank())).toEqual(['b', 'a']);\n });\n\n test(\"index byRank agrees pairwise with the retrieve packlet's rankCompare\", () => {\n // Guard against the two hand-duplicated comparators (index `_compareByRank`\n // and retrieve `rankCompare`) drifting: a future tie-break edit to one that\n // diverges from the other is caught here on a shared mixed fixture.\n const fixture = [\n makeEntry({ id: 'r-top', rank: 9, updated: 100, seq: 1 }),\n makeEntry({ id: 'r-mid', rank: 5, updated: 400, seq: 2 }),\n makeEntry({ id: 'r-tie-a', rank: 3, updated: 200, seq: 3 }),\n makeEntry({ id: 'r-tie-b', rank: 3, updated: 200, seq: 8 }),\n makeEntry({ id: 'absent-old', updated: 100, seq: 4 }),\n makeEntry({ id: 'absent-new', updated: 500, seq: 5 })\n ];\n index.rebuild(fixture).orThrow();\n const viaIndex = ids(index.byRank());\n const viaRankCompare = ids(fixture.map((e) => e.record).sort(rankCompare));\n expect(viaIndex).toEqual(viaRankCompare);\n // And the shared expected ordering is what both must produce.\n expect(viaIndex).toEqual(['r-top', 'r-mid', 'r-tie-b', 'r-tie-a', 'absent-new', 'absent-old']);\n });\n });\n\n describe('backlinks', () => {\n test('aggregates multiple sources pointing at one target', () => {\n index\n .rebuild([makeEntry({ id: 'a', links: ['target'] }), makeEntry({ id: 'b', links: ['target'] })])\n .orThrow();\n expect(targetIds(index.backlinks(bt('target'))).sort()).toEqual(['a', 'b']);\n });\n\n test('drops the target set once the last source is removed', () => {\n const a = makeEntry({ id: 'a', links: ['target'] });\n index.patch('put', a).orThrow();\n index.patch('delete', a).orThrow();\n expect(index.backlinks(bt('target'))).toHaveLength(0);\n });\n\n test('tracks same-id sources across scopes independently', () => {\n // Two distinct records that share the id 'a' under different scopes, both\n // linking 'target'. Removing one must NOT drop the other's inbound edge.\n const a1 = makeEntry({ id: 'a', scope: 'conversations/c1', links: ['target'] });\n const a2 = makeEntry({ id: 'a', scope: 'conversations/c2', links: ['target'] });\n index.patch('put', a1).orThrow();\n index.patch('put', a2).orThrow();\n expect(targetIds(index.backlinks(bt('target')))).toEqual(['a', 'a']);\n index.patch('delete', a1).orThrow();\n expect(targetIds(index.backlinks(bt('target')))).toEqual(['a']);\n });\n });\n\n describe('duplicate associations', () => {\n test('a record with duplicate tags and links is cleaned up exactly once on delete', () => {\n const entry = makeEntry({ id: 'a', tags: ['dup', 'dup'], links: ['t', 't'] });\n index.patch('put', entry).orThrow();\n expect(ids(index.byTag('dup' as Tag))).toEqual(['a']);\n expect(targetIds(index.backlinks(bt('t')))).toEqual(['a']);\n index.patch('delete', entry).orThrow();\n expect(index.byTag('dup' as Tag)).toHaveLength(0);\n expect(index.backlinks(bt('t'))).toHaveLength(0);\n });\n });\n});\n"]}
@@ -1,277 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Erik Fortune
3
- * SPDX-License-Identifier: MIT
4
- */
5
- /**
6
- * Antagonist torture tests — cycle guard adversarial graphs (target class 6) and
7
- * enum-branch parity (target class 7), exercised at the ORCHESTRATOR/integration
8
- * level over a real {@link FileTreeMemoryStore}, complementing the pure-function
9
- * unit tests in `cycleGuard.test.ts` and the per-verdict tests in
10
- * `orchestrator.test.ts`.
11
- */
12
- import '@fgv/ts-utils-jest';
13
- import { Converters, succeed } from '@fgv/ts-utils';
14
- import { FileTree } from '@fgv/ts-json-base';
15
- import { BodyConverterRegistry, FileTreeMemoryStore, InMemoryCosineIndex, KnowledgeIdentityCodec, MemoryIngestOrchestrator } from '../../../index';
16
- const noteKind = 'note';
17
- /** A scope-qualified target for the note fixtures (all under the knowledge scope). */
18
- function kt(id) {
19
- return { scope: 'knowledge', id: id };
20
- }
21
- function mutableRoot() {
22
- const tree = FileTree.inMemory([], { mutable: true }).orThrow();
23
- const root = tree.getDirectory('/').orThrow();
24
- if (!FileTree.isMutableDirectoryItem(root)) {
25
- throw new Error('expected a mutable root directory');
26
- }
27
- return root;
28
- }
29
- function registry() {
30
- const reg = BodyConverterRegistry.create().orThrow();
31
- reg.register(noteKind, Converters.string);
32
- return reg;
33
- }
34
- const codecs = new Map([
35
- [noteKind, new KnowledgeIdentityCodec()]
36
- ]);
37
- function buildStore() {
38
- return FileTreeMemoryStore.create({ root: mutableRoot(), registry: registry(), codecs }).orThrow();
39
- }
40
- async function putFull(store, entityId, body, links = []) {
41
- const rec = {
42
- envelope: {
43
- id: entityId,
44
- entityId: entityId,
45
- kind: noteKind,
46
- tags: [],
47
- links,
48
- created: 0,
49
- updated: 0,
50
- seq: 0,
51
- contentHash: '',
52
- provenance: { source: 'agent' }
53
- },
54
- body
55
- };
56
- (await store.put(rec)).orThrow();
57
- }
58
- function classifier(fn) {
59
- return { classify: (item) => Promise.resolve(fn(item)) };
60
- }
61
- function extractor(fn) {
62
- return { extract: (item, c) => Promise.resolve(fn(item, c)) };
63
- }
64
- function relater(fn) {
65
- return { relate: (ctx) => Promise.resolve(fn(ctx)) };
66
- }
67
- function resolver(fn) {
68
- return { resolve: (candidate, similar) => Promise.resolve(fn(candidate, similar)) };
69
- }
70
- const classifyNote = classifier(() => succeed({ kind: noteKind }));
71
- function candidate(entityId, body, links = []) {
72
- return {
73
- envelope: {
74
- entityId: entityId,
75
- kind: noteKind,
76
- tags: [],
77
- links,
78
- provenance: { source: 'agent' }
79
- },
80
- body
81
- };
82
- }
83
- function candEdge(source, type, target) {
84
- return { source: kt(source), edge: { type: type, target: kt(target) } };
85
- }
86
- function buildOrchestrator(params) {
87
- return MemoryIngestOrchestrator.create({
88
- store: params.store,
89
- registry: registry(),
90
- codecs,
91
- classifier: classifyNote,
92
- extractor: params.extractor,
93
- relationExtractor: params.relationExtractor,
94
- entityResolver: params.entityResolver
95
- }).orThrow();
96
- }
97
- describe('antagonist — cycle guard through EXISTING store edges (integration)', () => {
98
- // Wrong impl this catches: an orchestrator that only feeds the cycle guard the
99
- // proposed-edge batch (as its own pure-function unit tests do) and forgets to
100
- // fold in the store snapshot's existing edges, so a cycle that closes THROUGH
101
- // an already-persisted edge is silently admitted.
102
- test('a proposed edge that closes a cycle through a pre-existing on-disk edge is rejected', async () => {
103
- const store = buildStore();
104
- // Existing on-disk edge: doc-a -> doc-b (persisted before this ingest runs).
105
- await putFull(store, 'doc-a', 'anchor-a', [{ type: 'rel', target: kt('doc-b') }]);
106
- await putFull(store, 'doc-b', 'anchor-b');
107
- // This ingest re-writes doc-b (a 'new'-verdict same-id update, since no
108
- // resolver is wired) and proposes doc-b -> doc-a, which — unioned with the
109
- // EXISTING doc-a -> doc-b edge — closes a 2-cycle that exists ONLY because of
110
- // the on-disk edge, not anything proposed in this batch.
111
- const orch = buildOrchestrator({
112
- store,
113
- extractor: extractor(() => succeed([candidate('doc-b', 'anchor-b-v2')])),
114
- relationExtractor: relater(() => succeed([candEdge('doc-b', 'rel', 'doc-a')]))
115
- });
116
- expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(/would create a cycle/);
117
- // Confirm the guard fired BEFORE any write — doc-b's content must be unchanged.
118
- expect(await store.get(noteKind, 'doc-b')).toSucceedAndSatisfy((rec) => expect(rec === null || rec === void 0 ? void 0 : rec.body).toBe('anchor-b'));
119
- });
120
- test('a long existing chain plus one proposed edge closing the loop is rejected', async () => {
121
- const store = buildStore();
122
- // Existing chain: a -> b -> c -> d (four pre-existing on-disk edges spanning
123
- // three hops), persisted before this ingest.
124
- await putFull(store, 'chain-a', 'a', [{ type: 'rel', target: kt('chain-b') }]);
125
- await putFull(store, 'chain-b', 'b', [{ type: 'rel', target: kt('chain-c') }]);
126
- await putFull(store, 'chain-c', 'c', [{ type: 'rel', target: kt('chain-d') }]);
127
- await putFull(store, 'chain-d', 'd');
128
- // Proposed: chain-d -> chain-a, closing the whole loop through the existing chain.
129
- const orch = buildOrchestrator({
130
- store,
131
- extractor: extractor(() => succeed([candidate('chain-d', 'd-v2')])),
132
- relationExtractor: relater(() => succeed([candEdge('chain-d', 'rel', 'chain-a')]))
133
- });
134
- expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(/would create a cycle/);
135
- });
136
- test('cycleGuard "off" admits a cycle that closes through an existing edge', async () => {
137
- const store = buildStore();
138
- await putFull(store, 'doc-a', 'anchor-a', [{ type: 'rel', target: kt('doc-b') }]);
139
- await putFull(store, 'doc-b', 'anchor-b');
140
- const orch = MemoryIngestOrchestrator.create({
141
- store,
142
- registry: registry(),
143
- codecs,
144
- classifier: classifyNote,
145
- extractor: extractor(() => succeed([candidate('doc-b', 'anchor-b-v2')])),
146
- relationExtractor: relater(() => succeed([candEdge('doc-b', 'rel', 'doc-a')])),
147
- cycleGuard: 'off'
148
- }).orThrow();
149
- expect(await orch.ingestItem({ id: 'i', content: 'x' })).toSucceedAndSatisfy((r) => {
150
- var _a;
151
- expect((_a = r.records[0].record) === null || _a === void 0 ? void 0 : _a.envelope.links).toEqual([{ type: 'rel', target: kt('doc-a') }]);
152
- });
153
- });
154
- });
155
- describe('antagonist — resolver target need not be a surfaced `similar` candidate (structural-only gate)', () => {
156
- // Documents (and locks in) the actual contract: fgv validates a target-bearing
157
- // verdict STRUCTURALLY (exists in the store + matching kind), uniformly across
158
- // all three target-bearing verdicts, regardless of whether the resolver's
159
- // choice was among the `similar` candidates it was shown. Wrong impl this
160
- // guards against: fgv silently restricting itself to `similar` membership
161
- // (which would incorrectly reject a host resolver with external knowledge), OR
162
- // fgv skipping the structural check for one of the three verdicts.
163
- test.each(['duplicate-of', 'supersede', 'merge-into'])("verdict '%s' targeting a valid existing record OUTSIDE the surfaced similar set is accepted", async (verdict) => {
164
- const store = buildStore();
165
- await putFull(store, 'doc-a', 'apple pie'); // will be surfaced as `similar`
166
- await putFull(store, 'doc-q', 'unrelated target'); // exists, but never surfaced
167
- const vectorIndex = InMemoryCosineIndex.create().orThrow();
168
- const embed = () => Promise.resolve(succeed(Float32Array.from([1, 0, 0])));
169
- // Only doc-a is embedded/indexed; doc-q is never surfaced by similarity —
170
- // it can only be reached by the resolver's own out-of-band choice.
171
- (await vectorIndex.add(kt('doc-a'), Float32Array.from([1, 0, 0]))).orThrow();
172
- const orch = MemoryIngestOrchestrator.create({
173
- store,
174
- registry: registry(),
175
- codecs,
176
- classifier: classifyNote,
177
- extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),
178
- relationExtractor: relater(() => succeed([])),
179
- vectorIndex,
180
- embed,
181
- entityResolver: resolver(() => succeed({ verdict, target: kt('doc-q') }))
182
- }).orThrow();
183
- const result = await orch.ingestItem({ id: 'i', content: 'x' });
184
- if (verdict === 'duplicate-of') {
185
- expect(result).toSucceedAndSatisfy((r) => {
186
- expect(r.records[0].disposition).toBe('deduped');
187
- expect(r.records[0].id).toBe('doc-q');
188
- });
189
- }
190
- else if (verdict === 'supersede') {
191
- expect(result).toSucceedAndSatisfy((r) => {
192
- expect(r.records[0].disposition).toBe('written');
193
- expect(r.records[0].resolution).toEqual({ verdict: 'supersede', target: kt('doc-q') });
194
- });
195
- }
196
- else {
197
- expect(result).toSucceedAndSatisfy((r) => {
198
- expect(r.records[0].disposition).toBe('merged');
199
- expect(r.records[0].id).toBe('doc-q');
200
- });
201
- }
202
- });
203
- });
204
- describe('antagonist — enum-branch parity: uniform structural rejection across target-bearing verdicts', () => {
205
- // A single table-driven test locking in that EVERY target-bearing verdict arm
206
- // shares the SAME two structural checks (existence, then kind match) in the
207
- // SAME order — the exact class of hole ("only merge-into checked") that a
208
- // prior review caught. Wrong impl this guards against: a future edit that adds
209
- // a fourth verdict or refactors validation per-branch and re-introduces an
210
- // asymmetric gap.
211
- const verdicts = ['duplicate-of', 'supersede', 'merge-into'];
212
- test.each(verdicts)("verdict '%s' rejects a nonexistent target with the SAME message shape", async (verdict) => {
213
- const store = buildStore();
214
- await putFull(store, 'doc-a', 'apple pie');
215
- const vectorIndex = InMemoryCosineIndex.create().orThrow();
216
- const embed = () => Promise.resolve(succeed(Float32Array.from([1, 0, 0])));
217
- const orch = MemoryIngestOrchestrator.create({
218
- store,
219
- registry: registry(),
220
- codecs,
221
- classifier: classifyNote,
222
- extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),
223
- relationExtractor: relater(() => succeed([])),
224
- vectorIndex,
225
- embed,
226
- entityResolver: resolver(() => succeed({ verdict, target: kt('ghost') }))
227
- }).orThrow();
228
- (await vectorIndex.add(kt('doc-a'), Float32Array.from([1, 0, 0]))).orThrow();
229
- expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(`ingest 'i': ${verdict} target 'knowledge/ghost' does not exist in the store`);
230
- });
231
- test.each(verdicts)("verdict '%s' rejects a foreign-kind target with the SAME message shape", async (verdict) => {
232
- const otherKind = 'other';
233
- const reg = registry();
234
- reg.register(otherKind, Converters.string);
235
- const otherCodecs = new Map([
236
- ...codecs,
237
- [otherKind, new KnowledgeIdentityCodec()]
238
- ]);
239
- const store = FileTreeMemoryStore.create({
240
- root: mutableRoot(),
241
- registry: reg,
242
- codecs: otherCodecs
243
- }).orThrow();
244
- const foreignRec = {
245
- envelope: {
246
- id: 'foreign-1',
247
- entityId: 'foreign-1',
248
- kind: otherKind,
249
- tags: [],
250
- links: [],
251
- created: 0,
252
- updated: 0,
253
- seq: 0,
254
- contentHash: '',
255
- provenance: { source: 'agent' }
256
- },
257
- body: 'apple pie'
258
- };
259
- (await store.put(foreignRec)).orThrow();
260
- const vectorIndex = InMemoryCosineIndex.create().orThrow();
261
- const embed = () => Promise.resolve(succeed(Float32Array.from([1, 0, 0])));
262
- const orch = MemoryIngestOrchestrator.create({
263
- store,
264
- registry: reg,
265
- codecs: otherCodecs,
266
- classifier: classifyNote,
267
- extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),
268
- relationExtractor: relater(() => succeed([])),
269
- vectorIndex,
270
- embed,
271
- entityResolver: resolver(() => succeed({ verdict, target: kt('foreign-1') }))
272
- }).orThrow();
273
- (await vectorIndex.add(kt('foreign-1'), Float32Array.from([1, 0, 0]))).orThrow();
274
- expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(`ingest 'i': ${verdict} target 'knowledge/foreign-1' is kind 'other' but the candidate is kind 'note'`);
275
- });
276
- });
277
- //# sourceMappingURL=antagonistCycleAndParity.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"antagonistCycleAndParity.test.js","sourceRoot":"","sources":["../../../../src/test/unit/ingest/antagonistCycleAndParity.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,qBAAqB,EAErB,mBAAmB,EAiBnB,mBAAmB,EAEnB,sBAAsB,EAEtB,wBAAwB,EAIzB,MAAM,gBAAgB,CAAC;AAExB,MAAM,QAAQ,GAAS,MAAc,CAAC;AAEtC,sFAAsF;AACtF,SAAS,EAAE,CAAC,EAAU;IACpB,OAAO,EAAE,KAAK,EAAE,WAA6B,EAAE,EAAE,EAAE,EAAc,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,WAAW;IAClB,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9C,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ;IACf,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC;IACrD,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CA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C,WAAW,CAAC,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACjF,MAAM,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,UAAU,CACjE,eAAe,OAAO,gFAAgF,CACvG,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\n/**\n * Antagonist torture tests — cycle guard adversarial graphs (target class 6) and\n * enum-branch parity (target class 7), exercised at the ORCHESTRATOR/integration\n * level over a real {@link FileTreeMemoryStore}, complementing the pure-function\n * unit tests in `cycleGuard.test.ts` and the per-verdict tests in\n * `orchestrator.test.ts`.\n */\n\nimport '@fgv/ts-utils-jest';\nimport { Converters, Result, succeed } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n BodyConverterRegistry,\n EntityId,\n FileTreeMemoryStore,\n IBodyConverterRegistry,\n ICandidateEdge,\n ICandidateRecord,\n IEdgeTarget,\n IEntityResolutionCandidate,\n IEntityResolver,\n IFactExtractor,\n IIdentityCodec,\n IIngestItem,\n IIngestItemResult,\n IMemoryClassification,\n IMemoryClassifier,\n IMemoryEnvelope,\n IMemoryRecord,\n IRelationContext,\n IRelationExtractor,\n InMemoryCosineIndex,\n Kind,\n KnowledgeIdentityCodec,\n MemoryId,\n MemoryIngestOrchestrator,\n MemoryScopeKey,\n ResolutionVerdict,\n Tag\n} from '../../../index';\n\nconst noteKind: Kind = 'note' as Kind;\n\n/** A scope-qualified target for the note fixtures (all under the knowledge scope). */\nfunction kt(id: string): IEdgeTarget {\n return { scope: 'knowledge' as MemoryScopeKey, id: id as MemoryId };\n}\n\nfunction mutableRoot(): FileTree.IMutableFileTreeDirectoryItem {\n const tree = FileTree.inMemory([], { mutable: true }).orThrow();\n const root = tree.getDirectory('/').orThrow();\n if (!FileTree.isMutableDirectoryItem(root)) {\n throw new Error('expected a mutable root directory');\n }\n return root;\n}\n\nfunction registry(): IBodyConverterRegistry {\n const reg = BodyConverterRegistry.create().orThrow();\n reg.register(noteKind, Converters.string);\n return reg;\n}\n\nconst codecs: ReadonlyMap<Kind, IIdentityCodec> = new Map<Kind, IIdentityCodec>([\n [noteKind, new KnowledgeIdentityCodec()]\n]);\n\nfunction buildStore(): FileTreeMemoryStore {\n return FileTreeMemoryStore.create({ root: mutableRoot(), registry: registry(), codecs }).orThrow();\n}\n\nasync function putFull(\n store: FileTreeMemoryStore,\n entityId: string,\n body: string,\n links: IMemoryEnvelope['links'] = []\n): Promise<void> {\n const rec: IMemoryRecord<unknown> = {\n envelope: {\n id: entityId as MemoryId,\n entityId: entityId as EntityId,\n kind: noteKind,\n tags: [],\n links,\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n },\n body\n };\n (await store.put(rec)).orThrow();\n}\n\nfunction classifier(fn: (item: IIngestItem) => Result<IMemoryClassification>): IMemoryClassifier {\n return { classify: (item) => Promise.resolve(fn(item)) };\n}\nfunction extractor(\n fn: (item: IIngestItem, c: IMemoryClassification) => Result<ReadonlyArray<ICandidateRecord>>\n): IFactExtractor {\n return { extract: (item, c) => Promise.resolve(fn(item, c)) };\n}\nfunction relater(fn: (ctx: IRelationContext) => Result<ReadonlyArray<ICandidateEdge>>): IRelationExtractor {\n return { relate: (ctx) => Promise.resolve(fn(ctx)) };\n}\nfunction resolver(\n fn: (\n candidate: ICandidateRecord,\n similar: ReadonlyArray<IEntityResolutionCandidate>\n ) => Result<ResolutionVerdict>\n): IEntityResolver {\n return { resolve: (candidate, similar) => Promise.resolve(fn(candidate, similar)) };\n}\n\nconst classifyNote: IMemoryClassifier = classifier(() => succeed({ kind: noteKind }));\n\nfunction candidate(\n entityId: string,\n body: unknown,\n links: ICandidateRecord['envelope']['links'] = []\n): ICandidateRecord {\n return {\n envelope: {\n entityId: entityId as EntityId,\n kind: noteKind,\n tags: [],\n links,\n provenance: { source: 'agent' }\n },\n body\n };\n}\n\nfunction candEdge(source: string, type: string, target: string): ICandidateEdge {\n return { source: kt(source), edge: { type: type as never, target: kt(target) } };\n}\n\nfunction buildOrchestrator(params: {\n store: FileTreeMemoryStore;\n extractor: IFactExtractor;\n relationExtractor: IRelationExtractor;\n entityResolver?: IEntityResolver;\n}): MemoryIngestOrchestrator {\n return MemoryIngestOrchestrator.create({\n store: params.store,\n registry: registry(),\n codecs,\n classifier: classifyNote,\n extractor: params.extractor,\n relationExtractor: params.relationExtractor,\n entityResolver: params.entityResolver\n }).orThrow();\n}\n\ndescribe('antagonist — cycle guard through EXISTING store edges (integration)', () => {\n // Wrong impl this catches: an orchestrator that only feeds the cycle guard the\n // proposed-edge batch (as its own pure-function unit tests do) and forgets to\n // fold in the store snapshot's existing edges, so a cycle that closes THROUGH\n // an already-persisted edge is silently admitted.\n test('a proposed edge that closes a cycle through a pre-existing on-disk edge is rejected', async () => {\n const store = buildStore();\n // Existing on-disk edge: doc-a -> doc-b (persisted before this ingest runs).\n await putFull(store, 'doc-a', 'anchor-a', [{ type: 'rel' as never, target: kt('doc-b') }]);\n await putFull(store, 'doc-b', 'anchor-b');\n\n // This ingest re-writes doc-b (a 'new'-verdict same-id update, since no\n // resolver is wired) and proposes doc-b -> doc-a, which — unioned with the\n // EXISTING doc-a -> doc-b edge — closes a 2-cycle that exists ONLY because of\n // the on-disk edge, not anything proposed in this batch.\n const orch = buildOrchestrator({\n store,\n extractor: extractor(() => succeed([candidate('doc-b', 'anchor-b-v2')])),\n relationExtractor: relater(() => succeed([candEdge('doc-b', 'rel', 'doc-a')]))\n });\n expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(/would create a cycle/);\n\n // Confirm the guard fired BEFORE any write — doc-b's content must be unchanged.\n expect(await store.get(noteKind, 'doc-b' as EntityId)).toSucceedAndSatisfy(\n (rec: IMemoryRecord<unknown> | undefined) => expect(rec?.body).toBe('anchor-b')\n );\n });\n\n test('a long existing chain plus one proposed edge closing the loop is rejected', async () => {\n const store = buildStore();\n // Existing chain: a -> b -> c -> d (four pre-existing on-disk edges spanning\n // three hops), persisted before this ingest.\n await putFull(store, 'chain-a', 'a', [{ type: 'rel' as never, target: kt('chain-b') }]);\n await putFull(store, 'chain-b', 'b', [{ type: 'rel' as never, target: kt('chain-c') }]);\n await putFull(store, 'chain-c', 'c', [{ type: 'rel' as never, target: kt('chain-d') }]);\n await putFull(store, 'chain-d', 'd');\n\n // Proposed: chain-d -> chain-a, closing the whole loop through the existing chain.\n const orch = buildOrchestrator({\n store,\n extractor: extractor(() => succeed([candidate('chain-d', 'd-v2')])),\n relationExtractor: relater(() => succeed([candEdge('chain-d', 'rel', 'chain-a')]))\n });\n expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(/would create a cycle/);\n });\n\n test('cycleGuard \"off\" admits a cycle that closes through an existing edge', async () => {\n const store = buildStore();\n await putFull(store, 'doc-a', 'anchor-a', [{ type: 'rel' as never, target: kt('doc-b') }]);\n await putFull(store, 'doc-b', 'anchor-b');\n const orch = MemoryIngestOrchestrator.create({\n store,\n registry: registry(),\n codecs,\n classifier: classifyNote,\n extractor: extractor(() => succeed([candidate('doc-b', 'anchor-b-v2')])),\n relationExtractor: relater(() => succeed([candEdge('doc-b', 'rel', 'doc-a')])),\n cycleGuard: 'off'\n }).orThrow();\n expect(await orch.ingestItem({ id: 'i', content: 'x' })).toSucceedAndSatisfy((r: IIngestItemResult) => {\n expect(r.records[0].record?.envelope.links).toEqual([{ type: 'rel', target: kt('doc-a') }]);\n });\n });\n});\n\ndescribe('antagonist — resolver target need not be a surfaced `similar` candidate (structural-only gate)', () => {\n // Documents (and locks in) the actual contract: fgv validates a target-bearing\n // verdict STRUCTURALLY (exists in the store + matching kind), uniformly across\n // all three target-bearing verdicts, regardless of whether the resolver's\n // choice was among the `similar` candidates it was shown. Wrong impl this\n // guards against: fgv silently restricting itself to `similar` membership\n // (which would incorrectly reject a host resolver with external knowledge), OR\n // fgv skipping the structural check for one of the three verdicts.\n test.each(['duplicate-of', 'supersede', 'merge-into'] as const)(\n \"verdict '%s' targeting a valid existing record OUTSIDE the surfaced similar set is accepted\",\n async (verdict) => {\n const store = buildStore();\n await putFull(store, 'doc-a', 'apple pie'); // will be surfaced as `similar`\n await putFull(store, 'doc-q', 'unrelated target'); // exists, but never surfaced\n\n const vectorIndex = InMemoryCosineIndex.create().orThrow();\n const embed = (): Promise<Result<Float32Array>> =>\n Promise.resolve(succeed(Float32Array.from([1, 0, 0])));\n // Only doc-a is embedded/indexed; doc-q is never surfaced by similarity —\n // it can only be reached by the resolver's own out-of-band choice.\n (await vectorIndex.add(kt('doc-a'), Float32Array.from([1, 0, 0]))).orThrow();\n\n const orch = MemoryIngestOrchestrator.create({\n store,\n registry: registry(),\n codecs,\n classifier: classifyNote,\n extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),\n relationExtractor: relater(() => succeed([])),\n vectorIndex,\n embed,\n entityResolver: resolver(() => succeed({ verdict, target: kt('doc-q') } as ResolutionVerdict))\n }).orThrow();\n\n const result = await orch.ingestItem({ id: 'i', content: 'x' });\n if (verdict === 'duplicate-of') {\n expect(result).toSucceedAndSatisfy((r: IIngestItemResult) => {\n expect(r.records[0].disposition).toBe('deduped');\n expect(r.records[0].id).toBe('doc-q');\n });\n } else if (verdict === 'supersede') {\n expect(result).toSucceedAndSatisfy((r: IIngestItemResult) => {\n expect(r.records[0].disposition).toBe('written');\n expect(r.records[0].resolution).toEqual({ verdict: 'supersede', target: kt('doc-q') });\n });\n } else {\n expect(result).toSucceedAndSatisfy((r: IIngestItemResult) => {\n expect(r.records[0].disposition).toBe('merged');\n expect(r.records[0].id).toBe('doc-q');\n });\n }\n }\n );\n});\n\ndescribe('antagonist — enum-branch parity: uniform structural rejection across target-bearing verdicts', () => {\n // A single table-driven test locking in that EVERY target-bearing verdict arm\n // shares the SAME two structural checks (existence, then kind match) in the\n // SAME order — the exact class of hole (\"only merge-into checked\") that a\n // prior review caught. Wrong impl this guards against: a future edit that adds\n // a fourth verdict or refactors validation per-branch and re-introduces an\n // asymmetric gap.\n const verdicts = ['duplicate-of', 'supersede', 'merge-into'] as const;\n\n test.each(verdicts)(\n \"verdict '%s' rejects a nonexistent target with the SAME message shape\",\n async (verdict) => {\n const store = buildStore();\n await putFull(store, 'doc-a', 'apple pie');\n const vectorIndex = InMemoryCosineIndex.create().orThrow();\n const embed = (): Promise<Result<Float32Array>> =>\n Promise.resolve(succeed(Float32Array.from([1, 0, 0])));\n const orch = MemoryIngestOrchestrator.create({\n store,\n registry: registry(),\n codecs,\n classifier: classifyNote,\n extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),\n relationExtractor: relater(() => succeed([])),\n vectorIndex,\n embed,\n entityResolver: resolver(() => succeed({ verdict, target: kt('ghost') } as ResolutionVerdict))\n }).orThrow();\n (await vectorIndex.add(kt('doc-a'), Float32Array.from([1, 0, 0]))).orThrow();\n expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(\n `ingest 'i': ${verdict} target 'knowledge/ghost' does not exist in the store`\n );\n }\n );\n\n test.each(verdicts)(\n \"verdict '%s' rejects a foreign-kind target with the SAME message shape\",\n async (verdict) => {\n const otherKind: Kind = 'other' as Kind;\n const reg = registry();\n reg.register(otherKind, Converters.string);\n const otherCodecs: ReadonlyMap<Kind, IIdentityCodec> = new Map<Kind, IIdentityCodec>([\n ...codecs,\n [otherKind, new KnowledgeIdentityCodec()]\n ]);\n const store = FileTreeMemoryStore.create({\n root: mutableRoot(),\n registry: reg,\n codecs: otherCodecs\n }).orThrow();\n const foreignRec: IMemoryRecord<unknown> = {\n envelope: {\n id: 'foreign-1' as MemoryId,\n entityId: 'foreign-1' as EntityId,\n kind: otherKind,\n tags: [] as ReadonlyArray<Tag>,\n links: [],\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n },\n body: 'apple pie'\n };\n (await store.put(foreignRec)).orThrow();\n const vectorIndex = InMemoryCosineIndex.create().orThrow();\n const embed = (): Promise<Result<Float32Array>> =>\n Promise.resolve(succeed(Float32Array.from([1, 0, 0])));\n const orch = MemoryIngestOrchestrator.create({\n store,\n registry: reg,\n codecs: otherCodecs,\n classifier: classifyNote,\n extractor: extractor(() => succeed([candidate('doc-b', 'apple tart')])),\n relationExtractor: relater(() => succeed([])),\n vectorIndex,\n embed,\n entityResolver: resolver(() => succeed({ verdict, target: kt('foreign-1') } as ResolutionVerdict))\n }).orThrow();\n (await vectorIndex.add(kt('foreign-1'), Float32Array.from([1, 0, 0]))).orThrow();\n expect(await orch.ingestItem({ id: 'i', content: 'x' })).toFailWith(\n `ingest 'i': ${verdict} target 'knowledge/foreign-1' is kind 'other' but the candidate is kind 'note'`\n );\n }\n );\n});\n"]}
@@ -1,81 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Erik Fortune
3
- * SPDX-License-Identifier: MIT
4
- */
5
- import '@fgv/ts-utils-jest';
6
- import { assertNoCycles, buildCycleKey } from '../../../index';
7
- const rel = 'rel';
8
- const DEFAULT_SCOPE = 'exp';
9
- /** A scope-qualified node, `scope#id` or a bare id defaulting to {@link DEFAULT_SCOPE}. */
10
- function node(spec) {
11
- const hash = spec.indexOf('#');
12
- const scope = hash >= 0 ? spec.slice(0, hash) : DEFAULT_SCOPE;
13
- const id = hash >= 0 ? spec.slice(hash + 1) : spec;
14
- return { scope: scope, id: id };
15
- }
16
- function edge(source, target, type = rel) {
17
- return { source: node(source), target: node(target), type };
18
- }
19
- describe('buildCycleKey', () => {
20
- test('is deterministic for the same edge', () => {
21
- expect(buildCycleKey(edge('a', 'b'))).toSucceedAndSatisfy((key) => {
22
- expect(buildCycleKey(edge('a', 'b'))).toSucceedWith(key);
23
- });
24
- });
25
- test('differs by direction and type', () => {
26
- const forward = buildCycleKey(edge('a', 'b')).orThrow();
27
- const reverse = buildCycleKey(edge('b', 'a')).orThrow();
28
- const typed = buildCycleKey(edge('a', 'b', 'other')).orThrow();
29
- expect(forward).not.toBe(reverse);
30
- expect(forward).not.toBe(typed);
31
- });
32
- });
33
- describe('assertNoCycles', () => {
34
- test('accepts an acyclic graph', () => {
35
- expect(assertNoCycles([edge('a', 'b')], [edge('b', 'c'), edge('c', 'd')])).toSucceed();
36
- });
37
- test('rejects a proposed edge that closes a cycle against existing edges', () => {
38
- expect(assertNoCycles([edge('a', 'b'), edge('b', 'c')], [edge('c', 'a')])).toFailWith(/would create a cycle/);
39
- });
40
- test('rejects a cycle formed entirely within the proposed batch', () => {
41
- expect(assertNoCycles([], [edge('a', 'b'), edge('b', 'a')])).toFailWith(/would create a cycle/);
42
- });
43
- test('rejects a self-loop', () => {
44
- expect(assertNoCycles([], [edge('a', 'a')])).toFailWith(/self-loop/);
45
- });
46
- test('tolerates a duplicate proposed edge (deduped by canonical key)', () => {
47
- expect(assertNoCycles([], [edge('a', 'b'), edge('a', 'b')])).toSucceed();
48
- });
49
- test('tolerates a duplicate existing edge', () => {
50
- expect(assertNoCycles([edge('a', 'b'), edge('a', 'b')], [edge('b', 'c')])).toSucceed();
51
- });
52
- test('accepts a diamond (shared descendant is not a cycle)', () => {
53
- expect(assertNoCycles([], [edge('a', 'b'), edge('a', 'c'), edge('b', 'd'), edge('c', 'd')])).toSucceed();
54
- });
55
- test('reachability tolerates a frontier node reached by two paths (revisit guard)', () => {
56
- // Existing graph: a->c, a->b, b->c. A proposed edge z->a runs reachability
57
- // from `a`, whose DFS pushes `c` twice before it is visited — exercising the
58
- // visited-node skip in the traversal.
59
- expect(assertNoCycles([edge('a', 'c'), edge('a', 'b'), edge('b', 'c')], [edge('z', 'a')])).toSucceed();
60
- });
61
- describe('scope-qualified nodes', () => {
62
- test('does NOT conflate a stem shared across scopes into one node', () => {
63
- // ca#x -> cb#y and cb#x -> ca#z reuse the stem `x` across scopes ca/cb.
64
- // If the guard keyed on bare id, the two `x` nodes would merge and a false
65
- // cycle could appear; with scoped keys they are distinct and the graph is acyclic.
66
- expect(assertNoCycles([], [edge('ca#x', 'cb#y'), edge('cb#x', 'ca#z')])).toSucceed();
67
- });
68
- test('still rejects a genuine within-scope cycle across the same stems', () => {
69
- expect(assertNoCycles([], [edge('ca#x', 'ca#y'), edge('ca#y', 'ca#x')])).toFailWith(/would create a cycle/);
70
- });
71
- test('a self-loop is detected on the full scoped identity', () => {
72
- expect(assertNoCycles([], [edge('ca#x', 'ca#x')])).toFailWith(/self-loop/);
73
- // Same stem, different scope is NOT a self-loop.
74
- expect(assertNoCycles([], [edge('ca#x', 'cb#x')])).toSucceed();
75
- });
76
- test('names the scope in the diagnostic', () => {
77
- expect(assertNoCycles([], [edge('ca#x', 'ca#x')])).toFailWith(/ca\/x/);
78
- });
79
- });
80
- });
81
- //# sourceMappingURL=cycleGuard.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cycleGuard.test.js","sourceRoot":"","sources":["../../../../src/test/unit/ingest/cycleGuard.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAML,cAAc,EACd,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,MAAM,GAAG,GAAa,KAAiB,CAAC;AACxC,MAAM,aAAa,GAAW,KAAK,CAAC;AAEpC,2FAA2F;AAC3F,SAAS,IAAI,CAAC,IAAY;IACxB,MAAM,IAAI,GAAW,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,KAAK,GAAW,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IACtE,MAAM,EAAE,GAAW,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,C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AAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACvF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,kEAAkE,EAAE,GAAG,EAAE;YAC5E,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CACjF,sBAAsB,CACvB,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;YAC/D,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC3E,iDAAiD;YACjD,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACjE,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC7C,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport '@fgv/ts-utils-jest';\nimport {\n ICycleGuardEdge,\n IEdgeTarget,\n LinkType,\n MemoryId,\n MemoryScopeKey,\n assertNoCycles,\n buildCycleKey\n} from '../../../index';\n\nconst rel: LinkType = 'rel' as LinkType;\nconst DEFAULT_SCOPE: string = 'exp';\n\n/** A scope-qualified node, `scope#id` or a bare id defaulting to {@link DEFAULT_SCOPE}. */\nfunction node(spec: string): IEdgeTarget {\n const hash: number = spec.indexOf('#');\n const scope: string = hash >= 0 ? spec.slice(0, hash) : DEFAULT_SCOPE;\n const id: string = hash >= 0 ? spec.slice(hash + 1) : spec;\n return { scope: scope as MemoryScopeKey, id: id as MemoryId };\n}\n\nfunction edge(source: string, target: string, type: LinkType = rel): ICycleGuardEdge {\n return { source: node(source), target: node(target), type };\n}\n\ndescribe('buildCycleKey', () => {\n test('is deterministic for the same edge', () => {\n expect(buildCycleKey(edge('a', 'b'))).toSucceedAndSatisfy((key: string) => {\n expect(buildCycleKey(edge('a', 'b'))).toSucceedWith(key);\n });\n });\n\n test('differs by direction and type', () => {\n const forward = buildCycleKey(edge('a', 'b')).orThrow();\n const reverse = buildCycleKey(edge('b', 'a')).orThrow();\n const typed = buildCycleKey(edge('a', 'b', 'other' as LinkType)).orThrow();\n expect(forward).not.toBe(reverse);\n expect(forward).not.toBe(typed);\n });\n});\n\ndescribe('assertNoCycles', () => {\n test('accepts an acyclic graph', () => {\n expect(assertNoCycles([edge('a', 'b')], [edge('b', 'c'), edge('c', 'd')])).toSucceed();\n });\n\n test('rejects a proposed edge that closes a cycle against existing edges', () => {\n expect(assertNoCycles([edge('a', 'b'), edge('b', 'c')], [edge('c', 'a')])).toFailWith(\n /would create a cycle/\n );\n });\n\n test('rejects a cycle formed entirely within the proposed batch', () => {\n expect(assertNoCycles([], [edge('a', 'b'), edge('b', 'a')])).toFailWith(/would create a cycle/);\n });\n\n test('rejects a self-loop', () => {\n expect(assertNoCycles([], [edge('a', 'a')])).toFailWith(/self-loop/);\n });\n\n test('tolerates a duplicate proposed edge (deduped by canonical key)', () => {\n expect(assertNoCycles([], [edge('a', 'b'), edge('a', 'b')])).toSucceed();\n });\n\n test('tolerates a duplicate existing edge', () => {\n expect(assertNoCycles([edge('a', 'b'), edge('a', 'b')], [edge('b', 'c')])).toSucceed();\n });\n\n test('accepts a diamond (shared descendant is not a cycle)', () => {\n expect(assertNoCycles([], [edge('a', 'b'), edge('a', 'c'), edge('b', 'd'), edge('c', 'd')])).toSucceed();\n });\n\n test('reachability tolerates a frontier node reached by two paths (revisit guard)', () => {\n // Existing graph: a->c, a->b, b->c. A proposed edge z->a runs reachability\n // from `a`, whose DFS pushes `c` twice before it is visited — exercising the\n // visited-node skip in the traversal.\n expect(assertNoCycles([edge('a', 'c'), edge('a', 'b'), edge('b', 'c')], [edge('z', 'a')])).toSucceed();\n });\n\n describe('scope-qualified nodes', () => {\n test('does NOT conflate a stem shared across scopes into one node', () => {\n // ca#x -> cb#y and cb#x -> ca#z reuse the stem `x` across scopes ca/cb.\n // If the guard keyed on bare id, the two `x` nodes would merge and a false\n // cycle could appear; with scoped keys they are distinct and the graph is acyclic.\n expect(assertNoCycles([], [edge('ca#x', 'cb#y'), edge('cb#x', 'ca#z')])).toSucceed();\n });\n\n test('still rejects a genuine within-scope cycle across the same stems', () => {\n expect(assertNoCycles([], [edge('ca#x', 'ca#y'), edge('ca#y', 'ca#x')])).toFailWith(\n /would create a cycle/\n );\n });\n\n test('a self-loop is detected on the full scoped identity', () => {\n expect(assertNoCycles([], [edge('ca#x', 'ca#x')])).toFailWith(/self-loop/);\n // Same stem, different scope is NOT a self-loop.\n expect(assertNoCycles([], [edge('ca#x', 'cb#x')])).toSucceed();\n });\n\n test('names the scope in the diagnostic', () => {\n expect(assertNoCycles([], [edge('ca#x', 'ca#x')])).toFailWith(/ca\\/x/);\n });\n });\n});\n"]}