Files
kandev/apps/backend/internal/agentctl/server/process/testing_helpers.go
T
2026-07-11 12:31:21 +01:00

46 lines
1.2 KiB
Go

package process
import (
"time"
"github.com/kandev/kandev/internal/agentctl/server/adapter"
)
// SetAdapterForTest injects an adapter without starting a real agent process.
// Intended for API handler tests that need to exercise adapter interactions.
func (m *Manager) SetAdapterForTest(a adapter.AgentAdapter) {
m.mu.Lock()
defer m.mu.Unlock()
m.adapter = a
}
// SetVscodeForTest injects a VscodeManager with the given status and port.
// Intended for use in tests where starting a real code-server is not feasible.
func (m *Manager) SetVscodeForTest(status VscodeStatus, port int) {
m.vscodeMu.Lock()
defer m.vscodeMu.Unlock()
m.vscode = &VscodeManager{
status: status,
port: port,
}
}
// SetVscodeTransitionForTest injects a VscodeManager that starts in the given
// status and transitions to VscodeStatusRunning after the specified delay.
// Useful for testing code that calls WaitForRunning.
func (m *Manager) SetVscodeTransitionForTest(initialStatus VscodeStatus, port int, delay time.Duration) {
m.vscodeMu.Lock()
defer m.vscodeMu.Unlock()
vm := &VscodeManager{
status: initialStatus,
port: port,
}
m.vscode = vm
go func() {
time.Sleep(delay)
vm.mu.Lock()
vm.status = VscodeStatusRunning
vm.mu.Unlock()
}()
}