ATOM Documentation

← Back to App

Jest to Vitest Conversion Summary

File: `src/lib/__tests__/agent-governance.test.ts`

Conversion Status: IN PROGRESS

Completed:

  1. ✅ Imported vi from vitest
  2. ✅ Changed jest.fn() to vi.fn()
  3. ✅ Changed jest.clearAllMocks() to vi.clearAllMocks()
  4. ✅ Changed jest.useFakeTimers() to vi.useFakeTimers()
  5. ✅ Changed jest.useRealTimers() to vi.useRealTimers()
  6. ✅ Changed jest.advanceTimersByTime() to vi.advanceTimersByTime()
  7. ✅ Changed jest.spyOn() to vi.spyOn()
  8. ✅ Created mockFetch variable instead of casting global.fetch
  9. ✅ Added clone() method to mock response
  10. ✅ Created createMockBackendResponse() helper

Remaining Work:

The test failures are due to API contract mismatches, not vitest conversion issues:

  1. **API Endpoint**: Tests expect /api/v1/agent-governance/evaluate but implementation uses /api/v1/agent-governance/enforce-action
  2. **Request Body**: Tests use context field but implementation uses action_details
  3. **Response Format**: Tests use frontend format {allowed, reason, ...} but backend returns {proceed, status, reason, ...}
  4. **Error Messages**: Tests expect 'Backend governance service unavailable' but implementation returns 'Backend governance service unavailable (500)'

Test Results:

  • **Passing**: 6/20 tests
  • **Failing**: 14/20 tests
  • **Failure Reasons**: API contract mismatches (not vitest issues)

Recommendation:

The vitest conversion is syntactically complete. The remaining failures are due to the test file not matching the actual backend API implementation. The test scenarios are correct, but the mock data needs to match the real backend contract.

Next Steps:

To complete the conversion, update test mocks to match the actual backend API contract found in src/lib/ai/agent-governance.ts.