Forge
csharpdeeb25a2
1using CascadeIDE.Features.EnvironmentReadiness.Application;
2using CascadeIDE.Features.EnvironmentReadiness.DataAcquisition;
3using CascadeIDE.Models;
4using CascadeIDE.Services;
5using Xunit;
6
7namespace CascadeIDE.Tests;
8
9public sealed class EnvironmentReadinessEnvProbeTests
10{
11 [Fact]
12 public void BuildEnvProbeRows_unset_notes_ok_config_and_dbg_advisory()
13 {
14 var rows = EnvironmentReadinessSnapshotBuilder.BuildEnvProbeRows(
15 new EnvironmentReadinessEnvSnapshot(null, null, null),
16 new CascadeIdeSettings(),
17 tryResolveNetcoreDbgWhenUnset: static () => null);
18
19 Assert.Equal(3, rows.Count);
20 Assert.Equal(EnvironmentReadinessCellIds.AgentNotesFile, rows[0].Id);
21 Assert.Equal(WellKnownEnv.AgentNotesFile, rows[0].Title);
22 Assert.Equal(AnnunciatorLampLevel.Ok, rows[0].Level);
23
24 Assert.Equal(EnvironmentReadinessCellIds.AgentNotesCanonPath, rows[1].Id);
25 Assert.Equal(AnnunciatorLampLevel.Advisory, rows[1].Level);
26
27 Assert.Equal(EnvironmentReadinessCellIds.NetcoreDbgPath, rows[2].Id);
28 Assert.Equal(AnnunciatorLampLevel.Advisory, rows[2].Level);
29 }
30
31 [Fact]
32 public void BuildEnvProbeRows_unset_netcoredbg_resolved_from_path_ok()
33 {
34 var rows = EnvironmentReadinessSnapshotBuilder.BuildEnvProbeRows(
35 new EnvironmentReadinessEnvSnapshot(null, null, null),
36 new CascadeIdeSettings(),
37 tryResolveNetcoreDbgWhenUnset: static () => @"C:\fake\netcoredbg.exe");
38
39 var dbg = Assert.Single(rows, r => r.Id == EnvironmentReadinessCellIds.NetcoreDbgPath);
40 Assert.Equal(AnnunciatorLampLevel.Ok, dbg.Level);
41 Assert.Contains("PATH", dbg.Detail, StringComparison.Ordinal);
42 }
43
44 [Fact]
45 public void BuildEnvProbeRows_valid_config_toml_ok()
46 {
47 var root = Path.Combine(Path.GetTempPath(), "cascade-ers-kb-" + Guid.NewGuid().ToString("n"));
48 Directory.CreateDirectory(Path.Combine(root, "knowledge", "work", "local"));
49 var tomlPath = Path.Combine(root, "agent-notes.toml");
50 File.WriteAllText(
51 tomlPath,
52 $"""
53 version = 1
54 [knowledge]
55 primary = "test"
56 [knowledge.roots]
57 test = "{root.Replace('\\', '/')}"
58 [workspace]
59 default_scope = "door-to-singularity"
60 scope_map = "work/local/workspace-scope-map-v1.md"
61 scope_aliases = "work/local/scope-alias-map-v1.md"
62 """);
63 File.WriteAllText(Path.Combine(root, "knowledge", "work", "local", "workspace-scope-map-v1.md"), "# map\n");
64 File.WriteAllText(Path.Combine(root, "agent-notes.md"), "<!-- section:active-scope -->\n<!-- /section:active-scope -->\n");
65
66 try
67 {
68 var settings = new CascadeIdeSettings { AgentNotes = new AgentNotesSettings { ConfigPath = tomlPath } };
69 var rows = EnvironmentReadinessSnapshotBuilder.BuildEnvProbeRows(
70 EnvironmentReadinessEnvSnapshot.FromSettings(settings),
71 settings);
72
73 var kb = Assert.Single(rows, r => r.Id == EnvironmentReadinessCellIds.AgentNotesCanonPath);
74 Assert.Equal(AnnunciatorLampLevel.Ok, kb.Level);
75 }
76 finally
77 {
78 AgentNotesRuntimeLoader.Reset();
79 try
80 {
81 Directory.Delete(root, recursive: true);
82 }
83 catch
84 {
85 // best-effort
86 }
87 }
88 }
89
90 [Fact]
91 public void BuildEnvProbeRows_netcoredbg_bare_name_not_on_path_is_caution()
92 {
93 var rows = EnvironmentReadinessSnapshotBuilder.BuildEnvProbeRows(
94 new EnvironmentReadinessEnvSnapshot(null, null, "zzz_cascade_ers_missing_exe_9f2a"),
95 new CascadeIdeSettings());
96
97 var dbg = Assert.Single(rows, r => r.Id == EnvironmentReadinessCellIds.NetcoreDbgPath);
98 Assert.Equal(AnnunciatorLampLevel.Caution, dbg.Level);
99 }
100
101 [Fact]
102 public void BuildEnvProbeRows_netcoredbg_existing_file_path_ok()
103 {
104 var temp = Path.Combine(Path.GetTempPath(), "cascade-ers-dbg-" + Guid.NewGuid().ToString("n") + ".exe");
105 File.WriteAllText(temp, "");
106 try
107 {
108 var rows = EnvironmentReadinessSnapshotBuilder.BuildEnvProbeRows(
109 new EnvironmentReadinessEnvSnapshot(null, null, temp),
110 new CascadeIdeSettings());
111
112 var dbg = Assert.Single(rows, r => r.Id == EnvironmentReadinessCellIds.NetcoreDbgPath);
113 Assert.Equal(AnnunciatorLampLevel.Ok, dbg.Level);
114 }
115 finally
116 {
117 try
118 {
119 File.Delete(temp);
120 }
121 catch
122 {
123 // best-effort
124 }
125 }
126 }
127}
128
View only · write via MCP/CIDE