serviceCli.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { mkdtempSync, rmSync, symlinkSync } from 'node:fs'
  2. import { homedir, tmpdir } from 'node:os'
  3. import { join } from 'node:path'
  4. import { describe, expect, it } from 'vitest'
  5. import { isMainModule, launchAgentPlist } from '../bin/hermes-yaoyao.mjs'
  6. describe('hermes-yaoyao LaunchAgent plist', () => {
  7. it('includes the local Hermes CLI directory in PATH', () => {
  8. const plist = launchAgentPlist()
  9. expect(plist).toContain(`${join(homedir(), '.local', 'bin')}:`)
  10. })
  11. it('enables Dashboard supervision by default', () => {
  12. expect(launchAgentPlist()).toContain('<key>HERMES_YAOYAO_SUPERVISE_DASHBOARD</key>')
  13. })
  14. it('can point the managed service at the stable current release link', () => {
  15. const root = join(homedir(), '.local', 'share', 'hermes-yaoyao', 'current')
  16. const plist = launchAgentPlist({ serviceRoot: root })
  17. expect(plist).toContain(`<string>${join(root, 'dist-server', 'server', 'index.js')}</string>`)
  18. expect(plist).toContain(`<key>WorkingDirectory</key><string>${root}</string>`)
  19. })
  20. it('runs the CLI when its entry path uses the stable current symlink', () => {
  21. const root = mkdtempSync(join(tmpdir(), 'hermes-service-cli-'))
  22. const entry = join(root, 'hermes-yaoyao.mjs')
  23. symlinkSync(join(process.cwd(), 'bin', 'hermes-yaoyao.mjs'), entry)
  24. try {
  25. expect(isMainModule(entry)).toBe(true)
  26. } finally {
  27. rmSync(root, { recursive: true, force: true })
  28. }
  29. })
  30. })