Jest to Vitest Conversion Summary
File: `src/lib/__tests__/agent-governance.test.ts`
Conversion Status: IN PROGRESS
Completed:
- ✅ Imported
vifrom vitest - ✅ Changed
jest.fn()tovi.fn() - ✅ Changed
jest.clearAllMocks()tovi.clearAllMocks() - ✅ Changed
jest.useFakeTimers()tovi.useFakeTimers() - ✅ Changed
jest.useRealTimers()tovi.useRealTimers() - ✅ Changed
jest.advanceTimersByTime()tovi.advanceTimersByTime() - ✅ Changed
jest.spyOn()tovi.spyOn() - ✅ Created
mockFetchvariable instead of casting global.fetch - ✅ Added
clone()method to mock response - ✅ Created
createMockBackendResponse()helper
Remaining Work:
The test failures are due to API contract mismatches, not vitest conversion issues:
- **API Endpoint**: Tests expect
/api/v1/agent-governance/evaluatebut implementation uses/api/v1/agent-governance/enforce-action - **Request Body**: Tests use
contextfield but implementation usesaction_details - **Response Format**: Tests use frontend format
{allowed, reason, ...}but backend returns{proceed, status, reason, ...} - **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.