| 1 | using AgentForge.Plugin.Ci.Ir; |
| 2 | |
| 3 | namespace AgentForge.Tests; |
| 4 | |
| 5 | public sealed class ForgeCiIrTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void Default_template_validates_and_serializes() |
| 9 | { |
| 10 | var document = ForgeCiTemplates.CreateDefault("default"); |
| 11 | ForgeCiDocumentValidator.Validate(document); |
| 12 | var json = document.ToJson(); |
| 13 | var roundTrip = ForgeCiDocument.FromJson(json); |
| 14 | Assert.Equal(ForgeCiDocument.SchemaVersion, roundTrip.Schema); |
| 15 | Assert.Equal(3, roundTrip.Nodes.Count(n => n.Kind == "task")); |
| 16 | } |
| 17 | |
| 18 | [Fact] |
| 19 | public void AddTask_appends_to_phase_and_depends_on_previous() |
| 20 | { |
| 21 | var document = ForgeCiTemplates.CreateDefault("build"); |
| 22 | ForgeCiDocumentEditor.AddTask(document, "script"); |
| 23 | ForgeCiDocumentValidator.Validate(document); |
| 24 | Assert.Equal(4, document.Nodes.Count(n => n.Kind == "task")); |
| 25 | Assert.Contains(document.Edges, e => e.Kind == "dependsOn" && e.From == "test"); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public void Validator_rejects_unknown_task() |
| 30 | { |
| 31 | var document = ForgeCiTemplates.CreateDefault("x"); |
| 32 | document.Nodes.Add(new ForgeCiNode { Id = "bad", Kind = "task", Task = "unknown.task" }); |
| 33 | Assert.Throws<ForgeCiValidationException>(() => ForgeCiDocumentValidator.Validate(document)); |
| 34 | } |
| 35 | } |
| 36 | |