Files
hermes-ui/tests/server/profile-delete-managed-gateway.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

76 lines
2.2 KiB
TypeScript

import { EventEmitter } from 'events'
import { mkdir, mkdtemp, rm, writeFile } from 'fs/promises'
import { tmpdir } from 'os'
import { join } from 'path'
import { afterEach, describe, expect, it, vi } from 'vitest'
const originalEnv = { ...process.env }
class FakeChild extends EventEmitter {
pid: number
killSignals: string[] = []
constructor(pid: number) {
super()
this.pid = pid
}
unref() { /* no-op */ }
kill(signal?: string) {
this.killSignals.push(signal || 'SIGTERM')
return true
}
}
let fakeChildren: FakeChild[] = []
vi.mock('../../packages/server/src/services/hermes/hermes-process', () => ({
execHermesWithBin: vi.fn().mockResolvedValue({ stdout: '', stderr: '' }),
spawnHermesWithBin: vi.fn(() => {
const child = new FakeChild(20000 + fakeChildren.length)
fakeChildren.push(child)
return child
}),
}))
afterEach(() => {
vi.useRealTimers()
vi.restoreAllMocks()
vi.resetModules()
process.env = { ...originalEnv }
fakeChildren = []
})
describe('profile delete managed gateway lifecycle', () => {
it('reproduces #1633 and proves delete prep suppresses managed respawn', async () => {
vi.useFakeTimers()
vi.resetModules()
const home = await mkdtemp(join(tmpdir(), 'wui-1633-'))
process.env.HERMES_HOME = home
process.env.HERMES_BIN = '/usr/bin/hermes'
const profileDir = join(home, 'profiles', 'work')
await mkdir(profileDir, { recursive: true })
await writeFile(join(profileDir, 'config.yaml'), 'model:\n default: test\n', 'utf-8')
try {
const { startGatewayRunManaged } = await import('../../packages/server/src/services/hermes/gateway-runner')
const { prepareGatewayForProfileDelete } = await import('../../packages/server/src/services/hermes/gateway-autostart')
startGatewayRunManaged('/usr/bin/hermes', { profileDir })
expect(fakeChildren).toHaveLength(1)
const prep = prepareGatewayForProfileDelete('work')
expect(fakeChildren[0].killSignals).toEqual(['SIGTERM'])
fakeChildren[0].emit('exit', 0, 'SIGTERM')
await prep
await vi.advanceTimersByTimeAsync(6000)
expect(fakeChildren).toHaveLength(1)
} finally {
await rm(home, { recursive: true, force: true })
}
})
})