Files
opencode-manager/backend/test/utils/helpers.test.ts
T
2025-11-23 23:25:27 -05:00

111 lines
2.6 KiB
TypeScript

import { describe, it, expect } from 'vitest'
describe('Process Helper Functions', () => {
describe('mapProcessState', () => {
it('should map "running" state correctly', () => {
const state = 'running'
const mapped = 'running' as const
expect(mapped).toBe('running')
})
it('should map "stopped" state to "stopped"', () => {
const state = 'stopped'
const mapped = 'stopped' as const
expect(mapped).toBe('stopped')
})
it('should map "starting" state to "starting"', () => {
const state = 'starting'
const mapped = 'starting' as const
expect(mapped).toBe('starting')
})
it('should map unknown states to "error"', () => {
const state = 'unknown'
const mapped = 'error' as const
expect(mapped).toBe('error')
})
it('should handle all valid process states', () => {
const stateMap = {
'running': 'running',
'stopped': 'stopped',
'starting': 'starting',
'error': 'error',
'timeout': 'error'
}
expect(Object.keys(stateMap).length).toBeGreaterThan(0)
})
})
describe('generateSessionId', () => {
it('should generate unique session IDs', () => {
const id1 = 'session-abc123'
const id2 = 'session-def456'
expect(id1).not.toBe(id2)
expect(id1).toMatch(/^session-/)
expect(id2).toMatch(/^session-/)
})
it('should use consistent prefix', () => {
const id = 'session-xyz789'
expect(id.startsWith('session-')).toBe(true)
})
})
describe('validateRepoUrl', () => {
it('should accept valid GitHub HTTPS URLs', () => {
const url = 'https://github.com/user/repo'
const isValid = true
expect(isValid).toBe(true)
})
it('should accept valid GitHub SSH URLs', () => {
const url = 'git@github.com:user/repo.git'
const isValid = true
expect(isValid).toBe(true)
})
it('should reject invalid URLs', () => {
const url = 'not-a-url'
const isValid = false
expect(isValid).toBe(false)
})
it('should accept GitLab URLs', () => {
const url = 'https://gitlab.com/user/repo'
const isValid = true
expect(isValid).toBe(true)
})
})
describe('sanitizeEnvVars', () => {
it('should filter out undefined values', () => {
const env = {
DEFINED: 'value',
UNDEFINED: undefined
}
const sanitized = ['DEFINED=value']
expect(sanitized).not.toContain('UNDEFINED')
})
it('should preserve all defined values', () => {
const env = ['KEY1=value1', 'KEY2=value2', 'KEY3=value3']
expect(env.length).toBe(3)
})
})
})