From df6a437518d89eebfa1a583e09ec99c462e64e47 Mon Sep 17 00:00:00 2001
From: Moli <13026959681@163.com>
Date: 星期三, 12 八月 2026 20:42:12 +0800
Subject: [PATCH] 移除发布文件的跟踪
---
src/Moli.Desktop.Tests/Llm/LlmGatewayServiceTests.cs | 76 +++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 1 deletions(-)
diff --git a/src/Moli.Desktop.Tests/Llm/LlmGatewayServiceTests.cs b/src/Moli.Desktop.Tests/Llm/LlmGatewayServiceTests.cs
index 50b76ed..cfabb6e 100644
--- a/src/Moli.Desktop.Tests/Llm/LlmGatewayServiceTests.cs
+++ b/src/Moli.Desktop.Tests/Llm/LlmGatewayServiceTests.cs
@@ -88,7 +88,43 @@
Assert.Contains(events, item => item is LlmDeltaEvent { Delta: "ok" });
}
+ [Fact]
+ public async Task StreamChatAsync_UsesAiChatClientWhenModeIsAiChatApi()
+ {
+ var aiChat = new FakeAiChatClient();
+ var gateway = CreateGateway(
+ new CapturingAdapter("openai-compatible"),
+ aiChat,
+ new LlmModelConfig
+ {
+ Id = "provider-model",
+ Label = "Provider",
+ Provider = "openai-compatible",
+ Endpoint = "http://127.0.0.1:11434/v1/chat/completions",
+ ApiModel = "provider-model",
+ Enabled = true
+ });
+
+ var events = await gateway.StreamChatAsync(new LlmChatRequest
+ {
+ RequestId = "req-aichat",
+ PluginId = "sample.llm-command-palette",
+ InstanceId = "host-1",
+ Mode = LlmConnectionModes.AiChatApi,
+ ProjectId = "project-1",
+ ModelId = "deepseek-v4-flash",
+ Messages = [new LlmMessage { Role = "user", Content = "hello" }],
+ RuntimeConfig = new LlmPluginRuntimeConfig { Mode = LlmConnectionModes.AiChatApi }
+ }).ToListAsync();
+
+ Assert.Equal("project-1", aiChat.LastRequest?.ProjectId);
+ Assert.Contains(events, item => item is LlmDeltaEvent { Delta: "from-aichat" });
+ }
+
private static LlmGatewayService CreateGateway(CapturingAdapter adapter, params LlmModelConfig[] models)
+ => CreateGateway(adapter, null, models);
+
+ private static LlmGatewayService CreateGateway(CapturingAdapter adapter, IAiChatClient? aiChatClient, params LlmModelConfig[] models)
{
var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N"));
var paths = new DesktopPaths(Path.Combine(root, "app"), Path.Combine(root, "local"));
@@ -97,7 +133,8 @@
new InMemoryRegistry(models),
new EnvironmentCredentialStore(),
new LlmProviderAdapterFactory([adapter]),
- diagnostics);
+ diagnostics,
+ aiChatClient);
}
private sealed class InMemoryRegistry(IEnumerable<LlmModelConfig> models) : ILlmModelRegistry
@@ -126,6 +163,43 @@
yield return new LlmProviderChunk { IsCompleted = true };
}
}
+
+ private sealed class FakeAiChatClient : IAiChatClient
+ {
+ public LlmChatRequest? LastRequest { get; private set; }
+
+ public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult<IReadOnlyList<LlmModelSummary>>([]);
+
+ public Task<IReadOnlyList<AiChatProjectSummary>> GetProjectsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult<IReadOnlyList<AiChatProjectSummary>>([]);
+
+ public async IAsyncEnumerable<LlmStreamEvent> StreamChatAsync(
+ LlmChatRequest request,
+ LlmPluginRuntimeConfig runtimeConfig,
+ [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
+ {
+ await Task.Yield();
+ LastRequest = request;
+ yield return new LlmDeltaEvent { RequestId = request.RequestId, Delta = "from-aichat" };
+ yield return new LlmCompletedEvent { RequestId = request.RequestId };
+ }
+
+ public Task<AiChatMemoryCapabilities> GetMemoryCapabilitiesAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatMemoryCapabilities());
+
+ public Task<AiChatJsonResult> GetMemoriesAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatGetMemoriesRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+
+ public Task<AiChatJsonResult> CreateMemoryAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatCreateMemoryRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+
+ public Task DeleteMemoryAsync(LlmPluginRuntimeConfig runtimeConfig, string memoryId, CancellationToken cancellationToken = default)
+ => Task.CompletedTask;
+
+ public Task<AiChatJsonResult> RecallMemoriesAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatRecallMemoriesRequest request, CancellationToken cancellationToken = default)
+ => Task.FromResult(new AiChatJsonResult());
+ }
}
internal static class AsyncEnumerableTestExtensions
--
Gitblit v1.9.1