fix(template-engine): resolve TemplateEngine-015,016 — cascade-rename nested derived templates, correct composed-script ParentPath

This commit is contained in:
Joseph Doherty
2026-05-17 03:18:41 -04:00
parent 0135a6b2a6
commit d6221419c6
5 changed files with 177 additions and 14 deletions

View File

@@ -624,4 +624,46 @@ public class FlatteningServiceTests
var alarm = result.Value.Alarms.First(a => a.CanonicalName == "MainPump.PumpFault");
Assert.Equal("MainPump.PumpAlarmHandler", alarm.OnTriggerScriptCanonicalName);
}
// ── TemplateEngine-016: composed-script ScriptScope.ParentPath ─────────
[Fact]
public void Flatten_NestedComposedScript_ScopeCarriesCorrectParentPath()
{
// Station composes Pump (level 1); Pump composes Motor (level 2).
// The depth-1 script's parent is the root template (ParentPath "");
// the depth-2 script's parent is the Pump module (ParentPath "MainPump").
var motor = CreateTemplate(3, "Motor");
motor.Scripts.Add(new TemplateScript("MonitorMotor", "// m") { Id = 70 });
var pump = CreateTemplate(2, "Pump");
pump.Scripts.Add(new TemplateScript("MonitorPump", "// p") { Id = 71 });
var station = CreateTemplate(1, "Station");
var compositions = new Dictionary<int, IReadOnlyList<TemplateComposition>>
{
[1] = new List<TemplateComposition> { new("MainPump") { ComposedTemplateId = 2 } },
[2] = new List<TemplateComposition> { new("DriveMotor") { ComposedTemplateId = 3 } },
};
var composedChains = new Dictionary<int, IReadOnlyList<Template>>
{
[2] = [pump], [3] = [motor],
};
var instance = CreateInstance();
var result = _sut.Flatten(instance, [station], compositions, composedChains,
new Dictionary<int, DataConnection>());
Assert.True(result.IsSuccess);
var depth1 = result.Value.Scripts.First(s => s.CanonicalName == "MainPump.MonitorPump");
Assert.Equal("MainPump", depth1.Scope.SelfPath);
Assert.Equal("", depth1.Scope.ParentPath);
var depth2 = result.Value.Scripts.First(s => s.CanonicalName == "MainPump.DriveMotor.MonitorMotor");
Assert.Equal("MainPump.DriveMotor", depth2.Scope.SelfPath);
// Parent module of a depth-2 script is the enclosing Pump module.
Assert.Equal("MainPump", depth2.Scope.ParentPath);
}
}