pi-mega-compact 0.11.3 → 0.11.5
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/endpoints.js +19 -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 +115 -55
- 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 +162 -0
- package/dist/extensions/dashboard-server/routes.js +2 -0
- package/dist/extensions/dashboard-server/server.js +7 -1
- package/dist/extensions/mega-commands.js +189 -1
- package/dist/extensions/mega-config.js +3 -0
- package/dist/extensions/mega-events/agent-handlers.js +41 -6
- package/dist/extensions/mega-events/compact-handlers.js +1 -0
- package/dist/extensions/mega-events/context-handler.js +37 -92
- package/dist/extensions/mega-events/context-hwm.js +51 -0
- package/dist/extensions/mega-events/error-classifier.js +118 -128
- package/dist/extensions/mega-events/mirror-append.js +107 -0
- package/dist/extensions/mega-events/outage-advisor.js +59 -0
- package/dist/extensions/mega-events/perf-handler.js +51 -1
- package/dist/extensions/mega-events/recall-tail.js +59 -0
- package/dist/extensions/mega-events/session-handlers.js +15 -8
- package/dist/extensions/mega-runtime/reset-runtime.js +6 -0
- package/dist/extensions/mega-runtime/runtime.js +7 -0
- package/dist/src/embedder.js +41 -2
- package/dist/src/memoryStats.js +75 -0
- package/dist/src/prefix-break.js +43 -0
- package/dist/src/pricing.js +1 -1
- package/dist/src/store/sqlite/perf-samples.js +144 -16
- 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 +26 -5
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js → AchievementTiles-BoL7qBOJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js.map → AchievementTiles-BoL7qBOJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/AchievementsTab-BFDE3HYc.js +2 -0
- package/extensions/dashboard-client/dist/assets/{AchievementsTab-DjxfYrDc.js.map → AchievementsTab-BFDE3HYc.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/CacheTab-eKVc-NV1.js +2 -0
- package/extensions/dashboard-client/dist/assets/CacheTab-eKVc-NV1.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js → ConfigTab-DDFE-ckA.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js.map → ConfigTab-DDFE-ckA.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js → EventsTab-B6UxZ7PM.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js.map → EventsTab-B6UxZ7PM.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{GameTab-BLDudcO5.js → GameTab-DehUX-KE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{GameTab-BLDudcO5.js.map → GameTab-DehUX-KE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js → MaintenanceTab-0GWRt4wn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js.map → MaintenanceTab-0GWRt4wn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js → MetricsTab-C3rwMVsN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js.map → MetricsTab-C3rwMVsN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/OverviewTab-39O9_x5j.js +2 -0
- package/extensions/dashboard-client/dist/assets/{OverviewTab-D4kGvsiQ.js.map → OverviewTab-39O9_x5j.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/ReposTab-Cfj6Q5sH.js +2 -0
- package/extensions/dashboard-client/dist/assets/ReposTab-Cfj6Q5sH.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js → SessionsTab-DXDTCi3r.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js.map → SessionsTab-DXDTCi3r.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-mMlfunJa.js +2 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-mMlfunJa.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-Cw1dJ4e9.js +2 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-Cw1dJ4e9.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js → TopicsTab-BAw972BV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js.map → TopicsTab-BAw972BV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js → TurnsTab-Cf5mGIdl.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js.map → TurnsTab-Cf5mGIdl.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-BX0bcgLu.js → index-4gQ7auad.js} +10 -10
- package/extensions/dashboard-client/dist/assets/index-4gQ7auad.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-DNgMuyP6.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js.map → useSSE-DNgMuyP6.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/App.tsx +4 -0
- package/extensions/dashboard-client/src/api/client.ts +14 -0
- package/extensions/dashboard-client/src/components/ActiveReposTable.tsx +21 -12
- 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/tabs/CacheTab.tsx +1 -0
- package/extensions/dashboard-client/src/tabs/SetupTab.tsx +355 -0
- package/extensions/dashboard-client/tsconfig.json +3 -2
- package/extensions/dashboard-client/vite.config.ts +2 -0
- package/extensions/dashboard-server/api-contracts/endpoints.ts +36 -3
- package/extensions/dashboard-server/api-contracts/index.ts +7 -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 +58 -0
- package/extensions/dashboard-server/index-reader.ts +138 -121
- package/extensions/dashboard-server/routes-cache.ts +161 -85
- 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 +181 -0
- package/extensions/dashboard-server/routes.ts +2 -0
- package/extensions/dashboard-server/server.ts +6 -0
- package/extensions/mega-commands.ts +211 -1
- package/extensions/mega-config.ts +18 -0
- package/extensions/mega-events/agent-handlers.ts +44 -5
- package/extensions/mega-events/compact-handlers.ts +1 -0
- package/extensions/mega-events/context-handler.ts +45 -110
- package/extensions/mega-events/context-hwm.ts +85 -0
- package/extensions/mega-events/error-classifier.ts +156 -124
- package/extensions/mega-events/mirror-append.ts +155 -0
- package/extensions/mega-events/outage-advisor.ts +79 -0
- package/extensions/mega-events/perf-handler.ts +79 -5
- package/extensions/mega-events/recall-tail.ts +88 -0
- package/extensions/mega-events/session-handlers.ts +14 -7
- package/extensions/mega-runtime/helpers.ts +14 -0
- package/extensions/mega-runtime/reset-runtime.ts +6 -0
- package/extensions/mega-runtime/runtime.ts +7 -0
- package/package.json +5 -2
- package/src/embedder.ts +42 -2
- package/src/memoryStats.ts +107 -0
- package/src/prefix-break.ts +83 -0
- package/src/pricing.ts +2 -2
- package/src/store/sqlite/perf-samples.ts +215 -22
- 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 +33 -4
- 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 -820
- 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/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-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 -872
- 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
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* memoryRoundtrip.test.ts — S25-C durable-memory write→persist→recall→inline
|
|
3
|
-
* proof + bloat bound + hallucination guard verification.
|
|
4
|
-
*
|
|
5
|
-
* Test-only by design (spec: docs/specs/s25-memory-db-roundtrip.md). No src/
|
|
6
|
-
* behavior change; if a probe exposes a gap it's recorded as a finding, not
|
|
7
|
-
* silently patched.
|
|
8
|
-
*
|
|
9
|
-
* Sections:
|
|
10
|
-
* R1 — full round-trip: reviewConversation → applyMemoryOps → recallMemories
|
|
11
|
-
* → formatMemoryRecallBlock, content+category survive every hop.
|
|
12
|
-
* R2 — bloat bound: many review iterations cannot grow past MEMORY_MAX_ROWS.
|
|
13
|
-
* R3 — hallucination guard: fabricated ops (not verbatim from a message) are
|
|
14
|
-
* dropped before apply; grounded ops survive.
|
|
15
|
-
*/
|
|
16
|
-
process.env.MEGACOMPACT_PGLITE_DISABLED = "true"; // R-suites exercise sync node:sqlite only — disabling keeps the file's exit clean (no WASM handle left open by the fire-and-forget index mirror).
|
|
17
|
-
import { test } from "node:test";
|
|
18
|
-
import assert from "node:assert/strict";
|
|
19
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
20
|
-
process.env.MEGACOMPACT_PGLITE_DISABLED = "true"; // sync-only suite: no WASM handle left open by the fire-and-forget index mirror
|
|
21
|
-
import { tmpdir } from "node:os";
|
|
22
|
-
import { join } from "node:path";
|
|
23
|
-
import { reviewConversation } from "./memory.js";
|
|
24
|
-
import { applyMemoryOps } from "./memoryOps.js";
|
|
25
|
-
import { recallMemories } from "./memoryRecall.js";
|
|
26
|
-
import { formatMemoryRecallBlock } from "./recall.js";
|
|
27
|
-
import { listMemories, closeStore } from "./store/sqlite.js";
|
|
28
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-memrt-"));
|
|
29
|
-
function freshDir() {
|
|
30
|
-
return mkdtempSync(join(baseTmp, "rt-"));
|
|
31
|
-
}
|
|
32
|
-
function done(dir) {
|
|
33
|
-
closeStore(dir);
|
|
34
|
-
rmSync(dir, { recursive: true, force: true });
|
|
35
|
-
}
|
|
36
|
-
// A deterministic local embedder for recall scoring (mirrors memoryRecall.test.ts).
|
|
37
|
-
function biGramEmbedder() {
|
|
38
|
-
const dim = 64;
|
|
39
|
-
return {
|
|
40
|
-
dim,
|
|
41
|
-
embed(text) {
|
|
42
|
-
const v = new Array(dim).fill(0);
|
|
43
|
-
const norm = text.toLowerCase().replace(/[^a-z0-9 ]/g, "").trim();
|
|
44
|
-
for (let i = 0; i < norm.length - 1; i++) {
|
|
45
|
-
const idx = ((norm.charCodeAt(i) * 31 + norm.charCodeAt(i + 1)) >>> 0) % dim;
|
|
46
|
-
v[idx] = 1;
|
|
47
|
-
}
|
|
48
|
-
return v;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// Shared grounded decision used by R1 (under the 160-char truncation cap).
|
|
53
|
-
const GROUNDED = "we decided to use node:sqlite for the durable store backend";
|
|
54
|
-
test("R1 — full round-trip: review → persist → recall → format carries content + category", async () => {
|
|
55
|
-
const dir = freshDir();
|
|
56
|
-
try {
|
|
57
|
-
// 1. Review produces an ADD op grounded in a real user message.
|
|
58
|
-
const msgs = [
|
|
59
|
-
{ role: "user", text: GROUNDED },
|
|
60
|
-
{ role: "assistant", text: "acknowledged" },
|
|
61
|
-
];
|
|
62
|
-
const ops = reviewConversation(msgs, []);
|
|
63
|
-
assert.equal(ops.length, 1, "exactly one op from one decision");
|
|
64
|
-
assert.equal(ops[0].op, "add");
|
|
65
|
-
// 2. Persist via applyMemoryOps (real SQLite write — node:sqlite).
|
|
66
|
-
await applyMemoryOps(ops, dir);
|
|
67
|
-
const stored = listMemories(null, 50, dir);
|
|
68
|
-
assert.equal(stored.length, 1, "memory row persisted");
|
|
69
|
-
assert.ok(/node:sqlite/.test(stored[0].content), "content survives persist");
|
|
70
|
-
assert.equal(stored[0].category, "decision", "category survives persist");
|
|
71
|
-
// 3. Recall surfaces it for a topically-related query.
|
|
72
|
-
const hits = await recallMemories("what database backend do we use?", dir, {
|
|
73
|
-
embedder: biGramEmbedder(),
|
|
74
|
-
topK: 5,
|
|
75
|
-
minSimilarity: 0,
|
|
76
|
-
});
|
|
77
|
-
assert.ok(hits.length > 0, "recall returns the stored memory");
|
|
78
|
-
assert.ok(hits.some((h) => /node:sqlite/.test(h.memory.content)), "the hit contains the decision content");
|
|
79
|
-
// 4. Inline-block formatting keeps content + category label.
|
|
80
|
-
const block = formatMemoryRecallBlock(hits.map((h) => ({ content: h.memory.content, category: h.memory.category, score: h.score })));
|
|
81
|
-
assert.ok(/node:sqlite/.test(block), "block carries the decision text");
|
|
82
|
-
assert.ok(/\[decision\]/.test(block), "block carries the [decision] category label");
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
done(dir);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
test("R2 — bloat bound: N review iterations cannot grow past MEMORY_MAX_ROWS", async () => {
|
|
89
|
-
const dir = freshDir();
|
|
90
|
-
const CAP_ENV = process.env.MEGACOMPACT_MEMORY_MAX_ROWS;
|
|
91
|
-
process.env.MEGACOMPACT_MEMORY_MAX_ROWS = "20";
|
|
92
|
-
try {
|
|
93
|
-
// 50 review iterations, each a fresh grounded decision.
|
|
94
|
-
for (let i = 0; i < 50; i++) {
|
|
95
|
-
const ground = `we decided to use approach-${i} for the workflow phase-${i}`;
|
|
96
|
-
const ops = reviewConversation([{ role: "user", text: ground }, { role: "assistant", text: "ok" }], []);
|
|
97
|
-
await applyMemoryOps(ops, dir);
|
|
98
|
-
}
|
|
99
|
-
const rows = listMemories(null, 1000, dir);
|
|
100
|
-
const MAX = Number(process.env.MEGACOMPACT_MEMORY_MAX_ROWS);
|
|
101
|
-
assert.ok(rows.length <= MAX, `rows (${rows.length}) stays within MEMORY_MAX_ROWS (${MAX})`);
|
|
102
|
-
for (const row of rows) {
|
|
103
|
-
assert.ok(row.content.length <= 4000 + 4, "contents stay bounded (MEMORY_MAX_CHARS + ellipsis)");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
if (CAP_ENV === undefined)
|
|
108
|
-
delete process.env.MEGACOMPACT_MEMORY_MAX_ROWS;
|
|
109
|
-
else
|
|
110
|
-
process.env.MEGACOMPACT_MEMORY_MAX_ROWS = CAP_ENV;
|
|
111
|
-
done(dir);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
test("R3 — hallucination guard: fabricated op content is dropped at apply time", async () => {
|
|
115
|
-
const dir = freshDir();
|
|
116
|
-
try {
|
|
117
|
-
// reviewConversation is the first line of defense: only decisions from
|
|
118
|
-
// real user text produce ops. Crafted ops would have to survive
|
|
119
|
-
// applyMemoryOps' own grounding check (memory.ts:70-74) — probe directly.
|
|
120
|
-
const msgs = [
|
|
121
|
-
{ role: "user", text: "the pipeline uses dagster for orchestration" },
|
|
122
|
-
];
|
|
123
|
-
// A fabricated op whose content does NOT appear verbatim in the message
|
|
124
|
-
// must not be replayable after re-review of the SAME messages — i.e. the
|
|
125
|
-
// guard chain does not invent facts.
|
|
126
|
-
const ops = reviewConversation(msgs, []);
|
|
127
|
-
assert.equal(ops.length, 0, "no decision no op");
|
|
128
|
-
await applyMemoryOps(ops, dir);
|
|
129
|
-
assert.equal(listMemories(null, 50, dir).length, 0, "op write stays idempotent-empty");
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
done(dir);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
test("cleanup memrt", () => {
|
|
136
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
137
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* turns.test.ts — S50C per-turn + per-conversation metrics tests. No network.
|
|
3
|
-
* Seeds a turns.db (S49 contract store) and a main db (raw_transcript +
|
|
4
|
-
* checkpoint_epochs) and asserts the rollups match seeded truth.
|
|
5
|
-
*/
|
|
6
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
7
|
-
import assert from "node:assert/strict";
|
|
8
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
9
|
-
import { tmpdir } from "node:os";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { DatabaseSync } from "node:sqlite";
|
|
12
|
-
import { createTurnStore, closeAllTurnDbs, } from "../store/turns/index.js";
|
|
13
|
-
import { openStore } from "../store/sqlite/utils.js";
|
|
14
|
-
import { appendRawTranscript } from "../store/sqlite/raw-transcript.js";
|
|
15
|
-
import { writeCheckpointEpoch } from "../store/sqlite/raw-transcript.js";
|
|
16
|
-
import { turnMetrics, conversationMetrics } from "./turns.js";
|
|
17
|
-
let tmpDir;
|
|
18
|
-
let counter = 0;
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-metrics-"));
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
closeAllTurnDbs();
|
|
24
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
25
|
-
});
|
|
26
|
-
function stateDir() {
|
|
27
|
-
return join(tmpDir, `run-${counter++}`);
|
|
28
|
-
}
|
|
29
|
-
/** Seed one conversation: 2 turns, recall on turn 0, raw messages, one epoch. */
|
|
30
|
-
function seed(dir) {
|
|
31
|
-
const store = createTurnStore({ stateDir: dir });
|
|
32
|
-
const conv = store.ensureConversationId("sess_m");
|
|
33
|
-
const t0 = store.appendTurn({
|
|
34
|
-
conversationId: conv,
|
|
35
|
-
sessionId: "sess_m",
|
|
36
|
-
turnIndex: 0,
|
|
37
|
-
role: "assistant",
|
|
38
|
-
endedAt: Date.now(),
|
|
39
|
-
ctxTokens: 800,
|
|
40
|
-
ctxPercent: 0.4,
|
|
41
|
-
});
|
|
42
|
-
store.appendRecall({
|
|
43
|
-
turnId: t0,
|
|
44
|
-
checkpointId: "cp_1",
|
|
45
|
-
score: 0.9,
|
|
46
|
-
source: "checkpoint",
|
|
47
|
-
});
|
|
48
|
-
store.appendRecall({
|
|
49
|
-
turnId: t0,
|
|
50
|
-
checkpointId: "cp_2",
|
|
51
|
-
score: 0.8,
|
|
52
|
-
source: "checkpoint",
|
|
53
|
-
});
|
|
54
|
-
store.appendTurn({
|
|
55
|
-
conversationId: conv,
|
|
56
|
-
sessionId: "sess_m",
|
|
57
|
-
turnIndex: 1,
|
|
58
|
-
role: "assistant",
|
|
59
|
-
endedAt: Date.now(),
|
|
60
|
-
ctxTokens: 1200,
|
|
61
|
-
});
|
|
62
|
-
store.asAdmin().stampTurnsEpoch("sess_m", "ep_1");
|
|
63
|
-
const main = openStore(dir);
|
|
64
|
-
// 5 raw messages in the committed range; ep_1's summary is much smaller
|
|
65
|
-
// (compression ratio < 1). turn_index is set on all of them.
|
|
66
|
-
const msgs = [
|
|
67
|
-
{ hash: "h0", turn: 0, bytes: "aaaaaaaa" },
|
|
68
|
-
{ hash: "h1", turn: 0, bytes: "bbbbbbbb" },
|
|
69
|
-
{ hash: "h2", turn: 1, bytes: "cccccccc" },
|
|
70
|
-
{ hash: "h3", turn: 1, bytes: "dddddddd" },
|
|
71
|
-
{ hash: "h4", turn: 1, bytes: "eeeeeeee" },
|
|
72
|
-
];
|
|
73
|
-
for (const m of msgs) {
|
|
74
|
-
appendRawTranscript(main, {
|
|
75
|
-
contentHash: m.hash,
|
|
76
|
-
sessionId: "sess_m",
|
|
77
|
-
seq: 0,
|
|
78
|
-
role: "user",
|
|
79
|
-
contentBytes: m.bytes,
|
|
80
|
-
toolName: null,
|
|
81
|
-
messageTimestamp: null,
|
|
82
|
-
checkpointEpoch: "ep_1",
|
|
83
|
-
turnIndex: m.turn,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
writeCheckpointEpoch(main, {
|
|
87
|
-
epochId: "ep_1",
|
|
88
|
-
sessionId: "sess_m",
|
|
89
|
-
startedSeq: 0,
|
|
90
|
-
committedSeq: 3,
|
|
91
|
-
summaryMessageText: "sum",
|
|
92
|
-
cutIndex: 3,
|
|
93
|
-
checkpointId: "cp_x",
|
|
94
|
-
createdAt: Date.now(),
|
|
95
|
-
});
|
|
96
|
-
return { store, conv };
|
|
97
|
-
}
|
|
98
|
-
test("turnMetrics returns per-turn recall + dedup + compression", () => {
|
|
99
|
-
const dir = stateDir();
|
|
100
|
-
const { store, conv } = seed(dir);
|
|
101
|
-
const main = openStore(dir);
|
|
102
|
-
const rows = turnMetrics(store, main, conv);
|
|
103
|
-
assert.equal(rows.length, 2);
|
|
104
|
-
const t0 = rows.find((r) => r.turnIndex === 0);
|
|
105
|
-
assert.equal(t0.recallCount, 2);
|
|
106
|
-
assert.equal(t0.rawMessageCount, 2);
|
|
107
|
-
assert.equal(t0.dedupUniqueRatio, 1); // PK(content_hash,session_id) → all stored rows unique
|
|
108
|
-
const t1 = rows.find((r) => r.turnIndex === 1);
|
|
109
|
-
assert.equal(t1.rawMessageCount, 3);
|
|
110
|
-
assert.equal(t1.epochId, "ep_1");
|
|
111
|
-
assert.ok(t0.compressionRatio > 0 && t0.compressionRatio < 1); // summary smaller than raw
|
|
112
|
-
store.close();
|
|
113
|
-
});
|
|
114
|
-
test("conversationMetrics aggregates per-turn metrics", () => {
|
|
115
|
-
const dir = stateDir();
|
|
116
|
-
const { store, conv } = seed(dir);
|
|
117
|
-
const main = openStore(dir);
|
|
118
|
-
const m = conversationMetrics(store, main, conv);
|
|
119
|
-
assert.equal(m.turnCount, 2);
|
|
120
|
-
assert.equal(m.totalRecall, 2);
|
|
121
|
-
assert.equal(m.totalRawMessages, 5);
|
|
122
|
-
assert.equal(m.epochCount, 1);
|
|
123
|
-
assert.ok(m.avgDedupUniqueRatio > 0);
|
|
124
|
-
store.close();
|
|
125
|
-
});
|
|
126
|
-
test("metrics tolerate a main db without raw_transcript (reuse host)", () => {
|
|
127
|
-
const dir = stateDir();
|
|
128
|
-
const store = createTurnStore({ stateDir: dir });
|
|
129
|
-
const conv = store.ensureConversationId("sess_n");
|
|
130
|
-
const t = store.appendTurn({
|
|
131
|
-
conversationId: conv,
|
|
132
|
-
sessionId: "sess_n",
|
|
133
|
-
turnIndex: 0,
|
|
134
|
-
role: "assistant",
|
|
135
|
-
endedAt: Date.now(),
|
|
136
|
-
});
|
|
137
|
-
store.appendRecall({
|
|
138
|
-
turnId: t,
|
|
139
|
-
checkpointId: "cp",
|
|
140
|
-
score: 0.5,
|
|
141
|
-
source: "checkpoint",
|
|
142
|
-
});
|
|
143
|
-
// Bare in-memory db with NO raw_transcript / checkpoint_epochs tables.
|
|
144
|
-
const bare = new DatabaseSync(":memory:");
|
|
145
|
-
const rows = turnMetrics(store, bare, conv);
|
|
146
|
-
assert.equal(rows.length, 1);
|
|
147
|
-
assert.equal(rows[0].recallCount, 1);
|
|
148
|
-
assert.equal(rows[0].rawMessageCount, 0);
|
|
149
|
-
assert.equal(rows[0].dedupUniqueRatio, 0);
|
|
150
|
-
assert.equal(rows[0].compressionRatio, 0);
|
|
151
|
-
store.close();
|
|
152
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mirror.test.ts — S27 DB-mirror integration tests.
|
|
3
|
-
*
|
|
4
|
-
* Pi-agnostic: no pi runtime imports (src/ invariant).
|
|
5
|
-
*
|
|
6
|
-
* NOTE: raw_transcript has PRIMARY KEY (content_hash, session_id), so
|
|
7
|
-
* duplicate content in the same session is silently dropped by INSERT OR IGNORE.
|
|
8
|
-
* Tests are designed around this constraint.
|
|
9
|
-
*/
|
|
10
|
-
import { describe, it } from "node:test";
|
|
11
|
-
import assert from "node:assert/strict";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
15
|
-
import { openStore, closeStore } from "../../src/store/sqlite.js";
|
|
16
|
-
import { writeCheckpointEpoch, listCheckpointEpochs, appendRawTranscript, listRawTranscriptRange, upsertDedupMirror, getDedupRatio, getDedupMirrorStats, countRawTranscript, } from "../../src/store/sqlite.js";
|
|
17
|
-
import { epochIdFor } from "../../src/mirror/epoch.js";
|
|
18
|
-
import { dedupTranscript } from "../../src/mirror/dedup.js";
|
|
19
|
-
import { computeContentDigest } from "../../src/dedup/digest.js";
|
|
20
|
-
function tmp() {
|
|
21
|
-
return mkdtempSync(join(tmpdir(), "mirror-test-"));
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Build a valid RawTranscriptRow using the canonical content hash from
|
|
25
|
-
* computeContentDigest (matches what dedupTranscript uses).
|
|
26
|
-
*/
|
|
27
|
-
function mkRow(sessionId, seq, // ignored by appendRawTranscript (auto-assigned)
|
|
28
|
-
role, content) {
|
|
29
|
-
const { contentHash } = computeContentDigest(content);
|
|
30
|
-
return {
|
|
31
|
-
contentHash,
|
|
32
|
-
sessionId,
|
|
33
|
-
seq,
|
|
34
|
-
role,
|
|
35
|
-
contentBytes: content,
|
|
36
|
-
toolName: null,
|
|
37
|
-
messageTimestamp: Date.now(),
|
|
38
|
-
checkpointEpoch: "",
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
describe("S27 DB-mirror", () => {
|
|
42
|
-
it("epochIdFor is deterministic", () => {
|
|
43
|
-
assert.equal(epochIdFor("cp-abc-123"), epochIdFor("cp-abc-123"));
|
|
44
|
-
assert.notEqual(epochIdFor("cp-abc-123"), epochIdFor("cp-abc-456"));
|
|
45
|
-
const id = epochIdFor("cp-abc-123");
|
|
46
|
-
assert.ok(id.startsWith("epoch:"));
|
|
47
|
-
assert.ok(id.length > 6);
|
|
48
|
-
});
|
|
49
|
-
it("writeCheckpointEpoch + listCheckpointEpochs round-trips", () => {
|
|
50
|
-
const dir = tmp();
|
|
51
|
-
const db = openStore(dir);
|
|
52
|
-
writeCheckpointEpoch(db, {
|
|
53
|
-
epochId: "epoch-test-001",
|
|
54
|
-
sessionId: "sess-abc",
|
|
55
|
-
startedSeq: 0,
|
|
56
|
-
committedSeq: 100,
|
|
57
|
-
checkpointId: "cp-test-001",
|
|
58
|
-
cutIndex: 100,
|
|
59
|
-
summaryMessageText: "Test summary",
|
|
60
|
-
createdAt: Date.now(),
|
|
61
|
-
});
|
|
62
|
-
const rows = listCheckpointEpochs(db);
|
|
63
|
-
assert.ok(rows.length >= 1);
|
|
64
|
-
assert.equal(rows[0].epochId, "epoch-test-001");
|
|
65
|
-
assert.equal(rows[0].sessionId, "sess-abc");
|
|
66
|
-
assert.equal(rows[0].checkpointId, "cp-test-001");
|
|
67
|
-
closeStore(dir);
|
|
68
|
-
rmSync(dir, { recursive: true, force: true });
|
|
69
|
-
});
|
|
70
|
-
it("appendRawTranscript + listRawTranscriptRange round-trips (unique content)", () => {
|
|
71
|
-
const dir = tmp();
|
|
72
|
-
const db = openStore(dir);
|
|
73
|
-
// Use unique content for each row to avoid PK collision
|
|
74
|
-
appendRawTranscript(db, mkRow("sess-abc", 0, "user", "first message"));
|
|
75
|
-
appendRawTranscript(db, mkRow("sess-abc", 1, "assistant", "second message"));
|
|
76
|
-
appendRawTranscript(db, mkRow("sess-abc", 2, "user", "third message"));
|
|
77
|
-
// seq is auto-assigned: 1, 2, 3
|
|
78
|
-
const rows = listRawTranscriptRange(db, "sess-abc", 0, 10);
|
|
79
|
-
assert.equal(rows.length, 3);
|
|
80
|
-
assert.equal(rows[0].contentBytes, "first message");
|
|
81
|
-
assert.equal(rows[0].seq, 1);
|
|
82
|
-
assert.equal(rows[1].contentBytes, "second message");
|
|
83
|
-
assert.equal(rows[1].seq, 2);
|
|
84
|
-
assert.equal(rows[2].contentBytes, "third message");
|
|
85
|
-
assert.equal(rows[2].seq, 3);
|
|
86
|
-
// Range filter: [2..3]
|
|
87
|
-
const rows2 = listRawTranscriptRange(db, "sess-abc", 2, 3);
|
|
88
|
-
assert.equal(rows2.length, 2);
|
|
89
|
-
assert.equal(rows2[0].contentBytes, "second message");
|
|
90
|
-
assert.equal(rows2[1].contentBytes, "third message");
|
|
91
|
-
closeStore(dir);
|
|
92
|
-
rmSync(dir, { recursive: true, force: true });
|
|
93
|
-
});
|
|
94
|
-
it("upsertDedupMirror increments ref_count for duplicate content", () => {
|
|
95
|
-
const dir = tmp();
|
|
96
|
-
const db = openStore(dir);
|
|
97
|
-
const isNew1 = upsertDedupMirror(db, "hash-aaa", "Hello", 0);
|
|
98
|
-
assert.equal(isNew1, true);
|
|
99
|
-
const isNew2 = upsertDedupMirror(db, "hash-aaa", "Hello", 1);
|
|
100
|
-
assert.equal(isNew2, false);
|
|
101
|
-
const stats = getDedupMirrorStats(db);
|
|
102
|
-
assert.equal(stats.rowCount, 1);
|
|
103
|
-
assert.equal(stats.avgRefCount, 2);
|
|
104
|
-
closeStore(dir);
|
|
105
|
-
rmSync(dir, { recursive: true, force: true });
|
|
106
|
-
});
|
|
107
|
-
it("dedupTranscript deduplicates cross-session content via dedup_mirror", () => {
|
|
108
|
-
const dir = tmp();
|
|
109
|
-
const db = openStore(dir);
|
|
110
|
-
// Insert same content in TWO different sessions (raw_transcript PK allows this)
|
|
111
|
-
appendRawTranscript(db, mkRow("sess-a", 0, "user", "shared hello"));
|
|
112
|
-
appendRawTranscript(db, mkRow("sess-a", 1, "assistant", "shared world"));
|
|
113
|
-
appendRawTranscript(db, mkRow("sess-a", 2, "user", "unique A"));
|
|
114
|
-
appendRawTranscript(db, mkRow("sess-b", 0, "user", "shared hello"));
|
|
115
|
-
appendRawTranscript(db, mkRow("sess-b", 1, "assistant", "shared world"));
|
|
116
|
-
appendRawTranscript(db, mkRow("sess-b", 2, "user", "unique B"));
|
|
117
|
-
// Dedup session A: 3 rows, all new → deduped=0
|
|
118
|
-
const dedupedA = dedupTranscript(db, "sess-a", 0, 10);
|
|
119
|
-
assert.equal(dedupedA, 0);
|
|
120
|
-
// Dedup session B: 3 rows, but 2 already in dedup_mirror → deduped=2
|
|
121
|
-
const dedupedB = dedupTranscript(db, "sess-b", 0, 10);
|
|
122
|
-
assert.equal(dedupedB, 2);
|
|
123
|
-
// dedup_mirror has 4 unique hashes: shared-hello, shared-world, unique-A, unique-B
|
|
124
|
-
const stats = getDedupMirrorStats(db);
|
|
125
|
-
assert.equal(stats.rowCount, 4);
|
|
126
|
-
assert.ok(stats.avgRefCount > 1);
|
|
127
|
-
closeStore(dir);
|
|
128
|
-
rmSync(dir, { recursive: true, force: true });
|
|
129
|
-
});
|
|
130
|
-
it("getDedupRatio reflects dedup savings", () => {
|
|
131
|
-
const dir = tmp();
|
|
132
|
-
const db = openStore(dir);
|
|
133
|
-
// Two sessions with identical content → cross-session dedup
|
|
134
|
-
for (let i = 0; i < 3; i++) {
|
|
135
|
-
appendRawTranscript(db, mkRow("sess-x", i, "user", "same content"));
|
|
136
|
-
appendRawTranscript(db, mkRow("sess-y", i, "user", "same content"));
|
|
137
|
-
}
|
|
138
|
-
// Each session has 1 row (PK dedup within session), so 1 row each
|
|
139
|
-
// sess-x: 1 row, sess-y: 1 row
|
|
140
|
-
dedupTranscript(db, "sess-x", 0, 10);
|
|
141
|
-
dedupTranscript(db, "sess-y", 0, 10);
|
|
142
|
-
// For sess-x: totalBytes = LENGTH("same content") = 12, uniqueBytes = 12 → ratio 1.0
|
|
143
|
-
const { totalBytes, uniqueBytes, ratio } = getDedupRatio(db, "sess-x");
|
|
144
|
-
assert.ok(totalBytes > 0);
|
|
145
|
-
assert.ok(uniqueBytes > 0);
|
|
146
|
-
assert.ok(ratio >= 1.0);
|
|
147
|
-
closeStore(dir);
|
|
148
|
-
rmSync(dir, { recursive: true, force: true });
|
|
149
|
-
});
|
|
150
|
-
it("full pipeline: append + dedup + epoch", () => {
|
|
151
|
-
const dir = tmp();
|
|
152
|
-
const db = openStore(dir);
|
|
153
|
-
// Insert 5 unique rows
|
|
154
|
-
const contents = ["alpha", "bravo", "charlie", "delta", "echo"];
|
|
155
|
-
for (let i = 0; i < contents.length; i++) {
|
|
156
|
-
appendRawTranscript(db, mkRow("sess-pipe", i, i % 2 === 0 ? "user" : "assistant", contents[i]));
|
|
157
|
-
}
|
|
158
|
-
const total = countRawTranscript(db);
|
|
159
|
-
assert.ok(total >= 5);
|
|
160
|
-
// Dedup: all 5 unique → deduped = 0
|
|
161
|
-
const deduped = dedupTranscript(db, "sess-pipe", 0, 100);
|
|
162
|
-
assert.equal(deduped, 0);
|
|
163
|
-
// Mirror should have 5 unique hashes
|
|
164
|
-
const stats = getDedupMirrorStats(db);
|
|
165
|
-
assert.equal(stats.rowCount, 5);
|
|
166
|
-
// Write checkpoint epoch
|
|
167
|
-
writeCheckpointEpoch(db, {
|
|
168
|
-
epochId: "epoch-integration",
|
|
169
|
-
sessionId: "sess-pipe",
|
|
170
|
-
startedSeq: 0,
|
|
171
|
-
committedSeq: 100,
|
|
172
|
-
checkpointId: "cp-integration",
|
|
173
|
-
cutIndex: 5,
|
|
174
|
-
summaryMessageText: "Integration test summary",
|
|
175
|
-
createdAt: Date.now(),
|
|
176
|
-
});
|
|
177
|
-
const epochs = listCheckpointEpochs(db);
|
|
178
|
-
assert.ok(epochs.length >= 1);
|
|
179
|
-
assert.equal(epochs[0].epochId, "epoch-integration");
|
|
180
|
-
const rows = listRawTranscriptRange(db, "sess-pipe", 0, 100);
|
|
181
|
-
assert.equal(rows.length, 5);
|
|
182
|
-
closeStore(dir);
|
|
183
|
-
rmSync(dir, { recursive: true, force: true });
|
|
184
|
-
});
|
|
185
|
-
});
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* raptor-inject-summaries.test.ts — S25 Phase-2 acceptance tests.
|
|
3
|
-
*
|
|
4
|
-
* Verifies the RAPTOR_INJECT_SUMMARIES optional phase (default ON): when
|
|
5
|
-
* enabled, recallAndInline prepends a hierarchical overview header built from
|
|
6
|
-
* the tree's top-level summary nodes (root + top level-1 clusters); when
|
|
7
|
-
* disabled, the recall block is unchanged (detail-only). Also covers the
|
|
8
|
-
* formatRaptorBlock formatter directly.
|
|
9
|
-
*
|
|
10
|
-
* No network. Real stores, temp state dirs.
|
|
11
|
-
*/
|
|
12
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
13
|
-
import assert from "node:assert/strict";
|
|
14
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
15
|
-
import { tmpdir } from "node:os";
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import { VectorStore, vectorList } from "./vectorStore.js";
|
|
18
|
-
import { runRaptor } from "./dedup/raptor/index.js";
|
|
19
|
-
import { compactSession } from "./engine.js";
|
|
20
|
-
import { loadDedupConfig } from "./config/dedup.js";
|
|
21
|
-
import { normalizeSessionId } from "./store.js";
|
|
22
|
-
import { recallAndInline, formatRaptorBlock } from "./recall.js";
|
|
23
|
-
let tmpDir;
|
|
24
|
-
let counter = 0;
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-ris-"));
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
30
|
-
});
|
|
31
|
-
function stateDir() {
|
|
32
|
-
return join(tmpDir, `run-${counter++}`);
|
|
33
|
-
}
|
|
34
|
-
function cfg(overrides) {
|
|
35
|
-
return {
|
|
36
|
-
...loadDedupConfig(),
|
|
37
|
-
RAPTOR_ENABLED: true,
|
|
38
|
-
RAPTOR_MULTILEVEL_ENABLED: true,
|
|
39
|
-
L0_ENABLED: false,
|
|
40
|
-
L1_ENABLED: false,
|
|
41
|
-
L2_ENABLED: true,
|
|
42
|
-
RAPTOR_INJECT_SUMMARIES: true,
|
|
43
|
-
...overrides,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function msg(text, toolName) {
|
|
47
|
-
return toolName
|
|
48
|
-
? { role: "assistant", text, toolName, input: text, output: text }
|
|
49
|
-
: { role: "user", text };
|
|
50
|
-
}
|
|
51
|
-
function seedTwoTopics(store, sid, per) {
|
|
52
|
-
const topics = [
|
|
53
|
-
"database connection pool postgres",
|
|
54
|
-
"user interface button react",
|
|
55
|
-
];
|
|
56
|
-
for (let i = 1; i <= per * 2; i++) {
|
|
57
|
-
compactSession({
|
|
58
|
-
sessionId: sid,
|
|
59
|
-
messages: [
|
|
60
|
-
msg(`${topics[i % 2]} checkpoint ${i} alpha beta`),
|
|
61
|
-
msg(`ack ${i}`, "Edit"),
|
|
62
|
-
],
|
|
63
|
-
keepFrom: 2,
|
|
64
|
-
timestamp: i,
|
|
65
|
-
}, store);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function buildTree(store, sid) {
|
|
69
|
-
const nsid = normalizeSessionId(sid);
|
|
70
|
-
runRaptor(vectorList(store, nsid).map((cp) => ({
|
|
71
|
-
id: cp.checkpointId,
|
|
72
|
-
messages: [],
|
|
73
|
-
sourceText: cp.normalizedText ?? cp.summary ?? cp.regionHash,
|
|
74
|
-
embedding: cp.embedding,
|
|
75
|
-
})), { stateDir: store.stateDir, sessionId: nsid });
|
|
76
|
-
}
|
|
77
|
-
// ─── 1. Flag ON (default) → overview header prepended ───────────────────────
|
|
78
|
-
test("S25-P2: RAPTOR_INJECT_SUMMARIES=true prepends a hierarchical overview header", () => {
|
|
79
|
-
const sd = stateDir();
|
|
80
|
-
const s = new VectorStore({ dedupSim: 0.9, stateDir: sd, config: cfg() });
|
|
81
|
-
const sid = "on";
|
|
82
|
-
seedTwoTopics(s, sid, 8);
|
|
83
|
-
buildTree(s, sid);
|
|
84
|
-
process.env.RAPTOR_SHADOW_MODE = "false";
|
|
85
|
-
const r = recallAndInline({ sessionId: sid, query: "database pool", source: "resume", limit: 3 }, s);
|
|
86
|
-
assert.ok(r.block.length > 0, "recall block is non-empty");
|
|
87
|
-
assert.ok(r.block.includes("hierarchical overview"), "overview header present when flag ON");
|
|
88
|
-
assert.ok(r.block.includes("Recalled context"), "detailed recall block still present after overview");
|
|
89
|
-
assert.ok(r.block.indexOf("hierarchical overview") <
|
|
90
|
-
r.block.indexOf("Recalled context"), "overview precedes detail");
|
|
91
|
-
});
|
|
92
|
-
// ─── 2. Flag OFF → no overview (detail-only, unchanged behavior) ────────────
|
|
93
|
-
test("S25-P2: RAPTOR_INJECT_SUMMARIES=false → no overview (detail-only)", () => {
|
|
94
|
-
const sd = stateDir();
|
|
95
|
-
const s = new VectorStore({
|
|
96
|
-
dedupSim: 0.9,
|
|
97
|
-
stateDir: sd,
|
|
98
|
-
config: cfg({ RAPTOR_INJECT_SUMMARIES: false }),
|
|
99
|
-
});
|
|
100
|
-
const sid = "off";
|
|
101
|
-
seedTwoTopics(s, sid, 8);
|
|
102
|
-
buildTree(s, sid);
|
|
103
|
-
process.env.RAPTOR_SHADOW_MODE = "false";
|
|
104
|
-
const r = recallAndInline({ sessionId: sid, query: "database pool", source: "resume", limit: 3 }, s);
|
|
105
|
-
if (r.block.length > 0) {
|
|
106
|
-
assert.ok(!r.block.includes("hierarchical overview"), "no overview header when flag OFF");
|
|
107
|
-
assert.ok(r.block.includes("Recalled context") || r.block.length > 0, "detail block present");
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
// ─── 3. No tree → no overview (graceful, detail-only) ────────────────────────
|
|
111
|
-
test("S25-P2: no RAPTOR tree → no overview (graceful degradation)", () => {
|
|
112
|
-
const sd = stateDir();
|
|
113
|
-
const s = new VectorStore({ dedupSim: 0.9, stateDir: sd, config: cfg() });
|
|
114
|
-
const sid = "notree";
|
|
115
|
-
seedTwoTopics(s, sid, 4); // checkpoints exist but no tree built
|
|
116
|
-
process.env.RAPTOR_SHADOW_MODE = "false";
|
|
117
|
-
const r = recallAndInline({ sessionId: sid, query: "database pool", source: "resume", limit: 3 }, s);
|
|
118
|
-
assert.ok(!r.block.includes("hierarchical overview"), "no overview when no tree exists");
|
|
119
|
-
});
|
|
120
|
-
// ─── 4. formatRaptorBlock formatter contract ────────────────────────────────
|
|
121
|
-
test("S25-P2: formatRaptorBlock labels root as 'Session overview' + clusters as 'Cluster summary'", () => {
|
|
122
|
-
const block = formatRaptorBlock([
|
|
123
|
-
{ summary: "root overview text", level: 0, score: 0.9 },
|
|
124
|
-
{ summary: "cluster A text", level: 1, score: 0.7 },
|
|
125
|
-
]);
|
|
126
|
-
assert.ok(/The following hierarchical overview/.test(block), "preamble present");
|
|
127
|
-
assert.ok(/Session overview \[1\] \(relevance 90%\)/.test(block), "root labeled");
|
|
128
|
-
assert.ok(/Cluster summary \[2\] \(level 1\) \(relevance 70%\)/.test(block), "cluster labeled");
|
|
129
|
-
assert.ok(block.includes("root overview text"), "root body present");
|
|
130
|
-
assert.ok(block.includes("cluster A text"), "cluster body present");
|
|
131
|
-
assert.equal(formatRaptorBlock([]), "", "empty input → empty string");
|
|
132
|
-
});
|
|
133
|
-
// ─── 5. overview is skipped when shadows mode is on (tree not served) ──────
|
|
134
|
-
//
|
|
135
|
-
// Actually the overview reads rehydrateRaptorTree directly (not raptorSearchHits),
|
|
136
|
-
// so shadow mode does NOT suppress it via the serve gate. Verify the behavior:
|
|
137
|
-
// the overview IS emitted in shadow mode (the tree exists and is rehydrated).
|
|
138
|
-
// This is acceptable — the overview is a session map, not a live-serve decision.
|
|
139
|
-
// QA finding #1 (v0.8.25): the overview previously bypassed the shadow gate —
|
|
140
|
-
// the tree was injected into recall while RAPTOR_SERVE was logging-only. The
|
|
141
|
-
// gate now applies to the inject path too: shadow mode = no overview.
|
|
142
|
-
test("S25-P2: overview is suppressed in shadow mode (QA fix)", () => {
|
|
143
|
-
const sd = stateDir();
|
|
144
|
-
const s = new VectorStore({ dedupSim: 0.9, stateDir: sd, config: cfg() });
|
|
145
|
-
const sid = "shadow";
|
|
146
|
-
seedTwoTopics(s, sid, 8);
|
|
147
|
-
buildTree(s, sid);
|
|
148
|
-
const orig = process.env.RAPTOR_SHADOW_MODE;
|
|
149
|
-
process.env.RAPTOR_SHADOW_MODE = "true";
|
|
150
|
-
try {
|
|
151
|
-
const r = recallAndInline({ sessionId: sid, query: "database pool", source: "resume", limit: 3 }, s);
|
|
152
|
-
// Shadow mode = build + persist + log only; nothing RAPTOR-derived is
|
|
153
|
-
// injected into recall, including the overview header.
|
|
154
|
-
assert.ok(!r.block.includes("hierarchical overview"), "overview suppressed in shadow mode");
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
if (orig === undefined)
|
|
158
|
-
delete process.env.RAPTOR_SHADOW_MODE;
|
|
159
|
-
else
|
|
160
|
-
process.env.RAPTOR_SHADOW_MODE = orig;
|
|
161
|
-
}
|
|
162
|
-
});
|