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,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dashboard-server.test.ts — S32 game-state API + settings strip tests.
|
|
3
|
-
*
|
|
4
|
-
* GET/PUT /api/game-state round-trips the game_state SQLite row through the
|
|
5
|
-
* real server subprocess (spawn + waitFor + fetch), and the HTML template
|
|
6
|
-
* carries the data-theme attribute + settings strip + theme CSS-var blocks.
|
|
7
|
-
*/
|
|
8
|
-
import { test, describe } from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { mkdtempSync, rmSync, readFileSync } from "node:fs";
|
|
11
|
-
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import { spawn } from "node:child_process";
|
|
14
|
-
import { dashboardHtml } from "./dashboard-server/html.js";
|
|
15
|
-
import { setGameState, getGameState } from "../src/store/sqlite.js";
|
|
16
|
-
const SERVER_ENTRY = new URL("./dashboard-server.js", import.meta.url).pathname;
|
|
17
|
-
function waitFor(cond, timeoutMs = 6000) {
|
|
18
|
-
const start = Date.now();
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
const tick = async () => {
|
|
21
|
-
if (await cond())
|
|
22
|
-
return resolve();
|
|
23
|
-
if (Date.now() - start > timeoutMs)
|
|
24
|
-
return reject(new Error("timeout"));
|
|
25
|
-
setTimeout(tick, 50);
|
|
26
|
-
};
|
|
27
|
-
tick();
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function freshDir(prefix) {
|
|
31
|
-
return mkdtempSync(join(tmpdir(), prefix));
|
|
32
|
-
}
|
|
33
|
-
async function withServer(port, dir, fn) {
|
|
34
|
-
process.env.MEGACOMPACT_DASHBOARD_PORT = port;
|
|
35
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
36
|
-
try {
|
|
37
|
-
await waitFor(async () => {
|
|
38
|
-
try {
|
|
39
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
40
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
41
|
-
return res.ok;
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
48
|
-
return await fn(raw.port);
|
|
49
|
-
}
|
|
50
|
-
finally {
|
|
51
|
-
child.kill("SIGTERM");
|
|
52
|
-
delete process.env.MEGACOMPACT_DASHBOARD_PORT;
|
|
53
|
-
rmSync(dir, { recursive: true, force: true });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
describe("S32 /api/game-state", () => {
|
|
57
|
-
test("GET returns the current game_state row (seeded via setGameState)", async () => {
|
|
58
|
-
const dir = freshDir("dash-gs-get-");
|
|
59
|
-
setGameState({ game_mode_on: true, theme: "retro", tui_display_mode: "minimal" }, dir);
|
|
60
|
-
await withServer("19330", dir, async (port) => {
|
|
61
|
-
const gs = (await fetch(`http://localhost:${port}/api/game-state`).then((r) => r.json()));
|
|
62
|
-
assert.equal(gs.game_mode_on, true);
|
|
63
|
-
assert.equal(gs.theme, "retro");
|
|
64
|
-
assert.equal(gs.tui_display_mode, "minimal");
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
test("PUT {theme:'retro'} -> 200 and getGameState(dir).theme === 'retro'", async () => {
|
|
68
|
-
const dir = freshDir("dash-gs-theme-");
|
|
69
|
-
await withServer("19331", dir, async (port) => {
|
|
70
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
71
|
-
method: "PUT",
|
|
72
|
-
headers: { "Content-Type": "application/json" },
|
|
73
|
-
body: JSON.stringify({ theme: "retro" }),
|
|
74
|
-
});
|
|
75
|
-
assert.equal(res.status, 200);
|
|
76
|
-
const body = (await res.json());
|
|
77
|
-
assert.equal(body.theme, "retro");
|
|
78
|
-
// And the authoritative DB read reflects the write.
|
|
79
|
-
assert.equal(getGameState(dir).theme, "retro");
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
test("PUT invalid theme 'bogus' -> 400 and row unchanged", async () => {
|
|
83
|
-
const dir = freshDir("dash-gs-invalid-");
|
|
84
|
-
setGameState({ theme: "orange-bold" }, dir);
|
|
85
|
-
const before = getGameState(dir).theme;
|
|
86
|
-
await withServer("19332", dir, async (port) => {
|
|
87
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
88
|
-
method: "PUT",
|
|
89
|
-
headers: { "Content-Type": "application/json" },
|
|
90
|
-
body: JSON.stringify({ theme: "bogus" }),
|
|
91
|
-
});
|
|
92
|
-
assert.equal(res.status, 400);
|
|
93
|
-
});
|
|
94
|
-
assert.equal(getGameState(dir).theme, before, "row unchanged after invalid PUT");
|
|
95
|
-
});
|
|
96
|
-
test("PUT body 'null' (valid-but-non-object JSON) -> 400, server stays up (audit P1)", async () => {
|
|
97
|
-
const dir = freshDir("dash-gs-nullobj-");
|
|
98
|
-
setGameState({ theme: "amber-mono" }, dir);
|
|
99
|
-
const before = getGameState(dir).theme;
|
|
100
|
-
await withServer("19335", dir, async (port) => {
|
|
101
|
-
// A valid-JSON-but-non-object body must NOT crash the detached server
|
|
102
|
-
// (audit P1: unhandled TypeError on patch.game_mode_on deref).
|
|
103
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
104
|
-
method: "PUT",
|
|
105
|
-
headers: { "Content-Type": "application/json" },
|
|
106
|
-
body: JSON.stringify(null),
|
|
107
|
-
});
|
|
108
|
-
assert.equal(res.status, 400, "non-object JSON -> 400, not a crash");
|
|
109
|
-
const body = (await res.json());
|
|
110
|
-
assert.equal(body.error, "invalid_patch_object");
|
|
111
|
-
// Server must still be up — a follow-up GET must succeed.
|
|
112
|
-
const follow = await fetch(`http://localhost:${port}/api/game-state`);
|
|
113
|
-
assert.equal(follow.status, 200, "server survived the non-object PUT");
|
|
114
|
-
});
|
|
115
|
-
assert.equal(getGameState(dir).theme, before, "row unchanged after non-object PUT");
|
|
116
|
-
});
|
|
117
|
-
test("PUT body '[]' (array) -> 400, server stays up", async () => {
|
|
118
|
-
const dir = freshDir("dash-gs-arr-");
|
|
119
|
-
await withServer("19336", dir, async (port) => {
|
|
120
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
121
|
-
method: "PUT",
|
|
122
|
-
headers: { "Content-Type": "application/json" },
|
|
123
|
-
body: JSON.stringify([]),
|
|
124
|
-
});
|
|
125
|
-
assert.equal(res.status, 400);
|
|
126
|
-
const follow = await fetch(`http://localhost:${port}/api/game-state`);
|
|
127
|
-
assert.equal(follow.status, 200, "server survived the array PUT");
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
test("PUT {tui_display_mode:'minimal'} round-trips", async () => {
|
|
131
|
-
const dir = freshDir("dash-gs-tui-");
|
|
132
|
-
await withServer("19333", dir, async (port) => {
|
|
133
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
134
|
-
method: "PUT",
|
|
135
|
-
headers: { "Content-Type": "application/json" },
|
|
136
|
-
body: JSON.stringify({ tui_display_mode: "minimal" }),
|
|
137
|
-
});
|
|
138
|
-
assert.equal(res.status, 200);
|
|
139
|
-
const body = (await res.json());
|
|
140
|
-
assert.equal(body.tui_display_mode, "minimal");
|
|
141
|
-
assert.equal(getGameState(dir).tui_display_mode, "minimal");
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
test("PUT {game_mode_on:true} round-trips", async () => {
|
|
145
|
-
const dir = freshDir("dash-gs-mode-");
|
|
146
|
-
await withServer("19334", dir, async (port) => {
|
|
147
|
-
const res = await fetch(`http://localhost:${port}/api/game-state`, {
|
|
148
|
-
method: "PUT",
|
|
149
|
-
headers: { "Content-Type": "application/json" },
|
|
150
|
-
body: JSON.stringify({ game_mode_on: true }),
|
|
151
|
-
});
|
|
152
|
-
assert.equal(res.status, 200);
|
|
153
|
-
const body = (await res.json());
|
|
154
|
-
assert.equal(body.game_mode_on, true);
|
|
155
|
-
assert.equal(getGameState(dir).game_mode_on, true);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe("S32 dashboard HTML skin", () => {
|
|
160
|
-
test("carries data-theme on <html> + settings strip + theme CSS-var blocks", () => {
|
|
161
|
-
const html = dashboardHtml("custom");
|
|
162
|
-
// default transparent theme attribute on <html>
|
|
163
|
-
assert.match(html, /<html lang="en" data-theme="transparent">/);
|
|
164
|
-
// settings strip with the three controls
|
|
165
|
-
assert.match(html, /<div class="settings-strip">/);
|
|
166
|
-
assert.match(html, /id="set-game-mode"/);
|
|
167
|
-
assert.match(html, /id="set-theme"/);
|
|
168
|
-
assert.match(html, /id="set-tui-mode"/);
|
|
169
|
-
// all 6 theme ids appear as :root[data-theme="<id>"] override blocks
|
|
170
|
-
for (const id of ["transparent", "retro", "orange-bold", "cyan-neon", "amber-mono", "grayscale"]) {
|
|
171
|
-
assert.ok(html.includes(`:root[data-theme="${id}"]{`), `${id} data-theme block present`);
|
|
172
|
-
}
|
|
173
|
-
// core CSS vars defined in the base :root
|
|
174
|
-
assert.match(html, /--bg: #0d1117;/);
|
|
175
|
-
assert.match(html, /--fg: #c9d1d9;/);
|
|
176
|
-
assert.match(html, /--accent: #3fb950;/);
|
|
177
|
-
assert.match(html, /--mega: #f0883e;/);
|
|
178
|
-
// body uses the themed var (not a hardcoded hex)
|
|
179
|
-
assert.match(html, /body\s*\{[^}]*background: var\(--bg\)/);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dashboard-server.test.ts — unit tests for the standalone HTTP dashboard server.
|
|
3
|
-
*
|
|
4
|
-
* Tests the core logic (snapshot building, API responses) without requiring
|
|
5
|
-
* a live pi session or model.
|
|
6
|
-
*/
|
|
7
|
-
import { test, describe } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { mkdtempSync, rmSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { spawn } from "node:child_process";
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// helpers
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
function tmpDir() {
|
|
17
|
-
return mkdtempSync(join(tmpdir(), "dashboard-test-"));
|
|
18
|
-
}
|
|
19
|
-
function writeSnapshot(dir, data) {
|
|
20
|
-
writeFileSync(join(dir, "snapshot.json"), JSON.stringify(data, null, 2));
|
|
21
|
-
}
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// Tests
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
describe("snapshot.json reading", () => {
|
|
26
|
-
test("returns valid snapshot when file exists", () => {
|
|
27
|
-
const dir = tmpDir();
|
|
28
|
-
const snapshot = {
|
|
29
|
-
updatedAt: new Date().toISOString(),
|
|
30
|
-
tier: "medium",
|
|
31
|
-
version: 1,
|
|
32
|
-
config: { activeTier: "medium" },
|
|
33
|
-
session: { id: "test-123", state: "running", persistedThisSession: true },
|
|
34
|
-
context: { tokens: 50000, percent: 50, contextWindow: 100000 },
|
|
35
|
-
trigger: { armed: true, ready: false, currentTokens: 50000, thresholdTokens: 100000 },
|
|
36
|
-
store: { checkpointCount: 3, totalTokenEstimate: 15000 },
|
|
37
|
-
};
|
|
38
|
-
writeSnapshot(dir, snapshot);
|
|
39
|
-
const content = readFileSync(join(dir, "snapshot.json"), "utf-8");
|
|
40
|
-
const parsed = JSON.parse(content);
|
|
41
|
-
assert.equal(parsed.tier, "medium");
|
|
42
|
-
assert.equal(parsed.session.id, "test-123");
|
|
43
|
-
assert.equal(parsed.context.percent, 50);
|
|
44
|
-
assert.equal(parsed.store.checkpointCount, 3);
|
|
45
|
-
rmSync(dir, { recursive: true });
|
|
46
|
-
});
|
|
47
|
-
test("handles missing snapshot.json gracefully", () => {
|
|
48
|
-
const dir = tmpDir();
|
|
49
|
-
const snapshotPath = join(dir, "snapshot.json");
|
|
50
|
-
assert.equal(existsSync(snapshotPath), false);
|
|
51
|
-
rmSync(dir, { recursive: true });
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe("dashboard.json (compact snapshot)", () => {
|
|
55
|
-
test("round-trips correctly", () => {
|
|
56
|
-
const dir = tmpDir();
|
|
57
|
-
const data = {
|
|
58
|
-
updatedAt: "2025-01-01T00:00:00.000Z",
|
|
59
|
-
tier: "mega",
|
|
60
|
-
version: 1,
|
|
61
|
-
config: { activeTier: "mega", thresholdTokens: 10000000 },
|
|
62
|
-
session: { id: "abc", state: "running", persistedThisSession: false },
|
|
63
|
-
context: { tokens: null, percent: null, contextWindow: 200000 },
|
|
64
|
-
trigger: { armed: false, ready: false, currentTokens: null, thresholdTokens: 10000000 },
|
|
65
|
-
store: { checkpointCount: 0, totalTokenEstimate: 0 },
|
|
66
|
-
};
|
|
67
|
-
writeFileSync(join(dir, "dashboard.json"), JSON.stringify(data));
|
|
68
|
-
const content = readFileSync(join(dir, "dashboard.json"), "utf-8");
|
|
69
|
-
const parsed = JSON.parse(content);
|
|
70
|
-
assert.equal(parsed.tier, "mega");
|
|
71
|
-
assert.equal(parsed.config.thresholdTokens, 10000000);
|
|
72
|
-
assert.equal(parsed.context.tokens, null);
|
|
73
|
-
rmSync(dir, { recursive: true });
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("events.log (JSONL)", () => {
|
|
77
|
-
test("parses multiple JSONL lines", () => {
|
|
78
|
-
const dir = tmpDir();
|
|
79
|
-
const events = [
|
|
80
|
-
{ ts: "2025-01-01T00:00:00.000Z", type: "compact_start", trigger: "auto", tier: "medium", sessionId: "s1" },
|
|
81
|
-
{ ts: "2025-01-01T00:00:01.000Z", type: "compact_end", trigger: "auto", durationMs: 1500, mode: "mega", fromTokens: 100000, toTokens: 5000 },
|
|
82
|
-
{ ts: "2025-01-01T00:00:02.000Z", type: "checkpoint_persisted", checkpointId: "chk_1", totalCheckpoints: 1 },
|
|
83
|
-
];
|
|
84
|
-
writeFileSync(join(dir, "events.log"), events.map((e) => JSON.stringify(e)).join("\n") + "\n");
|
|
85
|
-
const lines = readFileSync(join(dir, "events.log"), "utf-8").trim().split("\n");
|
|
86
|
-
assert.equal(lines.length, 3);
|
|
87
|
-
const parsed = lines.map((l) => JSON.parse(l));
|
|
88
|
-
assert.equal(parsed[0].type, "compact_start");
|
|
89
|
-
assert.equal(parsed[1].durationMs, 1500);
|
|
90
|
-
assert.equal(parsed[2].checkpointId, "chk_1");
|
|
91
|
-
rmSync(dir, { recursive: true });
|
|
92
|
-
});
|
|
93
|
-
test("ignores empty lines", () => {
|
|
94
|
-
const dir = tmpDir();
|
|
95
|
-
writeFileSync(join(dir, "events.log"), '{"type":"test"}\n\n\n{"type":"test2"}\n');
|
|
96
|
-
const lines = readFileSync(join(dir, "events.log"), "utf-8").trim().split("\n").filter(Boolean);
|
|
97
|
-
assert.equal(lines.length, 2);
|
|
98
|
-
rmSync(dir, { recursive: true });
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe("port.pid file", () => {
|
|
102
|
-
test("round-trips port and pid", () => {
|
|
103
|
-
const dir = tmpDir();
|
|
104
|
-
const info = { port: 3847, pid: 12345 };
|
|
105
|
-
writeFileSync(join(dir, "port.pid"), JSON.stringify(info));
|
|
106
|
-
const content = readFileSync(join(dir, "port.pid"), "utf-8");
|
|
107
|
-
const parsed = JSON.parse(content);
|
|
108
|
-
assert.equal(parsed.port, 3847);
|
|
109
|
-
assert.equal(parsed.pid, 12345);
|
|
110
|
-
rmSync(dir, { recursive: true });
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
// ---------------------------------------------------------------------------
|
|
114
|
-
// Multi-repo dashboard (S19 / Phase 5b) — launch the real server subprocess,
|
|
115
|
-
// seed the machine-wide repo_registry, and assert /api/index returns every repo
|
|
116
|
-
// plus the aggregate summary the Summary + All-repos tabs render.
|
|
117
|
-
// ---------------------------------------------------------------------------
|
|
118
|
-
describe("multi-repo /api/index (S19)", () => {
|
|
119
|
-
test("lists all repos from the global index with an aggregate summary", async () => {
|
|
120
|
-
const dir = mkdtempSync(join(tmpdir(), "dash-index-"));
|
|
121
|
-
const indexDir = mkdtempSync(join(tmpdir(), "index-"));
|
|
122
|
-
// The server reads MEGACOMPACT_INDEX_DIR for the machine-wide registry.
|
|
123
|
-
process.env.MEGACOMPACT_INDEX_DIR = indexDir;
|
|
124
|
-
process.env.MEGACOMPACT_DASHBOARD_PORT = "19321"; // private base, non-colliding
|
|
125
|
-
const { upsertRepoRegistry } = await import("../src/store/sqlite.js");
|
|
126
|
-
upsertRepoRegistry({ repoRoot: "/home/u/repoA", displayName: "repoA", stateDir: join(dir, "a"), checkpointCount: 3, tokensSaved: 1000, compressedOriginalBytes: 0 }, indexDir);
|
|
127
|
-
upsertRepoRegistry({ repoRoot: "/home/u/repoB", displayName: "repoB", stateDir: join(dir, "b"), checkpointCount: 5, tokensSaved: 2000, compressedOriginalBytes: 0 }, indexDir);
|
|
128
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
129
|
-
try {
|
|
130
|
-
await waitFor(async () => {
|
|
131
|
-
try {
|
|
132
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
133
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
134
|
-
return res.ok;
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
141
|
-
const idx = (await fetch(`http://localhost:${raw.port}/api/index`).then((r) => r.json()));
|
|
142
|
-
const names = idx.repos.map((r) => r.displayName).sort();
|
|
143
|
-
assert.deepEqual(names, ["repoA", "repoB"], "both repos from the global index");
|
|
144
|
-
assert.equal(idx.summary.totalRepos, 2, "repo count");
|
|
145
|
-
assert.equal(idx.summary.totalCheckpoints, 8, "3 + 5 checkpoints");
|
|
146
|
-
assert.equal(idx.summary.totalTokensSaved, 3000, "1000 + 2000 tokens saved");
|
|
147
|
-
}
|
|
148
|
-
finally {
|
|
149
|
-
child.kill("SIGTERM");
|
|
150
|
-
delete process.env.MEGACOMPACT_INDEX_DIR;
|
|
151
|
-
delete process.env.MEGACOMPACT_DASHBOARD_PORT;
|
|
152
|
-
rmSync(dir, { recursive: true, force: true });
|
|
153
|
-
rmSync(indexDir, { recursive: true, force: true });
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
test("/api/repos filters by ?active=Nh and /api/summary counts activeRepos", async () => {
|
|
157
|
-
const dir = mkdtempSync(join(tmpdir(), "dash-active-"));
|
|
158
|
-
const indexDir = mkdtempSync(join(tmpdir(), "index-active-"));
|
|
159
|
-
process.env.MEGACOMPACT_INDEX_DIR = indexDir;
|
|
160
|
-
process.env.MEGACOMPACT_DASHBOARD_PORT = "19322";
|
|
161
|
-
const { upsertRepoRegistry } = await import("../src/store/sqlite.js");
|
|
162
|
-
// Fresh repo, last_seen = now
|
|
163
|
-
upsertRepoRegistry({ repoRoot: "/home/u/fresh", displayName: "fresh", stateDir: dir, checkpointCount: 1, tokensSaved: 100, compressedOriginalBytes: 0, lastSeen: Math.floor(Date.now() / 1000) }, indexDir);
|
|
164
|
-
// Stale repo, last_seen = 90 days ago — must be filtered out by ?active=24h.
|
|
165
|
-
const longAgo = Math.floor(Date.now() / 1000) - 90 * 86_400;
|
|
166
|
-
upsertRepoRegistry({ repoRoot: "/home/u/stale", displayName: "stale", stateDir: dir, checkpointCount: 2, tokensSaved: 200, compressedOriginalBytes: 0, lastSeen: longAgo }, indexDir);
|
|
167
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
168
|
-
try {
|
|
169
|
-
await waitFor(async () => {
|
|
170
|
-
try {
|
|
171
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
172
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
173
|
-
return res.ok;
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
180
|
-
const allRepos = (await fetch(`http://localhost:${raw.port}/api/repos`).then((r) => r.json()));
|
|
181
|
-
assert.equal(allRepos.count, 2, "unfiltered list has both repos");
|
|
182
|
-
const activeRepos = (await fetch(`http://localhost:${raw.port}/api/repos?active=24h`).then((r) => r.json()));
|
|
183
|
-
assert.equal(activeRepos.count, 1, "active=24h drops the 90-day-old repo");
|
|
184
|
-
assert.equal(activeRepos.repos[0].displayName, "fresh");
|
|
185
|
-
const summary = (await fetch(`http://localhost:${raw.port}/api/summary`).then((r) => r.json()));
|
|
186
|
-
assert.equal(summary.activeRepos, 1, "summary counts only fresh repo as active");
|
|
187
|
-
assert.equal(summary.totalRepos, 2, "summary counts both repos total");
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
child.kill("SIGTERM");
|
|
191
|
-
delete process.env.MEGACOMPACT_INDEX_DIR;
|
|
192
|
-
delete process.env.MEGACOMPACT_DASHBOARD_PORT;
|
|
193
|
-
rmSync(dir, { recursive: true, force: true });
|
|
194
|
-
rmSync(indexDir, { recursive: true, force: true });
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe("multi-repo /api/servers (active cache-hit stats)", () => {
|
|
199
|
-
test("returns active repos with live dashboard.json cache-hit/compaction stats", async () => {
|
|
200
|
-
const dir = mkdtempSync(join(tmpdir(), "dash-servers-"));
|
|
201
|
-
const indexDir = mkdtempSync(join(tmpdir(), "index-servers-"));
|
|
202
|
-
process.env.MEGACOMPACT_INDEX_DIR = indexDir;
|
|
203
|
-
process.env.MEGACOMPACT_DASHBOARD_PORT = "19323";
|
|
204
|
-
const { upsertRepoRegistry } = await import("../src/store/sqlite.js");
|
|
205
|
-
const activeState = mkdtempSync(join(tmpdir(), "srv-active-"));
|
|
206
|
-
writeFileSync(join(activeState, "dashboard.json"), JSON.stringify({
|
|
207
|
-
updatedAt: new Date().toISOString(),
|
|
208
|
-
tier: "high",
|
|
209
|
-
context: { tokens: 5000, percent: 0.42, contextWindow: 12000 },
|
|
210
|
-
session: { id: "s1", state: "idle" },
|
|
211
|
-
cacheHits: { session: 3, total: 7, sessionTokensSaved: 1200, totalTokensSaved: 9000 },
|
|
212
|
-
compacts: { session: 2, total: 5 },
|
|
213
|
-
timeSaved: { compact: { sessionSec: 1.5, totalSec: 4 }, cacheHit: { sessionSec: 0.6, totalSec: 4.5 } },
|
|
214
|
-
}, null, 2));
|
|
215
|
-
upsertRepoRegistry({ repoRoot: "/home/u/active", displayName: "active", stateDir: activeState, checkpointCount: 4, tokensSaved: 9000, compressedOriginalBytes: 0, lastSeen: Math.floor(Date.now() / 1000), modelName: "gpt-4o", providerName: "OpenAI" }, indexDir);
|
|
216
|
-
const staleState = mkdtempSync(join(tmpdir(), "srv-stale-"));
|
|
217
|
-
writeFileSync(join(staleState, "dashboard.json"), JSON.stringify({ updatedAt: new Date().toISOString(), tier: "low" }, null, 2));
|
|
218
|
-
const longAgo = Math.floor(Date.now() / 1000) - 7 * 86_400;
|
|
219
|
-
upsertRepoRegistry({ repoRoot: "/home/u/stale", displayName: "stale", stateDir: staleState, checkpointCount: 1, tokensSaved: 100, compressedOriginalBytes: 0, lastSeen: longAgo }, indexDir);
|
|
220
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
221
|
-
try {
|
|
222
|
-
await waitFor(async () => {
|
|
223
|
-
try {
|
|
224
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
225
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
226
|
-
return res.ok;
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
233
|
-
const body = (await fetch(`http://localhost:${raw.port}/api/servers`).then((r) => r.json()));
|
|
234
|
-
assert.equal(body.servers.length, 1, "only the active repo is returned");
|
|
235
|
-
const s = body.servers[0];
|
|
236
|
-
assert.equal(s.displayName, "active");
|
|
237
|
-
assert.equal(s.tier, "high");
|
|
238
|
-
assert.equal(s.model, "gpt-4o");
|
|
239
|
-
assert.equal(s.provider, "OpenAI");
|
|
240
|
-
assert.equal(s.contextPct, 0.42);
|
|
241
|
-
assert.equal(s.state, "idle");
|
|
242
|
-
assert.deepEqual(s.cacheHits, { session: 3, total: 7, sessionTokensSaved: 1200, totalTokensSaved: 9000 });
|
|
243
|
-
assert.deepEqual(s.compacts, { session: 2, total: 5 });
|
|
244
|
-
const ts = s.timeSaved;
|
|
245
|
-
assert.equal(ts.compact.sessionSec, 1.5);
|
|
246
|
-
assert.equal(ts.cacheHit.sessionSec, 0.6);
|
|
247
|
-
}
|
|
248
|
-
finally {
|
|
249
|
-
child.kill("SIGTERM");
|
|
250
|
-
delete process.env.MEGACOMPACT_INDEX_DIR;
|
|
251
|
-
delete process.env.MEGACOMPACT_DASHBOARD_PORT;
|
|
252
|
-
rmSync(dir, { recursive: true, force: true });
|
|
253
|
-
rmSync(indexDir, { recursive: true, force: true });
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
// ---------------------------------------------------------------------------
|
|
258
|
-
// Lifecycle integration — launch the compiled server as a real subprocess
|
|
259
|
-
// (the same way the /dashboard command spawns it) and assert the two failure
|
|
260
|
-
// modes that historically produced a silent "failed to start":
|
|
261
|
-
// 1. a stale port.pid pointing at a dead port is dropped, and the server
|
|
262
|
-
// binds fresh (instead of returning the dead port);
|
|
263
|
-
// 2. a module-load crash is captured to the launch log instead of going
|
|
264
|
-
// silent under stdio:"ignore".
|
|
265
|
-
// ---------------------------------------------------------------------------
|
|
266
|
-
const SERVER_ENTRY = new URL("./dashboard-server.js", import.meta.url).pathname;
|
|
267
|
-
// Tests run in parallel across files and a killed run can leave a server bound
|
|
268
|
-
// to 9320. Use a private, non-colliding base so this file never races the
|
|
269
|
-
// mega-compact.test.js dashboard tests (which scan a DIFFERENT base) and never
|
|
270
|
-
// collides with a leftover production server on 9320.
|
|
271
|
-
process.env.MEGACOMPACT_DASHBOARD_PORT = "19320";
|
|
272
|
-
function waitFor(cond, timeoutMs = 6000) {
|
|
273
|
-
const start = Date.now();
|
|
274
|
-
return new Promise((resolve, reject) => {
|
|
275
|
-
const tick = async () => {
|
|
276
|
-
if (await cond())
|
|
277
|
-
return resolve();
|
|
278
|
-
if (Date.now() - start > timeoutMs)
|
|
279
|
-
return reject(new Error("timeout"));
|
|
280
|
-
setTimeout(tick, 50);
|
|
281
|
-
};
|
|
282
|
-
tick();
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
describe("server lifecycle", () => {
|
|
286
|
-
test("drops a stale port.pid and binds a fresh port", async () => {
|
|
287
|
-
const dir = mkdtempSync(join(tmpdir(), "dash-stale-"));
|
|
288
|
-
// A marker claiming a port where nothing is listening — use the test's own
|
|
289
|
-
// private base + 5 so the dead port is inside the server's scan range.
|
|
290
|
-
const deadPort = 19325;
|
|
291
|
-
writeFileSync(join(dir, "port.pid"), JSON.stringify({ port: deadPort, pid: 999999 }));
|
|
292
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
293
|
-
try {
|
|
294
|
-
// Wait for the server to actually be live (not just any port.pid — the
|
|
295
|
-
// stale marker already exists at t=0 and would pass a naive check).
|
|
296
|
-
await waitFor(async () => {
|
|
297
|
-
try {
|
|
298
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
299
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
300
|
-
return res.ok;
|
|
301
|
-
}
|
|
302
|
-
catch {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
|
|
307
|
-
assert.equal(typeof raw.port, "number");
|
|
308
|
-
assert.notEqual(raw.port, deadPort, "should not reuse the dead port from the stale marker");
|
|
309
|
-
// And a real server must answer on it.
|
|
310
|
-
const res = await fetch(`http://localhost:${raw.port}/api/version`);
|
|
311
|
-
assert.equal(res.ok, true);
|
|
312
|
-
}
|
|
313
|
-
finally {
|
|
314
|
-
child.kill("SIGTERM");
|
|
315
|
-
rmSync(dir, { recursive: true, force: true });
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
test("writes a dashboard.log with startup lines", async () => {
|
|
319
|
-
const dir = mkdtempSync(join(tmpdir(), "dash-log-"));
|
|
320
|
-
const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
|
|
321
|
-
try {
|
|
322
|
-
await waitFor(() => {
|
|
323
|
-
try {
|
|
324
|
-
return /server running/.test(readFileSync(join(dir, "dashboard.log"), "utf-8"));
|
|
325
|
-
}
|
|
326
|
-
catch {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
const log = readFileSync(join(dir, "dashboard.log"), "utf-8");
|
|
331
|
-
assert.match(log, /\[mega-compact\]\[dashboard\]/);
|
|
332
|
-
assert.match(log, /server running/);
|
|
333
|
-
}
|
|
334
|
-
finally {
|
|
335
|
-
child.kill("SIGTERM");
|
|
336
|
-
rmSync(dir, { recursive: true, force: true });
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
});
|