| 1 | using AgentNotes.Core; |
| 2 | using CascadeIDE.Models; |
| 3 | using CascadeIDE.Services; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class AgentNotesRuntimeLoaderTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void EnsureInitialized_loads_primary_root_from_config_path() |
| 12 | { |
| 13 | var root = Path.Combine(Path.GetTempPath(), "cascade-anl-" + Guid.NewGuid().ToString("n")); |
| 14 | Directory.CreateDirectory(Path.Combine(root, "knowledge", "work", "local")); |
| 15 | var tomlPath = Path.Combine(root, "agent-notes.toml"); |
| 16 | File.WriteAllText( |
| 17 | tomlPath, |
| 18 | $""" |
| 19 | version = 1 |
| 20 | [knowledge] |
| 21 | primary = "test" |
| 22 | [knowledge.roots] |
| 23 | test = "{root.Replace('\\', '/')}" |
| 24 | [workspace] |
| 25 | default_scope = "door-to-singularity" |
| 26 | scope_map = "work/local/workspace-scope-map-v1.md" |
| 27 | scope_aliases = "work/local/scope-alias-map-v1.md" |
| 28 | """); |
| 29 | File.WriteAllText(Path.Combine(root, "knowledge", "work", "local", "workspace-scope-map-v1.md"), "# map\n"); |
| 30 | |
| 31 | try |
| 32 | { |
| 33 | var settings = new CascadeIdeSettings { AgentNotes = new AgentNotesSettings { ConfigPath = tomlPath } }; |
| 34 | Assert.True(AgentNotesRuntimeLoader.EnsureInitialized(settings)); |
| 35 | Assert.True(AgentNotesRuntime.TryGetPrimaryKnowledgeRoot(out var primary)); |
| 36 | Assert.Equal(Path.GetFullPath(root), Path.GetFullPath(primary)); |
| 37 | } |
| 38 | finally |
| 39 | { |
| 40 | AgentNotesRuntimeLoader.Reset(); |
| 41 | try |
| 42 | { |
| 43 | Directory.Delete(root, recursive: true); |
| 44 | } |
| 45 | catch |
| 46 | { |
| 47 | // best-effort |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |