feat(commons): TryParseRelayBody — detect pure ctx.GetTag relay scripts

This commit is contained in:
Joseph Doherty
2026-06-11 20:59:10 -04:00
parent 93a9c6d3db
commit 2ba2f8a899
2 changed files with 58 additions and 0 deletions
@@ -211,4 +211,29 @@ public class EquipmentScriptPathsTests
{
EquipmentScriptPaths.ContainsEquipToken(null).ShouldBeFalse();
}
// ---- TryParseRelayBody ----
[Theory]
[InlineData("return ctx.GetTag(\"TestMachine_020.TestChangingInt\").Value;", "TestMachine_020.TestChangingInt")]
[InlineData(" return ctx . GetTag ( \"A.B\" ) . Value ; ", "A.B")]
[InlineData("return ctx.GetTag(\"{{equip}}.Speed\").Value;", "{{equip}}.Speed")]
public void TryParseRelayBody_accepts_exact_passthrough(string src, string expectedRef)
{
EquipmentScriptPaths.TryParseRelayBody(src, out var r).ShouldBeTrue();
r.ShouldBe(expectedRef);
}
[Theory]
[InlineData("return ctx.GetTag(\"A.B\").Value * 2;")]
[InlineData("var x = ctx.GetTag(\"A.B\").Value; return x;")]
[InlineData("return ctx.GetTag(\"A.B\").Value + ctx.GetTag(\"C.D\").Value;")]
[InlineData("return ctx.GetTag(\"A.B\").Quality;")]
[InlineData("return 5;")]
[InlineData("")]
public void TryParseRelayBody_rejects_non_relay(string src)
{
EquipmentScriptPaths.TryParseRelayBody(src, out var r).ShouldBeFalse();
r.ShouldBeNull();
}
}