Files
hermes-ui/tests/server/terminal-cwd.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

50 lines
1.7 KiB
TypeScript

import { mkdtempSync, mkdirSync, rmSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { afterEach, describe, expect, it } from 'vitest'
import { canOpenTerminal, resolveTerminalCwd } from '../../packages/server/src/routes/hermes/terminal'
const tmpRoots: string[] = []
function makeTmpRoot() {
const root = mkdtempSync(join(tmpdir(), 'wui-terminal-cwd-'))
tmpRoots.push(root)
return root
}
afterEach(() => {
for (const root of tmpRoots.splice(0)) rmSync(root, { recursive: true, force: true })
})
describe('terminal cwd resolution', () => {
it('defaults terminal sessions to the active Hermes profile directory', () => {
const profileDir = makeTmpRoot()
expect(resolveTerminalCwd({}, profileDir)).toBe(profileDir)
})
it('resolves relative configured cwd from the Hermes profile directory', () => {
const profileDir = makeTmpRoot()
mkdirSync(join(profileDir, 'workspace'))
expect(resolveTerminalCwd({ cwd: 'workspace' }, profileDir)).toBe(join(profileDir, 'workspace'))
})
it('uses absolute configured cwd when it exists', () => {
const profileDir = makeTmpRoot()
const cwd = makeTmpRoot()
expect(resolveTerminalCwd({ cwd }, profileDir)).toBe(cwd)
})
it('falls back to the profile directory when configured cwd is missing', () => {
const profileDir = makeTmpRoot()
expect(resolveTerminalCwd({ cwd: 'missing' }, profileDir)).toBe(profileDir)
})
})
describe('terminal authorization', () => {
it('only allows super administrators to open terminal websocket sessions', () => {
expect(canOpenTerminal({ role: 'super_admin' })).toBe(true)
expect(canOpenTerminal({ role: 'admin' })).toBe(false)
expect(canOpenTerminal(null)).toBe(false)
})
})