pi-mega-compact 0.11.4 → 0.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/dashboard-server/api-contracts/cache-stripes.js +8 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints.js +32 -0
- package/dist/extensions/dashboard-server/api-contracts/memory-map.js +1 -0
- package/dist/extensions/dashboard-server/api-contracts/memory.js +8 -0
- package/dist/extensions/dashboard-server/api-contracts/provider-cache.js +1 -0
- package/dist/extensions/dashboard-server/api-contracts/setup.js +10 -0
- package/dist/extensions/dashboard-server/index-reader.js +6 -2
- package/dist/extensions/dashboard-server/routes-cache.js +135 -47
- package/dist/extensions/dashboard-server/routes-game.js +3 -0
- package/dist/extensions/dashboard-server/routes-memory-map.js +50 -0
- package/dist/extensions/dashboard-server/routes-memory.js +51 -0
- package/dist/extensions/dashboard-server/routes-repo.js +2 -2
- package/dist/extensions/dashboard-server/routes-setup.js +267 -0
- package/dist/extensions/dashboard-server/routes.js +4 -0
- package/dist/extensions/dashboard-server/server.js +13 -1
- package/dist/extensions/mega-commands.js +189 -1
- package/dist/extensions/mega-compact.js +5 -0
- package/dist/extensions/mega-config.js +7 -0
- package/dist/extensions/mega-events/agent-handlers.js +19 -4
- package/dist/extensions/mega-events/compact-handlers.js +1 -0
- package/dist/extensions/mega-events/context-handler.js +45 -92
- package/dist/extensions/mega-events/context-hwm.js +51 -0
- package/dist/extensions/mega-events/error-classifier.js +16 -5
- package/dist/extensions/mega-events/mirror-append.js +107 -0
- package/dist/extensions/mega-events/outage-advisor.js +7 -1
- package/dist/extensions/mega-events/perf-handler.js +134 -2
- package/dist/extensions/mega-events/recall-tail.js +59 -0
- package/dist/extensions/mega-events/separated-prompt.js +248 -0
- package/dist/extensions/mega-events/session-handlers.js +15 -8
- package/dist/extensions/mega-runtime/env-loader.js +56 -0
- package/dist/extensions/mega-runtime/reset-runtime.js +6 -0
- package/dist/extensions/mega-runtime/runtime-snapshot.js +1 -0
- package/dist/extensions/mega-runtime/runtime.js +7 -0
- package/dist/extensions/mega-runtime/snapshot.js +1 -0
- package/dist/extensions/mega-runtime/widget.js +5 -0
- package/dist/src/cache-stripe-impl.js +288 -0
- package/dist/src/cache-stripe.js +11 -0
- package/dist/src/config/stopwords.js +24 -0
- package/dist/src/config.js +17 -0
- package/dist/src/embedder.js +41 -2
- package/dist/src/memoryGraph.js +299 -0
- package/dist/src/memoryStats.js +75 -0
- package/dist/src/monitoring.js +13 -0
- package/dist/src/prefix-break.js +43 -0
- package/dist/src/pricing.js +1 -1
- package/dist/src/queryExpansion.js +163 -0
- package/dist/src/queryReformulation/cache.js +123 -0
- package/dist/src/queryReformulation/rrf.js +29 -0
- package/dist/src/queryReformulation/tfidf.js +61 -0
- package/dist/src/queryReformulation/vagueness.js +33 -0
- package/dist/src/queryReformulation.js +225 -0
- package/dist/src/recallMetrics.js +258 -0
- package/dist/src/store/sqlite/cache-stripes.js +133 -0
- package/dist/src/store/sqlite/fts5-search.js +68 -0
- package/dist/src/store/sqlite/perf-samples.js +145 -16
- package/dist/src/store/sqlite/schema.js +60 -1
- package/dist/src/store/sqlite.js +1 -0
- package/dist/src/store/turns/memory-store.js +8 -0
- package/dist/src/store/turns/sqlite-store.js +14 -3
- package/dist/src/store/turns/types.js +18 -1
- package/dist/src/store/vectorIndex.js +55 -10
- package/dist/src/tiered-router/types.js +18 -0
- package/dist/src/tieredRouter.js +421 -0
- package/dist/src/vectorStore.js +8 -6
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js → AchievementTiles-DR9cLGDL.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js.map → AchievementTiles-DR9cLGDL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/AchievementsTab-svNUgJ1e.js +2 -0
- package/extensions/dashboard-client/dist/assets/{AchievementsTab-DjxfYrDc.js.map → AchievementsTab-svNUgJ1e.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js +2 -0
- package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js → ConfigTab-CmmWheuW.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js.map → ConfigTab-CmmWheuW.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js → EventsTab-CFE7jLsa.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js.map → EventsTab-CFE7jLsa.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/GameTab-CJAX_th_.js +2 -0
- package/extensions/dashboard-client/dist/assets/{GameTab-BLDudcO5.js.map → GameTab-CJAX_th_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js → MaintenanceTab-P4SUsvMf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js.map → MaintenanceTab-P4SUsvMf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js +2 -0
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js → MetricsTab-CHQscixy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js.map → MetricsTab-CHQscixy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/OverviewTab-DBs4DJdd.js +2 -0
- package/extensions/dashboard-client/dist/assets/{OverviewTab-D4kGvsiQ.js.map → OverviewTab-DBs4DJdd.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js +2 -0
- package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js → SessionsTab-BWNsj1OB.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js.map → SessionsTab-BWNsj1OB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js +2 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js +2 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js → TopicsTab-BWWQxltv.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js.map → TopicsTab-BWWQxltv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js → TurnsTab-CVz4f4-o.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js.map → TurnsTab-CVz4f4-o.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js +2 -0
- package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/index-CUNn22iV.css +1 -0
- package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js +42 -0
- package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js +2 -0
- package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js → useSSE-Bf5LOLSi.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js.map → useSSE-Bf5LOLSi.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +2 -2
- package/extensions/dashboard-client/src/App.tsx +28 -8
- package/extensions/dashboard-client/src/api/client.ts +29 -0
- package/extensions/dashboard-client/src/components/ActiveReposTable.tsx +21 -12
- package/extensions/dashboard-client/src/components/CacheHitRateTrendCard.tsx +100 -0
- package/extensions/dashboard-client/src/components/ProviderCacheCard.tsx +56 -0
- package/extensions/dashboard-client/src/components/SavingsByModelTable.tsx +38 -57
- package/extensions/dashboard-client/src/components/StripeDistributionCard.tsx +110 -0
- package/extensions/dashboard-client/src/components/TabBar.tsx +49 -4
- package/extensions/dashboard-client/src/main.tsx +1 -0
- package/extensions/dashboard-client/src/styles/base.css +30 -0
- package/extensions/dashboard-client/src/styles/cache.css +167 -0
- package/extensions/dashboard-client/src/tabs/CacheTab.tsx +75 -12
- package/extensions/dashboard-client/src/tabs/MemoryMapTab.tsx +440 -0
- package/extensions/dashboard-client/src/tabs/SetupTab.tsx +418 -0
- package/extensions/dashboard-client/tsconfig.json +3 -2
- package/extensions/dashboard-client/vite.config.ts +2 -0
- package/extensions/dashboard-server/api-contracts/cache-stripes.ts +49 -0
- package/extensions/dashboard-server/api-contracts/endpoints.ts +66 -3
- package/extensions/dashboard-server/api-contracts/index.ts +22 -0
- package/extensions/dashboard-server/api-contracts/memory-map.ts +50 -0
- package/extensions/dashboard-server/api-contracts/memory.ts +27 -0
- package/extensions/dashboard-server/api-contracts/multi-repo.ts +231 -231
- package/extensions/dashboard-server/api-contracts/provider-cache.ts +37 -0
- package/extensions/dashboard-server/api-contracts/setup.ts +80 -0
- package/extensions/dashboard-server/index-reader.ts +138 -121
- package/extensions/dashboard-server/routes-cache.ts +186 -75
- package/extensions/dashboard-server/routes-game.ts +3 -0
- package/extensions/dashboard-server/routes-memory-map.ts +105 -0
- package/extensions/dashboard-server/routes-memory.ts +63 -0
- package/extensions/dashboard-server/routes-repo.ts +36 -36
- package/extensions/dashboard-server/routes-setup.ts +293 -0
- package/extensions/dashboard-server/routes.ts +4 -0
- package/extensions/dashboard-server/server.ts +12 -0
- package/extensions/mega-commands.ts +211 -1
- package/extensions/mega-compact.ts +5 -0
- package/extensions/mega-config.ts +27 -0
- package/extensions/mega-events/agent-handlers.ts +20 -4
- package/extensions/mega-events/compact-handlers.ts +1 -0
- package/extensions/mega-events/context-handler.ts +53 -110
- package/extensions/mega-events/context-hwm.ts +85 -0
- package/extensions/mega-events/error-classifier.ts +15 -4
- package/extensions/mega-events/mirror-append.ts +155 -0
- package/extensions/mega-events/outage-advisor.ts +11 -5
- package/extensions/mega-events/perf-handler.ts +190 -6
- package/extensions/mega-events/recall-tail.ts +88 -0
- package/extensions/mega-events/separated-prompt.ts +329 -0
- package/extensions/mega-events/session-handlers.ts +14 -7
- package/extensions/mega-runtime/env-loader.ts +55 -0
- package/extensions/mega-runtime/helpers.ts +14 -0
- package/extensions/mega-runtime/reset-runtime.ts +6 -0
- package/extensions/mega-runtime/runtime-snapshot.ts +1 -0
- package/extensions/mega-runtime/runtime.ts +7 -0
- package/extensions/mega-runtime/snapshot.ts +6 -0
- package/extensions/mega-runtime/widget-types.ts +3 -0
- package/extensions/mega-runtime/widget.ts +5 -0
- package/package.json +5 -2
- package/src/cache-stripe-impl.ts +385 -0
- package/src/cache-stripe.ts +18 -0
- package/src/config/stopwords.ts +25 -0
- package/src/config.ts +26 -0
- package/src/embedder.ts +42 -2
- package/src/memoryGraph.ts +438 -0
- package/src/memoryStats.ts +107 -0
- package/src/monitoring.ts +35 -0
- package/src/prefix-break.ts +83 -0
- package/src/pricing.ts +2 -2
- package/src/queryExpansion.ts +206 -0
- package/src/queryReformulation/cache.ts +169 -0
- package/src/queryReformulation/rrf.ts +51 -0
- package/src/queryReformulation/tfidf.ts +79 -0
- package/src/queryReformulation/vagueness.ts +38 -0
- package/src/queryReformulation.ts +355 -0
- package/src/recallMetrics.ts +388 -0
- package/src/store/sqlite/cache-stripes.ts +196 -0
- package/src/store/sqlite/fts5-search.ts +90 -0
- package/src/store/sqlite/perf-samples.ts +218 -23
- package/src/store/sqlite/schema.ts +60 -1
- package/src/store/sqlite.ts +1 -0
- package/src/store/turns/memory-store.ts +10 -1
- package/src/store/turns/sqlite-store.ts +27 -15
- package/src/store/turns/types.ts +21 -0
- package/src/store/vectorIndex.ts +71 -11
- package/src/tiered-router/types.ts +64 -0
- package/src/tieredRouter.ts +489 -0
- package/src/vectorStore.ts +9 -5
- package/dist/extensions/conflict-scan.test.js +0 -115
- package/dist/extensions/dashboard-server/api-contracts.test.js +0 -884
- package/dist/extensions/dashboard-server/html.test.js +0 -52
- package/dist/extensions/dashboard-server/perf-server.test.js +0 -80
- package/dist/extensions/dashboard-server/routes-cache.test.js +0 -248
- package/dist/extensions/dashboard-server/server.test.js +0 -120
- package/dist/extensions/dashboard-server-s32.test.js +0 -181
- package/dist/extensions/dashboard-server.test.js +0 -339
- package/dist/extensions/mega-cache-replay.test.js +0 -400
- package/dist/extensions/mega-compact-s38.test.js +0 -1383
- package/dist/extensions/mega-compact.test.js +0 -1112
- package/dist/extensions/mega-events.test.js +0 -47
- package/dist/extensions/mega-game-cmds.test.js +0 -163
- package/dist/extensions/mega-runtime/snapshot.test.js +0 -127
- package/dist/extensions/mega-runtime/state.test.js +0 -266
- package/dist/extensions/mega-runtime/widget.test.js +0 -343
- package/dist/extensions/mega-shutdown-widget.test.js +0 -121
- package/dist/extensions/mega-teamrun.test.js +0 -156
- package/dist/extensions/mega-trim.test.js +0 -58
- package/dist/extensions/mega-turn-store.test.js +0 -68
- package/dist/src/boundary.test.js +0 -170
- package/dist/src/compact.test.js +0 -78
- package/dist/src/config/themes.test.js +0 -94
- package/dist/src/dedup/dedup.test.js +0 -41
- package/dist/src/dedup/l1.test.js +0 -50
- package/dist/src/dedup/raptor/buildHistory.test.js +0 -292
- package/dist/src/dedup/raptor/multilevel-serve.test.js +0 -229
- package/dist/src/dedup/raptor/multilevel.test.js +0 -238
- package/dist/src/dedup/raptor/promote.test.js +0 -69
- package/dist/src/dedup/raptor/raptor.test.js +0 -248
- package/dist/src/dedup/raptor/retrieval.test.js +0 -95
- package/dist/src/dedup/raptor/serve-gate.test.js +0 -298
- package/dist/src/dedup/sprint12.test.js +0 -219
- package/dist/src/dedup-engine.test.js +0 -472
- package/dist/src/driftDetection.test.js +0 -87
- package/dist/src/e2e.test.js +0 -698
- package/dist/src/engine.test.js +0 -111
- package/dist/src/extractive.test.js +0 -147
- package/dist/src/fork.test.js +0 -81
- package/dist/src/game/scoring.test.js +0 -98
- package/dist/src/httpEmbedder.test.js +0 -277
- package/dist/src/importance.test.js +0 -372
- package/dist/src/intent.test.js +0 -78
- package/dist/src/log.test.js +0 -42
- package/dist/src/mechanical-fix.test.js +0 -65
- package/dist/src/memory.test.js +0 -70
- package/dist/src/memoryConsolidate.test.js +0 -38
- package/dist/src/memoryOps.test.js +0 -129
- package/dist/src/memoryRecall.test.js +0 -171
- package/dist/src/memoryRoundtrip.test.js +0 -137
- package/dist/src/metrics/turns.test.js +0 -152
- package/dist/src/mirror/mirror.test.js +0 -185
- package/dist/src/raptor-inject-summaries.test.js +0 -162
- package/dist/src/ratio.bench.test.js +0 -897
- package/dist/src/recall.integration.test.js +0 -77
- package/dist/src/recall.test.js +0 -379
- package/dist/src/sprint14.test.js +0 -219
- package/dist/src/sprint4x-rag-verification.test.js +0 -93
- package/dist/src/store/compression.test.js +0 -139
- package/dist/src/store/memoryIndex.test.js +0 -51
- package/dist/src/store/migrate.test.js +0 -139
- package/dist/src/store/pgOpenGuard.test.js +0 -74
- package/dist/src/store/phase01.test.js +0 -81
- package/dist/src/store/phase04.test.js +0 -54
- package/dist/src/store/sprint10.test.js +0 -186
- package/dist/src/store/sqlite/game-achievements.test.js +0 -67
- package/dist/src/store/sqlite/game-scores.test.js +0 -106
- package/dist/src/store/sqlite/game-state.test.js +0 -76
- package/dist/src/store/sqlite/global-index.test.js +0 -136
- package/dist/src/store/sqlite/mechanical-fix.test.js +0 -146
- package/dist/src/store/sqlite/perf-samples.test.js +0 -146
- package/dist/src/store/sqlite/raptor.test.js +0 -106
- package/dist/src/store/sqlite/turns.test.js +0 -183
- package/dist/src/store/sqlite.cachehit.test.js +0 -55
- package/dist/src/store/sqlite.dbmaint.test.js +0 -158
- package/dist/src/store/sqlite.dbmirror.test.js +0 -184
- package/dist/src/store/turns/contract-compliance.test.js +0 -428
- package/dist/src/store/turns/memory-store.test.js +0 -9
- package/dist/src/store/turns/migrations.test.js +0 -138
- package/dist/src/store/turns/sqlite-store.test.js +0 -144
- package/dist/src/store/vectorIndex.test.js +0 -123
- package/dist/src/store.test.js +0 -161
- package/dist/src/supersede.test.js +0 -36
- package/dist/src/topics/cluster.test.js +0 -150
- package/dist/src/topics/store.test.js +0 -117
- package/dist/src/types.test.js +0 -9
- package/dist/src/vector-search-cache.test.js +0 -157
- package/dist/src/vectorStore.test.js +0 -479
- package/dist/src/wiki.test.js +0 -171
- package/extensions/conflict-scan.test.ts +0 -129
- package/extensions/dashboard-client/dist/assets/AchievementsTab-DjxfYrDc.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/GameTab-BLDudcO5.js +0 -2
- package/extensions/dashboard-client/dist/assets/OverviewTab-D4kGvsiQ.js +0 -2
- package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js +0 -2
- package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js +0 -2
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-BEdKlpAB.css +0 -1
- package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js +0 -42
- package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js.map +0 -1
- package/extensions/dashboard-server/api-contracts.test.ts +0 -1065
- package/extensions/dashboard-server/html.test.ts +0 -62
- package/extensions/dashboard-server/perf-server.test.ts +0 -101
- package/extensions/dashboard-server/routes-cache.test.ts +0 -302
- package/extensions/dashboard-server/server.test.ts +0 -131
- package/extensions/dashboard-server-s32.test.ts +0 -195
- package/extensions/dashboard-server.test.ts +0 -382
- package/extensions/mega-cache-replay.test.ts +0 -526
- package/extensions/mega-compact-s38.test.ts +0 -1433
- package/extensions/mega-compact.test.ts +0 -1509
- package/extensions/mega-events.test.ts +0 -55
- package/extensions/mega-game-cmds.test.ts +0 -197
- package/extensions/mega-runtime/snapshot.test.ts +0 -139
- package/extensions/mega-runtime/state.test.ts +0 -262
- package/extensions/mega-runtime/widget.test.ts +0 -468
- package/extensions/mega-shutdown-widget.test.ts +0 -141
- package/extensions/mega-teamrun.test.ts +0 -176
- package/extensions/mega-trim.test.ts +0 -64
- package/extensions/mega-turn-store.test.ts +0 -108
- package/src/boundary.test.ts +0 -187
- package/src/compact.test.ts +0 -99
- package/src/config/themes.test.ts +0 -116
- package/src/dedup/dedup.test.ts +0 -46
- package/src/dedup/l1.test.ts +0 -57
- package/src/dedup/raptor/buildHistory.test.ts +0 -353
- package/src/dedup/raptor/multilevel-serve.test.ts +0 -273
- package/src/dedup/raptor/multilevel.test.ts +0 -325
- package/src/dedup/raptor/promote.test.ts +0 -82
- package/src/dedup/raptor/raptor.test.ts +0 -297
- package/src/dedup/raptor/retrieval.test.ts +0 -118
- package/src/dedup/raptor/serve-gate.test.ts +0 -348
- package/src/dedup/sprint12.test.ts +0 -242
- package/src/dedup-engine.test.ts +0 -670
- package/src/driftDetection.test.ts +0 -100
- package/src/e2e.test.ts +0 -843
- package/src/engine.test.ts +0 -123
- package/src/extractive.test.ts +0 -174
- package/src/fork.test.ts +0 -94
- package/src/game/scoring.test.ts +0 -103
- package/src/httpEmbedder.test.ts +0 -286
- package/src/importance.test.ts +0 -538
- package/src/intent.test.ts +0 -87
- package/src/log.test.ts +0 -47
- package/src/mechanical-fix.test.ts +0 -70
- package/src/memory.test.ts +0 -92
- package/src/memoryConsolidate.test.ts +0 -47
- package/src/memoryOps.test.ts +0 -148
- package/src/memoryRecall.test.ts +0 -194
- package/src/memoryRoundtrip.test.ts +0 -155
- package/src/metrics/turns.test.ts +0 -165
- package/src/mirror/mirror.test.ts +0 -240
- package/src/raptor-inject-summaries.test.ts +0 -228
- package/src/ratio.bench.test.ts +0 -1316
- package/src/recall.integration.test.ts +0 -96
- package/src/recall.test.ts +0 -467
- package/src/sprint14.test.ts +0 -245
- package/src/sprint4x-rag-verification.test.ts +0 -119
- package/src/store/compression.test.ts +0 -168
- package/src/store/memoryIndex.test.ts +0 -61
- package/src/store/migrate.test.ts +0 -158
- package/src/store/pgOpenGuard.test.ts +0 -89
- package/src/store/phase01.test.ts +0 -88
- package/src/store/phase04.test.ts +0 -58
- package/src/store/sprint10.test.ts +0 -214
- package/src/store/sqlite/game-achievements.test.ts +0 -80
- package/src/store/sqlite/game-scores.test.ts +0 -132
- package/src/store/sqlite/game-state.test.ts +0 -89
- package/src/store/sqlite/global-index.test.ts +0 -222
- package/src/store/sqlite/mechanical-fix.test.ts +0 -162
- package/src/store/sqlite/perf-samples.test.ts +0 -169
- package/src/store/sqlite/raptor.test.ts +0 -139
- package/src/store/sqlite/turns.test.ts +0 -218
- package/src/store/sqlite.cachehit.test.ts +0 -68
- package/src/store/sqlite.dbmaint.test.ts +0 -193
- package/src/store/sqlite.dbmirror.test.ts +0 -229
- package/src/store/turns/contract-compliance.test.ts +0 -562
- package/src/store/turns/memory-store.test.ts +0 -15
- package/src/store/turns/migrations.test.ts +0 -161
- package/src/store/turns/sqlite-store.test.ts +0 -161
- package/src/store/vectorIndex.test.ts +0 -140
- package/src/store.test.ts +0 -191
- package/src/supersede.test.ts +0 -42
- package/src/topics/cluster.test.ts +0 -176
- package/src/topics/store.test.ts +0 -132
- package/src/types.test.ts +0 -10
- package/src/vector-search-cache.test.ts +0 -190
- package/src/vectorStore.test.ts +0 -533
- package/src/wiki.test.ts +0 -217
package/src/sprint14.test.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sprint14.test.ts — Sprint 14 full-pipeline wiring (flags, backfill, monitoring, canary).
|
|
3
|
-
* Hermetic: isolated state dirs, no network, no remote.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { test } from "node:test";
|
|
7
|
-
import assert from "node:assert/strict";
|
|
8
|
-
import { mkdtempSync, rmSync, readFileSync, existsSync } from "node:fs";
|
|
9
|
-
import { tmpdir } from "node:os";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { VectorStore, vectorSearch } from "./vectorStore.js";
|
|
12
|
-
import { defaultEmbedder } from "./embedder.js";
|
|
13
|
-
import { loadDedupConfig, type DedupConfigShape } from "./config/dedup.js";
|
|
14
|
-
import {
|
|
15
|
-
loadMetrics,
|
|
16
|
-
saveMetrics,
|
|
17
|
-
recordDecision,
|
|
18
|
-
evaluateAlerts,
|
|
19
|
-
fpRate,
|
|
20
|
-
p95,
|
|
21
|
-
type DedupMetrics,
|
|
22
|
-
} from "./monitoring.js";
|
|
23
|
-
import { backfillPhase, backfillRaptor } from "./store/backfill.js";
|
|
24
|
-
import { listCheckpoints, closeStore } from "./store/sqlite.js";
|
|
25
|
-
import { CanaryController, runCanary } from "./canary.js";
|
|
26
|
-
|
|
27
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-s14-"));
|
|
28
|
-
|
|
29
|
-
function cfg(over: Partial<DedupConfigShape> = {}): DedupConfigShape {
|
|
30
|
-
return { ...loadDedupConfig(), ...over };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function store(over: Partial<DedupConfigShape> = {}, eventsPath?: string): VectorStore {
|
|
34
|
-
const dir = join(baseTmp, `run-${Math.floor(performance.now() * 1000)}-${Math.random()}`);
|
|
35
|
-
return new VectorStore({ stateDir: dir, config: cfg(over), eventsPath });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// --- 1. Flag matrix: 16 combos don't crash add()/search() -------------------
|
|
39
|
-
|
|
40
|
-
test("flag matrix: all 16 L0/L1/L2/RAPTOR enable combos are safe", () => {
|
|
41
|
-
const flags = [false, true];
|
|
42
|
-
let combos = 0;
|
|
43
|
-
for (const l0 of flags)
|
|
44
|
-
for (const l1 of flags)
|
|
45
|
-
for (const l2 of flags)
|
|
46
|
-
for (const raptor of flags) {
|
|
47
|
-
combos++;
|
|
48
|
-
const s = store({ L0_ENABLED: l0, L1_ENABLED: l1, L2_ENABLED: l2, RAPTOR_ENABLED: raptor });
|
|
49
|
-
s.add({ sessionId: "s", summary: "x", regionText: `region A for combo ${combos} about the cache`, timestamp: 1 });
|
|
50
|
-
const r2 = s.add({ sessionId: "s", summary: "x", regionText: `region B for combo ${combos} about the parser`, timestamp: 2 });
|
|
51
|
-
// search must not throw under any combination
|
|
52
|
-
const hits = vectorSearch(s, "s", "cache", 3);
|
|
53
|
-
assert.ok(Array.isArray(hits));
|
|
54
|
-
// With all tiers off, the second add is always "new" (no collapse).
|
|
55
|
-
if (!l0 && !l1 && !l2) assert.equal(r2.deduped, false);
|
|
56
|
-
}
|
|
57
|
-
assert.equal(combos, 16);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// --- 2. MARK_ONLY_L1 records but doesn't collapse ---------------------------
|
|
61
|
-
|
|
62
|
-
test("MARK_ONLY_L1: L1 match is recorded but not collapsed (new checkpoint)", () => {
|
|
63
|
-
// Disable L2 so we isolate L1 behavior (L2 cosine would otherwise catch the near-dup).
|
|
64
|
-
const s = store({ L1_ENABLED: true, MARK_ONLY_L1: true, L2_ENABLED: false });
|
|
65
|
-
const a = s.add({ sessionId: "s", summary: "x", regionText: "the parser optimized the hot loop", timestamp: 1 });
|
|
66
|
-
const b = s.add({ sessionId: "s", summary: "x", regionText: "the parser optimized the hot loops", timestamp: 2 });
|
|
67
|
-
assert.equal(a.deduped, false);
|
|
68
|
-
// MARK_ONLY → b is NOT collapsed into a; both stored as active.
|
|
69
|
-
assert.equal(b.deduped, false);
|
|
70
|
-
const all = listCheckpoints("s", (s as any).stateDir);
|
|
71
|
-
assert.equal(all.length, 2);
|
|
72
|
-
assert.ok(all.every((c) => c.dedupStatus === "active"));
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("MARK_ONLY_L1 off: L1 match IS collapsed", () => {
|
|
76
|
-
const s = store({ L1_ENABLED: true, MARK_ONLY_L1: false });
|
|
77
|
-
s.add({ sessionId: "s", summary: "x", regionText: "the parser optimized the hot loop", timestamp: 1 });
|
|
78
|
-
const b = s.add({ sessionId: "s", summary: "x", regionText: "the parser optimized the hot loops", timestamp: 2 });
|
|
79
|
-
assert.equal(b.deduped, true);
|
|
80
|
-
assert.equal(b.reason, "l1MinHash");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// --- 3. Backfill resumes after interrupt -------------------------------------
|
|
84
|
-
|
|
85
|
-
test("backfill L1 resumes after simulated interrupt", () => {
|
|
86
|
-
const dir = join(baseTmp, `bf-${Math.floor(performance.now())}`);
|
|
87
|
-
// Seed 12 checkpoints, 2 per batch of 5.
|
|
88
|
-
const s = new VectorStore({ stateDir: dir, config: cfg() });
|
|
89
|
-
const texts = [
|
|
90
|
-
"The walrus drifted past the lighthouse while the baker kneaded sourdough at dawn",
|
|
91
|
-
"Quantum entanglement linked the two photons across the lab in a cryogenic chamber",
|
|
92
|
-
"A medieval scribe copied the gospel by candlelight atop a windswept cliff",
|
|
93
|
-
"The rover sampled basalt from the crater and transmitted spectra to mission control",
|
|
94
|
-
"Jazz musicians improvised a syncopated triangle rhythm beneath the streetlamp",
|
|
95
|
-
"The glacier calved a towering iceberg into the fjord with a thunderous crack",
|
|
96
|
-
"A botanist cataloged the orchid species thriving in the cloud forest canopy",
|
|
97
|
-
"The blacksmith forged a horseshoe while sparks danced across the anvil",
|
|
98
|
-
"Astronomers imaged a distant nebula glowing with newborn stellar furnaces",
|
|
99
|
-
"The ferry crossed the strait as gulls wheeled above the churning wake",
|
|
100
|
-
"A weaver threaded crimson silk through the loom in the mountain village",
|
|
101
|
-
"The surgeon sutured the incision with steady hands under the theatre lights",
|
|
102
|
-
];
|
|
103
|
-
for (let i = 0; i < 12; i++) {
|
|
104
|
-
s.add({ sessionId: "sess_bf", summary: `n${i}`, regionText: texts[i], timestamp: i });
|
|
105
|
-
}
|
|
106
|
-
// Interrupt after batch 1 (5 rows).
|
|
107
|
-
const r1 = backfillPhase("L1", "sess_bf", dir, { batchSize: 5, interruptAfterBatches: 1 });
|
|
108
|
-
assert.equal(r1.interrupted, true);
|
|
109
|
-
assert.equal(r1.processed, 5);
|
|
110
|
-
assert.ok(r1.cursor === "chkpt_005" || r1.cursor === "chkpt_05");
|
|
111
|
-
// Resume: should continue from the cursor → process the remaining 7.
|
|
112
|
-
const r2 = backfillPhase("L1", "sess_bf", dir, { batchSize: 5 });
|
|
113
|
-
assert.equal(r2.interrupted, false);
|
|
114
|
-
assert.equal(r2.processed, 12); // total across both runs (cursor-based resume)
|
|
115
|
-
closeStore(dir);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// --- 4. Alert fires on injected FP spike -------------------------------------
|
|
119
|
-
|
|
120
|
-
test("alert: FP spike breaches threshold → MARK_ONLY flagged + warning", () => {
|
|
121
|
-
const config = cfg();
|
|
122
|
-
const m: DedupMetrics = loadMetrics("/dev/null");
|
|
123
|
-
// Inject 100 L1 decisions, 20 false positives → 20% > FP_RATE_L1L2 (5%).
|
|
124
|
-
for (let i = 0; i < 100; i++) {
|
|
125
|
-
recordDecision(m, "L1", i < 20 ? "deduped" : "new", 5, i < 20);
|
|
126
|
-
}
|
|
127
|
-
const res = evaluateAlerts(m, config);
|
|
128
|
-
assert.ok(res.breached.includes("L1"));
|
|
129
|
-
assert.ok(res.warnings.some((w) => w.includes("DEDUP FP BREACH tier=L1")));
|
|
130
|
-
assert.ok(fpRate(m, "L1") > config.FP_RATE_L1L2);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("alert: clean run does NOT breach", () => {
|
|
134
|
-
const config = cfg();
|
|
135
|
-
const m = loadMetrics("/dev/null");
|
|
136
|
-
for (let i = 0; i < 100; i++) recordDecision(m, "L1", "new", 5, false);
|
|
137
|
-
const res = evaluateAlerts(m, config);
|
|
138
|
-
assert.equal(res.breached.length, 0);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// --- 5. Canary auto-disables a tier whose p95 exceeds budget ---------------
|
|
142
|
-
|
|
143
|
-
test("canary: auto-disables a tier whose p95 exceeds budget", () => {
|
|
144
|
-
// Feed where L2 always has high latency (breaches P95_BUDGET_MS).
|
|
145
|
-
const feed = (_step: number, c: DedupConfigShape): DedupMetrics => {
|
|
146
|
-
const m = loadMetrics("/dev/null");
|
|
147
|
-
if (c.L0_ENABLED) recordDecision(m, "L0", "new", 1, false);
|
|
148
|
-
if (c.L1_ENABLED) recordDecision(m, "L1", "new", 1, false);
|
|
149
|
-
if (c.L2_ENABLED) recordDecision(m, "L2", "new", 500, false); // > 100ms budget
|
|
150
|
-
if (c.RAPTOR_ENABLED) recordDecision(m, "RAPTOR", "new", 1, false);
|
|
151
|
-
return m;
|
|
152
|
-
};
|
|
153
|
-
const { controller, disabled } = runCanary(feed, cfg({ P95_BUDGET_MS: 100 }));
|
|
154
|
-
assert.ok(disabled.includes("L2"), `expected L2 auto-disabled, got ${JSON.stringify(disabled)}`);
|
|
155
|
-
assert.equal(controller.config.L2_ENABLED, false);
|
|
156
|
-
// Lower tiers should still be enabled.
|
|
157
|
-
assert.equal(controller.config.L0_ENABLED, true);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test("canary: sequential enablement order L0→L1→L2→RAPTOR", () => {
|
|
161
|
-
const c = new CanaryController(cfg());
|
|
162
|
-
assert.deepEqual([...c.getState().enabled], ["L0"]);
|
|
163
|
-
const t1 = c.stepForward();
|
|
164
|
-
assert.equal(t1, "L1");
|
|
165
|
-
assert.equal(c.stepForward(), "L2");
|
|
166
|
-
assert.equal(c.stepForward(), "RAPTOR");
|
|
167
|
-
assert.equal(c.stepForward(), null); // all enabled
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// --- 6. Monitoring: structured decision events written ----------------------
|
|
171
|
-
|
|
172
|
-
test("monitoring: add() writes structured decision events to events.log", () => {
|
|
173
|
-
const dir = join(baseTmp, `mon-${Math.floor(performance.now())}`);
|
|
174
|
-
const eventsPath = join(dir, "events.log");
|
|
175
|
-
const s = new VectorStore({
|
|
176
|
-
stateDir: dir,
|
|
177
|
-
config: cfg(),
|
|
178
|
-
eventsPath,
|
|
179
|
-
});
|
|
180
|
-
s.add({ sessionId: "s", summary: "x", regionText: "unique region alpha one", timestamp: 1 });
|
|
181
|
-
s.add({ sessionId: "s", summary: "x", regionText: "unique region alpha one", timestamp: 2 }); // L0 content dup
|
|
182
|
-
assert.ok(existsSync(eventsPath));
|
|
183
|
-
const lines = readFileSync(eventsPath, "utf-8").trim().split("\n").filter(Boolean);
|
|
184
|
-
assert.ok(lines.length >= 2);
|
|
185
|
-
const ev = JSON.parse(lines[0]);
|
|
186
|
-
assert.ok(["L0"].includes(ev.tier));
|
|
187
|
-
assert.ok(["new", "deduped", "mark_only"].includes(ev.result));
|
|
188
|
-
closeStore(dir);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// --- 7. RAPTOR backfill builds + persists a tree ---------------------------
|
|
192
|
-
|
|
193
|
-
test("backfill RAPTOR builds + persists a tree for a session", () => {
|
|
194
|
-
const dir = join(baseTmp, `raptorbf-${Math.floor(performance.now())}`);
|
|
195
|
-
const s = new VectorStore({ stateDir: dir, config: cfg() });
|
|
196
|
-
const texts = [
|
|
197
|
-
"The whale breached beside the research vessel near the polar ice shelf",
|
|
198
|
-
"A potter shaped the clay vessel on the spinning wheel at the riverside studio",
|
|
199
|
-
"The comet streaked across the pre dawn sky witnessed by the hilltop observatory",
|
|
200
|
-
"Lumberjacks felled the ancient cedar while the river carried the logs downstream",
|
|
201
|
-
"The chemist titrated the solution until the indicator turned faint violet",
|
|
202
|
-
"A flock of cranes migrated northward over the thawing wetland at first light",
|
|
203
|
-
"The locksmith picked the stubborn tumbler and opened the oak cabinet",
|
|
204
|
-
"Geologists hammered the schist sample from the canyon wall into the satchel",
|
|
205
|
-
"The chocolatier tempered the couverture until it snapped with a clean gloss",
|
|
206
|
-
"A fisher cast the line into the mist where the trout rose to the fly",
|
|
207
|
-
"The archivist unsealed the parchment scroll recovered from the coastal ruin",
|
|
208
|
-
"Beekeepers harvested the golden comb while the orchard blossoms drifted down",
|
|
209
|
-
"The pilot navigated the canyon winds using only the instrument panel glow",
|
|
210
|
-
"A tailor stitched the velvet cuff with silk thread by the window",
|
|
211
|
-
"The miner extracted the quartz crystal from the vein deep in the shaft",
|
|
212
|
-
"Cartographers plotted the uncharted island onto the worn leather map",
|
|
213
|
-
"The gardener pruned the rosebush and tied the canes to the cedar trellis",
|
|
214
|
-
"A violinist tuned the gut strings until the chamber rang pure and bright",
|
|
215
|
-
"The diver surfaced with the amphora lifted from the sunken galleon",
|
|
216
|
-
"Shepherds guided the flock across the high pasture toward the stone bothy",
|
|
217
|
-
];
|
|
218
|
-
for (let i = 0; i < 20; i++) {
|
|
219
|
-
s.add({ sessionId: "sess_rb", summary: `n${i}`, regionText: texts[i], timestamp: i });
|
|
220
|
-
}
|
|
221
|
-
const res = backfillRaptor("sess_rb", dir, defaultEmbedder());
|
|
222
|
-
assert.ok(res.processed > 0);
|
|
223
|
-
// Sanity: source checkpoints remain intact (backfill is additive).
|
|
224
|
-
const nodes = listCheckpoints("sess_rb", dir).length;
|
|
225
|
-
assert.ok(nodes >= 20);
|
|
226
|
-
closeStore(dir);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// --- 8. dashboard.json metrics round-trip -----------------------------------
|
|
230
|
-
|
|
231
|
-
test("metrics: dashboard.json persists + p95 computed", () => {
|
|
232
|
-
const path = join(baseTmp, `dash-${Math.floor(performance.now())}.json`);
|
|
233
|
-
const m = loadMetrics(path);
|
|
234
|
-
for (let i = 0; i < 10; i++) recordDecision(m, "L2", "new", i * 10, false);
|
|
235
|
-
saveMetrics(path, m);
|
|
236
|
-
const reloaded = loadMetrics(path);
|
|
237
|
-
assert.equal(reloaded.decisions.L2, 10);
|
|
238
|
-
assert.equal(p95(reloaded.latency.L2), 90); // 95th pct of [0,10,..,90]
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// --- cleanup ----------------------------------------------------------------
|
|
242
|
-
|
|
243
|
-
test("Sprint 14 cleanup", () => {
|
|
244
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
245
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sprint4x-rag-verification.test.ts — run the S40–S47 RAG suite once against
|
|
3
|
-
* the current implementation and assert the documented "default enable" claims.
|
|
4
|
-
*
|
|
5
|
-
* This is the verification pass demanded by the roadmap/backlog: each spec
|
|
6
|
-
* claims its feature flags DEFAULT ON. The honest check (not a re-statement of
|
|
7
|
-
* the spec) is: which flags actually exist in code, what do they default to,
|
|
8
|
-
* and is the consuming path wired?
|
|
9
|
-
*
|
|
10
|
-
* Findings recorded here, per spec:
|
|
11
|
-
* S40 importance-scoring — module src/importance.ts exists (S40A) but is
|
|
12
|
-
* NOT consumed by compactSession/vector-paths;
|
|
13
|
-
* no shipped flag, no adapter wiring.
|
|
14
|
-
* S41 self-rag-quality-gate — spec-only; NO flag, NO consumer.
|
|
15
|
-
* S42 raptor-multilevel — PARTIALLY SHIPPED: RAPTOR_MULTILEVEL_ENABLED
|
|
16
|
-
* and RAPTOR_LEAF_EXPANSION both default true
|
|
17
|
-
* with real consumers; the spec's claim holds.
|
|
18
|
-
* S43 hyde-vague-queries — spec-only (QUERY_REFORMULATION_ENABLED absent).
|
|
19
|
-
* S44 three-tier-latency-routing — spec-only (TIERED_ROUTING_ENABLED absent).
|
|
20
|
-
* S45 crag-quality-metrics — spec-only (CRAG_ENABLED absent).
|
|
21
|
-
* S46 visual-memory-map — spec-only (MEMORY_MAP_ENABLED absent;
|
|
22
|
-
* memory-graph endpoint not in dashboard-server).
|
|
23
|
-
* S47 auto-categorizing-wiki — spec-only (AUTO_WIKI_ENABLED absent).
|
|
24
|
-
*
|
|
25
|
-
* Policy: the suite runs against the flags that EXIST today. Unimplemented spec
|
|
26
|
-
* claims are pinned by the S4X_SPEC_ONLY tests so regressions can't silently
|
|
27
|
-
* add them in the wrong state, and this file records exactly which
|
|
28
|
-
* spec-vs-implementation gaps remain.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import { test } from "node:test";
|
|
32
|
-
import assert from "node:assert/strict";
|
|
33
|
-
import { loadDedupConfig } from "./config/dedup.js";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Clear any env pollution so the default is measured, not the override.
|
|
37
|
-
*/
|
|
38
|
-
function fresh<T extends string>(envKey: T, get: () => unknown): unknown {
|
|
39
|
-
delete process.env[envKey];
|
|
40
|
-
try {
|
|
41
|
-
return get();
|
|
42
|
-
} finally {
|
|
43
|
-
delete process.env[envKey];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ---- S42: shipped flags default ON (claim holds) ----------------------------
|
|
48
|
-
|
|
49
|
-
test("S42 RAPTOR_MULTILEVEL_ENABLED defaults ON and honors env off", () => {
|
|
50
|
-
const d = fresh("MEGACOMPACT_RAPTOR_MULTILEVEL", () => loadDedupConfig());
|
|
51
|
-
assert.ok(
|
|
52
|
-
(d as { RAPTOR_MULTILEVEL_ENABLED: boolean }).RAPTOR_MULTILEVEL_ENABLED,
|
|
53
|
-
"ship claim: multi-level on by default",
|
|
54
|
-
);
|
|
55
|
-
process.env.MEGACOMPACT_RAPTOR_MULTILEVEL = "false";
|
|
56
|
-
const off = loadDedupConfig();
|
|
57
|
-
assert.ok(
|
|
58
|
-
!off.RAPTOR_MULTILEVEL_ENABLED,
|
|
59
|
-
"env override: MEGACOMPACT_RAPTOR_MULTILEVEL=false turns it off",
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("S42 RAPTOR_LEAF_EXPANSION defaults ON and honors env off", () => {
|
|
64
|
-
const d = fresh("MEGACOMPACT_RAPTOR_LEAF_EXPANSION", () => loadDedupConfig());
|
|
65
|
-
assert.ok(
|
|
66
|
-
(d as { RAPTOR_LEAF_EXPANSION: boolean }).RAPTOR_LEAF_EXPANSION,
|
|
67
|
-
"ship claim: leaf-expansion on by default",
|
|
68
|
-
);
|
|
69
|
-
process.env.MEGACOMPACT_RAPTOR_LEAF_EXPANSION = "false";
|
|
70
|
-
const off = loadDedupConfig();
|
|
71
|
-
assert.ok(!off.RAPTOR_LEAF_EXPANSION, "env override off");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// ---- S40: module exists, claims do NOT yet hold at the flag/consumer level --
|
|
75
|
-
|
|
76
|
-
test("S40 importance module exists in-tree (S40A artifact)", async () => {
|
|
77
|
-
// Load the module and confirm it exports the scoring surface the spec
|
|
78
|
-
// describes. This proves the S40A implementation exists even though nothing
|
|
79
|
-
// wires it into compaction/vector paths yet (documented gap).
|
|
80
|
-
const mod = await import("./importance.js");
|
|
81
|
-
assert.ok(mod && typeof mod === "object", "importance.ts loads");
|
|
82
|
-
// Exports per spec: score() plus item-type enum.
|
|
83
|
-
assert.ok(typeof (mod as Record<string, unknown>).score === "function",
|
|
84
|
-
"importance.ts exports score() function",
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("S40 has no shipped consumer flag in the current codebase (gap pinned)", async () => {
|
|
89
|
-
// The S40 spec claims an IMPORTANCE_SCORING flag defaults ON. In the
|
|
90
|
-
// current code no such flag exists, and no vector/compact path reads
|
|
91
|
-
// importance scores. This test documents the gap so a future wiring does
|
|
92
|
-
// not silently flip it on in the wrong shape.
|
|
93
|
-
const cfg = loadDedupConfig();
|
|
94
|
-
assert.ok(
|
|
95
|
-
!("IMPORTANCE_SCORING" in cfg),
|
|
96
|
-
"no IMPORTANCE_SCORING flag yet (S40 consumer wiring missing)",
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// ---- S41/S43–S47: spec-only modules — pin the absence ------------------------
|
|
101
|
-
|
|
102
|
-
test("S4X spec-only flags absent from DedupConfig", () => {
|
|
103
|
-
const cfg = loadDedupConfig();
|
|
104
|
-
const specFlags = [
|
|
105
|
-
"CRITIQUE_ENABLED", // S41
|
|
106
|
-
"QUERY_REFORMULATION_ENABLED", // S43
|
|
107
|
-
"TIERED_ROUTING_ENABLED", // S44
|
|
108
|
-
"CRAG_ENABLED", // S45
|
|
109
|
-
"CRAG_EXPANSION_ENABLED", // S45
|
|
110
|
-
"MEMORY_MAP_ENABLED", // S46
|
|
111
|
-
"AUTO_WIKI_ENABLED", // S47
|
|
112
|
-
] as const;
|
|
113
|
-
for (const f of specFlags) {
|
|
114
|
-
assert.ok(
|
|
115
|
-
!(f in cfg),
|
|
116
|
-
`${f} is spec-only — should not be present in DedupConfig`,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* compression.test.ts — versioned compression tiers + backward compatibility.
|
|
3
|
-
*
|
|
4
|
-
* Proves Sprint 8's root-cause fix: the 0x03 tag collision is impossible because
|
|
5
|
-
* new blobs carry a 2-byte version magic, and legacy blobs (untagged gzip, legacy
|
|
6
|
-
* single-tag incl. the old 0x03=brotli) still decompress.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { test } from "node:test";
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
import { gzipSync, brotliCompressSync } from "node:zlib";
|
|
12
|
-
import {
|
|
13
|
-
compressSmart,
|
|
14
|
-
decompressSmart,
|
|
15
|
-
compressZstd,
|
|
16
|
-
decompressZstd,
|
|
17
|
-
isVersioned,
|
|
18
|
-
detectFormat,
|
|
19
|
-
decompressSyncAuto,
|
|
20
|
-
} from "./compression.js";
|
|
21
|
-
|
|
22
|
-
const buf = (s: string, n: number) => Buffer.from(s.repeat(n));
|
|
23
|
-
|
|
24
|
-
test("versioned format: all size tiers roundtrip and are versioned", () => {
|
|
25
|
-
const cases = [
|
|
26
|
-
{ label: "tiny", data: buf("x", 100), expectTag: 0x00 },
|
|
27
|
-
{ label: "small", data: buf("a", 600), expectTag: 0x01 },
|
|
28
|
-
{ label: "medium", data: buf("b", 8000), expectTag: 0x02 },
|
|
29
|
-
{ label: "large", data: buf("c", 40000), expectTag: 0x05 },
|
|
30
|
-
];
|
|
31
|
-
for (const { label, data, expectTag } of cases) {
|
|
32
|
-
const c = compressSmart(data);
|
|
33
|
-
// New 2-byte magic header present.
|
|
34
|
-
assert.ok(isVersioned(c), `${label}: should be versioned (0xEC 0x01)`);
|
|
35
|
-
assert.equal(c[0], 0xec, `${label}: magic hi`);
|
|
36
|
-
assert.equal(c[1], 0x01, `${label}: magic lo (version)`);
|
|
37
|
-
assert.equal(c[2], 0x01, `${label}: format version 1`);
|
|
38
|
-
assert.equal(c[3], expectTag, `${label}: tier tag ${expectTag.toString(16)}`);
|
|
39
|
-
// Roundtrips exactly.
|
|
40
|
-
assert.deepEqual(decompressSmart(c), data, `${label}: roundtrip`);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("large tier actually compresses better than raw (brotli 0x05)", () => {
|
|
45
|
-
const data = buf("this is a long summary of a coding session. ", 900);
|
|
46
|
-
const c = compressSmart(data);
|
|
47
|
-
assert.ok(c.length < data.length, "compressed smaller than raw");
|
|
48
|
-
assert.equal(c[3], 0x05, "tag is brotli-4");
|
|
49
|
-
assert.deepEqual(decompressSmart(c), data);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("legacy untagged gzip (0x1f magic) still decompresses", () => {
|
|
53
|
-
const data = Buffer.from(JSON.stringify({ legacy: true }));
|
|
54
|
-
const legacyGzip = gzipSync(data); // no tag byte, starts with 0x1f
|
|
55
|
-
assert.equal(legacyGzip[0], 0x1f, "gzip magic present");
|
|
56
|
-
assert.equal(detectFormat(legacyGzip), "legacy-gzip");
|
|
57
|
-
assert.deepEqual(JSON.parse(decompressSmart(legacyGzip).toString()), { legacy: true });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("legacy single-tag 0x03=brotli (the collision case) still decompresses", () => {
|
|
61
|
-
const data = buf("legacy brotli payload ", 200);
|
|
62
|
-
// Reconstruct the EXACT v0.1.0 legacy brotli frame: tag 0x03 + brotli payload.
|
|
63
|
-
const legacy = Buffer.concat([Buffer.from([0x03]), brotliCompressSync(data)]);
|
|
64
|
-
assert.equal(detectFormat(legacy), "legacy-tag");
|
|
65
|
-
assert.deepEqual(decompressSmart(legacy), data, "legacy 0x03 brotli roundtrips");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("detectFormat classifies all eras", () => {
|
|
69
|
-
assert.equal(detectFormat(compressSmart(buf("q", 700))), "versioned");
|
|
70
|
-
assert.equal(detectFormat(gzipSync(buf("q", 10))), "legacy-gzip");
|
|
71
|
-
assert.equal(detectFormat(Buffer.from([0x00, 1, 2, 3])), "legacy-tag");
|
|
72
|
-
assert.equal(detectFormat(Buffer.from([0x99, 0x88])), "unknown");
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("zstd helper roundtrips (async) and is not sync-decoded", async () => {
|
|
76
|
-
const data = buf("zstd dr export payload ", 1500);
|
|
77
|
-
const c = await compressZstd(data);
|
|
78
|
-
assert.ok(c.length < data.length, "zstd compresses");
|
|
79
|
-
// decompressSyncAuto reports zstd without throwing (caller awaits decompressZstd).
|
|
80
|
-
const auto = decompressSyncAuto(c);
|
|
81
|
-
assert.equal(auto.isZstd, true, "flagged as zstd");
|
|
82
|
-
assert.deepEqual(await decompressZstd(c), data, "zstd roundtrip");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("module loads without a top-level zstd import (Fix A: no load crash)", async () => {
|
|
86
|
-
// The extension must load even when the @mongodb-js/zstd native addon is
|
|
87
|
-
// absent (clean/allowScripts-blocked install). The dynamic import() lives
|
|
88
|
-
// inside the helpers, so importing this module must never throw.
|
|
89
|
-
const mod = await import("./compression.js");
|
|
90
|
-
assert.equal(typeof mod.compressSmart, "function", "compressSmart exported");
|
|
91
|
-
assert.equal(typeof mod.compressZstd, "function", "compressZstd exported");
|
|
92
|
-
// The real invariant: no STATIC `import ... from "@mongodb-js/zstd"` at the
|
|
93
|
-
// top level (that's what crashed the whole extension). zstd must be loaded
|
|
94
|
-
// lazily inside the helpers only. Check the source text.
|
|
95
|
-
const { readFileSync } = await import("node:fs");
|
|
96
|
-
const { join } = await import("node:path");
|
|
97
|
-
// Tests run with cwd at repo root (`node --test`), so resolve the source.
|
|
98
|
-
const src = readFileSync(join(process.cwd(), "src/store/compression.ts"), "utf-8");
|
|
99
|
-
const staticImport = /^import\s+.+\s+from\s+["']@mongodb-js\/zstd["'];?$/m;
|
|
100
|
-
assert.equal(
|
|
101
|
-
staticImport.test(src),
|
|
102
|
-
false,
|
|
103
|
-
"no static top-level import of @mongodb-js/zstd (would crash load if binary absent)",
|
|
104
|
-
);
|
|
105
|
-
assert.ok(
|
|
106
|
-
src.includes('await import("@mongodb-js/zstd")'),
|
|
107
|
-
"zstd is loaded lazily via dynamic import() inside the helpers",
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("compressSmart escalates brotli quality with pressure (Fix E)", () => {
|
|
112
|
-
// Large (>32KB) payloads hit the brotli tier; higher pressure → brotli-11
|
|
113
|
-
// → smaller output than the default brotli-4, and still decodes.
|
|
114
|
-
const words = Array.from({ length: 6000 }, (_, i) => "word" + ((i * 2654435761) % 9973));
|
|
115
|
-
const big = Buffer.from(words.join(" "));
|
|
116
|
-
const low = compressSmart(big, 0);
|
|
117
|
-
const high = compressSmart(big, 1);
|
|
118
|
-
assert.equal(isVersioned(low), true, "versioned header preserved at p=0");
|
|
119
|
-
assert.equal(isVersioned(high), true, "versioned header preserved at p=1");
|
|
120
|
-
assert.ok(high.length < low.length, "high pressure compresses smaller");
|
|
121
|
-
assert.deepEqual(decompressSmart(low), big, "p=0 roundtrip");
|
|
122
|
-
assert.deepEqual(decompressSmart(high), big, "p=1 roundtrip");
|
|
123
|
-
// Small payloads ignore pressure (gzip tier) but still roundtrip.
|
|
124
|
-
const small = buf("hello world ", 300);
|
|
125
|
-
assert.deepEqual(decompressSmart(compressSmart(small, 1)), small, "small ignores pressure");
|
|
126
|
-
// pressure out of range is clamped (no throw, still versioned + decodable).
|
|
127
|
-
assert.deepEqual(decompressSmart(compressSmart(big, 5)), big, "over-pressure clamped");
|
|
128
|
-
assert.deepEqual(decompressSmart(compressSmart(big, -1)), big, "under-pressure clamped");
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("pressureFromPct + preserveRecentForPressure scale with context (Fix E)", async () => {
|
|
132
|
-
const { pressureFromPct, preserveRecentForPressure } = await import("../config.js");
|
|
133
|
-
assert.equal(pressureFromPct(50), 0.5, "pct→pressure");
|
|
134
|
-
assert.equal(pressureFromPct(null), 0, "null pct → 0");
|
|
135
|
-
assert.equal(pressureFromPct(150), 1, "pct clamped");
|
|
136
|
-
// low pressure keeps preserveRecent; high pressure compacts deeper (min floor).
|
|
137
|
-
assert.equal(preserveRecentForPressure(0, 4, 2), 4, "p=0 → preserveRecent");
|
|
138
|
-
assert.equal(preserveRecentForPressure(1, 4, 2), 2, "p=1 → preserveRecentMin");
|
|
139
|
-
assert.equal(preserveRecentForPressure(0.5, 4, 2), 3, "p=0.5 → interpolates");
|
|
140
|
-
assert.ok(preserveRecentForPressure(1, 4, 2) >= 2, "never below floor");
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
test("S24: pressureRatio + pressureBand + memoryReviewCadence unify the signal", async () => {
|
|
144
|
-
const { pressureRatio, pressureBand, memoryReviewCadence } = await import("../config.js");
|
|
145
|
-
// pressureRatio: current/threshold, clamped to [0,1].
|
|
146
|
-
assert.equal(pressureRatio(50_000, 100_000), 0.5, "half threshold → 0.5");
|
|
147
|
-
assert.equal(pressureRatio(0, 100_000), 0, "no tokens → 0");
|
|
148
|
-
assert.equal(pressureRatio(10_000_000, 100_000), 1, "over threshold → clamped 1");
|
|
149
|
-
assert.equal(pressureRatio(50_000, 0), 0, "zero threshold → 0");
|
|
150
|
-
assert.equal(pressureRatio(NaN, 100_000), 0, "NaN current → 0");
|
|
151
|
-
|
|
152
|
-
// pressureBand: discrete bands drive the toolbar/dashboard tier label.
|
|
153
|
-
assert.equal(pressureBand(0.2), "low");
|
|
154
|
-
assert.equal(pressureBand(0.5), "medium");
|
|
155
|
-
assert.equal(pressureBand(0.75), "high");
|
|
156
|
-
assert.equal(pressureBand(0.9), "ultra");
|
|
157
|
-
assert.equal(pressureBand(1.0), "mega");
|
|
158
|
-
assert.equal(pressureBand(2.0), "mega", "over 1 → mega");
|
|
159
|
-
assert.equal(pressureBand(-1), "low", "below 0 → low");
|
|
160
|
-
|
|
161
|
-
// memoryReviewCadence: higher pressure → smaller (more frequent) divisor.
|
|
162
|
-
assert.equal(memoryReviewCadence("low", 10), 10, "low keeps base interval");
|
|
163
|
-
assert.equal(memoryReviewCadence("medium", 10), 7, "medium shortens");
|
|
164
|
-
assert.equal(memoryReviewCadence("high", 10), 5, "high halves");
|
|
165
|
-
assert.equal(memoryReviewCadence("ultra", 10), 3, "ultra shortens more");
|
|
166
|
-
assert.equal(memoryReviewCadence("mega", 10), 2, "mega near base/5");
|
|
167
|
-
assert.equal(memoryReviewCadence("high", 0), 1, "never below 1");
|
|
168
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { defaultEmbedder } from "../embedder.js";
|
|
7
|
-
import {
|
|
8
|
-
upsertMemoryEmbedding,
|
|
9
|
-
searchMemoriesAsync,
|
|
10
|
-
initMemoryIndex,
|
|
11
|
-
closeMemoryIndex,
|
|
12
|
-
isMemoryIndexDisabled,
|
|
13
|
-
} from "./memoryIndex.js";
|
|
14
|
-
|
|
15
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-memidx-"));
|
|
16
|
-
|
|
17
|
-
test("memoryIndex: disabled when MEGACOMPACT_PGLITE_DISABLED", async () => {
|
|
18
|
-
process.env.MEGACOMPACT_PGLITE_DISABLED = "true";
|
|
19
|
-
try {
|
|
20
|
-
assert.equal(isMemoryIndexDisabled(), true, "kill-switch honored");
|
|
21
|
-
const hits = await searchMemoriesAsync(defaultEmbedder().embed("anything"), { k: 3 });
|
|
22
|
-
assert.deepEqual(hits, [], "search returns [] when disabled");
|
|
23
|
-
} finally {
|
|
24
|
-
delete process.env.MEGACOMPACT_PGLITE_DISABLED;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("memoryIndex: cross-repo upsert + NN search returns the right repo's memory", async () => {
|
|
29
|
-
// Isolate the global PGlite dir so concurrent test runs don't collide.
|
|
30
|
-
process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index");
|
|
31
|
-
const repoA = "/tmp/repo-a";
|
|
32
|
-
const repoB = "/tmp/repo-b";
|
|
33
|
-
try {
|
|
34
|
-
await initMemoryIndex();
|
|
35
|
-
// Two memories in different repos, with clearly distinct content so their
|
|
36
|
-
// trigram embeddings separate.
|
|
37
|
-
const vecA = defaultEmbedder().embed("We standardized on node:sqlite for the store backend");
|
|
38
|
-
const vecB = defaultEmbedder().embed("The deployment target is a raspberry pi in the closet");
|
|
39
|
-
await upsertMemoryEmbedding(repoA, 1, "We standardized on node:sqlite for the store backend", vecA);
|
|
40
|
-
await upsertMemoryEmbedding(repoB, 7, "The deployment target is a raspberry pi in the closet", vecB);
|
|
41
|
-
|
|
42
|
-
// Query close to A's content → top hit should be A's memory, not B's.
|
|
43
|
-
const q = defaultEmbedder().embed("standardized node:sqlite store backend choice");
|
|
44
|
-
const hits = await searchMemoriesAsync(q, { k: 3 });
|
|
45
|
-
assert.ok(hits.length >= 1, "at least one hit");
|
|
46
|
-
assert.equal(hits[0].repoId, repoA, "nearest neighbor is repo A");
|
|
47
|
-
assert.equal(hits[0].memoryId, 1, "correct memory id");
|
|
48
|
-
assert.ok(hits[0].score > 0.5, "high cosine for the matching memory");
|
|
49
|
-
|
|
50
|
-
// Scope to repoB only → A must not appear.
|
|
51
|
-
const scoped = await searchMemoriesAsync(q, { k: 3, repoId: repoB });
|
|
52
|
-
assert.ok(scoped.every((h) => h.repoId === repoB), "scoped search stays within repoB");
|
|
53
|
-
} finally {
|
|
54
|
-
await closeMemoryIndex();
|
|
55
|
-
delete process.env.MEGACOMPACT_INDEX_DIR;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("memoryIndex: cleanup", () => {
|
|
60
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
61
|
-
});
|