Public Access
Validate workflow rule writes
This commit is contained in:
@@ -540,6 +540,120 @@ public sealed class WorkflowRulesEditorTests
|
||||
Assert.Equal("rules: []", await File.ReadAllTextAsync(rulesPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RulesEditorToolsRefuseWorkflowRulesThatWouldFailAtRuntime()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(root);
|
||||
var rulesPath = Path.Combine(root, "rules.yaml");
|
||||
await File.WriteAllTextAsync(rulesPath, "rules: []");
|
||||
var tools = new WorkflowRulesEditorTools(new MeetingAssistantOptions
|
||||
{
|
||||
Automation = new AutomationOptions { RulesPath = rulesPath }
|
||||
});
|
||||
|
||||
var result = await tools.WriteRules("""
|
||||
rules:
|
||||
- name: broken-step
|
||||
on:
|
||||
- created: {}
|
||||
steps:
|
||||
- uses: send_email
|
||||
value: Manuel
|
||||
""", replace_file: true);
|
||||
|
||||
Assert.StartsWith("Refused: workflow rules are invalid.", result);
|
||||
Assert.Contains("broken-step", result);
|
||||
Assert.Contains("send_email", result);
|
||||
Assert.Contains("add_attendee", result);
|
||||
Assert.Equal("rules: []", await File.ReadAllTextAsync(rulesPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RulesEditorToolsExplainUnsupportedWorkflowProperties()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(root);
|
||||
var rulesPath = Path.Combine(root, "rules.yaml");
|
||||
await File.WriteAllTextAsync(rulesPath, "rules: []");
|
||||
var tools = new WorkflowRulesEditorTools(new MeetingAssistantOptions
|
||||
{
|
||||
Automation = new AutomationOptions { RulesPath = rulesPath }
|
||||
});
|
||||
|
||||
var result = await tools.WriteRules("""
|
||||
rules:
|
||||
- name: broken-property
|
||||
on:
|
||||
- created: {}
|
||||
steps:
|
||||
- uses: set_property
|
||||
property: meeting.status
|
||||
value: active
|
||||
""", replace_file: true);
|
||||
|
||||
Assert.StartsWith("Refused: workflow rules are invalid.", result);
|
||||
Assert.Contains("broken-property", result);
|
||||
Assert.Contains("meeting.status", result);
|
||||
Assert.Contains("title", result);
|
||||
Assert.Equal("rules: []", await File.ReadAllTextAsync(rulesPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RulesEditorToolsRefuseMalformedRazorStepValues()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(root);
|
||||
var rulesPath = Path.Combine(root, "rules.yaml");
|
||||
await File.WriteAllTextAsync(rulesPath, "rules: []");
|
||||
var tools = new WorkflowRulesEditorTools(new MeetingAssistantOptions
|
||||
{
|
||||
Automation = new AutomationOptions { RulesPath = rulesPath }
|
||||
});
|
||||
|
||||
var result = await tools.WriteRules("""
|
||||
rules:
|
||||
- name: broken-razor
|
||||
on:
|
||||
- created: {}
|
||||
steps:
|
||||
- uses: add_context
|
||||
value: "Invalid template: @ThisIsNotAModelVar"
|
||||
""", replace_file: true);
|
||||
|
||||
Assert.StartsWith("Refused: workflow rules are invalid.", result);
|
||||
Assert.Contains("broken-razor", result);
|
||||
Assert.Contains("Razor", result);
|
||||
Assert.Contains("ThisIsNotAModelVar", result);
|
||||
Assert.Equal("rules: []", await File.ReadAllTextAsync(rulesPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RulesEditorToolsAllowValidRazorAndEmailStepValues()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(root);
|
||||
var rulesPath = Path.Combine(root, "rules.yaml");
|
||||
var tools = new WorkflowRulesEditorTools(new MeetingAssistantOptions
|
||||
{
|
||||
Automation = new AutomationOptions { RulesPath = rulesPath }
|
||||
});
|
||||
|
||||
var result = await tools.WriteRules("""
|
||||
rules:
|
||||
- name: valid-razor
|
||||
on:
|
||||
- speaker_identified: {}
|
||||
steps:
|
||||
- uses: add_context
|
||||
value: "Speaker @Model.Speaker.Name can contact Support@example.com"
|
||||
""", replace_file: true);
|
||||
|
||||
Assert.Equal(rulesPath, result);
|
||||
Assert.Contains("@Model.Speaker.Name", await File.ReadAllTextAsync(rulesPath));
|
||||
Assert.Contains("Support@example.com", await File.ReadAllTextAsync(rulesPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InstructionBuilderIncludesConfiguredRulesPathAndWorkflowDocs()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user