computerFailures.test.ts 1.1 KB

1234567891011121314151617181920
  1. import {describe,expect,it} from 'vitest'
  2. import {HttpError} from '../../src/server/errors.js'
  3. import {ComputerError} from '../../src/runner/computers/container.js'
  4. import {needsVmLease,softComputerFailure} from '../../src/runner/computers/computerFailures.js'
  5. describe('computerFailures',()=>{
  6. it('treats pool/env codes and ComputerError as soft tool failures',()=>{
  7. expect(softComputerFailure(new ComputerError('computer_busy','电脑正在使用或需要核对停止状态'))).toBe(true)
  8. expect(softComputerFailure(new HttpError(409,'请先准备','computer_image_required'))).toBe(true)
  9. expect(softComputerFailure(new HttpError(502,'模型失败','run_failed'))).toBe(false)
  10. expect(softComputerFailure(new Error('random'))).toBe(false)
  11. })
  12. it('requires a VM lease only for computer_* and skill tools, not host or team tools',()=>{
  13. expect(needsVmLease('computer_shell')).toBe(true)
  14. expect(needsVmLease('computer_desktop_state')).toBe(true)
  15. expect(needsVmLease('skills_list',[],['skills_list'])).toBe(true)
  16. expect(needsVmLease('host_shell')).toBe(false)
  17. expect(needsVmLease('team_ping',['team_ping'])).toBe(false)
  18. })
  19. })