W17: extract ai_common shared module + fix anthropic data race + brace bugs
- New plugins_upper/ai_common/ static library: shared PluginConfig, ToolCallAccum, StreamContext, secure_zero, extract_host_port, serialize_tool_calls, free_chat_result - Refactored openai/anthropic plugins to use dstalk_ai:: namespace from ai_common - Fixed anthropic g_config raw pointer → std::atomic (data race) - Added SSE parse error counter with threshold abort (kMaxSseParseErrors=5) - Fixed missing closing brace in both plugins' error-body catch block - Updated test targets: ai_common include path + link, using namespace dstalk_ai - plugin_loader_test: added stub_unreg + service_registry.cpp for unregister_service - Includes pre-existing uncommitted changes from prior waves Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -186,7 +186,7 @@ int main()
|
||||
// 测试服务查询: ai(可能因为没有真实 API key 而失败,但服务应存在)
|
||||
// Test service query: ai (may fail without real API key, but service should exist)
|
||||
const char* ai_provider = dstalk_config_get("ai.provider");
|
||||
if (!ai_provider) ai_provider = "ai.openai";
|
||||
if (!ai_provider) ai_provider = "ai_openai";
|
||||
auto* ai = static_cast<const dstalk_ai_service_t*>(
|
||||
dstalk_service_query(ai_provider, 1));
|
||||
if (ai) {
|
||||
@@ -598,12 +598,12 @@ int main()
|
||||
std::cout << "[OK] R3: http error path, no response body (connection refused)\n";
|
||||
}
|
||||
} else {
|
||||
// 回退:测 AI 服务 (ai.openai) 错误路径
|
||||
// Fallback: test AI service (ai.openai) error path
|
||||
// 回退:测 AI 服务 (ai_openai) 错误路径
|
||||
// Fallback: test AI service (ai_openai) error path
|
||||
auto* ai_svc = static_cast<const dstalk_ai_service_t*>(
|
||||
dstalk_service_query("ai.openai", 1));
|
||||
dstalk_service_query("ai_openai", 1));
|
||||
if (ai_svc) {
|
||||
std::cout << "[OK] R3: ai.openai service found (http fallback)\n";
|
||||
std::cout << "[OK] R3: ai_openai service found (http fallback)\n";
|
||||
dstalk_message_t msg = {"user", "hi", nullptr, nullptr};
|
||||
dstalk_chat_result_t r = ai_svc->chat(&msg, 1, "", nullptr);
|
||||
// api_key="test-key" 为无效 key,应返回 error result 而非崩溃
|
||||
|
||||
Reference in New Issue
Block a user