| 1 | using AgentNotes.Core; |
| 2 | using System.Text; |
| 3 | |
| 4 | namespace AgentNotesMcp.Tests; |
| 5 | |
| 6 | /// <summary>Smoke against repo <c>group-kb</c> and a local <c>git clone</c> (see ADR 015).</summary> |
| 7 | public sealed class GroupKbCloneIntegrationTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void ReadSmoke_FromRepoGroupKb_WhenPresent() |
| 11 | { |
| 12 | var groupKb = FindSiblingDirectory("group-kb"); |
| 13 | if (groupKb is null) |
| 14 | return; |
| 15 | |
| 16 | using var primary = LocalSettingsLoaderTests.TempKnowledgeRoot.Create(); |
| 17 | using var runtime = InstallGroupReadOnly(primary.Path, groupKb); |
| 18 | var storage = new NotesStorage(); |
| 19 | var text = storage.ReadKnowledgeFile(null, "group/smoke-test-v1.md", knowledgeRootId: "group"); |
| 20 | Assert.Contains("group-kb smoke", text, StringComparison.Ordinal); |
| 21 | } |
| 22 | |
| 23 | [Fact] |
| 24 | public void ReadSmoke_FromClonedGroupKb_WhenPresent() |
| 25 | { |
| 26 | var clone = FindSiblingDirectory("group-kb-clone"); |
| 27 | if (clone is null) |
| 28 | return; |
| 29 | |
| 30 | using var primary = LocalSettingsLoaderTests.TempKnowledgeRoot.Create(); |
| 31 | using var runtime = InstallGroupReadOnly(primary.Path, clone); |
| 32 | var storage = new NotesStorage(); |
| 33 | var text = storage.ReadKnowledgeFile(null, "group/smoke-test-v1.md", knowledgeRootId: "group"); |
| 34 | Assert.Contains("group-kb smoke", text, StringComparison.Ordinal); |
| 35 | } |
| 36 | |
| 37 | private static AgentNotesTestToml.RuntimeScope InstallGroupReadOnly(string primaryPath, string groupPath) |
| 38 | { |
| 39 | var toml = $""" |
| 40 | version = 1 |
| 41 | |
| 42 | [knowledge] |
| 43 | primary = "test" |
| 44 | |
| 45 | [knowledge.roots] |
| 46 | test = "{primaryPath.Replace('\\', '/')}" |
| 47 | |
| 48 | [[knowledge.read_only]] |
| 49 | id = "group" |
| 50 | path = "{groupPath.Replace('\\', '/')}" |
| 51 | |
| 52 | [workspace] |
| 53 | default_scope = "door-to-singularity" |
| 54 | scope_map = "work/local/workspace-scope-map-v1.md" |
| 55 | scope_aliases = "work/local/scope-alias-map-v1.md" |
| 56 | |
| 57 | [status] |
| 58 | enabled = false |
| 59 | """; |
| 60 | var path = Path.Combine(Path.GetTempPath(), "AgentNotesMcpTests", $"cfg-{Guid.NewGuid():N}.toml"); |
| 61 | Directory.CreateDirectory(Path.GetDirectoryName(path)!); |
| 62 | File.WriteAllText(path, toml, Encoding.UTF8); |
| 63 | return AgentNotesTestToml.Install(path); |
| 64 | } |
| 65 | |
| 66 | private static string? FindSiblingDirectory(string name) |
| 67 | { |
| 68 | var dir = AppContext.BaseDirectory; |
| 69 | for (var i = 0; i < 12 && !string.IsNullOrEmpty(dir); i++) |
| 70 | { |
| 71 | var candidate = Path.Combine(dir, name); |
| 72 | if (File.Exists(Path.Combine(candidate, "knowledge", "group", "smoke-test-v1.md"))) |
| 73 | return Path.GetFullPath(candidate); |
| 74 | dir = Path.GetDirectoryName(dir); |
| 75 | } |
| 76 | |
| 77 | return null; |
| 78 | } |
| 79 | } |
| 80 | |