Forge
csharpc0b81713
1using AgentNotes.Core;
2
3namespace AgentNotesMcp.Tests;
4
5/// <summary>Fixture TOML и <see cref="AgentNotesRuntime"/> для интеграционных тестов (MCP 2.0).</summary>
6internal static class AgentNotesTestToml
7{
8 internal static string Write(
9 string knowledgeRoot,
10 string defaultScope = "door-to-singularity",
11 string scopeMap = "work/local/workspace-scope-map-v1.md",
12 string scopeAliases = "work/local/scope-alias-map-v1.md")
13 {
14 var root = knowledgeRoot.Replace('\\', '/');
15 var toml = $"""
16 version = 1
17
18 [knowledge]
19 primary = "test"
20
21 [knowledge.roots]
22 test = "{root}"
23
24 [workspace]
25 default_scope = "{defaultScope}"
26 scope_map = "{scopeMap}"
27 scope_aliases = "{scopeAliases}"
28
29 [status]
30 enabled = false
31 port = 17341
32 bind = "127.0.0.1"
33 """;
34 var path = Path.Combine(Path.GetTempPath(), "AgentNotesMcpTests", $"cfg-{Guid.NewGuid():N}.toml");
35 Directory.CreateDirectory(Path.GetDirectoryName(path)!);
36 File.WriteAllText(path, toml);
37 return path;
38 }
39
40 internal static string WriteFromEmbeddedTemplate(string knowledgeRoot)
41 {
42 var templatePath = Path.Combine(AppContext.BaseDirectory, "Fixtures", "minimal.local.toml");
43 var text = File.ReadAllText(templatePath).Replace("PLACEHOLDER_ROOT", knowledgeRoot.Replace('\\', '/'));
44 var path = Path.Combine(Path.GetTempPath(), "AgentNotesMcpTests", $"cfg-{Guid.NewGuid():N}.toml");
45 Directory.CreateDirectory(Path.GetDirectoryName(path)!);
46 File.WriteAllText(path, text);
47 return path;
48 }
49
50 internal static RuntimeScope Install(string tomlPath)
51 {
52 var settings = LocalSettingsLoader.Load(tomlPath);
53 AgentNotesRuntime.Initialize(settings, tomlPath);
54 return new RuntimeScope();
55 }
56
57 internal static RuntimeScope InstallForRoot(string knowledgeRoot, string? scopeMap = null, string? scopeAliases = null) =>
58 Install(Write(
59 knowledgeRoot,
60 scopeMap: scopeMap ?? "work/local/workspace-scope-map-v1.md",
61 scopeAliases: scopeAliases ?? "work/local/scope-alias-map-v1.md"));
62
63 internal sealed class RuntimeScope : IDisposable
64 {
65 public void Dispose() => AgentNotesRuntime.ClearConfiguration();
66 }
67}
68
View only · write via MCP/CIDE