1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
using Agent.App.Cli;
using Agent.App.Configuration;
using Agent.App;
using Agent.Core.Localization;
using Agent.Core.Skills;
namespace Agent.Core.Tests;
public sealed class ConfigurationTests
{
[Fact]
public void ValidYamlLoadsTypedConfiguration()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
AgentConfiguration result = ConfigurationLoader.Load(config);
Assert.Equal(1, result.SchemaVersion);
Assert.Equal("model", result.Ollama.Model);
Assert.Equal("deny", result.Sandbox.Network.Mode);
}
[Fact]
public void UnknownYamlPropertyIsFatal()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
System.IO.File.AppendAllText(config, "unknown_root: true\n");
Assert.Throws<ConfigurationException>(() => ConfigurationLoader.Load(config));
}
[Fact]
public void InvalidSchemaIsFatal()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
System.IO.File.WriteAllText(config, System.IO.File.ReadAllText(config).Replace("schema_version: 1", "schema_version: 2", StringComparison.Ordinal));
Assert.Throws<ConfigurationException>(() => ConfigurationLoader.Load(config));
}
[Theory]
[InlineData("true")]
[InlineData("false")]
[InlineData("low")]
[InlineData("medium")]
[InlineData("high")]
[InlineData("max")]
public void Ollama_think_accepts_native_boolean_and_level_values(string value)
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
System.IO.File.WriteAllText(config, System.IO.File.ReadAllText(config).Replace(" model: model", $" model: model\n think: {value}", StringComparison.Ordinal));
AgentConfiguration result = ConfigurationLoader.Load(config);
Assert.Equal(value is "true" or "false" ? bool.Parse(value) : value, result.Ollama.Think);
}
[Fact]
public void Ollama_think_rejects_unknown_level()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
System.IO.File.WriteAllText(config, System.IO.File.ReadAllText(config).Replace(" model: model", " model: model\n think: extreme", StringComparison.Ordinal));
ConfigurationException error = Assert.Throws<ConfigurationException>(() => ConfigurationLoader.Load(config));
Assert.Contains("ollama.think", error.Message, StringComparison.Ordinal);
}
[Fact]
public void CommandLineLanguageOverrideIsCaptured()
{
CommandLine result = CommandLine.Parse(["serve", "--lang", "ja", "--transport", "http"]);
Assert.Equal("ja", result.Language);
Assert.Equal("http", result.Transport);
}
[Fact]
public void CommandLine_defaults_to_serve_when_command_is_omitted()
{
Assert.Equal(AppCommand.Serve, CommandLine.Parse([]).Command);
CommandLine withOption = CommandLine.Parse(["--lang", "ja"]);
Assert.Equal(AppCommand.Serve, withOption.Command);
Assert.Equal("ja", withOption.Language);
}
[Fact]
public void Local_configuration_recursively_merges_maps_and_replaces_sequences()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
directory.File("agent.local.yaml", """
application:
language: ja
sandbox:
filesystem:
read: [C:/local-only]
""");
AgentConfiguration result = ConfigurationLoader.Load(config);
Assert.Equal("ja", result.Application.Language);
Assert.Equal(["C:/local-only"], result.Sandbox.Filesystem.Read);
Assert.Equal("model", result.Ollama.Model);
}
[Fact]
public void Unknown_local_configuration_property_is_fatal()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
directory.File("agent.local.yaml", "unknown_local: true\n");
Assert.Throws<ConfigurationException>(() => ConfigurationLoader.Load(config));
}
[Fact]
public void Execute_file_without_process_approval_reports_canonical_keys()
{
using var directory = new TestDirectory();
string config = CreateValidConfiguration(directory);
string executable = directory.File("tools/tool.exe", "fixture").Replace('\\', '/');
directory.File("agent.local.yaml", $$"""
sandbox:
filesystem:
execute: [{{executable}}]
""");
ConfigurationException error = Assert.Throws<ConfigurationException>(() => ConfigurationLoader.Load(config));
Assert.Contains("sandbox.filesystem.execute", error.Message, StringComparison.Ordinal);
Assert.Contains("sandbox.process.approvals", error.Message, StringComparison.Ordinal);
Assert.Contains(Path.GetFullPath(executable), error.Message, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void Runtime_configuration_values_are_propagated()
{
var configuration = new AgentConfiguration
{
Agent = new RuntimeOptions { MaxIterations = 41, SameFailureLimit = 4 },
Planner = new PlannerOptions { MaxTasks = 17 },
Ollama = new OllamaConfiguration { Model = "model-x", Options = new OllamaGenerationOptions { NumCtx = 12345 } },
Limits = new LimitOptions { ContextSummaryRatio = 0.65 }
};
LocaleCatalog locale = LocaleCatalog.Load(Path.GetFullPath("config/locales"), "ja");
Agent.Core.Runtime.AgentRuntimeSettings settings = Program.CreateRuntimeSettings(configuration, "prompt", "ja", [], locale);
Assert.Equal(41, settings.MaxIterations);
Assert.Equal(4, settings.SameFailureLimit);
Assert.Equal(17, settings.MaxTasks);
Assert.Equal(12345, settings.NumCtx);
Assert.Equal(0.65, settings.ContextSummaryThreshold);
Assert.Equal("model-x", settings.Model);
}
[Fact]
public void Startup_errors_follow_the_cli_locale()
{
string message = Program.FormatStartupError(["--lang", "ja"], new CommandLineException("bad option"));
Assert.Contains("コマンドラインが不正です", message, StringComparison.Ordinal);
Assert.Contains("bad option", message, StringComparison.Ordinal);
}
[Fact]
public void SkillLoader_loads_standard_skill_directories_only()
{
using var directory = new TestDirectory();
// Legacy single markdown — should be ignored (not loaded).
directory.File("skills/legacy.md", "legacy skill");
// Standard skill directory with frontmatter.
directory.File("skills/python/SKILL.md", "---\nname: python\ndescription: Python execution skill.\n---\n# Python\nInstructions here.");
// Non-SKILL.md files in skill directory should not be loaded as skills.
directory.File("skills/python/reference.md", "must not be loaded as a skill");
var skills = SkillLoader.Load(Path.Combine(directory.Path, "skills"));
Assert.Single(skills);
Assert.Equal("python", skills[0].Name);
Assert.Equal("Python execution skill.", skills[0].Description);
Assert.Contains("Instructions here.", skills[0].Instructions);
}
[Fact]
public void SkillLoader_rejects_missing_frontmatter()
{
using var directory = new TestDirectory();
directory.File("skills/no-frontmatter/SKILL.md", "# No frontmatter\nJust body.");
Assert.Throws<SkillLoadException>(() => SkillLoader.Load(Path.Combine(directory.Path, "skills")));
}
[Fact]
public void SkillLoader_rejects_name_mismatch()
{
using var directory = new TestDirectory();
directory.File("skills/wrong-name/SKILL.md", "---\nname: different-name\ndescription: A skill.\n---\nBody.");
Assert.Throws<SkillLoadException>(() => SkillLoader.Load(Path.Combine(directory.Path, "skills")));
}
[Fact]
public void SkillLoader_rejects_duplicate_names()
{
using var directory = new TestDirectory();
directory.File("skills/dup-skill/SKILL.md", "---\nname: dup-skill\ndescription: First.\n---\nBody1.");
// Create a second directory with the same skill name (via symlink or junction is not needed;
// just create another dir that also has name: dup-skill in frontmatter).
directory.File("skills/dup-skill-copy/SKILL.md", "---\nname: dup-skill\ndescription: Second.\n---\nBody2.");
Assert.Throws<SkillLoadException>(() => SkillLoader.Load(Path.Combine(directory.Path, "skills")));
}
private static string CreateValidConfiguration(TestDirectory directory)
{
directory.File("prompts/user-system.md", string.Empty);
Directory.CreateDirectory(System.IO.Path.Combine(directory.Path, "config/locales"));
Directory.CreateDirectory(System.IO.Path.Combine(directory.Path, "skills"));
return directory.File("agent.yaml", """
schema_version: 1
application:
language: en
agent:
user_system_prompt: prompts/user-system.md
ollama:
endpoint: http://127.0.0.1:11434
model: model
localization:
directory: config/locales
fallback: en
skills:
directory: skills
""");
}
}
|