Files
hermes-ui/tests/server/shutdown.test.ts
T
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

82 lines
3.4 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest'
import {
getShutdownForceExitMs,
shouldStopAgentBridgeOnShutdown,
shouldStopManagedGatewaysOnShutdown,
} from '../../packages/server/src/services/shutdown'
describe('shutdown bridge policy', () => {
const originalValue = process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN
const originalGatewayValue = process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN
const originalNodeEnv = process.env.NODE_ENV
const originalDesktop = process.env.HERMES_DESKTOP
const originalForceExitMs = process.env.HERMES_WEB_UI_SHUTDOWN_FORCE_EXIT_MS
afterEach(() => {
if (originalValue === undefined) delete process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN
else process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN = originalValue
if (originalGatewayValue === undefined) delete process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN
else process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN = originalGatewayValue
if (originalNodeEnv === undefined) delete process.env.NODE_ENV
else process.env.NODE_ENV = originalNodeEnv
if (originalDesktop === undefined) delete process.env.HERMES_DESKTOP
else process.env.HERMES_DESKTOP = originalDesktop
if (originalForceExitMs === undefined) delete process.env.HERMES_WEB_UI_SHUTDOWN_FORCE_EXIT_MS
else process.env.HERMES_WEB_UI_SHUTDOWN_FORCE_EXIT_MS = originalForceExitMs
})
it('stops the bridge for restart and service shutdown signals by default', () => {
delete process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN
expect(shouldStopAgentBridgeOnShutdown('SIGUSR2')).toBe(true)
expect(shouldStopAgentBridgeOnShutdown('SIGTERM')).toBe(true)
expect(shouldStopAgentBridgeOnShutdown('SIGINT')).toBe(true)
})
it('allows operators to force either bridge shutdown policy', () => {
process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN = '1'
expect(shouldStopAgentBridgeOnShutdown('SIGUSR2')).toBe(true)
process.env.HERMES_AGENT_BRIDGE_STOP_ON_SHUTDOWN = '0'
expect(shouldStopAgentBridgeOnShutdown('SIGUSR2')).toBe(false)
expect(shouldStopAgentBridgeOnShutdown('SIGTERM')).toBe(false)
})
it('stops managed gateways by default in production only', () => {
delete process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN
process.env.NODE_ENV = 'development'
expect(shouldStopManagedGatewaysOnShutdown()).toBe(false)
process.env.NODE_ENV = 'production'
expect(shouldStopManagedGatewaysOnShutdown()).toBe(true)
})
it('allows operators to force either managed gateway shutdown policy', () => {
process.env.NODE_ENV = 'development'
process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN = '1'
expect(shouldStopManagedGatewaysOnShutdown()).toBe(true)
process.env.NODE_ENV = 'production'
process.env.HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN = '0'
expect(shouldStopManagedGatewaysOnShutdown()).toBe(false)
})
it('keeps desktop shutdown force-exit timing long enough for runtime cleanup by default', () => {
delete process.env.HERMES_WEB_UI_SHUTDOWN_FORCE_EXIT_MS
delete process.env.HERMES_DESKTOP
expect(getShutdownForceExitMs()).toBe(15_000)
process.env.HERMES_DESKTOP = 'true'
expect(getShutdownForceExitMs()).toBe(15_000)
})
it('allows operators to override shutdown force-exit timing', () => {
process.env.HERMES_DESKTOP = 'true'
process.env.HERMES_WEB_UI_SHUTDOWN_FORCE_EXIT_MS = '7000'
expect(getShutdownForceExitMs()).toBe(7_000)
})
})