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,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* migrate + recall integration test — Sprint 8 acceptance proofs.
|
|
3
|
-
*
|
|
4
|
-
* 1. Migration is lossless: a v0.1.0 `<sess>.checkpoints.json.gz` roundtrips
|
|
5
|
-
* into SQLite with checkpoint count + regionHash set identical, and the JSON
|
|
6
|
-
* file is retained as a DR snapshot.
|
|
7
|
-
* 2. Cross-process recall: compact in one VectorStore, then recall via a FRESH
|
|
8
|
-
* VectorStore over the SAME stateDir (re-opens the same sqlite.db file) — the
|
|
9
|
-
* checkpoint must reappear. Mirrors Sprint 6.1's durability requirement.
|
|
10
|
-
*
|
|
11
|
-
* Uses MEGACOMPACT_STATE_DIR overrides; never the real user state dir.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { test } from "node:test";
|
|
15
|
-
import assert from "node:assert/strict";
|
|
16
|
-
import { mkdtempSync, rmSync, existsSync } from "node:fs";
|
|
17
|
-
import { tmpdir } from "node:os";
|
|
18
|
-
import { join } from "node:path";
|
|
19
|
-
import { VectorStore, vectorMarkInjected, vectorWasInjected, vectorSearch } from "../vectorStore.js";
|
|
20
|
-
import { writeGzJson } from "../store.js";
|
|
21
|
-
import type { StoredCheckpoint } from "../store.js";
|
|
22
|
-
import { migrateJsonToSqlite, readLegacyCheckpointFile } from "../store/migrate.js";
|
|
23
|
-
import { listCheckpoints, closeStore } from "../store/sqlite.js";
|
|
24
|
-
|
|
25
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-migrate-"));
|
|
26
|
-
let counter = 0;
|
|
27
|
-
function stateDir() {
|
|
28
|
-
return join(baseTmp, `run-${counter++}`);
|
|
29
|
-
}
|
|
30
|
-
function msgVec(): number[] {
|
|
31
|
-
// Deterministic 8-dim vector.
|
|
32
|
-
return [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8];
|
|
33
|
-
}
|
|
34
|
-
function fakeCheckpoints(sessionId: string): StoredCheckpoint[] {
|
|
35
|
-
return [
|
|
36
|
-
{
|
|
37
|
-
checkpointId: "chkpt_001",
|
|
38
|
-
sessionId,
|
|
39
|
-
summary: "Investigated the vector store and added a cosine helper.",
|
|
40
|
-
topicSummary: "Added cosine similarity helper to vector store.",
|
|
41
|
-
summaryHash: "a1b2c3d4e5f6a7b8",
|
|
42
|
-
keyDecisions: ["use linear scan"],
|
|
43
|
-
nextSteps: ["add tests"],
|
|
44
|
-
filesModified: ["src/vectorStore.ts"],
|
|
45
|
-
tokenEstimate: 1200,
|
|
46
|
-
regionHash: "r1",
|
|
47
|
-
embedding: msgVec(),
|
|
48
|
-
timestamp: 1,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
checkpointId: "chkpt_002",
|
|
52
|
-
sessionId,
|
|
53
|
-
summary: "Refactored the recall path to dedupe against the window.",
|
|
54
|
-
topicSummary: "Recall dedup against injected set.",
|
|
55
|
-
summaryHash: "b2c3d4e5f6a7b8c9",
|
|
56
|
-
keyDecisions: [],
|
|
57
|
-
nextSteps: [],
|
|
58
|
-
filesModified: ["src/recall.ts"],
|
|
59
|
-
tokenEstimate: 900,
|
|
60
|
-
regionHash: "r2",
|
|
61
|
-
embedding: msgVec().map((v) => v + 0.01),
|
|
62
|
-
timestamp: 2,
|
|
63
|
-
},
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
test("migration: v0.1.0 JSON checkpoints migrate losslessly into SQLite", () => {
|
|
68
|
-
const dir = stateDir();
|
|
69
|
-
const sid = "sess_migrate_lossless";
|
|
70
|
-
// Write a legacy JSON checkpoint file (the format v0.1.0 shipped).
|
|
71
|
-
writeGzJson(join(dir, `${sid}.checkpoints.json.gz`), fakeCheckpoints(sid));
|
|
72
|
-
|
|
73
|
-
const result = migrateJsonToSqlite(dir);
|
|
74
|
-
assert.equal(result.sessionsScanned, 1);
|
|
75
|
-
assert.equal(result.checkpointsMigrated, 2);
|
|
76
|
-
assert.equal(result.alreadyPresent, 0);
|
|
77
|
-
|
|
78
|
-
// SQLite now has both checkpoints, regionHash preserved.
|
|
79
|
-
const migrated = listCheckpoints(sid, dir);
|
|
80
|
-
assert.equal(migrated.length, 2, "both checkpoints present");
|
|
81
|
-
assert.ok(migrated.every((c) => c.regionHash && c.regionHash.length > 0), "regionHash preserved");
|
|
82
|
-
assert.deepEqual(migrated.map((c) => c.checkpointId).sort(), ["chkpt_001", "chkpt_002"]);
|
|
83
|
-
|
|
84
|
-
// content_hash columns populated (needed by Sprint 9).
|
|
85
|
-
const legacy = readLegacyCheckpointFile(sid, dir);
|
|
86
|
-
assert.equal(legacy.length, 2, "legacy file intact (DR snapshot retained)");
|
|
87
|
-
assert.ok(existsSync(join(dir, `${sid}.checkpoints.json.gz`)), "JSON DR snapshot retained");
|
|
88
|
-
|
|
89
|
-
closeStore(dir);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("migration: re-running is idempotent (no duplicates)", () => {
|
|
93
|
-
const dir = stateDir();
|
|
94
|
-
const sid = "sess_migrate_idem";
|
|
95
|
-
writeGzJson(join(dir, `${sid}.checkpoints.json.gz`), fakeCheckpoints(sid));
|
|
96
|
-
migrateJsonToSqlite(dir);
|
|
97
|
-
const r2 = migrateJsonToSqlite(dir);
|
|
98
|
-
assert.equal(r2.checkpointsMigrated, 0, "nothing new migrated");
|
|
99
|
-
assert.equal(r2.alreadyPresent, 2, "both counted as already present");
|
|
100
|
-
assert.equal(listCheckpoints(sid, dir).length, 2);
|
|
101
|
-
closeStore(dir);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test("cross-process recall: fresh VectorStore over same dir recalls prior checkpoint", () => {
|
|
105
|
-
const dir = stateDir();
|
|
106
|
-
const sid = "sess_xproc";
|
|
107
|
-
|
|
108
|
-
// Process A: compact a checkpoint into the store.
|
|
109
|
-
const a = new VectorStore({ stateDir: dir });
|
|
110
|
-
const added = a.add({
|
|
111
|
-
sessionId: sid,
|
|
112
|
-
summary: "Cross-process recall proof: persisted in process A.",
|
|
113
|
-
topicSummary: "Persisted checkpoint in process A.",
|
|
114
|
-
regionText: "cross process recall proof session A write path",
|
|
115
|
-
tokenEstimate: 500,
|
|
116
|
-
timestamp: 1,
|
|
117
|
-
});
|
|
118
|
-
assert.equal(added.deduped, false);
|
|
119
|
-
assert.equal(added.checkpoint.checkpointId, "chkpt_001");
|
|
120
|
-
|
|
121
|
-
// Force a clean reopen (simulates a new process opening the same file).
|
|
122
|
-
closeStore(dir);
|
|
123
|
-
|
|
124
|
-
// Process B: brand-new VectorStore, same stateDir.
|
|
125
|
-
const b = new VectorStore({ stateDir: dir });
|
|
126
|
-
const hits = vectorSearch(b, sid, "cross process recall proof", 5);
|
|
127
|
-
assert.equal(hits.length, 1, "checkpoint survives cross-process reopen");
|
|
128
|
-
assert.equal(hits[0].checkpoint.checkpointId, "chkpt_001");
|
|
129
|
-
assert.ok(hits[0].score > 0.5, "recall is relevant");
|
|
130
|
-
|
|
131
|
-
closeStore(dir);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("cross-process recall: injected state persists across reopen", () => {
|
|
135
|
-
const dir = stateDir();
|
|
136
|
-
const sid = "sess_xproc_inj";
|
|
137
|
-
const a = new VectorStore({ stateDir: dir });
|
|
138
|
-
const added = a.add({
|
|
139
|
-
sessionId: sid,
|
|
140
|
-
summary: "A checkpoint to inject and remember across processes.",
|
|
141
|
-
topicSummary: "Injected checkpoint.",
|
|
142
|
-
regionText: "injected state persists across process reopen test",
|
|
143
|
-
timestamp: 1,
|
|
144
|
-
});
|
|
145
|
-
vectorMarkInjected(a, sid, added.checkpoint.checkpointId);
|
|
146
|
-
assert.equal(vectorWasInjected(a, sid, added.checkpoint.checkpointId), true);
|
|
147
|
-
|
|
148
|
-
closeStore(dir);
|
|
149
|
-
|
|
150
|
-
const b = new VectorStore({ stateDir: dir });
|
|
151
|
-
assert.equal(vectorWasInjected(b, sid, added.checkpoint.checkpointId), true, "injection remembered");
|
|
152
|
-
|
|
153
|
-
closeStore(dir);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test("cleanup", () => {
|
|
157
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
158
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pgOpenGuard.test.ts — the PGlite open must never hang a turn.
|
|
3
|
-
*
|
|
4
|
-
* Regression cover for the wedge: a stalled `await new PGlite(...)` was cached
|
|
5
|
-
* in initPromise, so every later caller awaited a promise that could not settle
|
|
6
|
-
* and the pi turn awaiting it never ended.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { test } from "node:test";
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
import { withOpenTimeout, pgOpenTimeoutMs, DEFAULT_PG_OPEN_TIMEOUT_MS } from "./pgOpenGuard.js";
|
|
12
|
-
|
|
13
|
-
test("a never-settling open resolves to undefined instead of hanging", async () => {
|
|
14
|
-
const never = new Promise<string>(() => {
|
|
15
|
-
/* deliberately never settles — the wedge */
|
|
16
|
-
});
|
|
17
|
-
const reasons: string[] = [];
|
|
18
|
-
const t0 = Date.now();
|
|
19
|
-
|
|
20
|
-
const result = await withOpenTimeout(never, (r) => reasons.push(r), 50);
|
|
21
|
-
|
|
22
|
-
assert.equal(result, undefined, "caller gets undefined and can fall back");
|
|
23
|
-
assert.ok(Date.now() - t0 < 5_000, "returned promptly rather than hanging");
|
|
24
|
-
assert.equal(reasons.length, 1, "onTimeout fired exactly once");
|
|
25
|
-
assert.match(reasons[0], /timed out after 50ms/);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("a successful open passes its value through untouched", async () => {
|
|
29
|
-
const reasons: string[] = [];
|
|
30
|
-
const result = await withOpenTimeout(Promise.resolve("pg"), (r) => reasons.push(r), 5_000);
|
|
31
|
-
assert.equal(result, "pg");
|
|
32
|
-
assert.deepEqual(reasons, [], "no timeout reported on the happy path");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("a rejected open propagates so the corrupt-dir retry still runs", async () => {
|
|
36
|
-
const reasons: string[] = [];
|
|
37
|
-
await assert.rejects(
|
|
38
|
-
() => withOpenTimeout(Promise.reject(new Error("Aborted()")), (r) => reasons.push(r), 5_000),
|
|
39
|
-
/Aborted/,
|
|
40
|
-
"rejection reaches the caller's catch, which owns the wipe-and-retry path",
|
|
41
|
-
);
|
|
42
|
-
assert.deepEqual(reasons, [], "a rejection is not reported as a timeout");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("an abandoned open is closed if it settles after the timeout", async () => {
|
|
46
|
-
let closed = false;
|
|
47
|
-
let release: (v: { close: () => void }) => void = () => {};
|
|
48
|
-
const late = new Promise<{ close: () => void }>((r) => {
|
|
49
|
-
release = r;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const result = await withOpenTimeout(late, () => {}, 25);
|
|
53
|
-
assert.equal(result, undefined, "timed out first");
|
|
54
|
-
|
|
55
|
-
// The open finally completes, long after we stopped waiting for it.
|
|
56
|
-
release({
|
|
57
|
-
close: () => {
|
|
58
|
-
closed = true;
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
await late;
|
|
62
|
-
await new Promise((r) => setImmediate(r));
|
|
63
|
-
|
|
64
|
-
assert.ok(closed, "the orphaned instance was closed, not left holding the dataDir");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("timeout of 0 disables the guard (unbounded, original behavior)", async () => {
|
|
68
|
-
const result = await withOpenTimeout(Promise.resolve("pg"), () => {}, 0);
|
|
69
|
-
assert.equal(result, "pg");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("pgOpenTimeoutMs honors the env override and rejects junk", async () => {
|
|
73
|
-
const prev = process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS;
|
|
74
|
-
try {
|
|
75
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = "1234";
|
|
76
|
-
assert.equal(pgOpenTimeoutMs(), 1234);
|
|
77
|
-
|
|
78
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = "0";
|
|
79
|
-
assert.equal(pgOpenTimeoutMs(), 0, "0 is a valid opt-out, not junk");
|
|
80
|
-
|
|
81
|
-
for (const junk of ["", " ", "abc", "-5"]) {
|
|
82
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = junk;
|
|
83
|
-
assert.equal(pgOpenTimeoutMs(), DEFAULT_PG_OPEN_TIMEOUT_MS, `junk "${junk}" falls back`);
|
|
84
|
-
}
|
|
85
|
-
} finally {
|
|
86
|
-
if (prev === undefined) delete process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS;
|
|
87
|
-
else process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = prev;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
@@ -1,88 +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 { VectorStore } from "../vectorStore.js";
|
|
7
|
-
import { dataInvariantStats } from "./sqlite.js";
|
|
8
|
-
|
|
9
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-p01-"));
|
|
10
|
-
|
|
11
|
-
let counter = 0;
|
|
12
|
-
function store(opts: { dedupSim?: number } = {}) {
|
|
13
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
14
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// --- Phase 0: data-safety invariant ---------------------------------------
|
|
18
|
-
|
|
19
|
-
test("Phase 0: every added region retains a compressed-original and deletes nothing", () => {
|
|
20
|
-
const { s, dir } = store();
|
|
21
|
-
s.add({ sessionId: "sess_a", summary: "s1", regionText: "the quick brown fox jumps", tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
22
|
-
s.add({ sessionId: "sess_a", summary: "s2", regionText: "a totally different region of work", tokenEstimate: 6, originalTokenEstimate: 60, timestamp: 2 });
|
|
23
|
-
const di = dataInvariantStats(dir);
|
|
24
|
-
assert.equal(di.regionsRetained, 2, "both regions retained");
|
|
25
|
-
assert.ok(di.compressedOriginalBytes > 0, "compressed-original bytes retained");
|
|
26
|
-
assert.equal(di.bytesPermanentlyDeleted, 0, "INVARIANT: nothing permanently deleted");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("Phase 0: dedup collapses a duplicate but original is still retained (not deleted)", () => {
|
|
30
|
-
const { s, dir } = store();
|
|
31
|
-
const text = "identical region content that will dedup on the second add";
|
|
32
|
-
s.add({ sessionId: "sess_b", summary: "s", regionText: text, tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
33
|
-
const r2 = s.add({ sessionId: "sess_b", summary: "s", regionText: text, tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 2 });
|
|
34
|
-
assert.equal(r2.deduped, true, "second add deduped");
|
|
35
|
-
const di = dataInvariantStats(dir);
|
|
36
|
-
assert.equal(di.bytesPermanentlyDeleted, 0, "INVARIANT: dedup never deletes data");
|
|
37
|
-
assert.ok(di.regionsRetained >= 1, "survivor region still retained");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// --- Phase 1: per-tier progress callback ----------------------------------
|
|
41
|
-
|
|
42
|
-
test("Phase 1: onTier fires L0→L1→L2→stored for a genuinely new region", () => {
|
|
43
|
-
const { s } = store();
|
|
44
|
-
// Seed one checkpoint so L2 has something to scan against.
|
|
45
|
-
s.add({ sessionId: "sess_c", summary: "seed", regionText: "seed region alpha", timestamp: 1 });
|
|
46
|
-
const events: Array<{ tier: string; status: string }> = [];
|
|
47
|
-
s.add({
|
|
48
|
-
sessionId: "sess_c",
|
|
49
|
-
summary: "new",
|
|
50
|
-
regionText: "a brand new region beta that is not a duplicate",
|
|
51
|
-
timestamp: 2,
|
|
52
|
-
onTier: (ev) => events.push({ tier: ev.tier, status: ev.status }),
|
|
53
|
-
});
|
|
54
|
-
const tiers = events.map((e) => e.tier);
|
|
55
|
-
assert.ok(tiers.includes("L0"), "L0 fired");
|
|
56
|
-
assert.ok(tiers.includes("L1"), "L1 fired");
|
|
57
|
-
assert.ok(tiers.includes("L2"), "L2 fired");
|
|
58
|
-
assert.equal(events.at(-1)?.tier, "new", "final event is the 'new' tier");
|
|
59
|
-
assert.equal(events.at(-1)?.status, "stored", "final status is stored");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("Phase 1: onTier reports a deduped outcome and short-circuits at the matching tier", () => {
|
|
63
|
-
const { s } = store();
|
|
64
|
-
const text = "region that will exact-dedup on the second pass";
|
|
65
|
-
s.add({ sessionId: "sess_d", summary: "s", regionText: text, timestamp: 1 });
|
|
66
|
-
const events: Array<{ tier: string; status: string; detail?: string }> = [];
|
|
67
|
-
const r = s.add({
|
|
68
|
-
sessionId: "sess_d",
|
|
69
|
-
summary: "s",
|
|
70
|
-
regionText: text,
|
|
71
|
-
timestamp: 2,
|
|
72
|
-
onTier: (ev) => events.push(ev),
|
|
73
|
-
});
|
|
74
|
-
assert.equal(r.deduped, true);
|
|
75
|
-
const deduped = events.find((e) => e.status === "deduped");
|
|
76
|
-
assert.ok(deduped, "a deduped event fired");
|
|
77
|
-
assert.equal(deduped?.tier, "L0", "exact duplicate short-circuits at L0");
|
|
78
|
-
// Must NOT reach the final stored event.
|
|
79
|
-
assert.ok(!events.some((e) => e.status === "stored"), "no stored event on dedup");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("Phase 1: onTier is optional (back-compat) — add() works without it", () => {
|
|
83
|
-
const { s } = store();
|
|
84
|
-
const r = s.add({ sessionId: "sess_e", summary: "s", regionText: "no callback here", timestamp: 1 });
|
|
85
|
-
assert.equal(r.deduped, false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
process.on("exit", () => { try { rmSync(baseTmp, { recursive: true, force: true }); } catch { /* ignore */ } });
|
|
@@ -1,58 +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 { VectorStore } from "../vectorStore.js";
|
|
7
|
-
import { listCheckpoints, dataInvariantStats } from "./sqlite.js";
|
|
8
|
-
import { decompressSmart, compressSmart } from "./compression.js";
|
|
9
|
-
|
|
10
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-p04-"));
|
|
11
|
-
|
|
12
|
-
let counter = 0;
|
|
13
|
-
function store(opts: { dedupSim?: number } = {}) {
|
|
14
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
15
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test("Phase 4: added checkpoint is listed and its compressed-original round-trips", () => {
|
|
19
|
-
const { s, dir } = store();
|
|
20
|
-
const original = "the original region text that gets compacted and must be restorable verbatim";
|
|
21
|
-
const r = s.add({ sessionId: "sess_a", summary: "s", regionText: original, tokenEstimate: 5, originalTokenEstimate: 60, timestamp: 1 });
|
|
22
|
-
const all = listCheckpoints("sess_a", dir);
|
|
23
|
-
assert.equal(all.length, 1, "one checkpoint listed");
|
|
24
|
-
const cp = all[0];
|
|
25
|
-
assert.ok(cp.compressedOriginal, "compressed-original blob present");
|
|
26
|
-
// The DR/restore path: decompressSmart must return the exact original.
|
|
27
|
-
const restored = decompressSmart(cp.compressedOriginal!).toString("utf-8");
|
|
28
|
-
assert.equal(restored, original, "restored verbatim === original");
|
|
29
|
-
assert.equal(cp.checkpointId, r.checkpoint.checkpointId);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("Phase 4: findCheckpoint-by-id resolves a listed checkpoint", () => {
|
|
33
|
-
const { s, dir } = store();
|
|
34
|
-
s.add({ sessionId: "sess_b", summary: "s1", regionText: "region one text content here", tokenEstimate: 4, originalTokenEstimate: 40, timestamp: 1 });
|
|
35
|
-
const r2 = s.add({ sessionId: "sess_b", summary: "s2", regionText: "region two text content here different", tokenEstimate: 4, originalTokenEstimate: 45, timestamp: 2 });
|
|
36
|
-
const all = listCheckpoints("sess_b", dir);
|
|
37
|
-
assert.equal(all.length, 2);
|
|
38
|
-
const wanted = all.find((c) => c.checkpointId === r2.checkpoint.checkpointId)!;
|
|
39
|
-
assert.ok(wanted, "checkpoint resolved by id");
|
|
40
|
-
assert.ok(wanted.compressedOriginal, "has restorable original");
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("Phase 4: dataInvariantStats sanity for restore trust (0 deleted)", () => {
|
|
44
|
-
const { s, dir } = store();
|
|
45
|
-
s.add({ sessionId: "sess_c", summary: "s", regionText: "retained region body text", tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
46
|
-
const di = dataInvariantStats(dir);
|
|
47
|
-
assert.equal(di.regionsRetained, 1);
|
|
48
|
-
assert.ok(di.compressedOriginalBytes > 0);
|
|
49
|
-
assert.equal(di.bytesPermanentlyDeleted, 0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("Phase 4: compressSmart/decompressSmart round-trips arbitrary text", () => {
|
|
53
|
-
const text = "x".repeat(2000);
|
|
54
|
-
const back = decompressSmart(compressSmart(Buffer.from(text, "utf-8"))).toString("utf-8");
|
|
55
|
-
assert.equal(back, text);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
process.on("exit", () => { try { rmSync(baseTmp, { recursive: true, force: true }); } catch { /* ignore */ } });
|
|
@@ -1,214 +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 { VectorStore, vectorList, vectorRepoStats } from "../vectorStore.js";
|
|
7
|
-
import { normalize } from "../dedup/normalize.js";
|
|
8
|
-
import { openBloom, closeBloom } from "./bloom.js";
|
|
9
|
-
import { backfillContentHashes, isBackfillComplete } from "./backfill.js";
|
|
10
|
-
import { checkSessionIntegrity, checkAllIntegrity } from "./integrity.js";
|
|
11
|
-
import { openStore, closeStore, upsertCheckpoint, saveSessionState, loadSessionState } from "./sqlite.js";
|
|
12
|
-
import type { StoredCheckpoint } from "../store.js";
|
|
13
|
-
|
|
14
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-s10-"));
|
|
15
|
-
|
|
16
|
-
let counter = 0;
|
|
17
|
-
function store(opts: { dedupSim?: number } = {}) {
|
|
18
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
19
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// --- L0 normalization upgrade (case/whitespace/ANSI collapse) --------------
|
|
23
|
-
|
|
24
|
-
test("Sprint 10 L0: case/whitespace/ANSI variants dedup to one row", () => {
|
|
25
|
-
const { s } = store();
|
|
26
|
-
const variants = ["user reviewed the auth module and merged the PR", " USER REVIEWED the AUTH module and MERGED the PR ", "USER REVIEWED THE AUTH MODULE AND MERGED THE PR"];
|
|
27
|
-
let added = 0;
|
|
28
|
-
for (const v of variants) {
|
|
29
|
-
const r = s.add({ sessionId: "sess_norm", summary: "x", regionText: v, timestamp: added + 1 });
|
|
30
|
-
if (!r.deduped) added++;
|
|
31
|
-
}
|
|
32
|
-
assert.equal(vectorList(s, "sess_norm").length, 1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("normalize case-folds so Foo/foo/FOO are equal", () => {
|
|
36
|
-
assert.equal(normalize("Foo Bar"), normalize("foo bar"));
|
|
37
|
-
assert.equal(normalize("FOO BAR"), normalize("foo bar"));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("normalize strips ANSI before hashing", () => {
|
|
41
|
-
assert.equal(normalize("err\x1b[31m fatal\x1b[0m"), normalize("err fatal"));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// --- Bloom accelerator ------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
test("bloom miss short-circuits the scan; hit is confirmed by query", () => {
|
|
47
|
-
const { s, dir } = store();
|
|
48
|
-
const raw = "the region text under test for bloom behavior";
|
|
49
|
-
s.add({ sessionId: "sess_bloom", summary: "x", regionText: raw, timestamp: 1 });
|
|
50
|
-
const bloom = openBloom(dir);
|
|
51
|
-
// content_hash for `raw` is present → hit path must confirm via query and dedup.
|
|
52
|
-
assert.equal(bloom.maybeHas("this-key-is-not-present"), false); // definitive miss
|
|
53
|
-
const r2 = s.add({ sessionId: "sess_bloom", summary: "x", regionText: raw, timestamp: 2 });
|
|
54
|
-
assert.equal(r2.deduped, true);
|
|
55
|
-
assert.equal(r2.reason, "contentHash");
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test("bloom persists to disk and reloads warm", () => {
|
|
59
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
60
|
-
const s1 = new VectorStore({ stateDir: dir });
|
|
61
|
-
s1.add({ sessionId: "sess_persist", summary: "x", regionText: "persisted region", timestamp: 1 });
|
|
62
|
-
closeBloom(dir); // evict cache so the next open reads from disk
|
|
63
|
-
const s2 = new VectorStore({ stateDir: dir });
|
|
64
|
-
const r = s2.add({ sessionId: "sess_persist", summary: "x", regionText: "persisted region", timestamp: 2 });
|
|
65
|
-
assert.equal(r.deduped, true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// --- Atomic write + QA #13 timeout degrade ---------------------------------
|
|
69
|
-
|
|
70
|
-
test("duplicate add is idempotent (no partial rows, single checkpoint)", () => {
|
|
71
|
-
const { s } = store();
|
|
72
|
-
const raw = "idempotent region content for atomicity check";
|
|
73
|
-
const a = s.add({ sessionId: "sess_atom", summary: "x", regionText: raw, timestamp: 1 });
|
|
74
|
-
const b = s.add({ sessionId: "sess_atom", summary: "x", regionText: raw, timestamp: 2 });
|
|
75
|
-
assert.equal(a.deduped, false);
|
|
76
|
-
assert.equal(b.deduped, true);
|
|
77
|
-
assert.equal(vectorList(s, "sess_atom").length, 1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// --- Backfill orchestrator -------------------------------------------------
|
|
81
|
-
|
|
82
|
-
test("backfill populates null content_hash rows and is idempotent", () => {
|
|
83
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
84
|
-
openStore(dir);
|
|
85
|
-
// Seed two rows with null content_hash via direct upsert (simulating legacy data).
|
|
86
|
-
const cp = (id: string, summary: string): StoredCheckpoint => ({
|
|
87
|
-
checkpointId: id,
|
|
88
|
-
sessionId: "sess_bf",
|
|
89
|
-
summary,
|
|
90
|
-
keyDecisions: [],
|
|
91
|
-
nextSteps: [],
|
|
92
|
-
filesModified: [],
|
|
93
|
-
tokenEstimate: 0,
|
|
94
|
-
regionHash: "r",
|
|
95
|
-
embedding: [0, 0, 0],
|
|
96
|
-
timestamp: 1,
|
|
97
|
-
});
|
|
98
|
-
upsertCheckpoint(cp("chkpt_001", "alpha summary"), dir);
|
|
99
|
-
upsertCheckpoint(cp("chkpt_002", "beta summary"), dir);
|
|
100
|
-
|
|
101
|
-
const r1 = backfillContentHashes(dir);
|
|
102
|
-
assert.equal(r1.updated, 2);
|
|
103
|
-
assert.equal(r1.processed, 2);
|
|
104
|
-
assert.equal(isBackfillComplete(dir), true);
|
|
105
|
-
|
|
106
|
-
// Second run is a no-op (idempotent): no rows left to process.
|
|
107
|
-
const r2 = backfillContentHashes(dir);
|
|
108
|
-
assert.equal(r2.processed, 0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test("backfill resolves a content_hash collision keeping the oldest row", () => {
|
|
112
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
113
|
-
openStore(dir);
|
|
114
|
-
// Both rows share the same normalized summary → same content_hash.
|
|
115
|
-
const cp = (id: string): StoredCheckpoint => ({
|
|
116
|
-
checkpointId: id,
|
|
117
|
-
sessionId: "sess_dup",
|
|
118
|
-
summary: "identical normalized summary text",
|
|
119
|
-
keyDecisions: [],
|
|
120
|
-
nextSteps: [],
|
|
121
|
-
filesModified: [],
|
|
122
|
-
tokenEstimate: 0,
|
|
123
|
-
regionHash: "r",
|
|
124
|
-
embedding: [0, 0, 0],
|
|
125
|
-
timestamp: 1,
|
|
126
|
-
});
|
|
127
|
-
upsertCheckpoint(cp("chkpt_001"), dir);
|
|
128
|
-
upsertCheckpoint(cp("chkpt_002"), dir);
|
|
129
|
-
const r = backfillContentHashes(dir);
|
|
130
|
-
assert.equal(r.duplicatesResolved, 1);
|
|
131
|
-
assert.equal(r.updated, 1);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// --- Integrity checks ------------------------------------------------------
|
|
135
|
-
|
|
136
|
-
test("integrity flags a tampered storedRegionHashes set", () => {
|
|
137
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
138
|
-
const s = new VectorStore({ stateDir: dir });
|
|
139
|
-
s.add({ sessionId: "sess_int", summary: "x", regionText: "integrity region one", timestamp: 1 });
|
|
140
|
-
s.add({ sessionId: "sess_int", summary: "y", regionText: "integrity region two", timestamp: 2 });
|
|
141
|
-
const okReport = checkSessionIntegrity("sess_int", dir);
|
|
142
|
-
assert.equal(okReport.ok, true); // consistent after normal adds
|
|
143
|
-
|
|
144
|
-
// Simulate tampering: the sentinel stores a region hash the checkpoints lack.
|
|
145
|
-
const db = openStore(dir);
|
|
146
|
-
db.prepare(
|
|
147
|
-
"UPDATE session_state SET stored_region_hashes = ? WHERE session_id = ?",
|
|
148
|
-
).run(JSON.stringify(["deadbeefcafe0000"]), "sess_int");
|
|
149
|
-
const tampered = checkSessionIntegrity("sess_int", dir);
|
|
150
|
-
assert.equal(tampered.ok, false);
|
|
151
|
-
assert.equal(tampered.regionHashMismatch, true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("integrity detects an orphan injectedCheckpointId", () => {
|
|
155
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
156
|
-
const s = new VectorStore({ stateDir: dir });
|
|
157
|
-
s.add({ sessionId: "sess_orphan", summary: "x", regionText: "orphan region", timestamp: 1 });
|
|
158
|
-
// Manually inject a dangling id into session state (SQLite-backed).
|
|
159
|
-
const st = loadSessionState("sess_orphan", dir);
|
|
160
|
-
st.injectedCheckpointIds.push("chkpt_999");
|
|
161
|
-
saveSessionState("sess_orphan", st, dir);
|
|
162
|
-
const report = checkSessionIntegrity("sess_orphan", dir);
|
|
163
|
-
assert.equal(report.ok, false);
|
|
164
|
-
assert.deepEqual(report.orphanInjectedIds, ["chkpt_999"]);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test("checkAllIntegrity covers every session", () => {
|
|
168
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
169
|
-
const s = new VectorStore({ stateDir: dir });
|
|
170
|
-
s.add({ sessionId: "sess_a", summary: "x", regionText: "a region", timestamp: 1 });
|
|
171
|
-
s.add({ sessionId: "sess_b", summary: "y", regionText: "b region", timestamp: 1 });
|
|
172
|
-
const reports = checkAllIntegrity(dir);
|
|
173
|
-
assert.equal(reports.length, 2);
|
|
174
|
-
assert.ok(reports.every((r: { ok: boolean }) => r.ok));
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// --- schema migration (v0.4.2: original_token_estimate) -------------------
|
|
178
|
-
|
|
179
|
-
test("Sprint 10 migration: pre-0.4.2 db gains original_token_estimate and repoStats works", () => {
|
|
180
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
181
|
-
// Simulate a v0.4.1-era store: openStore() builds the full current schema,
|
|
182
|
-
// then drop the original_token_estimate column that 0.4.2 added. CREATE TABLE
|
|
183
|
-
// IF NOT EXISTS is a no-op on an existing table, which is exactly why the
|
|
184
|
-
// shipped v0.4.2 crashed at runtime on old repos ("no such column").
|
|
185
|
-
const db = openStore(dir);
|
|
186
|
-
db.exec("ALTER TABLE context_chunks DROP COLUMN original_token_estimate;");
|
|
187
|
-
closeStore(dir);
|
|
188
|
-
|
|
189
|
-
// Re-open through the real code path — must ALTER the column in, not crash.
|
|
190
|
-
const vs = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
191
|
-
vs.add({
|
|
192
|
-
sessionId: "sess_mig",
|
|
193
|
-
summary: "legacy region",
|
|
194
|
-
regionText: "some region text to compact",
|
|
195
|
-
tokenEstimate: 100,
|
|
196
|
-
originalTokenEstimate: 500,
|
|
197
|
-
timestamp: 1,
|
|
198
|
-
});
|
|
199
|
-
const repo = vectorRepoStats(vs);
|
|
200
|
-
// No "no such column" crash = migration succeeded; totals reflect the new col.
|
|
201
|
-
assert.equal(repo.checkpointCount, 1);
|
|
202
|
-
assert.equal(repo.originalTokens, 500, "originalTokens read from migrated column");
|
|
203
|
-
// Re-open a second time to prove idempotency (column already exists).
|
|
204
|
-
closeStore(dir);
|
|
205
|
-
const vs2 = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
206
|
-
assert.equal(vectorRepoStats(vs2).originalTokens, 500, "stable across re-open");
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// --- cleanup ---------------------------------------------------------------
|
|
210
|
-
|
|
211
|
-
test("Sprint 10 cleanup", () => {
|
|
212
|
-
closeStore(baseTmp);
|
|
213
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
214
|
-
});
|