claude-code-session-manager 0.97.0 → 0.100.0
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/README.md +3 -3
- package/bin/cli.cjs +16 -4
- package/bin/node-floor.cjs +41 -0
- package/dist/assets/{DataModel-D93FoaOm.js → DataModel-HdR0AxFq.js} +1 -1
- package/dist/assets/{History-CXxxqNP1.js → History-Dr4Jr_5z.js} +2 -2
- package/dist/assets/{Hooks-CzeYFQjq.js → Hooks-NhrvH3JP.js} +3 -3
- package/dist/assets/{Library-D2zPkwOC.js → Library-Dv_EtIMr.js} +1 -1
- package/dist/assets/{MarkdownEditor-DbinP78A.js → MarkdownEditor-DTKDWV_n.js} +1 -1
- package/dist/assets/{McpServers-Bu_sVGLr.js → McpServers-M034G9B3.js} +2 -2
- package/dist/assets/{Memory-BgiI6LZ_.js → Memory-DzF1B4gx.js} +6 -6
- package/dist/assets/{Permissions-C1MMzZRm.js → Permissions-DrgbSGWl.js} +3 -3
- package/dist/assets/{Plugins-Dhu6wAZi.js → Plugins-Bd3ef35w.js} +2 -2
- package/dist/assets/{ProvenanceBadge-C3AcWKMG.js → ProvenanceBadge-DcBHT1Iy.js} +1 -1
- package/dist/assets/{SaveBar-plwYm0iO.js → SaveBar-rimJem-Y.js} +1 -1
- package/dist/assets/Scheduler-DjgFJl2w.js +16 -0
- package/dist/assets/{ScopeSwitcher-DFy0vv_o.js → ScopeSwitcher-CnAzTBrl.js} +1 -1
- package/dist/assets/Settings-Dc1F_sSg.js +3 -0
- package/dist/assets/{SkillReferenceGraph-DsI7hRPB.js → SkillReferenceGraph-B9aZDecM.js} +1 -1
- package/dist/assets/{Skills-3E748UfB.js → Skills-DRXd18gu.js} +2 -2
- package/dist/assets/{SystemPrompt-BqmfUJOd.js → SystemPrompt-ahy5-Fwe.js} +1 -1
- package/dist/assets/{TagLibrary-CPz6fO8Q.js → TagLibrary-C_tToDeL.js} +1 -1
- package/dist/assets/{TiptapBody-D9EoBQ1P.js → TiptapBody-DvdefS6K.js} +1 -1
- package/dist/assets/{Toggle-BHAmZNDn.js → Toggle-6Jl5Njc6.js} +1 -1
- package/dist/assets/{index-CKH5Uxik.css → index-Bta-hwud.css} +1 -1
- package/dist/assets/{index-tn5JIVPj.js → index-vx8O73l8.js} +497 -502
- package/dist/assets/{settingsSchema-Crqy_aNz.js → settingsSchema-D6iRguNV.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +26 -29
- package/plugins/CLAUDE.md +6 -6
- package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +23 -19
- package/plugins/session-manager-dev/skills/builder/SKILL.md +3 -3
- package/plugins/session-manager-dev/skills/develop/SKILL.md +254 -510
- package/plugins/session-manager-dev/skills/develop/standards.md +17 -22
- package/scripts/README.md +3 -11
- package/scripts/audit-ops-hygiene.cjs +3 -3
- package/scripts/hooks/lib/guard-prd-writes-policy.cjs +1 -1
- package/scripts/hooks/lib/guard-self-schedule-policy.cjs +1 -1
- package/scripts/mint-epic.cjs +2 -3
- package/scripts/scheduler-mcp-server.cjs +36 -7
- package/src/main/agentLibrary.cjs +22 -2
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +41 -38
- package/src/main/docEdit.cjs +4 -1
- package/src/main/files.cjs +2 -5
- package/src/main/health.cjs +1 -1
- package/src/main/index.cjs +23 -10
- package/src/main/ipcSchemas.cjs +28 -35
- package/src/main/lib/agentPersonaSchema.cjs +13 -2
- package/src/main/lib/atomicFs.cjs +116 -0
- package/src/main/lib/branchSweep.cjs +13 -12
- package/src/main/lib/buildTarget.cjs +3 -3
- package/src/main/lib/claudeCliCaps.cjs +129 -0
- package/src/main/lib/credentials.cjs +2 -4
- package/src/main/lib/crossProjectFeedback.cjs +3 -3
- package/src/main/lib/cwdClassify.cjs +15 -3
- package/src/main/lib/definitionOfDone.cjs +207 -125
- package/src/main/lib/dodDrainHook.cjs +11 -5
- package/src/main/lib/epicMint.cjs +2 -4
- package/src/main/lib/epicStatusMirror.cjs +8 -10
- package/src/main/lib/epicWorktreeProjectConfig.cjs +2 -4
- package/src/main/lib/gateAuthority.cjs +96 -0
- package/src/main/lib/gitExec.cjs +69 -0
- package/src/main/lib/gitWorktree.cjs +656 -92
- package/src/main/lib/instanceLock.cjs +5 -8
- package/src/main/lib/launchFailure.cjs +2 -3
- package/src/main/lib/macroLibrary.cjs +386 -0
- package/src/main/lib/mcpToolCatalog.cjs +26 -17
- package/src/main/lib/needsReviewLedger.cjs +1 -1
- package/src/main/lib/opsErrorLog.cjs +11 -1
- package/src/main/lib/opsOwnership.cjs +0 -5
- package/src/main/lib/pidAlive.cjs +32 -0
- package/src/main/lib/prdCreate.cjs +153 -19
- package/src/main/lib/prdDisposition.cjs +2 -2
- package/src/main/lib/prdGateFiles.cjs +284 -0
- package/src/main/lib/prdLocations.cjs +61 -0
- package/src/main/lib/prdMigration.cjs +2 -3
- package/src/main/lib/prdSizing.cjs +2 -1
- package/src/main/lib/promptSessionSchema.cjs +10 -2
- package/src/main/lib/rcaReport.cjs +4 -6
- package/src/main/lib/reaperHelpers.cjs +8 -1
- package/src/main/lib/reservationExpiry.cjs +6 -1
- package/src/main/lib/reviewNotice.cjs +263 -0
- package/src/main/lib/runClaudeP.cjs +4 -1
- package/src/main/lib/schedulerPaths.cjs +22 -2
- package/src/main/lib/sessionSlots.cjs +2 -4
- package/src/main/lib/shippedPersonaSeeds.cjs +179 -0
- package/src/main/lib/timeoutShim.cjs +123 -0
- package/src/main/lib/timeoutShimScript.cjs +275 -0
- package/src/main/lib/upgradeDrain.cjs +4 -10
- package/src/main/lib/watchdogHelpers.cjs +33 -30
- package/src/main/lib/workTypeLibrary.cjs +7 -1
- package/src/main/promptSessionEvents.cjs +37 -13
- package/src/main/queueOps.cjs +17 -6
- package/src/main/scheduler.cjs +975 -203
- package/src/main/seedAgentPersonas.cjs +278 -23
- package/src/main/supervisor.cjs +4 -1
- package/src/main/templates/PRD_AUTHORING.md +126 -406
- package/src/preload/__tests__/preload-surface.test.cjs +68 -0
- package/src/preload/api.d.ts +41 -94
- package/src/preload/index.cjs +14 -9
- package/src/seed/agents/architect.md +1 -0
- package/src/seed/agents/dev-lead.md +17 -18
- package/src/seed/agents/project-home-builder.md +1 -0
- package/src/seed/agents/validator.md +10 -4
- package/dist/assets/HostBilko-nESrTRIg.js +0 -1
- package/dist/assets/Scheduler-BVYTeh39.js +0 -16
- package/dist/assets/Settings-DIhGgdfs.js +0 -3
- package/src/main/__tests__/activeIndexMerge.test.cjs +0 -235
- package/src/main/__tests__/agentEffortResolve.test.cjs +0 -117
- package/src/main/__tests__/agentLibrary.test.cjs +0 -276
- package/src/main/__tests__/agentModelResolve.test.cjs +0 -311
- package/src/main/__tests__/agentOverlayWrite.test.cjs +0 -95
- package/src/main/__tests__/bilkoHost-deriveSlug.test.cjs +0 -26
- package/src/main/__tests__/bilkoHost-integration.test.cjs +0 -118
- package/src/main/__tests__/bilkoHostCore.test.cjs +0 -72
- package/src/main/__tests__/broadcastCoalescer.test.cjs +0 -122
- package/src/main/__tests__/chat-cancel-terminal.test.cjs +0 -120
- package/src/main/__tests__/chat-dead-channels.test.cjs +0 -63
- package/src/main/__tests__/chat-exit-close-race.test.cjs +0 -146
- package/src/main/__tests__/chat-mcp-consent-notice.test.cjs +0 -139
- package/src/main/__tests__/chat-preamble-anchors.test.cjs +0 -100
- package/src/main/__tests__/chat-queue.test.cjs +0 -97
- package/src/main/__tests__/chat-stop-signal.test.cjs +0 -89
- package/src/main/__tests__/chatRunner-epic-worktree-execcwd.test.cjs +0 -125
- package/src/main/__tests__/chatRunner-session-flag-retry.test.cjs +0 -252
- package/src/main/__tests__/classifyPromptTicket.test.cjs +0 -101
- package/src/main/__tests__/classifyTranscriptLine.test.cjs +0 -201
- package/src/main/__tests__/computeDepHistorySatisfaction.test.cjs +0 -66
- package/src/main/__tests__/config-readText-bounded.test.cjs +0 -84
- package/src/main/__tests__/configWriteBoundaryOwners.test.cjs +0 -59
- package/src/main/__tests__/crossProjectFeedback.test.cjs +0 -334
- package/src/main/__tests__/crossProjectFeedbackRoutes.test.cjs +0 -161
- package/src/main/__tests__/dep-orphan-archive-health.test.cjs +0 -77
- package/src/main/__tests__/develop-skill-failure-modes.test.cjs +0 -70
- package/src/main/__tests__/docEdit.test.cjs +0 -244
- package/src/main/__tests__/dod-batchkey.test.cjs +0 -183
- package/src/main/__tests__/dod-drain-hook.test.cjs +0 -302
- package/src/main/__tests__/dod-report.test.cjs +0 -304
- package/src/main/__tests__/dod-reverify.test.cjs +0 -285
- package/src/main/__tests__/epicContextDigest.test.cjs +0 -174
- package/src/main/__tests__/epicMint.test.cjs +0 -332
- package/src/main/__tests__/epicMintTelemetryTap.test.cjs +0 -64
- package/src/main/__tests__/epicStatusMirror.test.cjs +0 -110
- package/src/main/__tests__/epicValidationHook.test.cjs +0 -291
- package/src/main/__tests__/exchanges.test.cjs +0 -122
- package/src/main/__tests__/exchangesPromptId.test.cjs +0 -61
- package/src/main/__tests__/extractJson.test.cjs +0 -51
- package/src/main/__tests__/files-reject-credentials.test.cjs +0 -40
- package/src/main/__tests__/fixtures/1218-fo-01-move-scripts-lib-into-src-main-lib.log +0 -556
- package/src/main/__tests__/flatPrdTickSweep.test.cjs +0 -110
- package/src/main/__tests__/health-build-freshness.test.cjs +0 -39
- package/src/main/__tests__/health-claude-md-budget.test.cjs +0 -57
- package/src/main/__tests__/health-credentials.test.cjs +0 -81
- package/src/main/__tests__/health-delegation-chain.test.cjs +0 -124
- package/src/main/__tests__/health-per-project-stall.test.cjs +0 -84
- package/src/main/__tests__/health-prd-migration.test.cjs +0 -37
- package/src/main/__tests__/health-queue-dispatch.test.cjs +0 -135
- package/src/main/__tests__/health-starve-escalation.test.cjs +0 -94
- package/src/main/__tests__/health-tick-liveness.test.cjs +0 -179
- package/src/main/__tests__/health-usage-poller.test.cjs +0 -144
- package/src/main/__tests__/health-worktree-cap-blocked.test.cjs +0 -65
- package/src/main/__tests__/heapSnapshot.test.cjs +0 -121
- package/src/main/__tests__/historyAggregatorIntraday.test.cjs +0 -313
- package/src/main/__tests__/historyDashboard.test.cjs +0 -163
- package/src/main/__tests__/historyRollup.test.cjs +0 -333
- package/src/main/__tests__/intradayRefresh.test.cjs +0 -39
- package/src/main/__tests__/ipcSchemas-dependsOn.test.cjs +0 -39
- package/src/main/__tests__/kg-augment.test.cjs +0 -195
- package/src/main/__tests__/loadGateDetailTick.test.cjs +0 -31
- package/src/main/__tests__/machineProfile.test.cjs +0 -152
- package/src/main/__tests__/mcpStatus.test.cjs +0 -61
- package/src/main/__tests__/memoryAggregate.test.cjs +0 -109
- package/src/main/__tests__/memoryStale.test.cjs +0 -88
- package/src/main/__tests__/needsReviewLedger.test.cjs +0 -162
- package/src/main/__tests__/openExternalApp-spawn-error.test.cjs +0 -25
- package/src/main/__tests__/opsErrorLog.test.cjs +0 -109
- package/src/main/__tests__/opsErrorLogTelemetryTap.test.cjs +0 -173
- package/src/main/__tests__/personaMerge.test.cjs +0 -169
- package/src/main/__tests__/planValidator.test.cjs +0 -125
- package/src/main/__tests__/pollLoop-dispatch-on-failure.test.cjs +0 -176
- package/src/main/__tests__/prd-group-allocator.test.cjs +0 -119
- package/src/main/__tests__/prdAdminRouteParity.test.cjs +0 -70
- package/src/main/__tests__/prdAdminRoutes.test.cjs +0 -718
- package/src/main/__tests__/prdAgentType.test.cjs +0 -103
- package/src/main/__tests__/prdAuthoringSeed.test.cjs +0 -39
- package/src/main/__tests__/prdCreate.test.cjs +0 -979
- package/src/main/__tests__/prdCreateDisposition.test.cjs +0 -201
- package/src/main/__tests__/prdCreatePlanId.test.cjs +0 -132
- package/src/main/__tests__/prdFrontmatterAgentType.test.cjs +0 -117
- package/src/main/__tests__/prdFrontmatterDependsOn.test.cjs +0 -136
- package/src/main/__tests__/prdFrontmatterDisposition.test.cjs +0 -125
- package/src/main/__tests__/prdFrontmatterQuietMachine.test.cjs +0 -108
- package/src/main/__tests__/prdLocations.test.cjs +0 -195
- package/src/main/__tests__/prdLocationsArchived.test.cjs +0 -201
- package/src/main/__tests__/prdMigration.test.cjs +0 -349
- package/src/main/__tests__/prdMigrationLegacyAdopt.test.cjs +0 -91
- package/src/main/__tests__/prdParserHighWater.test.cjs +0 -74
- package/src/main/__tests__/prdParserSourcePromptId.test.cjs +0 -65
- package/src/main/__tests__/prdSetDisposition.test.cjs +0 -222
- package/src/main/__tests__/prdSizing.test.cjs +0 -106
- package/src/main/__tests__/prdSourcePromptIdBackfill.test.cjs +0 -118
- package/src/main/__tests__/prdUpdateDependsOn.test.cjs +0 -160
- package/src/main/__tests__/proc-role-env.test.cjs +0 -125
- package/src/main/__tests__/procname-claude-spawn-sites.test.cjs +0 -304
- package/src/main/__tests__/procname-sm-processes.test.cjs +0 -127
- package/src/main/__tests__/projectHomeAdminRoutes.test.cjs +0 -177
- package/src/main/__tests__/projectPages.test.cjs +0 -137
- package/src/main/__tests__/promptSessionEvents.test.cjs +0 -234
- package/src/main/__tests__/promptSessionSchema.test.cjs +0 -101
- package/src/main/__tests__/promptSessionTranscript.test.cjs +0 -0
- package/src/main/__tests__/promptSessionsCreateEpicHandler.test.cjs +0 -159
- package/src/main/__tests__/pty-epic-worktree-spawn-cwd.test.cjs +0 -282
- package/src/main/__tests__/pty-session-open-telemetry.test.cjs +0 -96
- package/src/main/__tests__/pty-write-result.test.cjs +0 -46
- package/src/main/__tests__/queue-health-verdict.test.cjs +0 -170
- package/src/main/__tests__/queue-starvation-dispatch-driver.test.cjs +0 -286
- package/src/main/__tests__/queue-starvation-per-project.test.cjs +0 -147
- package/src/main/__tests__/queueHistory.test.cjs +0 -355
- package/src/main/__tests__/queueOps-interactive-ac-lint.test.cjs +0 -65
- package/src/main/__tests__/queueOpsArchiveDestination.test.cjs +0 -65
- package/src/main/__tests__/queueOpsAutoArchive.test.cjs +0 -154
- package/src/main/__tests__/rateLimitPollerStreak.test.cjs +0 -128
- package/src/main/__tests__/rcaReport.test.cjs +0 -266
- package/src/main/__tests__/reconcileFlatPrdSweep.test.cjs +0 -119
- package/src/main/__tests__/reconcileTiming.test.cjs +0 -135
- package/src/main/__tests__/runLogRetention.test.cjs +0 -489
- package/src/main/__tests__/runVerify-atomic-verdicts.test.cjs +0 -26
- package/src/main/__tests__/runVerify-blocked-by-foreign-wip.test.cjs +0 -58
- package/src/main/__tests__/runVerify-landed-commit-outranks.test.cjs +0 -191
- package/src/main/__tests__/runVerify-policy-denial.test.cjs +0 -89
- package/src/main/__tests__/runVerify-transcript-commit-evidence.test.cjs +0 -225
- package/src/main/__tests__/runVerify.test.cjs +0 -1784
- package/src/main/__tests__/scheduleJobSchema.test.cjs +0 -127
- package/src/main/__tests__/scheduleJobStatusDrift.test.cjs +0 -65
- package/src/main/__tests__/scheduleJobTransitions.test.cjs +0 -277
- package/src/main/__tests__/scheduleJobTransitionsGrep.test.cjs +0 -59
- package/src/main/__tests__/scheduleJobTransitionsTelemetryTap.test.cjs +0 -72
- package/src/main/__tests__/scheduler-admin-routes.test.cjs +0 -199
- package/src/main/__tests__/scheduler-adopted-run-supervision.test.cjs +0 -143
- package/src/main/__tests__/scheduler-already-satisfied-on-main.test.cjs +0 -105
- package/src/main/__tests__/scheduler-archive-completed-prd.test.cjs +0 -102
- package/src/main/__tests__/scheduler-archived-twin-guard.test.cjs +0 -155
- package/src/main/__tests__/scheduler-autofix-outcome.test.cjs +0 -188
- package/src/main/__tests__/scheduler-autofix-select.test.cjs +0 -439
- package/src/main/__tests__/scheduler-autopromote.test.cjs +0 -51
- package/src/main/__tests__/scheduler-bash-timeout-env.test.cjs +0 -101
- package/src/main/__tests__/scheduler-blocked-by-foreign-wip.test.cjs +0 -107
- package/src/main/__tests__/scheduler-boot-orphans.test.cjs +0 -153
- package/src/main/__tests__/scheduler-broadcast-reconcile.test.cjs +0 -121
- package/src/main/__tests__/scheduler-clear-queue-history.test.cjs +0 -134
- package/src/main/__tests__/scheduler-commit-guard-noop.test.cjs +0 -244
- package/src/main/__tests__/scheduler-committed-in-window.test.cjs +0 -182
- package/src/main/__tests__/scheduler-cross-project-batch.test.cjs +0 -43
- package/src/main/__tests__/scheduler-default-eligible-heal.test.cjs +0 -168
- package/src/main/__tests__/scheduler-dispatch-loop.test.cjs +0 -58
- package/src/main/__tests__/scheduler-effective-concurrency.test.cjs +0 -81
- package/src/main/__tests__/scheduler-epic-digest.test.cjs +0 -227
- package/src/main/__tests__/scheduler-failed-autoreset.test.cjs +0 -121
- package/src/main/__tests__/scheduler-finalize-dispatch-guards.test.cjs +0 -229
- package/src/main/__tests__/scheduler-find-prd-dir.test.cjs +0 -75
- package/src/main/__tests__/scheduler-fix-plan-path.test.cjs +0 -119
- package/src/main/__tests__/scheduler-force-tick-outcome.test.cjs +0 -46
- package/src/main/__tests__/scheduler-foreign-wip-manifest.test.cjs +0 -78
- package/src/main/__tests__/scheduler-gate-shadow.test.cjs +0 -119
- package/src/main/__tests__/scheduler-guard-verdict-autoresolve.test.cjs +0 -390
- package/src/main/__tests__/scheduler-heal-refusal.test.cjs +0 -61
- package/src/main/__tests__/scheduler-heartbeat-payload.test.cjs +0 -80
- package/src/main/__tests__/scheduler-inplace-salvage.test.cjs +0 -323
- package/src/main/__tests__/scheduler-integration-failure-stamp.test.cjs +0 -41
- package/src/main/__tests__/scheduler-investigation-clean-skip.test.cjs +0 -63
- package/src/main/__tests__/scheduler-investigation-prompt.test.cjs +0 -123
- package/src/main/__tests__/scheduler-job-budget.test.cjs +0 -172
- package/src/main/__tests__/scheduler-job-overrun.test.cjs +0 -175
- package/src/main/__tests__/scheduler-launch-failure.test.cjs +0 -199
- package/src/main/__tests__/scheduler-leftover-fields.test.cjs +0 -52
- package/src/main/__tests__/scheduler-leftover-quarantine.test.cjs +0 -199
- package/src/main/__tests__/scheduler-looks-done.test.cjs +0 -537
- package/src/main/__tests__/scheduler-manual-pause.test.cjs +0 -118
- package/src/main/__tests__/scheduler-mechanical-recovery.test.cjs +0 -245
- package/src/main/__tests__/scheduler-meta-code-sha.test.cjs +0 -46
- package/src/main/__tests__/scheduler-needs-review-autoresolve.test.cjs +0 -197
- package/src/main/__tests__/scheduler-never-stop.test.cjs +0 -157
- package/src/main/__tests__/scheduler-no-dead-end-status.test.cjs +0 -152
- package/src/main/__tests__/scheduler-no-orphan-run-dir.test.cjs +0 -81
- package/src/main/__tests__/scheduler-notify-originating-tab-transcript.test.cjs +0 -87
- package/src/main/__tests__/scheduler-notify-originating-tab.test.cjs +0 -343
- package/src/main/__tests__/scheduler-periodic-reverify-guard.test.cjs +0 -217
- package/src/main/__tests__/scheduler-porcelain-rename.test.cjs +0 -164
- package/src/main/__tests__/scheduler-prd-missing-skip.test.cjs +0 -161
- package/src/main/__tests__/scheduler-prd-persona-spawn.test.cjs +0 -178
- package/src/main/__tests__/scheduler-quarantine-autoresolve.test.cjs +0 -165
- package/src/main/__tests__/scheduler-quiet-machine-lease.test.cjs +0 -257
- package/src/main/__tests__/scheduler-rate-limit-cooldown-freshness.test.cjs +0 -123
- package/src/main/__tests__/scheduler-rate-limit-pause.test.cjs +0 -152
- package/src/main/__tests__/scheduler-rate-limit-spin-guard.test.cjs +0 -156
- package/src/main/__tests__/scheduler-reap-dead-running-jobs.test.cjs +0 -754
- package/src/main/__tests__/scheduler-reaper-helpers-basics.test.cjs +0 -87
- package/src/main/__tests__/scheduler-reconcile-cwd-preserve.test.cjs +0 -100
- package/src/main/__tests__/scheduler-reconcile-history-backfill.test.cjs +0 -105
- package/src/main/__tests__/scheduler-reconcile-invalid-repair.test.cjs +0 -203
- package/src/main/__tests__/scheduler-reconcile-quarantine.test.cjs +0 -247
- package/src/main/__tests__/scheduler-reset-job-fields-guard.test.cjs +0 -77
- package/src/main/__tests__/scheduler-resume-recovery.test.cjs +0 -254
- package/src/main/__tests__/scheduler-shard-quarantine.test.cjs +0 -115
- package/src/main/__tests__/scheduler-shared-tree-guard.test.cjs +0 -380
- package/src/main/__tests__/scheduler-sigterm-commit.test.cjs +0 -43
- package/src/main/__tests__/scheduler-stall-per-project.test.cjs +0 -126
- package/src/main/__tests__/scheduler-starve-escalation.test.cjs +0 -154
- package/src/main/__tests__/scheduler-stranded-autofix-park.test.cjs +0 -252
- package/src/main/__tests__/scheduler-stranded-investigation.test.cjs +0 -185
- package/src/main/__tests__/scheduler-stuck-failed-escalation.test.cjs +0 -136
- package/src/main/__tests__/scheduler-supervisor-record.test.cjs +0 -81
- package/src/main/__tests__/scheduler-tick-cancel-token.test.cjs +0 -54
- package/src/main/__tests__/scheduler-tick-wedge.test.cjs +0 -172
- package/src/main/__tests__/scheduler-transient-failure.test.cjs +0 -141
- package/src/main/__tests__/scheduler-unreadable-queue-guard.test.cjs +0 -62
- package/src/main/__tests__/scheduler-utilization-hold.test.cjs +0 -89
- package/src/main/__tests__/scheduler-verify-prd-path.test.cjs +0 -109
- package/src/main/__tests__/scheduler-worktree-cap-defer.test.cjs +0 -234
- package/src/main/__tests__/scheduler-worktree-exec-cwd.test.cjs +0 -120
- package/src/main/__tests__/scheduler-writeprd-epic-rollback.test.cjs +0 -105
- package/src/main/__tests__/schedulerBatchRootBlocker.test.cjs +0 -117
- package/src/main/__tests__/schedulerStateSidecarRestore.test.cjs +0 -110
- package/src/main/__tests__/seedAgentPersonas.test.cjs +0 -184
- package/src/main/__tests__/seedSchedulerMcp.test.cjs +0 -211
- package/src/main/__tests__/seedStatus.test.cjs +0 -100
- package/src/main/__tests__/seedValidatorPersona.test.cjs +0 -116
- package/src/main/__tests__/stop-signal-anchor.test.cjs +0 -75
- package/src/main/__tests__/telemetryClient.test.cjs +0 -1055
- package/src/main/__tests__/telemetryContract.test.cjs +0 -930
- package/src/main/__tests__/telemetrySettings.test.cjs +0 -210
- package/src/main/__tests__/transcripts-batch-flush.test.cjs +0 -249
- package/src/main/__tests__/transcripts-doFlush-array.test.cjs +0 -124
- package/src/main/__tests__/transcripts-paged-reads.test.cjs +0 -241
- package/src/main/__tests__/transcripts-worktree-epic-path.test.cjs +0 -154
- package/src/main/__tests__/transcriptsUsageFor.test.cjs +0 -206
- package/src/main/__tests__/uniquePrdNumbers.test.cjs +0 -153
- package/src/main/__tests__/usageSingleFlight.test.cjs +0 -169
- package/src/main/__tests__/validationSentinels.test.cjs +0 -84
- package/src/main/__tests__/workTypeLibrary.test.cjs +0 -89
- package/src/main/bilkoHost.cjs +0 -314
- package/src/main/bilkoHostCore.cjs +0 -89
- package/src/main/lib/__tests__/active-sessions.test.cjs +0 -251
- package/src/main/lib/__tests__/activeIndexRebuild.test.cjs +0 -179
- package/src/main/lib/__tests__/agentPersonaSchema.test.cjs +0 -67
- package/src/main/lib/__tests__/auditLog.test.cjs +0 -38
- package/src/main/lib/__tests__/bootSelfHeal.test.cjs +0 -107
- package/src/main/lib/__tests__/branchSweep.test.cjs +0 -164
- package/src/main/lib/__tests__/buildIdentity.test.cjs +0 -121
- package/src/main/lib/__tests__/buildTarget.test.cjs +0 -52
- package/src/main/lib/__tests__/childWithLog.test.cjs +0 -321
- package/src/main/lib/__tests__/coldBootPromptSessionsWrite.test.cjs +0 -87
- package/src/main/lib/__tests__/crashTelemetry.test.cjs +0 -103
- package/src/main/lib/__tests__/credentials-futile-refresh.test.cjs +0 -115
- package/src/main/lib/__tests__/cwdClassify.test.cjs +0 -111
- package/src/main/lib/__tests__/definitionOfDoneSequence.test.cjs +0 -95
- package/src/main/lib/__tests__/delegationReadiness.test.cjs +0 -1175
- package/src/main/lib/__tests__/dispatchLoop.test.cjs +0 -63
- package/src/main/lib/__tests__/effectiveModelInfo.test.cjs +0 -244
- package/src/main/lib/__tests__/ephemeralCwd.test.cjs +0 -91
- package/src/main/lib/__tests__/epicDelegationStats.test.cjs +0 -137
- package/src/main/lib/__tests__/epicSpawnCwd.test.cjs +0 -283
- package/src/main/lib/__tests__/epicSpawnPlan.test.cjs +0 -196
- package/src/main/lib/__tests__/epicTranscriptPath.test.cjs +0 -163
- package/src/main/lib/__tests__/epicWorktreeBoot.test.cjs +0 -136
- package/src/main/lib/__tests__/epicWorktreeMerge.test.cjs +0 -130
- package/src/main/lib/__tests__/epicWorktreeMint.test.cjs +0 -117
- package/src/main/lib/__tests__/epicWorktreeProjectConfig.test.cjs +0 -137
- package/src/main/lib/__tests__/fixChainDepth.test.cjs +0 -40
- package/src/main/lib/__tests__/fixtures/204-mercury-steam-horse.log.txt +0 -13
- package/src/main/lib/__tests__/fixtures/scheduler-machine.json.corrupt-1789147548 +0 -34
- package/src/main/lib/__tests__/gateFixtures.json +0 -20
- package/src/main/lib/__tests__/gitCacheBound.test.cjs +0 -69
- package/src/main/lib/__tests__/gitWorktree.test.cjs +0 -1478
- package/src/main/lib/__tests__/gitWorktreeSalvage.test.cjs +0 -107
- package/src/main/lib/__tests__/gitWorktreeSalvageDelta.test.cjs +0 -153
- package/src/main/lib/__tests__/guardShims.test.cjs +0 -158
- package/src/main/lib/__tests__/importReferences.spec.cjs +0 -56
- package/src/main/lib/__tests__/instanceLock.test.cjs +0 -173
- package/src/main/lib/__tests__/jobSupervisorRecord.test.cjs +0 -78
- package/src/main/lib/__tests__/jobWorktree.test.cjs +0 -199
- package/src/main/lib/__tests__/jobWorktreeBootLive.test.cjs +0 -82
- package/src/main/lib/__tests__/landedSinceRun.test.cjs +0 -133
- package/src/main/lib/__tests__/launchFailure.test.cjs +0 -220
- package/src/main/lib/__tests__/loadGate.test.cjs +0 -303
- package/src/main/lib/__tests__/localAdminHttp.test.cjs +0 -214
- package/src/main/lib/__tests__/loopDelay.test.cjs +0 -68
- package/src/main/lib/__tests__/mcpToolCatalog.test.cjs +0 -107
- package/src/main/lib/__tests__/modelCatalog.test.cjs +0 -202
- package/src/main/lib/__tests__/opsOwnership.test.cjs +0 -113
- package/src/main/lib/__tests__/opsRootAbsoluteCwd.test.cjs +0 -328
- package/src/main/lib/__tests__/opsRootNestedWrite.test.cjs +0 -51
- package/src/main/lib/__tests__/opsRootResolve.test.cjs +0 -149
- package/src/main/lib/__tests__/prdDeclaredPaths.test.cjs +0 -82
- package/src/main/lib/__tests__/prdDisposition.test.cjs +0 -224
- package/src/main/lib/__tests__/procIdentity.test.cjs +0 -119
- package/src/main/lib/__tests__/procName.test.cjs +0 -92
- package/src/main/lib/__tests__/projectBriefCore.test.cjs +0 -216
- package/src/main/lib/__tests__/projectRootResolve.test.cjs +0 -148
- package/src/main/lib/__tests__/queueHealth.test.cjs +0 -58
- package/src/main/lib/__tests__/queueStoreAtomicWrite.test.cjs +0 -88
- package/src/main/lib/__tests__/queueStoreMachineStateRecovery.test.cjs +0 -190
- package/src/main/lib/__tests__/quietMachineLease.test.cjs +0 -39
- package/src/main/lib/__tests__/rateLimitWindow.test.cjs +0 -88
- package/src/main/lib/__tests__/reaperHelpers.test.cjs +0 -577
- package/src/main/lib/__tests__/schedulerBatchDepends.test.cjs +0 -312
- package/src/main/lib/__tests__/schedulerBatchFairness.test.cjs +0 -213
- package/src/main/lib/__tests__/schedulerBatchLaunchHold.test.cjs +0 -125
- package/src/main/lib/__tests__/schedulerBatchProjectCap.test.cjs +0 -127
- package/src/main/lib/__tests__/schedulerBatchQuietMachine.test.cjs +0 -109
- package/src/main/lib/__tests__/schedulerMcpServerHeadlessRefusal.test.cjs +0 -71
- package/src/main/lib/__tests__/schedulerMcpServerHelp.test.cjs +0 -216
- package/src/main/lib/__tests__/schedulerMcpServerProjectHome.test.cjs +0 -183
- package/src/main/lib/__tests__/schedulerPaths.test.cjs +0 -226
- package/src/main/lib/__tests__/schedulerPathsWorktree.test.cjs +0 -133
- package/src/main/lib/__tests__/schedulerRuntimeState.test.cjs +0 -56
- package/src/main/lib/__tests__/sessionSlots.test.cjs +0 -144
- package/src/main/lib/__tests__/telemetryBacklog.test.cjs +0 -626
- package/src/main/lib/__tests__/telemetryBoot.test.cjs +0 -134
- package/src/main/lib/__tests__/telemetryConsent.test.cjs +0 -136
- package/src/main/lib/__tests__/telemetryCounters.test.cjs +0 -57
- package/src/main/lib/__tests__/telemetryCountersMetadataColumn.test.cjs +0 -98
- package/src/main/lib/__tests__/terminalRunOutcome.test.cjs +0 -200
- package/src/main/lib/__tests__/toolUseClassify.test.cjs +0 -53
- package/src/main/lib/__tests__/updateCheck.test.cjs +0 -63
- package/src/main/lib/__tests__/upgradeDrain.test.cjs +0 -130
- package/src/main/lib/__tests__/usageCircuit.test.cjs +0 -354
- package/src/main/lib/__tests__/watchdog-helpers.test.cjs +0 -375
- package/src/main/lib/__tests__/watchdog-relaunch.test.cjs +0 -266
- package/src/main/lib/kgExchangePairing.cjs +0 -75
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* health-starve-escalation.test.cjs — `npm run health` must report
|
|
3
|
-
* non-GREEN when any project has been starved (findStarvedProjects) past
|
|
4
|
-
* the LATER escalation threshold (STARVE_ESCALATION_MS), naming the project
|
|
5
|
-
* and the hold reason scheduler.cjs's runStarveEscalationSweep already
|
|
6
|
-
* recorded on the matching 'project_starve_escalated' audit event — health
|
|
7
|
-
* runs as its own cold process with no access to the live scheduler's
|
|
8
|
-
* in-memory `lastTick`, so the durable audit-log.jsonl trail is the only
|
|
9
|
-
* place that reason survives to be read from here.
|
|
10
|
-
*
|
|
11
|
-
* Exercises evaluateStarveEscalationHealth() and
|
|
12
|
-
* latestStarveEscalationReasons() directly — pure/fs-scoped, matching every
|
|
13
|
-
* other evaluate* helper's test pattern in this file (see
|
|
14
|
-
* health-queue-dispatch.test.cjs's header). `project_starve_escalation` is
|
|
15
|
-
* wired into health.cjs's `criticalComponents` gate, so `ok: false` here is
|
|
16
|
-
* exactly what flips `npm run health`'s exit code from 0 to 1.
|
|
17
|
-
*
|
|
18
|
-
* Run: timeout 120 npx vitest run src/main/__tests__/health-starve-escalation.test.cjs
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
import { test, expect } from 'vitest';
|
|
24
|
-
const fs = require('node:fs');
|
|
25
|
-
const os = require('node:os');
|
|
26
|
-
const path = require('node:path');
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
evaluateStarveEscalationHealth,
|
|
30
|
-
latestStarveEscalationReasons,
|
|
31
|
-
} = require('../health.cjs');
|
|
32
|
-
const { STARVE_ESCALATION_MS } = require('../scheduler.cjs');
|
|
33
|
-
|
|
34
|
-
const CWD = '/home/bilko/Projects/Bilko';
|
|
35
|
-
const NOW = Date.parse('2026-09-12T20:00:00.000Z');
|
|
36
|
-
const idleFor = (ms) => NOW - ms;
|
|
37
|
-
|
|
38
|
-
test('a project starved past the escalation threshold is non-GREEN and names the project + hold reason', () => {
|
|
39
|
-
const jobs = [{ slug: 'a', cwd: CWD, status: 'pending', createdAt: new Date(idleFor(STARVE_ESCALATION_MS + 60_000)).toISOString() }];
|
|
40
|
-
// findStarvedProjects requires some OTHER project to be running — an idle
|
|
41
|
-
// machine is not starvation, only a passed-over project is.
|
|
42
|
-
const allJobs = [...jobs, { slug: 'other', cwd: '/home/bilko/Projects/other', status: 'running' }];
|
|
43
|
-
const result = evaluateStarveEscalationHealth(allJobs, NOW, STARVE_ESCALATION_MS, { [CWD]: 'slots-exhausted' });
|
|
44
|
-
expect(result.ok).toBe(false);
|
|
45
|
-
expect(result.projects).toEqual([
|
|
46
|
-
expect.objectContaining({ cwd: CWD, pendingCount: 1, holdReason: 'slots-exhausted' }),
|
|
47
|
-
]);
|
|
48
|
-
expect(result.message).toMatch(new RegExp(CWD.replace(/\//g, '\\/')));
|
|
49
|
-
expect(result.message).toMatch(/slots-exhausted/);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('a starved project with no recorded escalation reason yet reports "unknown", not a throw', () => {
|
|
53
|
-
const allJobs = [
|
|
54
|
-
{ slug: 'a', cwd: CWD, status: 'pending', createdAt: new Date(idleFor(STARVE_ESCALATION_MS + 1)).toISOString() },
|
|
55
|
-
{ slug: 'other', cwd: '/home/bilko/Projects/other', status: 'running' },
|
|
56
|
-
];
|
|
57
|
-
const result = evaluateStarveEscalationHealth(allJobs, NOW, STARVE_ESCALATION_MS, {});
|
|
58
|
-
expect(result.ok).toBe(false);
|
|
59
|
-
expect(result.projects[0].holdReason).toBe('unknown');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('a starve below the escalation threshold stays GREEN', () => {
|
|
63
|
-
const allJobs = [
|
|
64
|
-
{ slug: 'a', cwd: CWD, status: 'pending', createdAt: new Date(idleFor(STARVE_ESCALATION_MS - 60_000)).toISOString() },
|
|
65
|
-
{ slug: 'other', cwd: '/home/bilko/Projects/other', status: 'running' },
|
|
66
|
-
];
|
|
67
|
-
const result = evaluateStarveEscalationHealth(allJobs, NOW, STARVE_ESCALATION_MS, {});
|
|
68
|
-
expect(result).toEqual({ ok: true });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('nothing pending anywhere stays GREEN', () => {
|
|
72
|
-
const result = evaluateStarveEscalationHealth([], NOW, STARVE_ESCALATION_MS, {});
|
|
73
|
-
expect(result).toEqual({ ok: true });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('latestStarveEscalationReasons reads the LAST recorded holdReason per cwd from the audit log', () => {
|
|
77
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'starve-health-audit-'));
|
|
78
|
-
const auditPath = path.join(dir, 'audit-log.jsonl');
|
|
79
|
-
const lines = [
|
|
80
|
-
{ kind: 'project_starved', cwd: CWD, ageMs: 1000 }, // different kind — must be ignored
|
|
81
|
-
{ kind: 'project_starve_escalated', cwd: CWD, holdReason: 'memory-deferred' },
|
|
82
|
-
{ kind: 'project_starve_escalated', cwd: CWD, holdReason: 'load-deferred' }, // latest wins
|
|
83
|
-
{ kind: 'project_starve_escalated', cwd: '/home/bilko/Projects/other', holdReason: 'held' },
|
|
84
|
-
];
|
|
85
|
-
fs.writeFileSync(auditPath, lines.map((l) => JSON.stringify(l)).join('\n') + '\n');
|
|
86
|
-
|
|
87
|
-
const reasons = latestStarveEscalationReasons(auditPath);
|
|
88
|
-
expect(reasons[CWD]).toBe('load-deferred');
|
|
89
|
-
expect(reasons['/home/bilko/Projects/other']).toBe('held');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('latestStarveEscalationReasons returns {} for a missing audit log, never a throw', () => {
|
|
93
|
-
expect(latestStarveEscalationReasons('/nonexistent/path/audit-log.jsonl')).toEqual({});
|
|
94
|
-
});
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* health-tick-liveness.test.cjs — tick-liveness assertion for the
|
|
3
|
-
* scheduler_queue health check (PRD: health stayed GREEN through the
|
|
4
|
-
* 2026-07-14 16.5h scheduler-tick stall while PRD 544 sat pending with free
|
|
5
|
-
* capacity). Exercises evaluateTickLiveness()/readFreshHeartbeat() directly
|
|
6
|
-
* since they're pure/fs-isolated — no need to mock os.homedir() through the
|
|
7
|
-
* full check() to cover the liveness logic.
|
|
8
|
-
*
|
|
9
|
-
* Run: timeout 300 npx vitest run src/main/__tests__/health-tick-liveness.test.cjs
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
import { test } from 'vitest';
|
|
15
|
-
const assert = require('node:assert/strict');
|
|
16
|
-
const fs = require('node:fs');
|
|
17
|
-
const os = require('node:os');
|
|
18
|
-
const path = require('node:path');
|
|
19
|
-
const {
|
|
20
|
-
evaluateTickLiveness,
|
|
21
|
-
readFreshHeartbeat,
|
|
22
|
-
TICK_STALL_THRESHOLD_MS,
|
|
23
|
-
} = require('../health.cjs');
|
|
24
|
-
|
|
25
|
-
// Real incident fixture, verified at triage (PRD notes): queue.json had one
|
|
26
|
-
// job pending, running:0, concurrencyCap:3, paused:null, enabled:true, and
|
|
27
|
-
// lastRunAt frozen at the moment the tick died.
|
|
28
|
-
const STALL_LAST_RUN_AT = '2026-07-14T14:40:39.274Z';
|
|
29
|
-
const NOW = Date.parse(STALL_LAST_RUN_AT) + 16.5 * 60 * 60_000; // 16.5h later
|
|
30
|
-
|
|
31
|
-
function baseQueue(overrides = {}) {
|
|
32
|
-
return {
|
|
33
|
-
config: {
|
|
34
|
-
concurrencyCap: 3,
|
|
35
|
-
firePolicy: 'when-available',
|
|
36
|
-
utilizationThreshold: 90,
|
|
37
|
-
enabled: true,
|
|
38
|
-
},
|
|
39
|
-
jobs: [
|
|
40
|
-
{ slug: '544-stuck-job', status: 'pending' },
|
|
41
|
-
],
|
|
42
|
-
lastRunAt: STALL_LAST_RUN_AT,
|
|
43
|
-
paused: null,
|
|
44
|
-
...overrides,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
test('reports stalled: pending job, free capacity, not paused, enabled, tick silent for 16.5h (heartbeat confirms utilization is not the explanation)', () => {
|
|
49
|
-
const heartbeat = { ts: NOW - 30_000, utilization: 0 };
|
|
50
|
-
const result = evaluateTickLiveness(baseQueue(), heartbeat, NOW);
|
|
51
|
-
assert.strictEqual(result.stalled, true);
|
|
52
|
-
assert.strictEqual(result.oldestPendingSlug, '544-stuck-job');
|
|
53
|
-
assert.ok(result.tickAgeMs > TICK_STALL_THRESHOLD_MS);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('no false positive: queue is paused (incl. rate-limit auto-pause)', () => {
|
|
57
|
-
const result = evaluateTickLiveness(
|
|
58
|
-
baseQueue({ paused: { reason: 'rate-limit', resumeAt: '2099-01-01T00:00:00.000Z' } }),
|
|
59
|
-
null,
|
|
60
|
-
NOW
|
|
61
|
-
);
|
|
62
|
-
assert.strictEqual(result.stalled, false);
|
|
63
|
-
assert.strictEqual(result.reason, 'paused');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('no false positive: running is already at concurrencyCap', () => {
|
|
67
|
-
const q = baseQueue({
|
|
68
|
-
jobs: [
|
|
69
|
-
{ slug: 'running-1', status: 'running' },
|
|
70
|
-
{ slug: 'running-2', status: 'running' },
|
|
71
|
-
{ slug: 'running-3', status: 'running' },
|
|
72
|
-
{ slug: '544-stuck-job', status: 'pending' },
|
|
73
|
-
],
|
|
74
|
-
});
|
|
75
|
-
q.slotCap = 3; // machine-wide sessionSlots pool is the only cap now
|
|
76
|
-
const result = evaluateTickLiveness(q, null, NOW);
|
|
77
|
-
assert.strictEqual(result.stalled, false);
|
|
78
|
-
assert.strictEqual(result.reason, 'at-capacity');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('no false positive: scheduler disabled', () => {
|
|
82
|
-
const q = baseQueue({ config: { ...baseQueue().config, enabled: false } });
|
|
83
|
-
const result = evaluateTickLiveness(q, null, NOW);
|
|
84
|
-
assert.strictEqual(result.stalled, false);
|
|
85
|
-
assert.strictEqual(result.reason, 'disabled');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('no false positive: billing utilization at/above utilizationThreshold (when-available is designed to hold)', () => {
|
|
89
|
-
const heartbeat = { ts: NOW - 30_000, utilization: 95 };
|
|
90
|
-
const result = evaluateTickLiveness(baseQueue(), heartbeat, NOW);
|
|
91
|
-
assert.strictEqual(result.stalled, false);
|
|
92
|
-
assert.strictEqual(result.reason, 'utilization-at-threshold');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('utilization hold with reset days out is flagged longHold; within 5h is benign', () => {
|
|
96
|
-
const far = evaluateTickLiveness(baseQueue(), { ts: NOW - 30_000, utilization: 95, utilizationWindow: 'weekly_all', nextReset: new Date(NOW + 3 * 86_400_000).toISOString() }, NOW);
|
|
97
|
-
assert.strictEqual(far.stalled, false);
|
|
98
|
-
assert.strictEqual(far.longHold, true);
|
|
99
|
-
assert.strictEqual(far.window, 'weekly_all');
|
|
100
|
-
const unknown = evaluateTickLiveness(baseQueue(), { ts: NOW - 30_000, utilization: 95, nextReset: null }, NOW);
|
|
101
|
-
assert.strictEqual(unknown.longHold, true);
|
|
102
|
-
const near = evaluateTickLiveness(baseQueue(), { ts: NOW - 30_000, utilization: 95, utilizationWindow: 'five_hour', nextReset: new Date(NOW + 2 * 3_600_000).toISOString() }, NOW);
|
|
103
|
-
assert.strictEqual(near.stalled, false);
|
|
104
|
-
assert.strictEqual(near.longHold, undefined);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('no false positive: no pending jobs at all', () => {
|
|
108
|
-
const q = baseQueue({ jobs: [] });
|
|
109
|
-
const result = evaluateTickLiveness(q, null, NOW);
|
|
110
|
-
assert.strictEqual(result.stalled, false);
|
|
111
|
-
assert.strictEqual(result.reason, 'no-pending-jobs');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('degrades honestly: heartbeat missing/stale means utilization cannot be ruled out — caveat, not a confident stall', () => {
|
|
115
|
-
const result = evaluateTickLiveness(baseQueue(), null, NOW);
|
|
116
|
-
assert.strictEqual(result.stalled, false);
|
|
117
|
-
assert.strictEqual(result.caveat, true);
|
|
118
|
-
assert.strictEqual(result.reason, 'cannot-verify-utilization');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('manual firePolicy: pending work with free capacity is configured behaviour, not a stall', () => {
|
|
122
|
-
const q = baseQueue({ config: { ...baseQueue().config, firePolicy: 'manual' } });
|
|
123
|
-
const result = evaluateTickLiveness(q, null, NOW);
|
|
124
|
-
assert.strictEqual(result.stalled, false);
|
|
125
|
-
assert.strictEqual(result.reason, 'manual-fire-policy');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('does not caveat when firePolicy is neither when-available nor manual (no heartbeat needed)', () => {
|
|
129
|
-
const q = baseQueue({ config: { ...baseQueue().config, firePolicy: 'always' } });
|
|
130
|
-
const result = evaluateTickLiveness(q, null, NOW);
|
|
131
|
-
assert.strictEqual(result.stalled, true);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('readFreshHeartbeat: returns null for missing file', () => {
|
|
135
|
-
const result = readFreshHeartbeat(path.join(os.tmpdir(), 'sm-health-test-nonexistent.log'));
|
|
136
|
-
assert.strictEqual(result, null);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test('readFreshHeartbeat: returns null for a stale (old) heartbeat line', () => {
|
|
140
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-health-heartbeat-'));
|
|
141
|
-
const p = path.join(dir, 'heartbeat.log');
|
|
142
|
-
try {
|
|
143
|
-
fs.writeFileSync(p, `${JSON.stringify({ ts: Date.now() - 60 * 60_000, utilization: 10 })}\n`);
|
|
144
|
-
assert.strictEqual(readFreshHeartbeat(p), null);
|
|
145
|
-
} finally {
|
|
146
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('readFreshHeartbeat: returns the parsed last line when fresh', () => {
|
|
151
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-health-heartbeat-'));
|
|
152
|
-
const p = path.join(dir, 'heartbeat.log');
|
|
153
|
-
try {
|
|
154
|
-
fs.writeFileSync(
|
|
155
|
-
p,
|
|
156
|
-
`${JSON.stringify({ ts: Date.now() - 5 * 60_000, utilization: 10 })}\n${JSON.stringify({ ts: Date.now(), utilization: 42 })}\n`
|
|
157
|
-
);
|
|
158
|
-
const entry = readFreshHeartbeat(p);
|
|
159
|
-
assert.strictEqual(entry.utilization, 42);
|
|
160
|
-
} finally {
|
|
161
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('no false positive: pending rows blocked on an unfinished dependsOn are waiting on a job, not a tick', () => {
|
|
166
|
-
const result = evaluateTickLiveness(
|
|
167
|
-
baseQueue({
|
|
168
|
-
jobs: [
|
|
169
|
-
{ slug: '265-head', status: 'running' },
|
|
170
|
-
{ slug: '266-next', status: 'pending', dependsOn: ['265-head'] },
|
|
171
|
-
],
|
|
172
|
-
}),
|
|
173
|
-
{ ts: NOW - 30_000, utilization: 0 },
|
|
174
|
-
NOW,
|
|
175
|
-
1,
|
|
176
|
-
);
|
|
177
|
-
assert.strictEqual(result.stalled, false);
|
|
178
|
-
assert.strictEqual(result.reason, 'no-pending-jobs');
|
|
179
|
-
});
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* health-usage-poller.test.cjs — `npm run health` must report GREEN / YELLOW
|
|
3
|
-
* / RED for the usage/rate-limit poller (scheduler.cjs pollLoop), driven by
|
|
4
|
-
* the shared usageCircuit's OWN open/closed state and how long it's been
|
|
5
|
-
* open (usageCircuitState/usageCircuitOpenedAt, persisted to
|
|
6
|
-
* ~/.claude/session-manager/scheduler-state.json by persistSchedulerState —
|
|
7
|
-
* this is a separate `npm run health` process, so it reads the PERSISTED
|
|
8
|
-
* circuit fields rather than holding the live in-memory breaker) — not the
|
|
9
|
-
* old binary consecutiveFailures<5 check, which read flatly non-GREEN
|
|
10
|
-
* forever after the fifth failure with no way to distinguish "just tripped"
|
|
11
|
-
* from "down for hours." Exercises evaluateUsagePollerHealth() and
|
|
12
|
-
* loadUsagePollerState() directly since both are pure/file-scoped, matching
|
|
13
|
-
* every other evaluate* helper's test pattern in this file — deliberately NOT
|
|
14
|
-
* driving the full (slow, machine-state-coupled) check() for this.
|
|
15
|
-
*
|
|
16
|
-
* Run: timeout 120 npx vitest run src/main/__tests__/health-usage-poller.test.cjs
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
import { test, expect } from 'vitest';
|
|
22
|
-
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
23
|
-
import { tmpdir } from 'node:os';
|
|
24
|
-
import { join } from 'node:path';
|
|
25
|
-
const { evaluateUsagePollerHealth, loadUsagePollerState } = require('../health.cjs');
|
|
26
|
-
const { FAILURE_STREAK_ESCALATION_MS } = require('../scheduler.cjs');
|
|
27
|
-
|
|
28
|
-
test('missing state (fresh install / poller never ran) is ok, not applicable', () => {
|
|
29
|
-
expect(evaluateUsagePollerHealth(null)).toEqual({ ok: true, applicable: false });
|
|
30
|
-
expect(evaluateUsagePollerHealth(undefined)).toEqual({ ok: true, applicable: false });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('circuit closed is GREEN, regardless of a nonzero consecutiveFailures count', () => {
|
|
34
|
-
const result = evaluateUsagePollerHealth({ usageCircuitState: 'closed', consecutiveFailures: 2, backoffMs: 60_000, lastPollAt: Date.now() });
|
|
35
|
-
expect(result.ok).toBe(true);
|
|
36
|
-
expect(result.applicable).toBe(true);
|
|
37
|
-
expect(result.color).toBe('GREEN');
|
|
38
|
-
expect(result.message).toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('no usageCircuitState field at all (pre-upgrade sidecar) defaults to closed -> GREEN', () => {
|
|
42
|
-
const result = evaluateUsagePollerHealth({ consecutiveFailures: 0, backoffMs: null, lastPollAt: Date.now() });
|
|
43
|
-
expect(result.ok).toBe(true);
|
|
44
|
-
expect(result.color).toBe('GREEN');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('circuit open for under FAILURE_STREAK_ESCALATION_MS (30 min) is YELLOW, not GREEN — but still ok:true, not yet critical', () => {
|
|
48
|
-
const now = Date.now();
|
|
49
|
-
const result = evaluateUsagePollerHealth({
|
|
50
|
-
usageCircuitState: 'open',
|
|
51
|
-
usageCircuitOpenedAt: now - 5 * 60_000, // 5 minutes ago
|
|
52
|
-
consecutiveFailures: 6,
|
|
53
|
-
backoffMs: 480_000,
|
|
54
|
-
lastPollAt: now,
|
|
55
|
-
});
|
|
56
|
-
// ok:true is deliberate — the circuit's own open threshold (3 consecutive
|
|
57
|
-
// failures) is LOWER than the old 5-failure WARN, so an ok:false YELLOW
|
|
58
|
-
// would silently tighten the overall `npm run health` rollup's failure bar
|
|
59
|
-
// from 5 down to 3. Graceful degradation must not itself read as critical.
|
|
60
|
-
expect(result.ok).toBe(true);
|
|
61
|
-
expect(result.color).toBe('YELLOW');
|
|
62
|
-
expect(result.message).toMatch(/YELLOW/);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('circuit open for AT LEAST FAILURE_STREAK_ESCALATION_MS (30 min) is RED — ok:false, this is the critical state', () => {
|
|
66
|
-
const now = Date.now();
|
|
67
|
-
const result = evaluateUsagePollerHealth({
|
|
68
|
-
usageCircuitState: 'open',
|
|
69
|
-
usageCircuitOpenedAt: now - FAILURE_STREAK_ESCALATION_MS,
|
|
70
|
-
consecutiveFailures: 57,
|
|
71
|
-
backoffMs: 480_000,
|
|
72
|
-
lastPollAt: now,
|
|
73
|
-
});
|
|
74
|
-
expect(result.ok).toBe(false);
|
|
75
|
-
expect(result.color).toBe('RED');
|
|
76
|
-
expect(result.consecutiveFailures).toBe(57);
|
|
77
|
-
expect(result.backoffMs).toBe(480_000);
|
|
78
|
-
expect(result.message).toMatch(/RED/);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('half_open (mid-probe) is treated the same as open — not GREEN just because a probe is in flight', () => {
|
|
82
|
-
const now = Date.now();
|
|
83
|
-
const result = evaluateUsagePollerHealth({
|
|
84
|
-
usageCircuitState: 'half_open',
|
|
85
|
-
usageCircuitOpenedAt: now - 60_000,
|
|
86
|
-
consecutiveFailures: 5,
|
|
87
|
-
lastPollAt: now,
|
|
88
|
-
});
|
|
89
|
-
expect(result.ok).toBe(true); // still YELLOW-shaped (under the red threshold), so still ok:true
|
|
90
|
-
expect(result.color).toBe('YELLOW');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('respects a custom redThresholdMs argument', () => {
|
|
94
|
-
const now = Date.now();
|
|
95
|
-
const openedAt = now - 10_000;
|
|
96
|
-
const red = evaluateUsagePollerHealth({ usageCircuitState: 'open', usageCircuitOpenedAt: openedAt, consecutiveFailures: 5 }, 5_000);
|
|
97
|
-
expect(red.color).toBe('RED');
|
|
98
|
-
expect(red.ok).toBe(false);
|
|
99
|
-
const yellow = evaluateUsagePollerHealth({ usageCircuitState: 'open', usageCircuitOpenedAt: openedAt, consecutiveFailures: 5 }, 60_000);
|
|
100
|
-
expect(yellow.color).toBe('YELLOW');
|
|
101
|
-
expect(yellow.ok).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('tolerates a malformed/partial state object without throwing', () => {
|
|
105
|
-
const result = evaluateUsagePollerHealth({});
|
|
106
|
-
expect(result.ok).toBe(true);
|
|
107
|
-
expect(result.color).toBe('GREEN');
|
|
108
|
-
expect(result.consecutiveFailures).toBe(0);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// loadUsagePollerState: must distinguish "never ran" (ENOENT) from "corrupt"
|
|
112
|
-
// (unparseable) — the exact silent-masking bug class as the sibling
|
|
113
|
-
// scheduler-machine.json torn-write incident (f56bdc0), just for this sidecar.
|
|
114
|
-
// Uses a real scratch temp dir/file, never the real ~/.claude/session-manager/.
|
|
115
|
-
let scratchDir;
|
|
116
|
-
function makeScratchPath() {
|
|
117
|
-
scratchDir = mkdtempSync(join(tmpdir(), 'sm-usage-poller-health-'));
|
|
118
|
-
return join(scratchDir, 'scheduler-state.json');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
test('loadUsagePollerState: missing file -> { missing: true }', () => {
|
|
122
|
-
const p = join(makeScratchPath()); // never written
|
|
123
|
-
const result = loadUsagePollerState(p);
|
|
124
|
-
expect(result).toEqual({ missing: true });
|
|
125
|
-
rmSync(scratchDir, { recursive: true, force: true });
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('loadUsagePollerState: corrupt/unparseable JSON -> errorMessage, not missing', () => {
|
|
129
|
-
const p = makeScratchPath();
|
|
130
|
-
writeFileSync(p, '{ not: valid json', 'utf8');
|
|
131
|
-
const result = loadUsagePollerState(p);
|
|
132
|
-
expect(result.missing).toBeUndefined();
|
|
133
|
-
expect(result.state).toBeUndefined();
|
|
134
|
-
expect(result.errorMessage).toMatch(/corrupt/);
|
|
135
|
-
rmSync(scratchDir, { recursive: true, force: true });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('loadUsagePollerState: valid JSON -> { state }', () => {
|
|
139
|
-
const p = makeScratchPath();
|
|
140
|
-
writeFileSync(p, JSON.stringify({ consecutiveFailures: 12, backoffMs: 480_000, lastPollAt: 123 }), 'utf8');
|
|
141
|
-
const result = loadUsagePollerState(p);
|
|
142
|
-
expect(result.state).toEqual({ consecutiveFailures: 12, backoffMs: 480_000, lastPollAt: 123 });
|
|
143
|
-
rmSync(scratchDir, { recursive: true, force: true });
|
|
144
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* health-worktree-cap-blocked.test.cjs — `npm run health` must report
|
|
3
|
-
* non-GREEN when the worktree cap (gitWorktree.cjs's reserveWorktreeSlot) is
|
|
4
|
-
* blocking every dispatchable pending job with nothing running. Before this
|
|
5
|
-
* check existed that state was invisible to health.cjs: rows in four
|
|
6
|
-
* separate project queues carried heldReason 'worktree cap reached (5
|
|
7
|
-
* concurrent)' for 16 hours with zero entries in
|
|
8
|
-
* session-manager-operations/logs/ and nothing non-GREEN here — only a
|
|
9
|
-
* console.log line and the heldReason field itself, which nothing surfaced.
|
|
10
|
-
*
|
|
11
|
-
* Exercises evaluateWorktreeCapBlocked() directly — pure, no fs — matching
|
|
12
|
-
* every other evaluate* helper's test pattern in this file (see
|
|
13
|
-
* health-usage-poller.test.cjs's header).
|
|
14
|
-
*
|
|
15
|
-
* Run: timeout 120 npx vitest run src/main/__tests__/health-worktree-cap-blocked.test.cjs
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
import { test, expect } from 'vitest';
|
|
21
|
-
const { evaluateWorktreeCapBlocked } = require('../health.cjs');
|
|
22
|
-
|
|
23
|
-
test('a pending job held on "worktree cap reached" with 0 running is non-GREEN, blocked', () => {
|
|
24
|
-
const jobs = [
|
|
25
|
-
{ slug: 'a', status: 'pending', heldReason: 'worktree cap reached (5 concurrent)' },
|
|
26
|
-
{ slug: 'b', status: 'pending', heldReason: 'worktree cap reached (5 concurrent)' },
|
|
27
|
-
];
|
|
28
|
-
const result = evaluateWorktreeCapBlocked(jobs, 0);
|
|
29
|
-
expect(result.ok).toBe(false);
|
|
30
|
-
expect(result.blocked).toBe(true);
|
|
31
|
-
expect(result.capBlockedSlugs).toEqual(['a', 'b']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('accepts a job map (queueStore.readMergedSync federated shape), not just an array', () => {
|
|
35
|
-
const jobs = {
|
|
36
|
-
a: { slug: 'a', status: 'pending', heldReason: 'worktree cap reached (5 concurrent)' },
|
|
37
|
-
b: { slug: 'b', status: 'completed' },
|
|
38
|
-
};
|
|
39
|
-
const result = evaluateWorktreeCapBlocked(jobs, 0);
|
|
40
|
-
expect(result.ok).toBe(false);
|
|
41
|
-
expect(result.capBlockedSlugs).toEqual(['a']);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('the same cap-reached row stays GREEN while at least one job is running', () => {
|
|
45
|
-
const jobs = [{ slug: 'a', status: 'pending', heldReason: 'worktree cap reached (5 concurrent)' }];
|
|
46
|
-
const result = evaluateWorktreeCapBlocked(jobs, 1);
|
|
47
|
-
expect(result.ok).toBe(true);
|
|
48
|
-
expect(result.blocked).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('a pending row with an unrelated heldReason (or none) stays GREEN', () => {
|
|
52
|
-
const jobs = [
|
|
53
|
-
{ slug: 'a', status: 'pending', heldReason: 'launch blocked (rate_limit) — re-probe at 2026-09-11T00:00:00Z' },
|
|
54
|
-
{ slug: 'b', status: 'pending' },
|
|
55
|
-
];
|
|
56
|
-
const result = evaluateWorktreeCapBlocked(jobs, 0);
|
|
57
|
-
expect(result.ok).toBe(true);
|
|
58
|
-
expect(result.blocked).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('no pending jobs at all stays GREEN', () => {
|
|
62
|
-
const result = evaluateWorktreeCapBlocked([], 0);
|
|
63
|
-
expect(result.ok).toBe(true);
|
|
64
|
-
expect(result.blocked).toBe(false);
|
|
65
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* heapSnapshot.test.cjs — unit tests for heapSnapshot.cjs's default-off
|
|
3
|
-
* gating, IPC/menu wiring, and the capture timeout bound.
|
|
4
|
-
*
|
|
5
|
-
* Run: timeout 120 npx vitest run src/main/__tests__/heapSnapshot.test.cjs
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
import { test, expect, beforeEach, afterEach } from 'vitest';
|
|
11
|
-
const os = require('node:os');
|
|
12
|
-
const path = require('node:path');
|
|
13
|
-
const fsp = require('node:fs/promises');
|
|
14
|
-
const heapSnapshot = require('../heapSnapshot.cjs');
|
|
15
|
-
|
|
16
|
-
const ORIGINAL_FLAG = process.env.SM_HEAP_SNAPSHOT;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
delete process.env.SM_HEAP_SNAPSHOT;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(async () => {
|
|
23
|
-
if (ORIGINAL_FLAG === undefined) delete process.env.SM_HEAP_SNAPSHOT;
|
|
24
|
-
else process.env.SM_HEAP_SNAPSHOT = ORIGINAL_FLAG;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('isEnabled is false by default (no env flag)', () => {
|
|
28
|
-
expect(heapSnapshot.isEnabled()).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('isEnabled is true only when SM_HEAP_SNAPSHOT=1', () => {
|
|
32
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
33
|
-
expect(heapSnapshot.isEnabled()).toBe(true);
|
|
34
|
-
process.env.SM_HEAP_SNAPSHOT = 'true';
|
|
35
|
-
expect(heapSnapshot.isEnabled()).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('registerIpc registers nothing when disabled — default-off IPC surface', () => {
|
|
39
|
-
const calls = [];
|
|
40
|
-
const fakeIpcMain = { handle: (channel, listener) => calls.push({ channel, listener }) };
|
|
41
|
-
const registered = heapSnapshot.registerIpc({ ipcMain: fakeIpcMain, getWindow: () => null });
|
|
42
|
-
expect(registered).toBe(false);
|
|
43
|
-
expect(calls).toHaveLength(0);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('registerIpc registers the channel when enabled', () => {
|
|
47
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
48
|
-
const calls = [];
|
|
49
|
-
const fakeIpcMain = { handle: (channel, listener) => calls.push({ channel, listener }) };
|
|
50
|
-
const registered = heapSnapshot.registerIpc({ ipcMain: fakeIpcMain, getWindow: () => null });
|
|
51
|
-
expect(registered).toBe(true);
|
|
52
|
-
expect(calls).toHaveLength(1);
|
|
53
|
-
expect(calls[0].channel).toBe(heapSnapshot.CHANNEL);
|
|
54
|
-
expect(calls[0].channel).toBe('diagnostics:heap-snapshot');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('buildMenuItem returns null when disabled — no menu entry added', () => {
|
|
58
|
-
expect(heapSnapshot.buildMenuItem(() => null)).toBeNull();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('buildMenuItem returns a clickable item when enabled', () => {
|
|
62
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
63
|
-
const item = heapSnapshot.buildMenuItem(() => null);
|
|
64
|
-
expect(item).not.toBeNull();
|
|
65
|
-
expect(typeof item.click).toBe('function');
|
|
66
|
-
expect(item.label).toMatch(/heap snapshot/i);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('captureSnapshot rejects when disabled, without touching the window', async () => {
|
|
70
|
-
const win = { webContents: { takeHeapSnapshot: () => { throw new Error('should not be called'); } } };
|
|
71
|
-
await expect(heapSnapshot.captureSnapshot(win)).rejects.toThrow(/disabled/i);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('captureSnapshot rejects when no window is available', async () => {
|
|
75
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
76
|
-
await expect(heapSnapshot.captureSnapshot(null)).rejects.toThrow(/no renderer window/i);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('captureSnapshot writes the file and reports size/duration on success', async () => {
|
|
80
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
81
|
-
const dir = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-heap-test-'));
|
|
82
|
-
try {
|
|
83
|
-
const win = {
|
|
84
|
-
webContents: {
|
|
85
|
-
takeHeapSnapshot: async (filePath) => {
|
|
86
|
-
await fsp.writeFile(filePath, Buffer.alloc(1024, 1));
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
const result = await heapSnapshot.captureSnapshot(win, { dir, now: new Date('2026-08-07T12:00:00.000Z') });
|
|
91
|
-
expect(result.filePath).toBe(path.join(dir, 'heap-2026-08-07T12-00-00-000Z.heapsnapshot'));
|
|
92
|
-
expect(result.bytes).toBe(1024);
|
|
93
|
-
expect(typeof result.ms).toBe('number');
|
|
94
|
-
const stat = await fsp.stat(result.filePath);
|
|
95
|
-
expect(stat.size).toBe(1024);
|
|
96
|
-
} finally {
|
|
97
|
-
await fsp.rm(dir, { recursive: true, force: true });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('captureSnapshot times out instead of hanging forever on a stuck write', async () => {
|
|
102
|
-
process.env.SM_HEAP_SNAPSHOT = '1';
|
|
103
|
-
const dir = await fsp.mkdtemp(path.join(os.tmpdir(), 'sm-heap-test-'));
|
|
104
|
-
try {
|
|
105
|
-
const win = {
|
|
106
|
-
webContents: {
|
|
107
|
-
// Never resolves — simulates a stuck/blocked renderer.
|
|
108
|
-
takeHeapSnapshot: () => new Promise(() => {}),
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
await expect(
|
|
112
|
-
heapSnapshot.captureSnapshot(win, { dir, timeoutMs: 20 })
|
|
113
|
-
).rejects.toThrow(/timed out/i);
|
|
114
|
-
} finally {
|
|
115
|
-
await fsp.rm(dir, { recursive: true, force: true });
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('snapshotDir points under ~/.claude/session-manager', () => {
|
|
120
|
-
expect(heapSnapshot.snapshotDir()).toBe(path.join(os.homedir(), '.claude', 'session-manager'));
|
|
121
|
-
});
|