mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-11 02:55:51 +00:00
Reuse loaded AI config when restarting stopped service
This commit is contained in:
@@ -311,6 +311,10 @@ type AIStateProvider interface {
|
||||
func (h *AIHandler) Start(ctx context.Context, stateProvider AIStateProvider) error {
|
||||
log.Info().Msg("AIHandler.Start called")
|
||||
aiCfg := h.loadAIConfig(ctx)
|
||||
return h.startWithConfig(ctx, stateProvider, aiCfg)
|
||||
}
|
||||
|
||||
func (h *AIHandler) startWithConfig(ctx context.Context, stateProvider AIStateProvider, aiCfg *config.AIConfig) error {
|
||||
if aiCfg == nil {
|
||||
log.Info().Msg("AI config is nil, AI is disabled")
|
||||
return nil
|
||||
@@ -396,7 +400,7 @@ func (h *AIHandler) Restart(ctx context.Context) error {
|
||||
}
|
||||
h.stateProvidersMu.RUnlock()
|
||||
|
||||
return h.Start(ctx, sp)
|
||||
return h.startWithConfig(ctx, sp, newCfg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ func TestRestart_StartsStoppedServiceWithSavedStateProvider(t *testing.T) {
|
||||
assert.Equal(t, "data", capturedCfg.DataDir)
|
||||
}
|
||||
|
||||
func TestStart_AllowsEmptyPersistenceDataDir(t *testing.T) {
|
||||
func TestStart_DefaultsEmptyPersistenceDataDir(t *testing.T) {
|
||||
oldNewService := newChatService
|
||||
defer func() { newChatService = oldNewService }()
|
||||
|
||||
@@ -327,7 +327,7 @@ func TestStart_AllowsEmptyPersistenceDataDir(t *testing.T) {
|
||||
|
||||
err := h.Start(context.Background(), mockState)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", capturedCfg.DataDir)
|
||||
assert.Equal(t, "data", capturedCfg.DataDir)
|
||||
assert.Same(t, mockState, capturedCfg.StateProvider)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user