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,74 +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
|
-
import { test } from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { withOpenTimeout, pgOpenTimeoutMs, DEFAULT_PG_OPEN_TIMEOUT_MS } from "./pgOpenGuard.js";
|
|
11
|
-
test("a never-settling open resolves to undefined instead of hanging", async () => {
|
|
12
|
-
const never = new Promise(() => {
|
|
13
|
-
/* deliberately never settles — the wedge */
|
|
14
|
-
});
|
|
15
|
-
const reasons = [];
|
|
16
|
-
const t0 = Date.now();
|
|
17
|
-
const result = await withOpenTimeout(never, (r) => reasons.push(r), 50);
|
|
18
|
-
assert.equal(result, undefined, "caller gets undefined and can fall back");
|
|
19
|
-
assert.ok(Date.now() - t0 < 5_000, "returned promptly rather than hanging");
|
|
20
|
-
assert.equal(reasons.length, 1, "onTimeout fired exactly once");
|
|
21
|
-
assert.match(reasons[0], /timed out after 50ms/);
|
|
22
|
-
});
|
|
23
|
-
test("a successful open passes its value through untouched", async () => {
|
|
24
|
-
const reasons = [];
|
|
25
|
-
const result = await withOpenTimeout(Promise.resolve("pg"), (r) => reasons.push(r), 5_000);
|
|
26
|
-
assert.equal(result, "pg");
|
|
27
|
-
assert.deepEqual(reasons, [], "no timeout reported on the happy path");
|
|
28
|
-
});
|
|
29
|
-
test("a rejected open propagates so the corrupt-dir retry still runs", async () => {
|
|
30
|
-
const reasons = [];
|
|
31
|
-
await assert.rejects(() => withOpenTimeout(Promise.reject(new Error("Aborted()")), (r) => reasons.push(r), 5_000), /Aborted/, "rejection reaches the caller's catch, which owns the wipe-and-retry path");
|
|
32
|
-
assert.deepEqual(reasons, [], "a rejection is not reported as a timeout");
|
|
33
|
-
});
|
|
34
|
-
test("an abandoned open is closed if it settles after the timeout", async () => {
|
|
35
|
-
let closed = false;
|
|
36
|
-
let release = () => { };
|
|
37
|
-
const late = new Promise((r) => {
|
|
38
|
-
release = r;
|
|
39
|
-
});
|
|
40
|
-
const result = await withOpenTimeout(late, () => { }, 25);
|
|
41
|
-
assert.equal(result, undefined, "timed out first");
|
|
42
|
-
// The open finally completes, long after we stopped waiting for it.
|
|
43
|
-
release({
|
|
44
|
-
close: () => {
|
|
45
|
-
closed = true;
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
await late;
|
|
49
|
-
await new Promise((r) => setImmediate(r));
|
|
50
|
-
assert.ok(closed, "the orphaned instance was closed, not left holding the dataDir");
|
|
51
|
-
});
|
|
52
|
-
test("timeout of 0 disables the guard (unbounded, original behavior)", async () => {
|
|
53
|
-
const result = await withOpenTimeout(Promise.resolve("pg"), () => { }, 0);
|
|
54
|
-
assert.equal(result, "pg");
|
|
55
|
-
});
|
|
56
|
-
test("pgOpenTimeoutMs honors the env override and rejects junk", async () => {
|
|
57
|
-
const prev = process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS;
|
|
58
|
-
try {
|
|
59
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = "1234";
|
|
60
|
-
assert.equal(pgOpenTimeoutMs(), 1234);
|
|
61
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = "0";
|
|
62
|
-
assert.equal(pgOpenTimeoutMs(), 0, "0 is a valid opt-out, not junk");
|
|
63
|
-
for (const junk of ["", " ", "abc", "-5"]) {
|
|
64
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = junk;
|
|
65
|
-
assert.equal(pgOpenTimeoutMs(), DEFAULT_PG_OPEN_TIMEOUT_MS, `junk "${junk}" falls back`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
if (prev === undefined)
|
|
70
|
-
delete process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS;
|
|
71
|
-
else
|
|
72
|
-
process.env.MEGACOMPACT_PGLITE_OPEN_TIMEOUT_MS = prev;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
@@ -1,81 +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
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-p01-"));
|
|
9
|
-
let counter = 0;
|
|
10
|
-
function store(opts = {}) {
|
|
11
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
12
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
13
|
-
}
|
|
14
|
-
// --- Phase 0: data-safety invariant ---------------------------------------
|
|
15
|
-
test("Phase 0: every added region retains a compressed-original and deletes nothing", () => {
|
|
16
|
-
const { s, dir } = store();
|
|
17
|
-
s.add({ sessionId: "sess_a", summary: "s1", regionText: "the quick brown fox jumps", tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
18
|
-
s.add({ sessionId: "sess_a", summary: "s2", regionText: "a totally different region of work", tokenEstimate: 6, originalTokenEstimate: 60, timestamp: 2 });
|
|
19
|
-
const di = dataInvariantStats(dir);
|
|
20
|
-
assert.equal(di.regionsRetained, 2, "both regions retained");
|
|
21
|
-
assert.ok(di.compressedOriginalBytes > 0, "compressed-original bytes retained");
|
|
22
|
-
assert.equal(di.bytesPermanentlyDeleted, 0, "INVARIANT: nothing permanently deleted");
|
|
23
|
-
});
|
|
24
|
-
test("Phase 0: dedup collapses a duplicate but original is still retained (not deleted)", () => {
|
|
25
|
-
const { s, dir } = store();
|
|
26
|
-
const text = "identical region content that will dedup on the second add";
|
|
27
|
-
s.add({ sessionId: "sess_b", summary: "s", regionText: text, tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
28
|
-
const r2 = s.add({ sessionId: "sess_b", summary: "s", regionText: text, tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 2 });
|
|
29
|
-
assert.equal(r2.deduped, true, "second add deduped");
|
|
30
|
-
const di = dataInvariantStats(dir);
|
|
31
|
-
assert.equal(di.bytesPermanentlyDeleted, 0, "INVARIANT: dedup never deletes data");
|
|
32
|
-
assert.ok(di.regionsRetained >= 1, "survivor region still retained");
|
|
33
|
-
});
|
|
34
|
-
// --- Phase 1: per-tier progress callback ----------------------------------
|
|
35
|
-
test("Phase 1: onTier fires L0→L1→L2→stored for a genuinely new region", () => {
|
|
36
|
-
const { s } = store();
|
|
37
|
-
// Seed one checkpoint so L2 has something to scan against.
|
|
38
|
-
s.add({ sessionId: "sess_c", summary: "seed", regionText: "seed region alpha", timestamp: 1 });
|
|
39
|
-
const events = [];
|
|
40
|
-
s.add({
|
|
41
|
-
sessionId: "sess_c",
|
|
42
|
-
summary: "new",
|
|
43
|
-
regionText: "a brand new region beta that is not a duplicate",
|
|
44
|
-
timestamp: 2,
|
|
45
|
-
onTier: (ev) => events.push({ tier: ev.tier, status: ev.status }),
|
|
46
|
-
});
|
|
47
|
-
const tiers = events.map((e) => e.tier);
|
|
48
|
-
assert.ok(tiers.includes("L0"), "L0 fired");
|
|
49
|
-
assert.ok(tiers.includes("L1"), "L1 fired");
|
|
50
|
-
assert.ok(tiers.includes("L2"), "L2 fired");
|
|
51
|
-
assert.equal(events.at(-1)?.tier, "new", "final event is the 'new' tier");
|
|
52
|
-
assert.equal(events.at(-1)?.status, "stored", "final status is stored");
|
|
53
|
-
});
|
|
54
|
-
test("Phase 1: onTier reports a deduped outcome and short-circuits at the matching tier", () => {
|
|
55
|
-
const { s } = store();
|
|
56
|
-
const text = "region that will exact-dedup on the second pass";
|
|
57
|
-
s.add({ sessionId: "sess_d", summary: "s", regionText: text, timestamp: 1 });
|
|
58
|
-
const events = [];
|
|
59
|
-
const r = s.add({
|
|
60
|
-
sessionId: "sess_d",
|
|
61
|
-
summary: "s",
|
|
62
|
-
regionText: text,
|
|
63
|
-
timestamp: 2,
|
|
64
|
-
onTier: (ev) => events.push(ev),
|
|
65
|
-
});
|
|
66
|
-
assert.equal(r.deduped, true);
|
|
67
|
-
const deduped = events.find((e) => e.status === "deduped");
|
|
68
|
-
assert.ok(deduped, "a deduped event fired");
|
|
69
|
-
assert.equal(deduped?.tier, "L0", "exact duplicate short-circuits at L0");
|
|
70
|
-
// Must NOT reach the final stored event.
|
|
71
|
-
assert.ok(!events.some((e) => e.status === "stored"), "no stored event on dedup");
|
|
72
|
-
});
|
|
73
|
-
test("Phase 1: onTier is optional (back-compat) — add() works without it", () => {
|
|
74
|
-
const { s } = store();
|
|
75
|
-
const r = s.add({ sessionId: "sess_e", summary: "s", regionText: "no callback here", timestamp: 1 });
|
|
76
|
-
assert.equal(r.deduped, false);
|
|
77
|
-
});
|
|
78
|
-
process.on("exit", () => { try {
|
|
79
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
80
|
-
}
|
|
81
|
-
catch { /* ignore */ } });
|
|
@@ -1,54 +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
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-p04-"));
|
|
10
|
-
let counter = 0;
|
|
11
|
-
function store(opts = {}) {
|
|
12
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
13
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
14
|
-
}
|
|
15
|
-
test("Phase 4: added checkpoint is listed and its compressed-original round-trips", () => {
|
|
16
|
-
const { s, dir } = store();
|
|
17
|
-
const original = "the original region text that gets compacted and must be restorable verbatim";
|
|
18
|
-
const r = s.add({ sessionId: "sess_a", summary: "s", regionText: original, tokenEstimate: 5, originalTokenEstimate: 60, timestamp: 1 });
|
|
19
|
-
const all = listCheckpoints("sess_a", dir);
|
|
20
|
-
assert.equal(all.length, 1, "one checkpoint listed");
|
|
21
|
-
const cp = all[0];
|
|
22
|
-
assert.ok(cp.compressedOriginal, "compressed-original blob present");
|
|
23
|
-
// The DR/restore path: decompressSmart must return the exact original.
|
|
24
|
-
const restored = decompressSmart(cp.compressedOriginal).toString("utf-8");
|
|
25
|
-
assert.equal(restored, original, "restored verbatim === original");
|
|
26
|
-
assert.equal(cp.checkpointId, r.checkpoint.checkpointId);
|
|
27
|
-
});
|
|
28
|
-
test("Phase 4: findCheckpoint-by-id resolves a listed checkpoint", () => {
|
|
29
|
-
const { s, dir } = store();
|
|
30
|
-
s.add({ sessionId: "sess_b", summary: "s1", regionText: "region one text content here", tokenEstimate: 4, originalTokenEstimate: 40, timestamp: 1 });
|
|
31
|
-
const r2 = s.add({ sessionId: "sess_b", summary: "s2", regionText: "region two text content here different", tokenEstimate: 4, originalTokenEstimate: 45, timestamp: 2 });
|
|
32
|
-
const all = listCheckpoints("sess_b", dir);
|
|
33
|
-
assert.equal(all.length, 2);
|
|
34
|
-
const wanted = all.find((c) => c.checkpointId === r2.checkpoint.checkpointId);
|
|
35
|
-
assert.ok(wanted, "checkpoint resolved by id");
|
|
36
|
-
assert.ok(wanted.compressedOriginal, "has restorable original");
|
|
37
|
-
});
|
|
38
|
-
test("Phase 4: dataInvariantStats sanity for restore trust (0 deleted)", () => {
|
|
39
|
-
const { s, dir } = store();
|
|
40
|
-
s.add({ sessionId: "sess_c", summary: "s", regionText: "retained region body text", tokenEstimate: 5, originalTokenEstimate: 50, timestamp: 1 });
|
|
41
|
-
const di = dataInvariantStats(dir);
|
|
42
|
-
assert.equal(di.regionsRetained, 1);
|
|
43
|
-
assert.ok(di.compressedOriginalBytes > 0);
|
|
44
|
-
assert.equal(di.bytesPermanentlyDeleted, 0);
|
|
45
|
-
});
|
|
46
|
-
test("Phase 4: compressSmart/decompressSmart round-trips arbitrary text", () => {
|
|
47
|
-
const text = "x".repeat(2000);
|
|
48
|
-
const back = decompressSmart(compressSmart(Buffer.from(text, "utf-8"))).toString("utf-8");
|
|
49
|
-
assert.equal(back, text);
|
|
50
|
-
});
|
|
51
|
-
process.on("exit", () => { try {
|
|
52
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
catch { /* ignore */ } });
|
|
@@ -1,186 +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
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-s10-"));
|
|
13
|
-
let counter = 0;
|
|
14
|
-
function store(opts = {}) {
|
|
15
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
16
|
-
return { s: new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir }), dir };
|
|
17
|
-
}
|
|
18
|
-
// --- L0 normalization upgrade (case/whitespace/ANSI collapse) --------------
|
|
19
|
-
test("Sprint 10 L0: case/whitespace/ANSI variants dedup to one row", () => {
|
|
20
|
-
const { s } = store();
|
|
21
|
-
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"];
|
|
22
|
-
let added = 0;
|
|
23
|
-
for (const v of variants) {
|
|
24
|
-
const r = s.add({ sessionId: "sess_norm", summary: "x", regionText: v, timestamp: added + 1 });
|
|
25
|
-
if (!r.deduped)
|
|
26
|
-
added++;
|
|
27
|
-
}
|
|
28
|
-
assert.equal(vectorList(s, "sess_norm").length, 1);
|
|
29
|
-
});
|
|
30
|
-
test("normalize case-folds so Foo/foo/FOO are equal", () => {
|
|
31
|
-
assert.equal(normalize("Foo Bar"), normalize("foo bar"));
|
|
32
|
-
assert.equal(normalize("FOO BAR"), normalize("foo bar"));
|
|
33
|
-
});
|
|
34
|
-
test("normalize strips ANSI before hashing", () => {
|
|
35
|
-
assert.equal(normalize("err\x1b[31m fatal\x1b[0m"), normalize("err fatal"));
|
|
36
|
-
});
|
|
37
|
-
// --- Bloom accelerator ------------------------------------------------------
|
|
38
|
-
test("bloom miss short-circuits the scan; hit is confirmed by query", () => {
|
|
39
|
-
const { s, dir } = store();
|
|
40
|
-
const raw = "the region text under test for bloom behavior";
|
|
41
|
-
s.add({ sessionId: "sess_bloom", summary: "x", regionText: raw, timestamp: 1 });
|
|
42
|
-
const bloom = openBloom(dir);
|
|
43
|
-
// content_hash for `raw` is present → hit path must confirm via query and dedup.
|
|
44
|
-
assert.equal(bloom.maybeHas("this-key-is-not-present"), false); // definitive miss
|
|
45
|
-
const r2 = s.add({ sessionId: "sess_bloom", summary: "x", regionText: raw, timestamp: 2 });
|
|
46
|
-
assert.equal(r2.deduped, true);
|
|
47
|
-
assert.equal(r2.reason, "contentHash");
|
|
48
|
-
});
|
|
49
|
-
test("bloom persists to disk and reloads warm", () => {
|
|
50
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
51
|
-
const s1 = new VectorStore({ stateDir: dir });
|
|
52
|
-
s1.add({ sessionId: "sess_persist", summary: "x", regionText: "persisted region", timestamp: 1 });
|
|
53
|
-
closeBloom(dir); // evict cache so the next open reads from disk
|
|
54
|
-
const s2 = new VectorStore({ stateDir: dir });
|
|
55
|
-
const r = s2.add({ sessionId: "sess_persist", summary: "x", regionText: "persisted region", timestamp: 2 });
|
|
56
|
-
assert.equal(r.deduped, true);
|
|
57
|
-
});
|
|
58
|
-
// --- Atomic write + QA #13 timeout degrade ---------------------------------
|
|
59
|
-
test("duplicate add is idempotent (no partial rows, single checkpoint)", () => {
|
|
60
|
-
const { s } = store();
|
|
61
|
-
const raw = "idempotent region content for atomicity check";
|
|
62
|
-
const a = s.add({ sessionId: "sess_atom", summary: "x", regionText: raw, timestamp: 1 });
|
|
63
|
-
const b = s.add({ sessionId: "sess_atom", summary: "x", regionText: raw, timestamp: 2 });
|
|
64
|
-
assert.equal(a.deduped, false);
|
|
65
|
-
assert.equal(b.deduped, true);
|
|
66
|
-
assert.equal(vectorList(s, "sess_atom").length, 1);
|
|
67
|
-
});
|
|
68
|
-
// --- Backfill orchestrator -------------------------------------------------
|
|
69
|
-
test("backfill populates null content_hash rows and is idempotent", () => {
|
|
70
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
71
|
-
openStore(dir);
|
|
72
|
-
// Seed two rows with null content_hash via direct upsert (simulating legacy data).
|
|
73
|
-
const cp = (id, summary) => ({
|
|
74
|
-
checkpointId: id,
|
|
75
|
-
sessionId: "sess_bf",
|
|
76
|
-
summary,
|
|
77
|
-
keyDecisions: [],
|
|
78
|
-
nextSteps: [],
|
|
79
|
-
filesModified: [],
|
|
80
|
-
tokenEstimate: 0,
|
|
81
|
-
regionHash: "r",
|
|
82
|
-
embedding: [0, 0, 0],
|
|
83
|
-
timestamp: 1,
|
|
84
|
-
});
|
|
85
|
-
upsertCheckpoint(cp("chkpt_001", "alpha summary"), dir);
|
|
86
|
-
upsertCheckpoint(cp("chkpt_002", "beta summary"), dir);
|
|
87
|
-
const r1 = backfillContentHashes(dir);
|
|
88
|
-
assert.equal(r1.updated, 2);
|
|
89
|
-
assert.equal(r1.processed, 2);
|
|
90
|
-
assert.equal(isBackfillComplete(dir), true);
|
|
91
|
-
// Second run is a no-op (idempotent): no rows left to process.
|
|
92
|
-
const r2 = backfillContentHashes(dir);
|
|
93
|
-
assert.equal(r2.processed, 0);
|
|
94
|
-
});
|
|
95
|
-
test("backfill resolves a content_hash collision keeping the oldest row", () => {
|
|
96
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
97
|
-
openStore(dir);
|
|
98
|
-
// Both rows share the same normalized summary → same content_hash.
|
|
99
|
-
const cp = (id) => ({
|
|
100
|
-
checkpointId: id,
|
|
101
|
-
sessionId: "sess_dup",
|
|
102
|
-
summary: "identical normalized summary text",
|
|
103
|
-
keyDecisions: [],
|
|
104
|
-
nextSteps: [],
|
|
105
|
-
filesModified: [],
|
|
106
|
-
tokenEstimate: 0,
|
|
107
|
-
regionHash: "r",
|
|
108
|
-
embedding: [0, 0, 0],
|
|
109
|
-
timestamp: 1,
|
|
110
|
-
});
|
|
111
|
-
upsertCheckpoint(cp("chkpt_001"), dir);
|
|
112
|
-
upsertCheckpoint(cp("chkpt_002"), dir);
|
|
113
|
-
const r = backfillContentHashes(dir);
|
|
114
|
-
assert.equal(r.duplicatesResolved, 1);
|
|
115
|
-
assert.equal(r.updated, 1);
|
|
116
|
-
});
|
|
117
|
-
// --- Integrity checks ------------------------------------------------------
|
|
118
|
-
test("integrity flags a tampered storedRegionHashes set", () => {
|
|
119
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
120
|
-
const s = new VectorStore({ stateDir: dir });
|
|
121
|
-
s.add({ sessionId: "sess_int", summary: "x", regionText: "integrity region one", timestamp: 1 });
|
|
122
|
-
s.add({ sessionId: "sess_int", summary: "y", regionText: "integrity region two", timestamp: 2 });
|
|
123
|
-
const okReport = checkSessionIntegrity("sess_int", dir);
|
|
124
|
-
assert.equal(okReport.ok, true); // consistent after normal adds
|
|
125
|
-
// Simulate tampering: the sentinel stores a region hash the checkpoints lack.
|
|
126
|
-
const db = openStore(dir);
|
|
127
|
-
db.prepare("UPDATE session_state SET stored_region_hashes = ? WHERE session_id = ?").run(JSON.stringify(["deadbeefcafe0000"]), "sess_int");
|
|
128
|
-
const tampered = checkSessionIntegrity("sess_int", dir);
|
|
129
|
-
assert.equal(tampered.ok, false);
|
|
130
|
-
assert.equal(tampered.regionHashMismatch, true);
|
|
131
|
-
});
|
|
132
|
-
test("integrity detects an orphan injectedCheckpointId", () => {
|
|
133
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
134
|
-
const s = new VectorStore({ stateDir: dir });
|
|
135
|
-
s.add({ sessionId: "sess_orphan", summary: "x", regionText: "orphan region", timestamp: 1 });
|
|
136
|
-
// Manually inject a dangling id into session state (SQLite-backed).
|
|
137
|
-
const st = loadSessionState("sess_orphan", dir);
|
|
138
|
-
st.injectedCheckpointIds.push("chkpt_999");
|
|
139
|
-
saveSessionState("sess_orphan", st, dir);
|
|
140
|
-
const report = checkSessionIntegrity("sess_orphan", dir);
|
|
141
|
-
assert.equal(report.ok, false);
|
|
142
|
-
assert.deepEqual(report.orphanInjectedIds, ["chkpt_999"]);
|
|
143
|
-
});
|
|
144
|
-
test("checkAllIntegrity covers every session", () => {
|
|
145
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
146
|
-
const s = new VectorStore({ stateDir: dir });
|
|
147
|
-
s.add({ sessionId: "sess_a", summary: "x", regionText: "a region", timestamp: 1 });
|
|
148
|
-
s.add({ sessionId: "sess_b", summary: "y", regionText: "b region", timestamp: 1 });
|
|
149
|
-
const reports = checkAllIntegrity(dir);
|
|
150
|
-
assert.equal(reports.length, 2);
|
|
151
|
-
assert.ok(reports.every((r) => r.ok));
|
|
152
|
-
});
|
|
153
|
-
// --- schema migration (v0.4.2: original_token_estimate) -------------------
|
|
154
|
-
test("Sprint 10 migration: pre-0.4.2 db gains original_token_estimate and repoStats works", () => {
|
|
155
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
156
|
-
// Simulate a v0.4.1-era store: openStore() builds the full current schema,
|
|
157
|
-
// then drop the original_token_estimate column that 0.4.2 added. CREATE TABLE
|
|
158
|
-
// IF NOT EXISTS is a no-op on an existing table, which is exactly why the
|
|
159
|
-
// shipped v0.4.2 crashed at runtime on old repos ("no such column").
|
|
160
|
-
const db = openStore(dir);
|
|
161
|
-
db.exec("ALTER TABLE context_chunks DROP COLUMN original_token_estimate;");
|
|
162
|
-
closeStore(dir);
|
|
163
|
-
// Re-open through the real code path — must ALTER the column in, not crash.
|
|
164
|
-
const vs = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
165
|
-
vs.add({
|
|
166
|
-
sessionId: "sess_mig",
|
|
167
|
-
summary: "legacy region",
|
|
168
|
-
regionText: "some region text to compact",
|
|
169
|
-
tokenEstimate: 100,
|
|
170
|
-
originalTokenEstimate: 500,
|
|
171
|
-
timestamp: 1,
|
|
172
|
-
});
|
|
173
|
-
const repo = vectorRepoStats(vs);
|
|
174
|
-
// No "no such column" crash = migration succeeded; totals reflect the new col.
|
|
175
|
-
assert.equal(repo.checkpointCount, 1);
|
|
176
|
-
assert.equal(repo.originalTokens, 500, "originalTokens read from migrated column");
|
|
177
|
-
// Re-open a second time to prove idempotency (column already exists).
|
|
178
|
-
closeStore(dir);
|
|
179
|
-
const vs2 = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
180
|
-
assert.equal(vectorRepoStats(vs2).originalTokens, 500, "stable across re-open");
|
|
181
|
-
});
|
|
182
|
-
// --- cleanup ---------------------------------------------------------------
|
|
183
|
-
test("Sprint 10 cleanup", () => {
|
|
184
|
-
closeStore(baseTmp);
|
|
185
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
186
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* game-achievements.test.ts — S35 game_achievements table + accessors.
|
|
3
|
-
* Pi-agnostic. Uses an isolated state dir (never the real user dir — G7).
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, before, after } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { closeStore } from "./utils.js";
|
|
11
|
-
import { listAchievements, getAchievement, isUnlocked, unlockAchievement, } from "./game-achievements.js";
|
|
12
|
-
describe("game-achievements (S35)", () => {
|
|
13
|
-
let dir;
|
|
14
|
-
before(() => {
|
|
15
|
-
dir = mkdtempSync(join(tmpdir(), "mc-ach-"));
|
|
16
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
17
|
-
});
|
|
18
|
-
after(() => {
|
|
19
|
-
closeStore(dir);
|
|
20
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
21
|
-
rmSync(dir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
it("seeds exactly 9 rows on first open (idempotent)", () => {
|
|
24
|
-
const rows = listAchievements(dir);
|
|
25
|
-
assert.equal(rows.length, 9);
|
|
26
|
-
// re-open: seeding is idempotent, still 9, unlocked_at still null
|
|
27
|
-
const again = listAchievements(dir);
|
|
28
|
-
assert.equal(again.length, 9);
|
|
29
|
-
assert.ok(again.every((r) => r.unlocked_at == null));
|
|
30
|
-
});
|
|
31
|
-
it("ordering: visible rows sorted by id asc; opie hidden+locked present", () => {
|
|
32
|
-
const rows = listAchievements(dir);
|
|
33
|
-
const opie = rows.find((r) => r.id === "opie_wild_ride");
|
|
34
|
-
assert.ok(opie, "opie_wild_ride present");
|
|
35
|
-
assert.equal(opie.hidden, 1);
|
|
36
|
-
assert.equal(opie.unlocked_at, null);
|
|
37
|
-
const visible = rows.filter((r) => !(r.hidden === 1 && r.unlocked_at == null));
|
|
38
|
-
const ids = visible.map((r) => r.id);
|
|
39
|
-
const sorted = [...ids].sort();
|
|
40
|
-
assert.deepEqual(ids, sorted, "visible rows ordered by id asc");
|
|
41
|
-
});
|
|
42
|
-
it("getAchievement returns a row by id, null for unknown", () => {
|
|
43
|
-
const r = getAchievement(dir, "first_compact");
|
|
44
|
-
assert.ok(r);
|
|
45
|
-
assert.equal(r.title, "First Compact");
|
|
46
|
-
assert.equal(getAchievement(dir, "nope"), null);
|
|
47
|
-
});
|
|
48
|
-
it("isUnlocked false before unlock, true after", () => {
|
|
49
|
-
assert.equal(isUnlocked(dir, "first_compact"), false);
|
|
50
|
-
assert.equal(unlockAchievement(dir, "first_compact"), true);
|
|
51
|
-
assert.equal(isUnlocked(dir, "first_compact"), true);
|
|
52
|
-
});
|
|
53
|
-
it("unlock is idempotent (second call false, unlocked_at unchanged)", () => {
|
|
54
|
-
assert.equal(unlockAchievement(dir, "turn_veteran"), true);
|
|
55
|
-
const t0 = getAchievement(dir, "turn_veteran").unlocked_at;
|
|
56
|
-
assert.equal(unlockAchievement(dir, "turn_veteran"), false);
|
|
57
|
-
assert.equal(getAchievement(dir, "turn_veteran").unlocked_at, t0);
|
|
58
|
-
});
|
|
59
|
-
it("unlockAchievement throws on unknown id", () => {
|
|
60
|
-
assert.throws(() => unlockAchievement(dir, "bogus"));
|
|
61
|
-
});
|
|
62
|
-
it("parameterizes id (no SQL injection via crafted id)", () => {
|
|
63
|
-
// The accessors bind id as a param; a hostile id is a literal lookup, never executed.
|
|
64
|
-
assert.equal(getAchievement(dir, "x'); DROP TABLE game_achievements; --"), null);
|
|
65
|
-
assert.throws(() => unlockAchievement(dir, "x'); DROP TABLE game_achievements; --"));
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* game-scores.test.ts — S33 game_scores table round-trip + leaderboard ordering.
|
|
3
|
-
* Pi-agnostic. Uses an isolated state dir (never the real user dir — G7).
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, before, after } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { closeStore } from "./utils.js";
|
|
11
|
-
import { recordScore, leaderboard, METRICS, } from "./game-scores.js";
|
|
12
|
-
describe("game-scores (S33)", () => {
|
|
13
|
-
let dir;
|
|
14
|
-
before(() => {
|
|
15
|
-
dir = mkdtempSync(join(tmpdir(), "mc-gamescores-"));
|
|
16
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
17
|
-
});
|
|
18
|
-
after(() => {
|
|
19
|
-
closeStore(dir);
|
|
20
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
21
|
-
rmSync(dir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
it("records + reads back a cache score with parsed meta", () => {
|
|
24
|
-
recordScore(dir, {
|
|
25
|
-
repo_root: "/repo/a",
|
|
26
|
-
metric: "cache",
|
|
27
|
-
value: 42,
|
|
28
|
-
meta: { hits: 7, lookups: 10 },
|
|
29
|
-
});
|
|
30
|
-
const rows = leaderboard(dir, "cache", { repoRoot: "/repo/a" });
|
|
31
|
-
assert.equal(rows.length, 1);
|
|
32
|
-
assert.equal(rows[0].repo_root, "/repo/a");
|
|
33
|
-
assert.equal(rows[0].value, 42);
|
|
34
|
-
assert.deepEqual(rows[0].meta, { hits: 7, lookups: 10 });
|
|
35
|
-
});
|
|
36
|
-
it("cache leaderboard ranks by latest value per repo, descending", () => {
|
|
37
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "cache", value: 10 });
|
|
38
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "cache", value: 99 }); // latest wins
|
|
39
|
-
recordScore(dir, { repo_root: "/repo/b", metric: "cache", value: 50 });
|
|
40
|
-
recordScore(dir, { repo_root: "/repo/c", metric: "cache", value: 75 });
|
|
41
|
-
const rows = leaderboard(dir, "cache"); // all repos, default limit 10
|
|
42
|
-
assert.equal(rows.length, 3);
|
|
43
|
-
assert.deepEqual(rows.map((r) => [r.repo_root, r.value]), [["/repo/a", 99], ["/repo/c", 75], ["/repo/b", 50]]);
|
|
44
|
-
const a = rows.find((r) => r.repo_root === "/repo/a");
|
|
45
|
-
assert.equal(a.value, 99); // not the older 10
|
|
46
|
-
});
|
|
47
|
-
it("turns leaderboard uses the latest value per repo", () => {
|
|
48
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "turns", value: 3 });
|
|
49
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "turns", value: 8 });
|
|
50
|
-
const rows = leaderboard(dir, "turns", { repoRoot: "/repo/a" });
|
|
51
|
-
assert.equal(rows.length, 1);
|
|
52
|
-
assert.equal(rows[0].value, 8);
|
|
53
|
-
});
|
|
54
|
-
it("dedupe leaderboard sums collapses per repo, descending", () => {
|
|
55
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "dedupe", value: 2 });
|
|
56
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "dedupe", value: 3 });
|
|
57
|
-
recordScore(dir, { repo_root: "/repo/b", metric: "dedupe", value: 10 });
|
|
58
|
-
const rows = leaderboard(dir, "dedupe");
|
|
59
|
-
assert.equal(rows.length, 2);
|
|
60
|
-
assert.deepEqual(rows.map((r) => [r.repo_root, r.value]), [["/repo/b", 10], ["/repo/a", 5]]);
|
|
61
|
-
});
|
|
62
|
-
it("mega_cache leaderboard returns the max trophy per repo", () => {
|
|
63
|
-
recordScore(dir, {
|
|
64
|
-
repo_root: "/repo/a",
|
|
65
|
-
metric: "mega_cache",
|
|
66
|
-
value: 120,
|
|
67
|
-
meta: { peakPct: 120 },
|
|
68
|
-
});
|
|
69
|
-
recordScore(dir, {
|
|
70
|
-
repo_root: "/repo/a",
|
|
71
|
-
metric: "mega_cache",
|
|
72
|
-
value: 150,
|
|
73
|
-
meta: { peakPct: 150 },
|
|
74
|
-
});
|
|
75
|
-
const rows = leaderboard(dir, "mega_cache", { repoRoot: "/repo/a" });
|
|
76
|
-
assert.equal(rows.length, 1);
|
|
77
|
-
assert.equal(rows[0].value, 150);
|
|
78
|
-
assert.deepEqual(rows[0].meta, { peakPct: 150 });
|
|
79
|
-
});
|
|
80
|
-
it("repos leaderboard is the derived COUNT(DISTINCT repo_root)", () => {
|
|
81
|
-
recordScore(dir, { repo_root: "/repo/a", metric: "cache", value: 1 });
|
|
82
|
-
recordScore(dir, { repo_root: "/repo/b", metric: "cache", value: 1 });
|
|
83
|
-
recordScore(dir, { repo_root: "/repo/c", metric: "cache", value: 1 });
|
|
84
|
-
const rows = leaderboard(dir, "repos");
|
|
85
|
-
assert.equal(rows.length, 1);
|
|
86
|
-
assert.equal(rows[0].value, 3);
|
|
87
|
-
});
|
|
88
|
-
it("parameterizes repo_root (no SQL injection via repo path)", () => {
|
|
89
|
-
const evil = "x'); DROP TABLE game_scores; --";
|
|
90
|
-
recordScore(dir, { repo_root: evil, metric: "cache", value: 5 });
|
|
91
|
-
const rows = leaderboard(dir, "cache", { repoRoot: evil });
|
|
92
|
-
assert.equal(rows.length, 1);
|
|
93
|
-
assert.equal(rows[0].repo_root, evil);
|
|
94
|
-
// the table is intact: a normal insert still works
|
|
95
|
-
recordScore(dir, { repo_root: "/repo/z", metric: "cache", value: 1 });
|
|
96
|
-
assert.equal(leaderboard(dir, "cache", { repoRoot: "/repo/z" }).length, 1);
|
|
97
|
-
});
|
|
98
|
-
it("rejects an unknown metric", () => {
|
|
99
|
-
const bad = "bogus";
|
|
100
|
-
assert.throws(() => recordScore(dir, { repo_root: "/r", metric: bad, value: 1 }));
|
|
101
|
-
assert.throws(() => leaderboard(dir, bad));
|
|
102
|
-
});
|
|
103
|
-
it("METRICS allow-list matches the schema CHECK set", () => {
|
|
104
|
-
assert.deepEqual([...METRICS].sort(), ["cache", "dedupe", "mega_cache", "repos", "turns"]);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* game-state.test.ts — S30 game_state table round-trip + validation.
|
|
3
|
-
* Pi-agnostic. Uses an isolated state dir (never the real user dir — G7).
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, before, after } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { closeStore } from "./utils.js";
|
|
11
|
-
import { getGameState, setGameState, DEFAULT_GAME_STATE, } from "./game-state.js";
|
|
12
|
-
describe("game-state (S30)", () => {
|
|
13
|
-
let dir;
|
|
14
|
-
before(() => {
|
|
15
|
-
dir = mkdtempSync(join(tmpdir(), "mc-gamestate-"));
|
|
16
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
17
|
-
});
|
|
18
|
-
after(() => {
|
|
19
|
-
closeStore(dir);
|
|
20
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
21
|
-
rmSync(dir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
it("returns DEFAULT_GAME_STATE on a fresh store", () => {
|
|
24
|
-
const s = getGameState();
|
|
25
|
-
assert.deepEqual(s, { ...DEFAULT_GAME_STATE });
|
|
26
|
-
assert.equal(s.game_mode_on, false);
|
|
27
|
-
assert.equal(s.theme, "transparent");
|
|
28
|
-
assert.equal(s.tui_display_mode, "full");
|
|
29
|
-
});
|
|
30
|
-
it("round-trips game_mode_on", () => {
|
|
31
|
-
setGameState({ game_mode_on: true });
|
|
32
|
-
assert.equal(getGameState().game_mode_on, true);
|
|
33
|
-
setGameState({ game_mode_on: false });
|
|
34
|
-
assert.equal(getGameState().game_mode_on, false);
|
|
35
|
-
});
|
|
36
|
-
it("round-trips a valid theme", () => {
|
|
37
|
-
setGameState({ theme: "retro" });
|
|
38
|
-
assert.equal(getGameState().theme, "retro");
|
|
39
|
-
setGameState({ theme: "cyan-neon" });
|
|
40
|
-
assert.equal(getGameState().theme, "cyan-neon");
|
|
41
|
-
});
|
|
42
|
-
it("rejects an unknown theme (keeps previous)", () => {
|
|
43
|
-
setGameState({ theme: "orange-bold" });
|
|
44
|
-
setGameState({ theme: "does-not-exist" });
|
|
45
|
-
assert.equal(getGameState().theme, "orange-bold");
|
|
46
|
-
});
|
|
47
|
-
it("round-trips tui_display_mode full|minimal", () => {
|
|
48
|
-
setGameState({ tui_display_mode: "minimal" });
|
|
49
|
-
assert.equal(getGameState().tui_display_mode, "minimal");
|
|
50
|
-
setGameState({ tui_display_mode: "full" });
|
|
51
|
-
assert.equal(getGameState().tui_display_mode, "full");
|
|
52
|
-
});
|
|
53
|
-
it("persists across a reopen (survives restart)", () => {
|
|
54
|
-
setGameState({ game_mode_on: true, theme: "amber-mono", tui_display_mode: "minimal" });
|
|
55
|
-
// evict + reopen the store to prove it hit disk
|
|
56
|
-
closeStore(dir);
|
|
57
|
-
const s = getGameState();
|
|
58
|
-
assert.equal(s.game_mode_on, true);
|
|
59
|
-
assert.equal(s.theme, "amber-mono");
|
|
60
|
-
assert.equal(s.tui_display_mode, "minimal");
|
|
61
|
-
});
|
|
62
|
-
it("setGameState is a partial merge (untouched fields preserved)", () => {
|
|
63
|
-
setGameState({ game_mode_on: true, theme: "grayscale", tui_display_mode: "minimal" });
|
|
64
|
-
const s = setGameState({ game_mode_on: false });
|
|
65
|
-
assert.equal(s.game_mode_on, false);
|
|
66
|
-
assert.equal(s.theme, "grayscale");
|
|
67
|
-
assert.equal(s.tui_display_mode, "minimal");
|
|
68
|
-
});
|
|
69
|
-
it("stays a single row (no duplicate id=1)", () => {
|
|
70
|
-
setGameState({ game_mode_on: true });
|
|
71
|
-
setGameState({ game_mode_on: false });
|
|
72
|
-
setGameState({ theme: "retro" });
|
|
73
|
-
const s = getGameState();
|
|
74
|
-
assert.ok(s); // single state, last-write-wins
|
|
75
|
-
});
|
|
76
|
-
});
|