H-354: cover Captain provider timeout (#67)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-21 13:10:04 +08:00
committed by GitHub
co-authored by rogee
parent 038f185b57
commit 181e9051ec
@@ -459,6 +459,20 @@ func TestCaptainAssistantHandler_PlaygroundEmbeddingFailureFailsClosed(t *testin
assert.Zero(t, provider.calls)
}
func TestCaptainAssistantHandler_PlaygroundProviderTimeoutFailsClosed(t *testing.T) {
provider := &captainPlaygroundFakeProvider{embeddingErr: &net.OpError{Op: "read", Net: "tcp", Err: context.DeadlineExceeded}}
router, db := setupCaptainAssistantHandlerTestWithProvider(t, provider)
account := seedCaptainAssistantAccount(t, db, "Captain Org")
assistant := &model.CaptainAssistant{AccountID: account.ID, Name: "Fin", Status: model.AssistantStatusActive}
require.NoError(t, db.Create(assistant).Error)
w := captainAssistantJSONRequest(t, router, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/captain/assistants/%d/playground", account.ID, assistant.ID), map[string]any{"message_content": "Hello assistant"})
assert.Equal(t, http.StatusGatewayTimeout, w.Code)
assert.JSONEq(t, `{"success":false,"error":{"code":"COPILOT_PROVIDER_TIMEOUT","message":"Copilot provider request timed out"}}`, w.Body.String())
assert.Equal(t, 1, provider.embeddingCalls)
assert.Zero(t, provider.calls)
}
func TestCaptainAssistantHandler_PlaygroundEmptyEmbeddingFailsClosed(t *testing.T) {
for name, embeddingResponse := range map[string]*llm.EmbeddingResponse{
"nil response": nil,