From b84db8983d63a9a981083ebce1a139860c6bdf25 Mon Sep 17 00:00:00 2001
From: chunhualin1 <chunhualin1@lenovo.com>
Date: 星期五, 14 八月 2026 15:35:21 +0800
Subject: [PATCH] commit

---
 src/Moli.Desktop.Tests/WebView/PluginBridgeDispatcherTests.cs |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/src/Moli.Desktop.Tests/WebView/PluginBridgeDispatcherTests.cs b/src/Moli.Desktop.Tests/WebView/PluginBridgeDispatcherTests.cs
index 5c441e8..d012cfa 100644
--- a/src/Moli.Desktop.Tests/WebView/PluginBridgeDispatcherTests.cs
+++ b/src/Moli.Desktop.Tests/WebView/PluginBridgeDispatcherTests.cs
@@ -67,6 +67,64 @@
         var json = JsonSerializer.Serialize(response.Result, new JsonSerializerOptions(JsonSerializerDefaults.Web));
         Assert.Contains("gpt-test", json);
         Assert.DoesNotContain("endpoint", json, StringComparison.OrdinalIgnoreCase);
+        Assert.DoesNotContain("baseUrl", json, StringComparison.OrdinalIgnoreCase);
+        Assert.DoesNotContain("authRef", json, StringComparison.OrdinalIgnoreCase);
+    }
+
+    [Fact]
+    public async Task DispatchAsync_ReturnsLlmModelsFromPluginConfig()
+    {
+        var dispatcher = CreateDispatcher(out _, out _);
+        var context = CreateContext(configJson: """
+        {
+          "mode": "provider-direct",
+          "defaultModel": "configured-model",
+          "models": [
+            {
+              "id": "configured-model",
+              "label": "Configured Model",
+              "provider": "test",
+              "endpoint": "https://example.test/chat",
+              "apiModel": "configured-model",
+              "supportsStreaming": true,
+              "enabled": true
+            }
+          ]
+        }
+        """);
+
+        var response = await dispatcher.DispatchAsync("""{"id":"40","method":"llm.getModels"}""", context);
+
+        Assert.True(response.Success);
+        var json = JsonSerializer.Serialize(response.Result, new JsonSerializerOptions(JsonSerializerDefaults.Web));
+        Assert.Contains("configured-model", json);
+    }
+
+    [Fact]
+    public async Task DispatchAsync_ReturnsAiChatProjects()
+    {
+        var dispatcher = CreateDispatcher(out _, out _);
+
+        var response = await dispatcher.DispatchAsync("""{"id":"41","method":"llm.getProjects"}""", CreateContext());
+
+        Assert.True(response.Success);
+        var json = JsonSerializer.Serialize(response.Result, new JsonSerializerOptions(JsonSerializerDefaults.Web));
+        Assert.Contains("project-1", json);
+        Assert.Contains("ready", json);
+    }
+
+    [Fact]
+    public async Task DispatchAsync_ReturnsMemoryRecallResult()
+    {
+        var dispatcher = CreateDispatcher(out _, out _);
+
+        var response = await dispatcher.DispatchAsync(
+            """{"id":"42","method":"llm.recallMemories","params":{"query":"hello","scope":"PROJECT","projectId":"project-1","limit":8}}""",
+            CreateContext());
+
+        Assert.True(response.Success);
+        var json = JsonSerializer.Serialize(response.Result, new JsonSerializerOptions(JsonSerializerDefaults.Web));
+        Assert.Contains("remember this", json);
     }
 
     [Fact]
@@ -116,6 +174,8 @@
         Assert.Contains("getRuntimeInfo", script);
         Assert.Contains("requestResize", script);
         Assert.Contains("llm", script);
+        Assert.Contains("getProjects", script);
+        Assert.Contains("recallMemories", script);
         Assert.Contains("streamChat", script);
         Assert.Contains("moliDesktopResponse", script);
     }
@@ -129,7 +189,7 @@
         return new PluginBridgeDispatcher(diagnostics, events, new FakeLlmGateway());
     }
 
-    private static PluginBridgeContext CreateContext(bool includeLlmPermission = true)
+    private static PluginBridgeContext CreateContext(bool includeLlmPermission = true, string configJson = """{"label":"clock"}""")
     {
         return new PluginBridgeContext
         {
@@ -149,13 +209,15 @@
                 PluginType = PluginType.Widget,
                 HostId = "host-1"
             },
-            Config = JsonDocument.Parse("""{"label":"clock"}""").RootElement.Clone()
+            Config = JsonDocument.Parse(configJson).RootElement.Clone()
         };
     }
 
     private sealed class FakeLlmGateway : ILlmGatewayService
     {
         public Task CancelAsync(string requestId, CancellationToken cancellationToken = default) => Task.CompletedTask;
+
+        public Task CancelPluginRequestsAsync(string pluginId, CancellationToken cancellationToken = default) => Task.CompletedTask;
 
         public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(CancellationToken cancellationToken = default)
             => Task.FromResult<IReadOnlyList<LlmModelSummary>>(
@@ -170,6 +232,46 @@
                 }
             ]);
 
+        public Task<IReadOnlyList<LlmModelSummary>> GetModelsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+            => runtimeConfig.Models.Count > 0
+                ? Task.FromResult<IReadOnlyList<LlmModelSummary>>(runtimeConfig.Models
+                    .Where(model => model.Enabled)
+                    .Select(model => new LlmModelSummary
+                    {
+                        Id = model.Id,
+                        Label = model.Label,
+                        Provider = model.Provider,
+                        SupportsStreaming = model.SupportsStreaming,
+                        Enabled = model.Enabled
+                    })
+                    .ToList())
+                : GetModelsAsync(cancellationToken);
+
+        public Task<AiChatProjectsResult> GetProjectsAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+            => Task.FromResult(new AiChatProjectsResult
+            {
+                Status = AiChatProjectStatuses.Ready,
+                Projects =
+                [
+                    new AiChatProjectSummary { Id = "project-1", Name = "Project 1" }
+                ]
+            });
+
+        public Task<AiChatMemoryCapabilities> GetMemoryCapabilitiesAsync(LlmPluginRuntimeConfig runtimeConfig, CancellationToken cancellationToken = default)
+            => Task.FromResult(new AiChatMemoryCapabilities { CanUseMemory = true, CanViewMemory = true, CanManageMemory = true });
+
+        public Task<AiChatJsonResult> GetMemoriesAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatGetMemoriesRequest request, CancellationToken cancellationToken = default)
+            => Task.FromResult(new AiChatJsonResult { Data = new[] { new { id = "mem-1", content = "remember this" } } });
+
+        public Task<AiChatJsonResult> CreateMemoryAsync(LlmPluginRuntimeConfig runtimeConfig, AiChatCreateMemoryRequest request, CancellationToken cancellationToken = default)
+            => Task.FromResult(new AiChatJsonResult { Data = new { id = "mem-2", content = request.Content } });
+
+        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 { Data = new { items = new[] { new { id = "mem-1", content = "remember this" } } } });
+
         public async IAsyncEnumerable<LlmStreamEvent> StreamChatAsync(
             LlmChatRequest request,
             [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)

--
Gitblit v1.9.1