From fadb5d75c4f55805d2a794ea5c46a33af9a8c164 Mon Sep 17 00:00:00 2001 From: Reviewer Date: Sun, 14 Jun 2026 09:20:28 +0200 Subject: [PATCH] Fix AgentService tests fixture path --- backend-tests/AgentServiceTests.cs | 70 ++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/backend-tests/AgentServiceTests.cs b/backend-tests/AgentServiceTests.cs index 03b9db6..b891197 100644 --- a/backend-tests/AgentServiceTests.cs +++ b/backend-tests/AgentServiceTests.cs @@ -11,12 +11,8 @@ public class AgentServiceTests [Fact] public async Task GetAgentsAsync_ReturnsCorrectCount() { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - ["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json" - }) - .Build(); + var configPath = CreateAgentConfigFile(); + var config = CreateConfiguration(configPath); var runtime = new FakeRuntime(); var service = new AgentService(config, runtime); @@ -27,12 +23,8 @@ public class AgentServiceTests [Fact] public async Task GetAgentAsync_Iris_ReturnsOrchestrator() { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - ["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json" - }) - .Build(); + var configPath = CreateAgentConfigFile(); + var config = CreateConfiguration(configPath); var runtime = new FakeRuntime(); var service = new AgentService(config, runtime); @@ -44,18 +36,60 @@ public class AgentServiceTests [Fact] public async Task GetAgentAsync_Unknown_ReturnsNull() { - var config = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - ["AgentConfigPath"] = "/home/node/.openclaw/openclaw.json" - }) - .Build(); + var configPath = CreateAgentConfigFile(); + var config = CreateConfiguration(configPath); var runtime = new FakeRuntime(); var service = new AgentService(config, runtime); var agent = await service.GetAgentAsync("nonexistent", CancellationToken.None); Assert.Null(agent); } + + private static IConfiguration CreateConfiguration(string configPath) + => new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + ["AgentConfigPath"] = configPath + }) + .Build(); + + private static string CreateAgentConfigFile() + { + var path = Path.Combine(Path.GetTempPath(), $"agent-config-{Guid.NewGuid():N}.json"); + File.WriteAllText(path, + """ + { + "agents": { + "defaults": { + "workspace": "/workspace/default", + "model": { + "primary": "deepseek/deepseek-v4-flash" + } + }, + "list": [ + { + "id": "iris", + "name": "iris" + }, + { + "id": "programmer", + "name": "programmer" + }, + { + "id": "reviewer", + "name": "reviewer" + }, + { + "id": "architekt", + "name": "architekt" + } + ] + } + } + """); + + return path; + } } public sealed class FakeRuntime : IAgentRuntime