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,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mega-turn-store.test.ts — S49C adapter routing tests.
|
|
3
|
-
*
|
|
4
|
-
* Proves the adapter writes to the isolated turns.db when turnsDbEnabled is
|
|
5
|
-
* true and to the legacy main-db helpers when false. No network; temp dirs.
|
|
6
|
-
*/
|
|
7
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { mkdtempSync, rmSync, existsSync } from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { DatabaseSync } from "node:sqlite";
|
|
13
|
-
import { ensureConversationIdFor, recordTurnWrite, recordRecallWrite, } from "./mega-turn-store.js";
|
|
14
|
-
import { closeTurnStore, turnDbPath } from "../src/store/turns/index.js";
|
|
15
|
-
let tmpDir;
|
|
16
|
-
let counter = 0;
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-adapter-"));
|
|
19
|
-
});
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
function stateDir() {
|
|
24
|
-
return join(tmpDir, `run-${counter++}`);
|
|
25
|
-
}
|
|
26
|
-
/** Minimal MegaConfig stub — only the flag the adapter reads. */
|
|
27
|
-
function cfg(turnsDbEnabled) {
|
|
28
|
-
return { turnsDbEnabled };
|
|
29
|
-
}
|
|
30
|
-
test("flag ON → writes land in turns.db (not main sqlite.db)", () => {
|
|
31
|
-
const dir = stateDir();
|
|
32
|
-
const c = cfg(true);
|
|
33
|
-
const conv = ensureConversationIdFor(c, "sess_on", dir);
|
|
34
|
-
const turnId = recordTurnWrite(c, {
|
|
35
|
-
conversationId: conv,
|
|
36
|
-
sessionId: "sess_on",
|
|
37
|
-
turnIndex: 0,
|
|
38
|
-
role: "assistant",
|
|
39
|
-
endedAt: Date.now(),
|
|
40
|
-
}, dir);
|
|
41
|
-
recordRecallWrite(c, turnId, [{ checkpointId: "cp_on", score: 0.5, source: "flat" }], dir);
|
|
42
|
-
closeTurnStore(dir);
|
|
43
|
-
assert.ok(existsSync(turnDbPath(dir)), "turns.db should exist");
|
|
44
|
-
assert.ok(!existsSync(join(dir, "sqlite.db")), "main sqlite.db must NOT be created on the flag-ON path");
|
|
45
|
-
});
|
|
46
|
-
test("flag OFF → writes land in main sqlite.db (legacy S48 path)", () => {
|
|
47
|
-
const dir = stateDir();
|
|
48
|
-
const c = cfg(false);
|
|
49
|
-
const conv = ensureConversationIdFor(c, "sess_off", dir);
|
|
50
|
-
const turnId = recordTurnWrite(c, {
|
|
51
|
-
conversationId: conv,
|
|
52
|
-
sessionId: "sess_off",
|
|
53
|
-
turnIndex: 0,
|
|
54
|
-
role: "assistant",
|
|
55
|
-
endedAt: Date.now(),
|
|
56
|
-
}, dir);
|
|
57
|
-
recordRecallWrite(c, turnId, [{ checkpointId: "cp_off", score: 0.5, source: "flat" }], dir);
|
|
58
|
-
// Legacy helpers open the main sqlite.db.
|
|
59
|
-
assert.ok(existsSync(join(dir, "sqlite.db")), "main sqlite.db should exist on the flag-OFF path");
|
|
60
|
-
assert.ok(!existsSync(turnDbPath(dir)), "turns.db must NOT be created on the flag-OFF path");
|
|
61
|
-
// And the row is actually in the main db's turns table.
|
|
62
|
-
const main = new DatabaseSync(join(dir, "sqlite.db"));
|
|
63
|
-
const rows = main
|
|
64
|
-
.prepare("SELECT * FROM turns WHERE session_id = ?")
|
|
65
|
-
.all("sess_off");
|
|
66
|
-
assert.equal(rows.length, 1);
|
|
67
|
-
main.close();
|
|
68
|
-
});
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { computeDropRange, isBoundarySafe, dropBefore } from "./boundary.js";
|
|
4
|
-
function user(t) { return { role: "user", text: t }; }
|
|
5
|
-
function assistant(t) { return { role: "assistant", text: t }; }
|
|
6
|
-
function toolUse(n, i = "{}") { return { role: "assistant", text: "", toolName: n, input: i }; }
|
|
7
|
-
function toolResult(n, o = "ok") { return { role: "tool", text: "", toolName: n, output: o }; }
|
|
8
|
-
function custom(t) { return { role: "custom", text: t }; }
|
|
9
|
-
test("walks back so first preserved message is not an orphaned tool result", () => {
|
|
10
|
-
const messages = [
|
|
11
|
-
user("Search for files"),
|
|
12
|
-
toolUse("search"),
|
|
13
|
-
toolResult("search", "found 5 files"),
|
|
14
|
-
assistant("Done."),
|
|
15
|
-
];
|
|
16
|
-
// keepFrom=2 would start the preserved run on the tool result at index 2,
|
|
17
|
-
// orphaning it. The guard walks back to include the assistant tool-call.
|
|
18
|
-
const [start, end] = computeDropRange(messages, 2, 0);
|
|
19
|
-
assert.equal(start, 0);
|
|
20
|
-
assert.equal(end, 1);
|
|
21
|
-
const kept = messages.slice(end);
|
|
22
|
-
assert.notEqual(kept[0].role, "tool");
|
|
23
|
-
assert.equal(kept[0].toolName, "search"); // assistant tool-call preserved
|
|
24
|
-
});
|
|
25
|
-
test("isBoundarySafe: cut that drops a toolCall but keeps its toolResult is unsafe (PREVENT-PI-002)", () => {
|
|
26
|
-
const messages = [user("a"), toolUse("search"), toolResult("search")];
|
|
27
|
-
// keepFrom=2 drops the toolUse at index 1 but keeps the toolResult at index 2 →
|
|
28
|
-
// the preserved run starts on an orphaned tool result. This is the shape the old
|
|
29
|
-
// check mis-validated (it only compared messages[keepFrom] to messages[keepFrom-1]).
|
|
30
|
-
assert.equal(isBoundarySafe(messages, 2), false);
|
|
31
|
-
// keepFrom=1 keeps the toolCall together with its toolResult → safe.
|
|
32
|
-
assert.equal(isBoundarySafe(messages, 1), true);
|
|
33
|
-
});
|
|
34
|
-
test("isBoundarySafe: orphaned tool result without preceding tool use is unsafe", () => {
|
|
35
|
-
const messages = [user("a"), toolResult("search", "orphan")];
|
|
36
|
-
assert.equal(isBoundarySafe(messages, 1), false);
|
|
37
|
-
});
|
|
38
|
-
test("anchor floor preserves the last N user messages", () => {
|
|
39
|
-
const messages = [
|
|
40
|
-
user("u1"), user("u2"), user("u3"),
|
|
41
|
-
assistant("a1"), assistant("a2"), assistant("a3"), assistant("a4"), assistant("a5"),
|
|
42
|
-
];
|
|
43
|
-
// Caller wants to keep from index 2 (would drop u2). Anchor=2 forces keeping
|
|
44
|
-
// from u2 (index 1) onward.
|
|
45
|
-
const out = dropBefore(messages, 2, 2);
|
|
46
|
-
assert.ok(out.some((m) => m.text === "u2"));
|
|
47
|
-
assert.ok(out.some((m) => m.text === "u3"));
|
|
48
|
-
});
|
|
49
|
-
test("anchor floor is a no-op when fewer users than anchor", () => {
|
|
50
|
-
const messages = [user("u1"), assistant("a1"), assistant("a2"), assistant("a3")];
|
|
51
|
-
const out = dropBefore(messages, 1, 2);
|
|
52
|
-
// only 1 user, anchor=2 → no floor; keep from index 1 (drop the user)
|
|
53
|
-
assert.ok(!out.some((m) => m.text === "u1"));
|
|
54
|
-
assert.equal(out.length, 3);
|
|
55
|
-
});
|
|
56
|
-
test("dropBefore returns original when range is empty", () => {
|
|
57
|
-
const messages = [user("a"), assistant("b")];
|
|
58
|
-
assert.equal(dropBefore(messages, 0, 1), messages);
|
|
59
|
-
});
|
|
60
|
-
// --- PREVENT-PI-002 regression cases for arbitrary interleavings ---
|
|
61
|
-
test("interleaved custom message between toolCall and toolResult: walk-back keeps the call", () => {
|
|
62
|
-
// [user, assistant(tc=read), custom/bashExecution, tool(read-result)] with
|
|
63
|
-
// desired keepFrom=3. The old walk-back saw messages[2] was not a toolUse and
|
|
64
|
-
// broke at k=2, dropping the assistant toolCall at index 1 while KEEPING its
|
|
65
|
-
// tool result at index 3 → orphaned tool result → provider 400.
|
|
66
|
-
const messages = [
|
|
67
|
-
user("Search for files"),
|
|
68
|
-
toolUse("read"),
|
|
69
|
-
custom("bash: ls -la"),
|
|
70
|
-
toolResult("read", "file contents"),
|
|
71
|
-
assistant("Done."),
|
|
72
|
-
];
|
|
73
|
-
const [start, end] = computeDropRange(messages, 3, 0);
|
|
74
|
-
assert.equal(start, 0);
|
|
75
|
-
assert.equal(end, 1); // keep the assistant toolCall at index 1 with its result
|
|
76
|
-
const kept = messages.slice(end);
|
|
77
|
-
assert.equal(kept[0].toolName, "read"); // assistant tool-call preserved
|
|
78
|
-
assert.ok(kept.some((m) => m.role === "tool" && m.toolName === "read"));
|
|
79
|
-
// The toolCall and its toolResult are both in the kept run.
|
|
80
|
-
const callIdx = kept.findIndex((m) => m.role === "assistant" && m.toolName === "read");
|
|
81
|
-
const resultIdx = kept.findIndex((m) => m.role === "tool" && m.toolName === "read");
|
|
82
|
-
assert.ok(callIdx !== -1 && resultIdx !== -1 && callIdx < resultIdx);
|
|
83
|
-
});
|
|
84
|
-
test("consecutive tool results sharing one call: no-op when the call cannot be kept", () => {
|
|
85
|
-
// [assistant(tc), T1, T2] with keepFrom=1: dropping the call orphans BOTH T1
|
|
86
|
-
// and T2. No pair-safe positive cut exists below keepFrom → no-op compaction
|
|
87
|
-
// (the [start,end) contract preserves a non-zero result only when one exists).
|
|
88
|
-
const messages = [toolUse("multi"), toolResult("multi", "r1"), toolResult("multi", "r2")];
|
|
89
|
-
const [start, end] = computeDropRange(messages, 1, 0);
|
|
90
|
-
assert.equal(start, 0);
|
|
91
|
-
assert.equal(end, 0); // no-op — pair rule outranks dropping
|
|
92
|
-
assert.equal(dropBefore(messages, 1, 0), messages);
|
|
93
|
-
});
|
|
94
|
-
test("consecutive tool results sharing one call: safe cut keeps the call with both results", () => {
|
|
95
|
-
// [user, assistant(tc), T1, T2, user2] — keepFrom=3 would orphan T2; the guard
|
|
96
|
-
// walks back to keep the call (dropEnd=1, only the first user is dropped).
|
|
97
|
-
const messages = [
|
|
98
|
-
user("u1"),
|
|
99
|
-
toolUse("multi"),
|
|
100
|
-
toolResult("multi", "r1"),
|
|
101
|
-
toolResult("multi", "r2"),
|
|
102
|
-
user("u2"),
|
|
103
|
-
];
|
|
104
|
-
const [start, end] = computeDropRange(messages, 3, 0);
|
|
105
|
-
assert.equal(start, 0);
|
|
106
|
-
assert.equal(end, 1); // keep [assistant(tc), T1, T2, user2]
|
|
107
|
-
const kept = messages.slice(end);
|
|
108
|
-
const callIdx = kept.findIndex((m) => m.role === "assistant" && m.toolName === "multi");
|
|
109
|
-
const r1Idx = kept.findIndex((m) => m.role === "tool" && m.output === "r1");
|
|
110
|
-
const r2Idx = kept.findIndex((m) => m.role === "tool" && m.output === "r2");
|
|
111
|
-
assert.ok(callIdx < r1Idx && r1Idx < r2Idx);
|
|
112
|
-
});
|
|
113
|
-
test("consecutive shared-call results: dropping call + all results together is safe", () => {
|
|
114
|
-
// keepFrom=4 preserves only the trailing user — the call and BOTH results are
|
|
115
|
-
// dropped together, so nothing is orphaned.
|
|
116
|
-
const messages = [
|
|
117
|
-
user("u1"),
|
|
118
|
-
toolUse("multi"),
|
|
119
|
-
toolResult("multi", "r1"),
|
|
120
|
-
toolResult("multi", "r2"),
|
|
121
|
-
user("u2"),
|
|
122
|
-
];
|
|
123
|
-
const [start, end] = computeDropRange(messages, 4, 0);
|
|
124
|
-
assert.equal(start, 0);
|
|
125
|
-
assert.equal(end, 4);
|
|
126
|
-
assert.deepEqual(messages.slice(end), [user("u2")]);
|
|
127
|
-
});
|
|
128
|
-
test("keepFrom landing on a call whose results follow is safe", () => {
|
|
129
|
-
// [user, assistant(tc1), T1, assistant(tc2), T2, user2] keepFrom=3 → preserved
|
|
130
|
-
// run starts on assistant(tc2) at index 3, whose result T2 follows. Safe.
|
|
131
|
-
const messages = [
|
|
132
|
-
user("u1"),
|
|
133
|
-
toolUse("read"),
|
|
134
|
-
toolResult("read", "r1"),
|
|
135
|
-
toolUse("write"),
|
|
136
|
-
toolResult("write", "r2"),
|
|
137
|
-
user("u2"),
|
|
138
|
-
];
|
|
139
|
-
const [start, end] = computeDropRange(messages, 3, 0);
|
|
140
|
-
assert.equal(start, 0);
|
|
141
|
-
assert.equal(end, 3);
|
|
142
|
-
const kept = messages.slice(end);
|
|
143
|
-
assert.equal(kept[0].role, "assistant");
|
|
144
|
-
assert.equal(kept[0].toolName, "write");
|
|
145
|
-
assert.ok(kept.some((m) => m.role === "tool" && m.toolName === "write"));
|
|
146
|
-
});
|
|
147
|
-
test("anchor floor + pair-rule conflict: pair rule wins, drop less", () => {
|
|
148
|
-
// [assistant(tc), user, T] with anchor=1: the anchor floor wants dropEnd<=1
|
|
149
|
-
// (keep the user at index 1), but keeping from index 1 orphans T (its owner at
|
|
150
|
-
// index 0 would be dropped). The pair rule outranks the floor — we drop LESS,
|
|
151
|
-
// keeping everything (no-op) rather than cross a pair.
|
|
152
|
-
const messages = [toolUse("read"), user("keep me"), toolResult("read", "r")];
|
|
153
|
-
const out = dropBefore(messages, 2, 1);
|
|
154
|
-
assert.equal(out, messages, "anchor floor would orphan the tool result → no-op");
|
|
155
|
-
});
|
|
156
|
-
test("isBoundarySafe: interleaved custom between call and result is detected unsafe", () => {
|
|
157
|
-
const messages = [user("a"), toolUse("read"), custom("bash"), toolResult("read", "r")];
|
|
158
|
-
// keepFrom=3 drops the call at index 1, keeps the result at index 3 → unsafe.
|
|
159
|
-
assert.equal(isBoundarySafe(messages, 3), false);
|
|
160
|
-
// keepFrom=2 ALSO drops the call at index 1 (drop [0,2) = [user, toolUse]) and
|
|
161
|
-
// keeps the result at index 3 → still orphaned → unsafe.
|
|
162
|
-
assert.equal(isBoundarySafe(messages, 2), false);
|
|
163
|
-
// keepFrom=1 keeps the call (index 1) together with its result at index 3 → safe.
|
|
164
|
-
assert.equal(isBoundarySafe(messages, 1), true);
|
|
165
|
-
});
|
|
166
|
-
test("isBoundarySafe: cut before any tool result is safe", () => {
|
|
167
|
-
const messages = [user("a"), toolUse("read"), toolResult("read", "r"), assistant("done")];
|
|
168
|
-
assert.equal(isBoundarySafe(messages, 0), true); // out of range → safe
|
|
169
|
-
assert.equal(isBoundarySafe(messages, messages.length), true); // out of range → safe
|
|
170
|
-
});
|
package/dist/src/compact.test.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { formatCompactSummary, summarizeMessages, mergeCompactSummaries, shouldCompact, autoCompactCheck, collectKeyFiles, inferPendingWork, extractFileCandidates, } from "./compact.js";
|
|
4
|
-
import { estimateSessionTokens } from "./tokens.js";
|
|
5
|
-
function user(text) { return { role: "user", text }; }
|
|
6
|
-
function assistant(text) { return { role: "assistant", text }; }
|
|
7
|
-
function toolUse(name, input) { return { role: "assistant", text: "", toolName: name, input }; }
|
|
8
|
-
function toolResult(name, output) { return { role: "tool", text: "", toolName: name, output }; }
|
|
9
|
-
test("formatCompactSummary strips analysis and formats summary block (claw-code parity)", () => {
|
|
10
|
-
const summary = "<analysis>scratch</analysis>\n<summary>Kept work</summary>";
|
|
11
|
-
assert.equal(formatCompactSummary(summary), "Summary:\nKept work");
|
|
12
|
-
});
|
|
13
|
-
test("leaves small sessions unchanged (shouldCompact false)", () => {
|
|
14
|
-
const messages = [user("hello")];
|
|
15
|
-
assert.equal(shouldCompact(messages, 1, 4), false);
|
|
16
|
-
});
|
|
17
|
-
test("compacts older messages into a summary with Scope + timeline", () => {
|
|
18
|
-
const messages = [
|
|
19
|
-
user("one ".repeat(200)),
|
|
20
|
-
assistant("two ".repeat(200)),
|
|
21
|
-
toolResult("bash", "ok ".repeat(200)),
|
|
22
|
-
assistant("recent"),
|
|
23
|
-
];
|
|
24
|
-
assert.equal(shouldCompact(messages, 1, 2), true);
|
|
25
|
-
const summary = summarizeMessages(messages.slice(0, 2));
|
|
26
|
-
const formatted = formatCompactSummary(summary);
|
|
27
|
-
assert.ok(formatted.includes("Scope:"));
|
|
28
|
-
assert.ok(formatted.includes("Key timeline:"));
|
|
29
|
-
});
|
|
30
|
-
test("merge keeps previous compacted context when compacting again", () => {
|
|
31
|
-
const first = summarizeMessages([
|
|
32
|
-
user("Investigate src/compact.ts"),
|
|
33
|
-
assistant("I will inspect the compact flow."),
|
|
34
|
-
]);
|
|
35
|
-
const second = summarizeMessages([
|
|
36
|
-
user("Also update src/boundary.ts"),
|
|
37
|
-
assistant("Next: preserve prior summary context."),
|
|
38
|
-
]);
|
|
39
|
-
const merged = mergeCompactSummaries(first, second);
|
|
40
|
-
assert.ok(merged.includes("Previously compacted context:"));
|
|
41
|
-
assert.ok(merged.includes("Newly compacted context:"));
|
|
42
|
-
assert.ok(merged.includes("src/boundary.ts"));
|
|
43
|
-
});
|
|
44
|
-
test("infers pending work from recent messages", () => {
|
|
45
|
-
const pending = inferPendingWork([
|
|
46
|
-
user("done"),
|
|
47
|
-
assistant("Next: update tests and follow up on remaining CLI polish."),
|
|
48
|
-
]);
|
|
49
|
-
assert.equal(pending.length, 1);
|
|
50
|
-
assert.ok(pending[0].includes("Next: update tests"));
|
|
51
|
-
});
|
|
52
|
-
test("extracts key files from message content", () => {
|
|
53
|
-
const files = collectKeyFiles([
|
|
54
|
-
user("Update src/compact.ts and extensions/mega-compact.ts next."),
|
|
55
|
-
]);
|
|
56
|
-
assert.ok(files.includes("src/compact.ts"));
|
|
57
|
-
assert.ok(files.includes("extensions/mega-compact.ts"));
|
|
58
|
-
});
|
|
59
|
-
test("extractFileCandidates ignores plain words and non-interesting extensions", () => {
|
|
60
|
-
const files = extractFileCandidates("look at foo/bar.png and src/x.ts and justaword");
|
|
61
|
-
assert.deepEqual(files, ["src/x.ts"]);
|
|
62
|
-
});
|
|
63
|
-
test("summarizeMessages lists tool names sorted + deduped", () => {
|
|
64
|
-
const summary = summarizeMessages([toolUse("search", "{}"), toolUse("bash", "{}"), toolResult("search", "ok")]);
|
|
65
|
-
assert.ok(summary.includes("Tools mentioned: bash, search."));
|
|
66
|
-
});
|
|
67
|
-
test("autoCompactCheck reports utilization and threshold gate", () => {
|
|
68
|
-
const under = autoCompactCheck(10000, 50000);
|
|
69
|
-
assert.equal(under.shouldCompact, false);
|
|
70
|
-
assert.equal(under.utilizationPct, 20);
|
|
71
|
-
const over = autoCompactCheck(60000, 50000);
|
|
72
|
-
assert.equal(over.shouldCompact, true);
|
|
73
|
-
});
|
|
74
|
-
test("token estimator counts text + tool payloads", () => {
|
|
75
|
-
const total = estimateSessionTokens([user("abcd"), toolResult("bash", "abcd")]);
|
|
76
|
-
// "abcd"/4+1 = 2 for user; tool: name "bash"/4+1=2 plus output "abcd"/4+1=2 => 4
|
|
77
|
-
assert.equal(total, 2 + 4);
|
|
78
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* themes.test.ts — S30 theme palette source-of-truth tests.
|
|
3
|
-
* Pi-agnostic: no pi runtime imports.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { THEMES, THEME_IDS, DEFAULT_THEME, getTheme, isValidTheme, nextTheme, themeCssVars, themeDataBlock, } from "./themes.js";
|
|
8
|
-
describe("themes (S30)", () => {
|
|
9
|
-
it("defines exactly 6 themes", () => {
|
|
10
|
-
assert.equal(THEMES.length, 6);
|
|
11
|
-
assert.equal(THEME_IDS.length, 6);
|
|
12
|
-
});
|
|
13
|
-
it("has unique ids", () => {
|
|
14
|
-
assert.equal(new Set(THEME_IDS).size, 6);
|
|
15
|
-
});
|
|
16
|
-
it("default theme is transparent", () => {
|
|
17
|
-
assert.equal(DEFAULT_THEME, "transparent");
|
|
18
|
-
assert.ok(isValidTheme(DEFAULT_THEME));
|
|
19
|
-
});
|
|
20
|
-
it("includes retro, orange-bold, cyan-neon, amber-mono, grayscale", () => {
|
|
21
|
-
for (const id of ["retro", "orange-bold", "cyan-neon", "amber-mono", "grayscale"]) {
|
|
22
|
-
assert.ok(isValidTheme(id), `missing ${id}`);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
it("transparent theme has null bg (CSS + ANSI)", () => {
|
|
26
|
-
const t = getTheme("transparent");
|
|
27
|
-
assert.ok(t);
|
|
28
|
-
assert.equal(t.css.bg, null);
|
|
29
|
-
assert.equal(t.ansi.bg, null);
|
|
30
|
-
});
|
|
31
|
-
it("every non-transparent theme has a non-null bg", () => {
|
|
32
|
-
for (const t of THEMES) {
|
|
33
|
-
if (t.id === "transparent")
|
|
34
|
-
continue;
|
|
35
|
-
assert.ok(t.css.bg, `${t.id} css.bg`);
|
|
36
|
-
assert.ok(t.ansi.bg, `${t.id} ansi.bg`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
it("every theme has css + ansi {fg,accent,mega} strings", () => {
|
|
40
|
-
for (const t of THEMES) {
|
|
41
|
-
assert.ok(typeof t.css.fg === "string" && t.css.fg.startsWith("#"));
|
|
42
|
-
assert.ok(typeof t.css.accent === "string");
|
|
43
|
-
assert.ok(typeof t.css.mega === "string");
|
|
44
|
-
assert.ok(typeof t.ansi.fg === "string");
|
|
45
|
-
assert.ok(typeof t.ansi.accent === "string");
|
|
46
|
-
assert.ok(typeof t.ansi.mega === "string");
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
it("getTheme returns undefined for unknown id", () => {
|
|
50
|
-
assert.equal(getTheme("nope"), undefined);
|
|
51
|
-
});
|
|
52
|
-
it("isValidTheme is false for unknown", () => {
|
|
53
|
-
assert.equal(isValidTheme("nope"), false);
|
|
54
|
-
});
|
|
55
|
-
it("nextTheme cycles through all themes and wraps", () => {
|
|
56
|
-
const seen = [];
|
|
57
|
-
let cur = DEFAULT_THEME;
|
|
58
|
-
for (let i = 0; i < THEME_IDS.length; i++) {
|
|
59
|
-
cur = nextTheme(cur);
|
|
60
|
-
seen.push(cur);
|
|
61
|
-
}
|
|
62
|
-
// after N steps we've visited every theme once
|
|
63
|
-
assert.equal(new Set(seen).size, THEME_IDS.length);
|
|
64
|
-
// wraps: one more step from the last returns to the first
|
|
65
|
-
const first = nextTheme(THEME_IDS[THEME_IDS.length - 1]);
|
|
66
|
-
assert.equal(first, THEME_IDS[0]);
|
|
67
|
-
});
|
|
68
|
-
it("nextTheme falls back to DEFAULT_THEME for unknown current", () => {
|
|
69
|
-
assert.equal(nextTheme("garbage"), DEFAULT_THEME);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe("themeCssVars / themeDataBlock (S32)", () => {
|
|
73
|
-
it("themeCssVars emits --bg/--fg/--accent/--mega for a normal theme", () => {
|
|
74
|
-
const t = getTheme("retro");
|
|
75
|
-
const vars = themeCssVars(t);
|
|
76
|
-
assert.match(vars, /--bg: #003300;/);
|
|
77
|
-
assert.match(vars, /--fg: #33ff33;/);
|
|
78
|
-
assert.match(vars, /--accent: #00ff41;/);
|
|
79
|
-
assert.match(vars, /--mega: #39ff14;/);
|
|
80
|
-
});
|
|
81
|
-
it("themeCssVars maps null bg to 'transparent'", () => {
|
|
82
|
-
const t = getTheme("transparent");
|
|
83
|
-
const vars = themeCssVars(t);
|
|
84
|
-
assert.match(vars, /--bg: transparent;/);
|
|
85
|
-
assert.match(vars, /--fg: #c9d1d9;/);
|
|
86
|
-
});
|
|
87
|
-
it("themeDataBlock wraps vars in a :root[data-theme=\"<id\"] selector", () => {
|
|
88
|
-
const t = getTheme("cyan-neon");
|
|
89
|
-
const block = themeDataBlock(t);
|
|
90
|
-
assert.equal(block.startsWith(':root[data-theme="cyan-neon"]{ '), true);
|
|
91
|
-
assert.equal(block.endsWith(" }"), true);
|
|
92
|
-
assert.ok(block.includes("--accent: #22d3ee;"));
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { normalize, stripAnsi } from "./normalize.js";
|
|
4
|
-
import { computeContentDigest, CONTENT_HASH_VERSION } from "./digest.js";
|
|
5
|
-
test("normalize collapses whitespace/newline variants to one form (Sprint 9)", () => {
|
|
6
|
-
// Sprint 9 normalizes whitespace/newlines/ANSI (not case — that is Sprint 10).
|
|
7
|
-
const variants = [
|
|
8
|
-
"foo bar",
|
|
9
|
-
"foo bar",
|
|
10
|
-
"foo\tbar",
|
|
11
|
-
"foo\nbar",
|
|
12
|
-
" foo bar ",
|
|
13
|
-
"foo\r\nbar",
|
|
14
|
-
];
|
|
15
|
-
const digests = variants.map((v) => computeContentDigest(v).contentHash);
|
|
16
|
-
const unique = new Set(digests);
|
|
17
|
-
assert.equal(unique.size, 1, "all whitespace/newline variants must collapse to one digest");
|
|
18
|
-
});
|
|
19
|
-
test("normalize is idempotent", () => {
|
|
20
|
-
const input = " Hello World \n";
|
|
21
|
-
assert.equal(normalize(normalize(input)), normalize(input));
|
|
22
|
-
});
|
|
23
|
-
test("stripAnsi removes terminal color codes", () => {
|
|
24
|
-
const colored = "err\x1b[31m fatal\x1b[0m boom";
|
|
25
|
-
assert.equal(stripAnsi(colored), "err fatal boom");
|
|
26
|
-
});
|
|
27
|
-
test("computeContentDigest emits full 64-hex dual hashes + version", () => {
|
|
28
|
-
const d = computeContentDigest("the same region text");
|
|
29
|
-
assert.equal(d.contentHash.length, 64);
|
|
30
|
-
assert.equal(d.contentHash2.length, 64);
|
|
31
|
-
assert.equal(d.contentHashVersion, CONTENT_HASH_VERSION);
|
|
32
|
-
assert.equal(d.normalizedText, "the same region text");
|
|
33
|
-
// Secondary is an independent view (reversed) so it differs from primary.
|
|
34
|
-
assert.notEqual(d.contentHash, d.contentHash2);
|
|
35
|
-
});
|
|
36
|
-
test("dual-hash: distinct content yields a distinct pair (both must agree to dedup)", () => {
|
|
37
|
-
const a = computeContentDigest("region about authentication");
|
|
38
|
-
const b = computeContentDigest("region about authorization");
|
|
39
|
-
assert.notEqual(a.contentHash, b.contentHash);
|
|
40
|
-
assert.notEqual(a.contentHash2, b.contentHash2);
|
|
41
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { minhashSignature, shingles, signatureSimilarity, NUM_HASHES } from "./l1-minhash.js";
|
|
4
|
-
import { lshBands, BANDS, ROWS_PER_BAND } from "./l1-lsh.js";
|
|
5
|
-
import { trigramSimilarity, isNearDuplicate, L1_VERIFY_THRESHOLD } from "./l1-verify.js";
|
|
6
|
-
test("minhashSignature is deterministic across calls (same input → same sig)", () => {
|
|
7
|
-
const a = minhashSignature("the authentication module handles login securely");
|
|
8
|
-
const b = minhashSignature("the authentication module handles login securely");
|
|
9
|
-
assert.deepEqual(a, b);
|
|
10
|
-
assert.equal(a.length, NUM_HASHES);
|
|
11
|
-
});
|
|
12
|
-
test("minhashSignature of near-identical text is more similar than of unrelated text", () => {
|
|
13
|
-
const s1 = minhashSignature("user logged in and viewed the dashboard");
|
|
14
|
-
const s2 = minhashSignature("user logged in and viewed the dashboard page"); // one word added
|
|
15
|
-
const s3 = minhashSignature("the compiler optimized the hot loop aggressively");
|
|
16
|
-
assert.ok(signatureSimilarity(s1, s2) > signatureSimilarity(s1, s3));
|
|
17
|
-
});
|
|
18
|
-
test("lshBands produces BANDS keys and is stable per session", () => {
|
|
19
|
-
const sig = minhashSignature("some text to band");
|
|
20
|
-
const k1 = lshBands(sig, "sess_a", 1);
|
|
21
|
-
const k2 = lshBands(sig, "sess_a", 1);
|
|
22
|
-
assert.equal(k1.length, BANDS);
|
|
23
|
-
assert.equal(BANDS * ROWS_PER_BAND, NUM_HASHES);
|
|
24
|
-
assert.deepEqual(k1, k2);
|
|
25
|
-
// Different session → different bucket keys (scoped, deterministic).
|
|
26
|
-
const k3 = lshBands(sig, "sess_b", 1);
|
|
27
|
-
assert.notDeepEqual(k1, k3);
|
|
28
|
-
});
|
|
29
|
-
test("lshBands keys are stable across restarts (no entropy source)", () => {
|
|
30
|
-
// Recomputed in a fresh call path — determinism is structural, not time-based.
|
|
31
|
-
const sig = minhashSignature("deterministic bucket key check");
|
|
32
|
-
const first = lshBands(sig, "sess_x", 1);
|
|
33
|
-
const again = lshBands(sig, "sess_x", 1);
|
|
34
|
-
assert.deepEqual(first, again);
|
|
35
|
-
});
|
|
36
|
-
test("trigramSimilarity is 1 for identical, high for one-word-edit, low for unrelated", () => {
|
|
37
|
-
const a = "the quick brown fox jumps";
|
|
38
|
-
assert.equal(trigramSimilarity(a, a), 1);
|
|
39
|
-
assert.ok(trigramSimilarity(a, "the quick brown fox jumps over") >= L1_VERIFY_THRESHOLD);
|
|
40
|
-
assert.ok(trigramSimilarity(a, "a completely different sentence about databases") < 0.5);
|
|
41
|
-
});
|
|
42
|
-
test("isNearDuplicate thresholds at 0.85", () => {
|
|
43
|
-
assert.equal(isNearDuplicate("user fixed the parser bug", "user fixed the parser bug today"), true);
|
|
44
|
-
assert.equal(isNearDuplicate("alpha beta gamma", "totally different words here"), false);
|
|
45
|
-
});
|
|
46
|
-
test("shingles are capped at 50K (complexity guard)", () => {
|
|
47
|
-
const huge = "x".repeat(200_000);
|
|
48
|
-
const sh = shingles(huge);
|
|
49
|
-
assert.ok(sh.length <= 50_000);
|
|
50
|
-
});
|