pi-mega-compact 0.11.4 → 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 +2 -0
- package/dist/extensions/mega-events/agent-handlers.js +19 -4
- package/dist/extensions/mega-events/compact-handlers.js +1 -0
- package/dist/extensions/mega-events/context-handler.js +37 -92
- package/dist/extensions/mega-events/context-hwm.js +51 -0
- package/dist/extensions/mega-events/error-classifier.js +16 -5
- package/dist/extensions/mega-events/mirror-append.js +107 -0
- package/dist/extensions/mega-events/outage-advisor.js +7 -1
- package/dist/extensions/mega-events/perf-handler.js +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 +5 -0
- package/dist/extensions/mega-runtime/runtime.js +6 -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 +10 -0
- package/extensions/mega-events/agent-handlers.ts +20 -4
- package/extensions/mega-events/compact-handlers.ts +1 -0
- package/extensions/mega-events/context-handler.ts +45 -110
- package/extensions/mega-events/context-hwm.ts +85 -0
- package/extensions/mega-events/error-classifier.ts +15 -4
- package/extensions/mega-events/mirror-append.ts +155 -0
- package/extensions/mega-events/outage-advisor.ts +11 -5
- package/extensions/mega-events/perf-handler.ts +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 +12 -0
- package/extensions/mega-runtime/reset-runtime.ts +5 -0
- package/extensions/mega-runtime/runtime.ts +6 -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 -1383
- package/dist/extensions/mega-compact.test.js +0 -1112
- package/dist/extensions/mega-events.test.js +0 -47
- package/dist/extensions/mega-game-cmds.test.js +0 -163
- package/dist/extensions/mega-runtime/snapshot.test.js +0 -127
- package/dist/extensions/mega-runtime/state.test.js +0 -266
- package/dist/extensions/mega-runtime/widget.test.js +0 -343
- package/dist/extensions/mega-shutdown-widget.test.js +0 -121
- package/dist/extensions/mega-teamrun.test.js +0 -156
- package/dist/extensions/mega-trim.test.js +0 -58
- package/dist/extensions/mega-turn-store.test.js +0 -68
- package/dist/src/boundary.test.js +0 -170
- package/dist/src/compact.test.js +0 -78
- package/dist/src/config/themes.test.js +0 -94
- package/dist/src/dedup/dedup.test.js +0 -41
- package/dist/src/dedup/l1.test.js +0 -50
- package/dist/src/dedup/raptor/buildHistory.test.js +0 -292
- package/dist/src/dedup/raptor/multilevel-serve.test.js +0 -229
- package/dist/src/dedup/raptor/multilevel.test.js +0 -238
- package/dist/src/dedup/raptor/promote.test.js +0 -69
- package/dist/src/dedup/raptor/raptor.test.js +0 -248
- package/dist/src/dedup/raptor/retrieval.test.js +0 -95
- package/dist/src/dedup/raptor/serve-gate.test.js +0 -298
- package/dist/src/dedup/sprint12.test.js +0 -219
- package/dist/src/dedup-engine.test.js +0 -472
- package/dist/src/driftDetection.test.js +0 -87
- package/dist/src/e2e.test.js +0 -698
- package/dist/src/engine.test.js +0 -111
- package/dist/src/extractive.test.js +0 -147
- package/dist/src/fork.test.js +0 -81
- package/dist/src/game/scoring.test.js +0 -98
- package/dist/src/httpEmbedder.test.js +0 -277
- package/dist/src/importance.test.js +0 -372
- package/dist/src/intent.test.js +0 -78
- package/dist/src/log.test.js +0 -42
- package/dist/src/mechanical-fix.test.js +0 -65
- package/dist/src/memory.test.js +0 -70
- package/dist/src/memoryConsolidate.test.js +0 -38
- package/dist/src/memoryOps.test.js +0 -129
- package/dist/src/memoryRecall.test.js +0 -171
- package/dist/src/memoryRoundtrip.test.js +0 -137
- package/dist/src/metrics/turns.test.js +0 -152
- package/dist/src/mirror/mirror.test.js +0 -185
- package/dist/src/raptor-inject-summaries.test.js +0 -162
- package/dist/src/ratio.bench.test.js +0 -897
- package/dist/src/recall.integration.test.js +0 -77
- package/dist/src/recall.test.js +0 -379
- package/dist/src/sprint14.test.js +0 -219
- package/dist/src/sprint4x-rag-verification.test.js +0 -93
- package/dist/src/store/compression.test.js +0 -139
- package/dist/src/store/memoryIndex.test.js +0 -51
- package/dist/src/store/migrate.test.js +0 -139
- package/dist/src/store/pgOpenGuard.test.js +0 -74
- package/dist/src/store/phase01.test.js +0 -81
- package/dist/src/store/phase04.test.js +0 -54
- package/dist/src/store/sprint10.test.js +0 -186
- package/dist/src/store/sqlite/game-achievements.test.js +0 -67
- package/dist/src/store/sqlite/game-scores.test.js +0 -106
- package/dist/src/store/sqlite/game-state.test.js +0 -76
- package/dist/src/store/sqlite/global-index.test.js +0 -136
- package/dist/src/store/sqlite/mechanical-fix.test.js +0 -146
- package/dist/src/store/sqlite/perf-samples.test.js +0 -146
- package/dist/src/store/sqlite/raptor.test.js +0 -106
- package/dist/src/store/sqlite/turns.test.js +0 -183
- package/dist/src/store/sqlite.cachehit.test.js +0 -55
- package/dist/src/store/sqlite.dbmaint.test.js +0 -158
- package/dist/src/store/sqlite.dbmirror.test.js +0 -184
- package/dist/src/store/turns/contract-compliance.test.js +0 -428
- package/dist/src/store/turns/memory-store.test.js +0 -9
- package/dist/src/store/turns/migrations.test.js +0 -138
- package/dist/src/store/turns/sqlite-store.test.js +0 -144
- package/dist/src/store/vectorIndex.test.js +0 -123
- package/dist/src/store.test.js +0 -161
- package/dist/src/supersede.test.js +0 -36
- package/dist/src/topics/cluster.test.js +0 -150
- package/dist/src/topics/store.test.js +0 -117
- package/dist/src/types.test.js +0 -9
- package/dist/src/vector-search-cache.test.js +0 -157
- package/dist/src/vectorStore.test.js +0 -479
- package/dist/src/wiki.test.js +0 -171
- package/extensions/conflict-scan.test.ts +0 -129
- package/extensions/dashboard-client/dist/assets/AchievementsTab-DjxfYrDc.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/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 -1433
- package/extensions/mega-compact.test.ts +0 -1509
- package/extensions/mega-events.test.ts +0 -55
- package/extensions/mega-game-cmds.test.ts +0 -197
- package/extensions/mega-runtime/snapshot.test.ts +0 -139
- package/extensions/mega-runtime/state.test.ts +0 -262
- package/extensions/mega-runtime/widget.test.ts +0 -468
- package/extensions/mega-shutdown-widget.test.ts +0 -141
- package/extensions/mega-teamrun.test.ts +0 -176
- package/extensions/mega-trim.test.ts +0 -64
- package/extensions/mega-turn-store.test.ts +0 -108
- package/src/boundary.test.ts +0 -187
- package/src/compact.test.ts +0 -99
- package/src/config/themes.test.ts +0 -116
- package/src/dedup/dedup.test.ts +0 -46
- package/src/dedup/l1.test.ts +0 -57
- package/src/dedup/raptor/buildHistory.test.ts +0 -353
- package/src/dedup/raptor/multilevel-serve.test.ts +0 -273
- package/src/dedup/raptor/multilevel.test.ts +0 -325
- package/src/dedup/raptor/promote.test.ts +0 -82
- package/src/dedup/raptor/raptor.test.ts +0 -297
- package/src/dedup/raptor/retrieval.test.ts +0 -118
- package/src/dedup/raptor/serve-gate.test.ts +0 -348
- package/src/dedup/sprint12.test.ts +0 -242
- package/src/dedup-engine.test.ts +0 -670
- package/src/driftDetection.test.ts +0 -100
- package/src/e2e.test.ts +0 -843
- package/src/engine.test.ts +0 -123
- package/src/extractive.test.ts +0 -174
- package/src/fork.test.ts +0 -94
- package/src/game/scoring.test.ts +0 -103
- package/src/httpEmbedder.test.ts +0 -286
- package/src/importance.test.ts +0 -538
- package/src/intent.test.ts +0 -87
- package/src/log.test.ts +0 -47
- package/src/mechanical-fix.test.ts +0 -70
- package/src/memory.test.ts +0 -92
- package/src/memoryConsolidate.test.ts +0 -47
- package/src/memoryOps.test.ts +0 -148
- package/src/memoryRecall.test.ts +0 -194
- package/src/memoryRoundtrip.test.ts +0 -155
- package/src/metrics/turns.test.ts +0 -165
- package/src/mirror/mirror.test.ts +0 -240
- package/src/raptor-inject-summaries.test.ts +0 -228
- package/src/ratio.bench.test.ts +0 -1316
- package/src/recall.integration.test.ts +0 -96
- package/src/recall.test.ts +0 -467
- package/src/sprint14.test.ts +0 -245
- package/src/sprint4x-rag-verification.test.ts +0 -119
- package/src/store/compression.test.ts +0 -168
- package/src/store/memoryIndex.test.ts +0 -61
- package/src/store/migrate.test.ts +0 -158
- package/src/store/pgOpenGuard.test.ts +0 -89
- package/src/store/phase01.test.ts +0 -88
- package/src/store/phase04.test.ts +0 -58
- package/src/store/sprint10.test.ts +0 -214
- package/src/store/sqlite/game-achievements.test.ts +0 -80
- package/src/store/sqlite/game-scores.test.ts +0 -132
- package/src/store/sqlite/game-state.test.ts +0 -89
- package/src/store/sqlite/global-index.test.ts +0 -222
- package/src/store/sqlite/mechanical-fix.test.ts +0 -162
- package/src/store/sqlite/perf-samples.test.ts +0 -169
- package/src/store/sqlite/raptor.test.ts +0 -139
- package/src/store/sqlite/turns.test.ts +0 -218
- package/src/store/sqlite.cachehit.test.ts +0 -68
- package/src/store/sqlite.dbmaint.test.ts +0 -193
- package/src/store/sqlite.dbmirror.test.ts +0 -229
- package/src/store/turns/contract-compliance.test.ts +0 -562
- package/src/store/turns/memory-store.test.ts +0 -15
- package/src/store/turns/migrations.test.ts +0 -161
- package/src/store/turns/sqlite-store.test.ts +0 -161
- package/src/store/vectorIndex.test.ts +0 -140
- package/src/store.test.ts +0 -191
- package/src/supersede.test.ts +0 -42
- package/src/topics/cluster.test.ts +0 -176
- package/src/topics/store.test.ts +0 -132
- package/src/types.test.ts +0 -10
- package/src/vector-search-cache.test.ts +0 -190
- package/src/vectorStore.test.ts +0 -533
- package/src/wiki.test.ts +0 -217
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* perf-samples.test.ts — v0.8.8 perf_samples table round-trip + filtering.
|
|
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 {
|
|
12
|
-
recordPerfSample,
|
|
13
|
-
readPerfSamples,
|
|
14
|
-
PERF_KINDS,
|
|
15
|
-
readProviderCacheLifetime,
|
|
16
|
-
readLatestCacheHitPct,
|
|
17
|
-
} from "./perf-samples.js";
|
|
18
|
-
|
|
19
|
-
describe("perf-samples (v0.8.8)", () => {
|
|
20
|
-
let dir: string;
|
|
21
|
-
before(() => {
|
|
22
|
-
dir = mkdtempSync(join(tmpdir(), "mc-perfsamples-"));
|
|
23
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
24
|
-
});
|
|
25
|
-
after(() => {
|
|
26
|
-
closeStore(dir);
|
|
27
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
28
|
-
rmSync(dir, { recursive: true, force: true });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("records + reads back a turn_latency_ms sample with parsed meta", () => {
|
|
32
|
-
recordPerfSample(dir, "turn_latency_ms", 123.4, { turnIndex: 2 });
|
|
33
|
-
const rows = readPerfSamples(dir, 0);
|
|
34
|
-
assert.equal(rows.length, 1);
|
|
35
|
-
assert.equal(rows[0].kind, "turn_latency_ms");
|
|
36
|
-
assert.equal(rows[0].value, 123.4);
|
|
37
|
-
assert.deepEqual(rows[0].meta, { turnIndex: 2 });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("filters by kind and by sinceTs", () => {
|
|
41
|
-
recordPerfSample(dir, "tps", 50);
|
|
42
|
-
recordPerfSample(dir, "rss_mb", 256);
|
|
43
|
-
const tps = readPerfSamples(dir, 0, "tps");
|
|
44
|
-
assert.equal(tps.length, 1);
|
|
45
|
-
assert.equal(tps[0].kind, "tps");
|
|
46
|
-
assert.equal(tps[0].value, 50);
|
|
47
|
-
const future = readPerfSamples(dir, Date.now() + 10000, "tps");
|
|
48
|
-
assert.equal(future.length, 0);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("ignores non-finite values + unknown kinds (never throws, nothing added)", () => {
|
|
52
|
-
const before = readPerfSamples(dir, 0).length;
|
|
53
|
-
recordPerfSample(dir, "tps", Number.NaN);
|
|
54
|
-
recordPerfSample(dir, "tps", Infinity);
|
|
55
|
-
assert.doesNotThrow(() => recordPerfSample(dir, "bogus" as never, 1));
|
|
56
|
-
const after = readPerfSamples(dir, 0).length;
|
|
57
|
-
assert.equal(after, before);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("PERF_KINDS lists the 10 instrumentation kinds", () => {
|
|
61
|
-
assert.equal(PERF_KINDS.length, 10);
|
|
62
|
-
assert.ok(PERF_KINDS.includes("db_recompute_ms"));
|
|
63
|
-
assert.ok(PERF_KINDS.includes("cache_hit_pct"));
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// ─── Provider cache lifetime aggregate tests (A.4) — each test uses its
|
|
68
|
-
// own clean stateDir so prior inserts never pollute later assertions. ───
|
|
69
|
-
|
|
70
|
-
describe("provider cache lifetime (A.4)", () => {
|
|
71
|
-
let dir2: string;
|
|
72
|
-
|
|
73
|
-
function freshDir(prefix: string) {
|
|
74
|
-
if (dir2) {
|
|
75
|
-
closeStore(dir2);
|
|
76
|
-
rmSync(dir2, { recursive: true, force: true });
|
|
77
|
-
}
|
|
78
|
-
dir2 = mkdtempSync(join(tmpdir(), prefix));
|
|
79
|
-
process.env.MEGACOMPACT_STATE_DIR = dir2;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
after(() => {
|
|
83
|
-
if (dir2) {
|
|
84
|
-
closeStore(dir2);
|
|
85
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
86
|
-
rmSync(dir2, { recursive: true, force: true });
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("empty table returns zeros/nulls", () => {
|
|
91
|
-
freshDir("mc-a4e-");
|
|
92
|
-
const r = readProviderCacheLifetime(dir2);
|
|
93
|
-
assert.equal(r.sampleCount, 0);
|
|
94
|
-
assert.equal(r.avgHitPct, 0);
|
|
95
|
-
assert.equal(r.totalCacheRead, 0);
|
|
96
|
-
assert.equal(r.totalCacheWrite, 0);
|
|
97
|
-
assert.equal(r.totalInput, 0);
|
|
98
|
-
assert.equal(r.firstSampleAt, null);
|
|
99
|
-
assert.equal(r.latestSampleAt, null);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("rows with NULL meta are counted but contribute 0 tokens", () => {
|
|
103
|
-
freshDir("mc-a4n-");
|
|
104
|
-
recordPerfSample(dir2, "cache_hit_pct", 50, null);
|
|
105
|
-
recordPerfSample(dir2, "cache_hit_pct", 60, null);
|
|
106
|
-
const r = readProviderCacheLifetime(dir2);
|
|
107
|
-
assert.equal(r.sampleCount, 2);
|
|
108
|
-
assert.equal(r.totalCacheRead, 0);
|
|
109
|
-
assert.equal(r.totalCacheWrite, 0);
|
|
110
|
-
assert.equal(r.totalInput, 0);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("partial meta — missing keys treated as 0", () => {
|
|
114
|
-
freshDir("mc-a4p-");
|
|
115
|
-
recordPerfSample(dir2, "cache_hit_pct", 42, { input: 1000 });
|
|
116
|
-
const r = readProviderCacheLifetime(dir2);
|
|
117
|
-
assert.equal(r.sampleCount, 1);
|
|
118
|
-
assert.equal(r.totalCacheRead, 0);
|
|
119
|
-
assert.equal(r.totalCacheWrite, 0);
|
|
120
|
-
assert.equal(r.totalInput, 1000);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("full rows produce correct sums + avg", () => {
|
|
124
|
-
freshDir("mc-a4f-");
|
|
125
|
-
// cacheRead=1000, cacheWrite=500, input=100 → hit% = 1000/1600=62.5%
|
|
126
|
-
// cacheRead=500, cacheWrite=100, input=400 → hit% = 500/1000=50.0%
|
|
127
|
-
// cacheRead=100, cacheWrite=200, input=700 → hit% = 100/1000=10.0%
|
|
128
|
-
recordPerfSample(dir2, "cache_hit_pct", 55, {
|
|
129
|
-
cacheRead: 1000,
|
|
130
|
-
cacheWrite: 500,
|
|
131
|
-
input: 100,
|
|
132
|
-
});
|
|
133
|
-
recordPerfSample(dir2, "cache_hit_pct", 56, {
|
|
134
|
-
cacheRead: 500,
|
|
135
|
-
cacheWrite: 100,
|
|
136
|
-
input: 400,
|
|
137
|
-
});
|
|
138
|
-
recordPerfSample(dir2, "cache_hit_pct", 57, {
|
|
139
|
-
cacheRead: 100,
|
|
140
|
-
cacheWrite: 200,
|
|
141
|
-
input: 700,
|
|
142
|
-
});
|
|
143
|
-
const r = readProviderCacheLifetime(dir2);
|
|
144
|
-
assert.equal(r.sampleCount, 3);
|
|
145
|
-
assert.equal(r.totalCacheRead, 1600);
|
|
146
|
-
assert.equal(r.totalCacheWrite, 800);
|
|
147
|
-
assert.equal(r.totalInput, 1200);
|
|
148
|
-
// avg: (62.5 + 50.0 + 10.0) / 3 ≈ 40.833
|
|
149
|
-
assert.ok(Math.abs(r.avgHitPct - 40.833) < 0.1);
|
|
150
|
-
assert.ok(r.firstSampleAt != null);
|
|
151
|
-
assert.ok(r.latestSampleAt != null);
|
|
152
|
-
assert.ok(
|
|
153
|
-
new Date(r.firstSampleAt!).getTime() <=
|
|
154
|
-
new Date(r.latestSampleAt!).getTime(),
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("readLatestCacheHitPct: empty → 0", () => {
|
|
159
|
-
freshDir("mc-a4le-");
|
|
160
|
-
assert.equal(readLatestCacheHitPct(dir2), 0);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("readLatestCacheHitPct: most recent by ts, tie → highest id", () => {
|
|
164
|
-
freshDir("mc-a4lm-");
|
|
165
|
-
recordPerfSample(dir2, "cache_hit_pct", 20);
|
|
166
|
-
recordPerfSample(dir2, "cache_hit_pct", 80);
|
|
167
|
-
assert.equal(readLatestCacheHitPct(dir2), 80);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* raptor.test.ts — regression tests for RAPTOR node persistence.
|
|
3
|
-
*
|
|
4
|
-
* Covers:
|
|
5
|
-
* 1. saveRaptorTree atomicity (withTx + openStore nesting safety): rebuilding
|
|
6
|
-
* a DIFFERENT tree for the same session leaves no stale nodes from the
|
|
7
|
-
* first tree.
|
|
8
|
-
* 2. listRaptorNodes robustness: corrupt `children` JSON in a row does not
|
|
9
|
-
* throw and that row's children come back as [].
|
|
10
|
-
*
|
|
11
|
-
* No network. Uses node:sqlite directly via openStore.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
15
|
-
import assert from "node:assert/strict";
|
|
16
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
17
|
-
import { tmpdir } from "node:os";
|
|
18
|
-
import { join } from "node:path";
|
|
19
|
-
import { openStore, closeStore } from "./utils.js";
|
|
20
|
-
import { saveRaptorTree, listRaptorNodes, type StoredRaptorNode } from "./raptor.js";
|
|
21
|
-
|
|
22
|
-
let tmpDir: string;
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-raptor-persist-"));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
closeStore(tmpDir);
|
|
30
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/** Build a simple tree map with the minimal shape saveRaptorTree expects. */
|
|
34
|
-
function makeTree(nodeSpecs: { id: string; level: number; children: string[] }[]) {
|
|
35
|
-
const nodes = new Map();
|
|
36
|
-
for (const spec of nodeSpecs) {
|
|
37
|
-
nodes.set(spec.id, {
|
|
38
|
-
id: spec.id,
|
|
39
|
-
level: spec.level,
|
|
40
|
-
parentId: spec.level === 0 ? null : "root",
|
|
41
|
-
children: spec.children,
|
|
42
|
-
summary: `summary for ${spec.id}`,
|
|
43
|
-
embedding: [1, 0, 0],
|
|
44
|
-
qualityMarker: "low",
|
|
45
|
-
tokenEstimate: 10,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return { nodes };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ── Test 1: rebuild + save a different tree → no stale nodes ──────────────────
|
|
52
|
-
|
|
53
|
-
test("saveRaptorTree: rebuilding a different tree for the same session leaves no stale nodes", () => {
|
|
54
|
-
const sid = "sess_replace";
|
|
55
|
-
const builtAt1 = 1000;
|
|
56
|
-
const builtAt2 = 2000;
|
|
57
|
-
|
|
58
|
-
// Tree A: nodes alpha, beta, root.
|
|
59
|
-
const treeA = makeTree([
|
|
60
|
-
{ id: "alpha", level: 1, children: ["leaf_0", "leaf_1"] },
|
|
61
|
-
{ id: "beta", level: 1, children: ["leaf_2", "leaf_3"] },
|
|
62
|
-
{ id: "root", level: 2, children: ["leaf_0", "leaf_1", "leaf_2", "leaf_3"] },
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
saveRaptorTree(sid, treeA, builtAt1, tmpDir);
|
|
66
|
-
|
|
67
|
-
const afterA = listRaptorNodes(sid, tmpDir);
|
|
68
|
-
assert.equal(afterA.length, 3, "tree A has 3 nodes");
|
|
69
|
-
assert.deepEqual(
|
|
70
|
-
afterA.map((n) => n.id).sort(),
|
|
71
|
-
["alpha", "beta", "root"],
|
|
72
|
-
"tree A node ids match",
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Tree B: completely different nodes gamma, delta, root.
|
|
76
|
-
const treeB = makeTree([
|
|
77
|
-
{ id: "gamma", level: 1, children: ["leaf_4", "leaf_5"] },
|
|
78
|
-
{ id: "delta", level: 1, children: ["leaf_6", "leaf_7"] },
|
|
79
|
-
{ id: "root", level: 2, children: ["leaf_4", "leaf_5", "leaf_6", "leaf_7"] },
|
|
80
|
-
]);
|
|
81
|
-
|
|
82
|
-
saveRaptorTree(sid, treeB, builtAt2, tmpDir);
|
|
83
|
-
|
|
84
|
-
const afterB = listRaptorNodes(sid, tmpDir);
|
|
85
|
-
assert.equal(afterB.length, 3, "tree B has 3 nodes (stale A nodes gone)");
|
|
86
|
-
|
|
87
|
-
// No stale node ids from tree A survive.
|
|
88
|
-
const idsAfterB = new Set(afterB.map((n) => n.id));
|
|
89
|
-
assert.ok(!idsAfterB.has("alpha"), "stale node alpha is gone");
|
|
90
|
-
assert.ok(!idsAfterB.has("beta"), "stale node beta is gone");
|
|
91
|
-
assert.ok(idsAfterB.has("gamma"), "new node gamma present");
|
|
92
|
-
assert.ok(idsAfterB.has("delta"), "new node delta present");
|
|
93
|
-
assert.ok(idsAfterB.has("root"), "root present (upserted, not duplicated)");
|
|
94
|
-
|
|
95
|
-
// builtAt was updated to the new timestamp.
|
|
96
|
-
for (const n of afterB) {
|
|
97
|
-
assert.equal(n.builtAt, builtAt2, `node ${n.id} builtAt updated to tree B timestamp`);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// ── Test 2: corrupt children JSON → no throw, children = [] ──────────────────
|
|
102
|
-
|
|
103
|
-
test("listRaptorNodes: corrupt children JSON does not throw and returns []", () => {
|
|
104
|
-
const sid = "sess_corrupt";
|
|
105
|
-
const builtAt = 5000;
|
|
106
|
-
|
|
107
|
-
const tree = makeTree([
|
|
108
|
-
{ id: "good", level: 1, children: ["leaf_0", "leaf_1"] },
|
|
109
|
-
{ id: "bad", level: 1, children: ["leaf_2", "leaf_3"] },
|
|
110
|
-
{ id: "root", level: 2, children: ["leaf_0", "leaf_1", "leaf_2", "leaf_3"] },
|
|
111
|
-
]);
|
|
112
|
-
|
|
113
|
-
saveRaptorTree(sid, tree, builtAt, tmpDir);
|
|
114
|
-
|
|
115
|
-
// Corrupt the `children` JSON for the "bad" row directly in SQLite.
|
|
116
|
-
const db = openStore(tmpDir);
|
|
117
|
-
db.prepare(
|
|
118
|
-
"UPDATE raptor_nodes SET children = ? WHERE session_id = ? AND id = ?",
|
|
119
|
-
).run("{not valid json", sid, "bad");
|
|
120
|
-
|
|
121
|
-
// listRaptorNodes must not throw.
|
|
122
|
-
let nodes: StoredRaptorNode[];
|
|
123
|
-
assert.doesNotThrow(() => {
|
|
124
|
-
nodes = listRaptorNodes(sid, tmpDir);
|
|
125
|
-
}, "listRaptorNodes must not throw on corrupt children JSON");
|
|
126
|
-
|
|
127
|
-
const badNode = nodes!.find((n) => n.id === "bad");
|
|
128
|
-
assert.ok(badNode, "bad node still present");
|
|
129
|
-
assert.deepEqual(badNode!.children, [], "corrupt children parsed to []");
|
|
130
|
-
|
|
131
|
-
// The good node is unaffected.
|
|
132
|
-
const goodNode = nodes!.find((n) => n.id === "good");
|
|
133
|
-
assert.ok(goodNode, "good node present");
|
|
134
|
-
assert.deepEqual(
|
|
135
|
-
goodNode!.children,
|
|
136
|
-
["leaf_0", "leaf_1"],
|
|
137
|
-
"good node children intact",
|
|
138
|
-
);
|
|
139
|
-
});
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* turns.test.ts — S43 per-turn + conversation tracking tests.
|
|
3
|
-
*
|
|
4
|
-
* No network. Real stores with temp state dirs.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { openStore } from "./utils.js";
|
|
13
|
-
import {
|
|
14
|
-
recordTurn,
|
|
15
|
-
recordTurnRecall,
|
|
16
|
-
getTurn,
|
|
17
|
-
getTurnById,
|
|
18
|
-
listTurnRecall,
|
|
19
|
-
listConversationTurns,
|
|
20
|
-
ensureConversationId,
|
|
21
|
-
forkConversation,
|
|
22
|
-
newConversationId,
|
|
23
|
-
clearTurns,
|
|
24
|
-
} from "./turns.js";
|
|
25
|
-
import { loadSessionState, saveSessionState } from "./session-state.js";
|
|
26
|
-
|
|
27
|
-
let tmpDir: string;
|
|
28
|
-
let counter = 0;
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-turns-"));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
function stateDir(): string {
|
|
39
|
-
return join(tmpDir, `run-${counter++}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ─── 1. recordTurn upserts + getTurn round-trip ────────────────────────────
|
|
43
|
-
|
|
44
|
-
test("S43-1: recordTurn inserts/updates + getTurn finds by conv+index", () => {
|
|
45
|
-
const sd = stateDir();
|
|
46
|
-
openStore(sd);
|
|
47
|
-
const conv = newConversationId();
|
|
48
|
-
const id = recordTurn({
|
|
49
|
-
conversationId: conv,
|
|
50
|
-
sessionId: "sess-1",
|
|
51
|
-
turnIndex: 3,
|
|
52
|
-
endedAt: 1000,
|
|
53
|
-
ctxTokens: 12000,
|
|
54
|
-
ctxPercent: 42.5,
|
|
55
|
-
pressureBand: "mid",
|
|
56
|
-
modelId: "claude-fable-5",
|
|
57
|
-
}, sd);
|
|
58
|
-
assert.ok(id > 0, "turn id returned");
|
|
59
|
-
const t = getTurn(conv, 3, sd);
|
|
60
|
-
assert.ok(t, "turn found");
|
|
61
|
-
assert.equal(t!.conversationId, conv);
|
|
62
|
-
assert.equal(t!.turnIndex, 3);
|
|
63
|
-
assert.equal(t!.ctxTokens, 12000);
|
|
64
|
-
assert.equal(t!.ctxPercent, 42.5);
|
|
65
|
-
assert.equal(t!.pressureBand, "mid");
|
|
66
|
-
assert.equal(t!.modelId, "claude-fable-5");
|
|
67
|
-
assert.equal(t!.endedAt, 1000);
|
|
68
|
-
// Re-record (upsert) with additional metrics — COALESCE preserves started_at.
|
|
69
|
-
const id2 = recordTurn({
|
|
70
|
-
conversationId: conv,
|
|
71
|
-
sessionId: "sess-1",
|
|
72
|
-
turnIndex: 3,
|
|
73
|
-
startedAt: 900,
|
|
74
|
-
ctxTokens: 12500,
|
|
75
|
-
}, sd);
|
|
76
|
-
assert.equal(id2, id, "same turn id on upsert");
|
|
77
|
-
const t2 = getTurn(conv, 3, sd);
|
|
78
|
-
assert.equal(t2!.ctxTokens, 12500, "metrics updated");
|
|
79
|
-
assert.equal(t2!.startedAt, 900, "started_at set on second write");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// ─── 2. recordTurnRecall + listTurnRecall ───────────────────────────────────
|
|
83
|
-
|
|
84
|
-
test("S43-2: recordTurnRecall stores provenance + listTurnRecall returns it", () => {
|
|
85
|
-
const sd = stateDir();
|
|
86
|
-
openStore(sd);
|
|
87
|
-
const conv = newConversationId();
|
|
88
|
-
const turnId = recordTurn({
|
|
89
|
-
conversationId: conv,
|
|
90
|
-
sessionId: "sess-1",
|
|
91
|
-
turnIndex: 1,
|
|
92
|
-
}, sd);
|
|
93
|
-
recordTurnRecall(turnId, [
|
|
94
|
-
{ checkpointId: "chkpt_003", score: 0.91, source: "flat" },
|
|
95
|
-
{ checkpointId: "r1_0", score: 0.78, source: "raptor", raptorLevel: 1 },
|
|
96
|
-
{ checkpointId: "chkpt_007", score: 0.65, source: "cross-repo" },
|
|
97
|
-
], sd);
|
|
98
|
-
const recalls = listTurnRecall(turnId, sd);
|
|
99
|
-
assert.equal(recalls.length, 3);
|
|
100
|
-
assert.equal(recalls[0].checkpointId, "chkpt_003", "sorted by score desc");
|
|
101
|
-
assert.equal(recalls[0].score, 0.91);
|
|
102
|
-
const raptorHit = recalls.find((r) => r.source === "raptor");
|
|
103
|
-
assert.ok(raptorHit, "raptor hit present");
|
|
104
|
-
assert.equal(raptorHit!.raptorLevel, 1);
|
|
105
|
-
assert.equal(raptorHit!.checkpointId, "r1_0");
|
|
106
|
-
// Re-record with a changed score → upsert, no duplicate.
|
|
107
|
-
recordTurnRecall(turnId, [{ checkpointId: "chkpt_003", score: 0.95, source: "flat" }], sd);
|
|
108
|
-
const recalls2 = listTurnRecall(turnId, sd);
|
|
109
|
-
assert.equal(recalls2.length, 3, "no duplicate on re-record");
|
|
110
|
-
const updated = recalls2.find((r) => r.checkpointId === "chkpt_003");
|
|
111
|
-
assert.equal(updated!.score, 0.95, "score updated");
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// ─── 3. listConversationTurns ───────────────────────────────────────────────
|
|
115
|
-
|
|
116
|
-
test("S43-3: listConversationTurns returns turns in order", () => {
|
|
117
|
-
const sd = stateDir();
|
|
118
|
-
openStore(sd);
|
|
119
|
-
const conv = newConversationId();
|
|
120
|
-
for (let i = 1; i <= 4; i++) {
|
|
121
|
-
recordTurn({
|
|
122
|
-
conversationId: conv,
|
|
123
|
-
sessionId: "sess-1",
|
|
124
|
-
turnIndex: i,
|
|
125
|
-
endedAt: i * 100,
|
|
126
|
-
}, sd);
|
|
127
|
-
}
|
|
128
|
-
const turns = listConversationTurns(conv, sd);
|
|
129
|
-
assert.equal(turns.length, 4);
|
|
130
|
-
assert.deepEqual(turns.map((t) => t.turnIndex), [1, 2, 3, 4]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// ─── 4. ensureConversationId persists + is stable across resumes ───────────
|
|
134
|
-
|
|
135
|
-
test("S43-4: ensureConversationId generates once, persists, survives reload", () => {
|
|
136
|
-
const sd = stateDir();
|
|
137
|
-
openStore(sd);
|
|
138
|
-
const sid = "sess-resume";
|
|
139
|
-
// First call generates + persists.
|
|
140
|
-
const conv1 = ensureConversationId(sid, sd);
|
|
141
|
-
assert.ok(conv1.startsWith("conv_"), "generated id has prefix");
|
|
142
|
-
// Second call (simulated resume) returns the same id — reads session_state.
|
|
143
|
-
const conv2 = ensureConversationId(sid, sd);
|
|
144
|
-
assert.equal(conv2, conv1, "stable across resumes");
|
|
145
|
-
// A different session gets a different conversation id.
|
|
146
|
-
const conv3 = ensureConversationId("sess-other", sd);
|
|
147
|
-
assert.notEqual(conv3, conv1);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// ─── 5. forkConversation records lineage + returns recall set ──────────────
|
|
151
|
-
|
|
152
|
-
test("S43-5: forkConversation creates child + returns parent's recall set", () => {
|
|
153
|
-
const sd = stateDir();
|
|
154
|
-
openStore(sd);
|
|
155
|
-
const parent = newConversationId();
|
|
156
|
-
// Parent conversation: turn 1 with 2 recalled checkpoints.
|
|
157
|
-
const turnId = recordTurn({
|
|
158
|
-
conversationId: parent,
|
|
159
|
-
sessionId: "sess-parent",
|
|
160
|
-
turnIndex: 1,
|
|
161
|
-
}, sd);
|
|
162
|
-
recordTurnRecall(turnId, [
|
|
163
|
-
{ checkpointId: "chkpt_001", score: 0.9, source: "flat" },
|
|
164
|
-
{ checkpointId: "chkpt_002", score: 0.7, source: "flat" },
|
|
165
|
-
], sd);
|
|
166
|
-
// Fork at turn 1.
|
|
167
|
-
const { conversationId: child, recalled } = forkConversation(parent, turnId, sd);
|
|
168
|
-
assert.ok(child.startsWith("conv_"), "child is a conversation id");
|
|
169
|
-
assert.notEqual(child, parent, "child differs from parent");
|
|
170
|
-
assert.equal(recalled.length, 2, "parent's recall set returned for replay");
|
|
171
|
-
assert.ok(
|
|
172
|
-
recalled.some((r) => r.checkpointId === "chkpt_001"),
|
|
173
|
-
"includes parent's recalled checkpoint",
|
|
174
|
-
);
|
|
175
|
-
// The child conversation is recorded as a branch.
|
|
176
|
-
const branches = openStore(sd).prepare(
|
|
177
|
-
"SELECT parent_conversation_id, fork_turn_id FROM conversation_branches WHERE conversation_id = ?",
|
|
178
|
-
).get(child) as { parent_conversation_id: string; fork_turn_id: number };
|
|
179
|
-
assert.equal(branches.parent_conversation_id, parent);
|
|
180
|
-
assert.equal(branches.fork_turn_id, turnId);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// ─── 6. clearTurns removes turns + their recall rows for a session ──────────
|
|
184
|
-
|
|
185
|
-
test("S43-6: clearTurns removes turns + cascade turn_recall", () => {
|
|
186
|
-
const sd = stateDir();
|
|
187
|
-
openStore(sd);
|
|
188
|
-
const conv = newConversationId();
|
|
189
|
-
const turnId = recordTurn({
|
|
190
|
-
conversationId: conv,
|
|
191
|
-
sessionId: "sess-clear",
|
|
192
|
-
turnIndex: 1,
|
|
193
|
-
}, sd);
|
|
194
|
-
recordTurnRecall(turnId, [{ checkpointId: "x", score: 0.5, source: "flat" }], sd);
|
|
195
|
-
assert.equal(listTurnRecall(turnId, sd).length, 1);
|
|
196
|
-
clearTurns("sess-clear", sd);
|
|
197
|
-
assert.equal(getTurnById(turnId, sd), null, "turn gone");
|
|
198
|
-
assert.equal(listTurnRecall(turnId, sd).length, 0, "recall rows cascaded");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// ─── 7. conversation id survives across SessionState save/load ──────────────
|
|
202
|
-
|
|
203
|
-
test("S43-7: conversationId round-trips through SessionState", () => {
|
|
204
|
-
const sd = stateDir();
|
|
205
|
-
openStore(sd);
|
|
206
|
-
const sid = "sess-rt";
|
|
207
|
-
// Save a state with a conversationId.
|
|
208
|
-
const conv = "conv_roundtrip";
|
|
209
|
-
saveSessionState(sid, {
|
|
210
|
-
injectedCheckpointIds: [],
|
|
211
|
-
storedRegionHashes: [],
|
|
212
|
-
conversationId: conv,
|
|
213
|
-
}, sd);
|
|
214
|
-
const loaded = loadSessionState(sid, sd);
|
|
215
|
-
assert.equal(loaded.conversationId, conv, "conversationId persisted");
|
|
216
|
-
// ensureConversationId picks up the existing one.
|
|
217
|
-
assert.equal(ensureConversationId(sid, sd), conv, "ensure keeps existing");
|
|
218
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sqlite.cachehit.test.ts — tests for the live dashboard counters
|
|
3
|
-
* (incCompactCount / getCompactCount, incRecallInjected / getRecallInjected,
|
|
4
|
-
* incCacheHitTokens / getCacheHitTokensSaved). These reuse the schemaless
|
|
5
|
-
* `meta` integer counter, so no migration is required and the same on-disk
|
|
6
|
-
* SQLite store persists the tallies across (re)opens.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import {
|
|
14
|
-
openStore,
|
|
15
|
-
incCompactCount,
|
|
16
|
-
getCompactCount,
|
|
17
|
-
incRecallInjected,
|
|
18
|
-
getRecallInjected,
|
|
19
|
-
incCacheHitTokens,
|
|
20
|
-
getCacheHitTokensSaved,
|
|
21
|
-
} from "./sqlite.js";
|
|
22
|
-
|
|
23
|
-
describe("live dashboard counters (meta integers)", () => {
|
|
24
|
-
let dir: string;
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
dir = mkdtempSync(join(tmpdir(), "cachehit-test-"));
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
rmSync(dir, { recursive: true, force: true });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("increments + reads compact_count and persists on reopen", () => {
|
|
33
|
-
incCompactCount(dir);
|
|
34
|
-
incCompactCount(dir);
|
|
35
|
-
assert.equal(getCompactCount(dir), 2);
|
|
36
|
-
// Ensure the store handle is (re)opened and the value is read back from disk.
|
|
37
|
-
openStore(dir);
|
|
38
|
-
assert.equal(getCompactCount(dir), 2);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("accumulates recall injections + cache-hit tokens", () => {
|
|
42
|
-
incRecallInjected(3, dir);
|
|
43
|
-
incRecallInjected(2, dir);
|
|
44
|
-
assert.equal(getRecallInjected(dir), 5);
|
|
45
|
-
incCacheHitTokens(1200, dir);
|
|
46
|
-
incCacheHitTokens(800, dir);
|
|
47
|
-
assert.equal(getCacheHitTokensSaved(dir), 2000);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("ignores non-positive increments (no-op)", () => {
|
|
51
|
-
incRecallInjected(0, dir);
|
|
52
|
-
incRecallInjected(-5, dir);
|
|
53
|
-
incCacheHitTokens(0, dir);
|
|
54
|
-
assert.equal(getRecallInjected(dir), 0);
|
|
55
|
-
assert.equal(getCacheHitTokensSaved(dir), 0);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("persists all three counters across a fresh openStore handle", () => {
|
|
59
|
-
incCompactCount(dir);
|
|
60
|
-
incRecallInjected(4, dir);
|
|
61
|
-
incCacheHitTokens(500, dir);
|
|
62
|
-
// openStore returns the canonical (on-disk) handle; reading back proves durability.
|
|
63
|
-
openStore(dir);
|
|
64
|
-
assert.equal(getCompactCount(dir), 1);
|
|
65
|
-
assert.equal(getRecallInjected(dir), 4);
|
|
66
|
-
assert.equal(getCacheHitTokensSaved(dir), 500);
|
|
67
|
-
});
|
|
68
|
-
});
|