sessionWorkingDirectory.test.ts 1.4 KB

1234567891011121314151617181920
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { configuredWorkingDirectory, applyWorkingDirectory } from '../../src/server/sessionWorkingDirectory.js'
  3. describe('profile working directory', () => {
  4. it.each(['/remote/agent work', '~/Agents', '.'])('leaves %s to Hermes to resolve on its own host', async cwd => {
  5. const request = vi.fn(async () => ({ status: 200, headers: new Headers(), body: Buffer.from(JSON.stringify({ terminal: { cwd } })) }))
  6. expect(await configuredWorkingDirectory(request, 'work')).toBe(cwd)
  7. expect(request).toHaveBeenCalledWith('/api/config', { search: new URLSearchParams({ profile: 'work' }), cache: 'reload' })
  8. const rpc = vi.fn(async () => ({ cwd: '/resolved/on/hermes' }))
  9. expect(await applyWorkingDirectory(rpc, 'session', cwd)).toEqual({ configured: cwd, resolved: '/resolved/on/hermes' })
  10. expect(rpc).toHaveBeenCalledWith('session.cwd.set', { session_id: 'session', cwd })
  11. })
  12. it('fails closed on unreadable configuration or unconfirmed cwd', async () => {
  13. await expect(configuredWorkingDirectory(async () => ({ status: 403, headers: new Headers(), body: Buffer.from('{}') }), 'work'))
  14. .rejects.toMatchObject({ code: 'working_directory_unavailable' })
  15. await expect(applyWorkingDirectory(async () => ({}), 'session', '/configured'))
  16. .rejects.toMatchObject({ code: 'working_directory_unconfirmed' })
  17. })
  18. })