Core - Fix node script and pin bugs found by the tests (#911)

* Core - Keep nodes of missing plugins and the connection an input reads from in node scripts

- Saving a script keeps nodes whose plugin is missing, and their connections, so they come back once the plugin is available again
- Loading keeps the first connection of an input, the one it reads from
- Disabling a node provider only removes the nodes it created, not those of another provider registering the same type
- RemoveNode only raises NodeRemoved for nodes that were in the script

* Core - Fix pin connections, null values and failing nodes

- Connecting pins that are already connected no longer adds a second connection
- Untyped pins turn null into the default value for value types, as intended
- A new InputPin<T> reads its connection right away instead of after its first reset
- Matching a specific enum to a pin of any enum now depends on forgivingEnumMatching
- A node that fails to evaluate sets its outputs to their default values, so it is evaluated once per run and old values don't flow on

* Core - Round Numeric to long and clamp it to the range of an sbyte
This commit is contained in:
RobertBeekman authored and GitHub committed 2026-10-24 16:22:44 +02:00
1 parent 83cf6da830
commit 5ddd50b4a8
12 files changed
+118 -92

No files matched your search

@@ -105,17 +105,15 @@ public class PinTests
}
[Fact]
public void ConnectTo_TheSamePinTwice_AddsTheConnectionTwiceOnOneSide()
public void ConnectTo_TheSamePinTwice_ConnectsThemOnce()
{
// Pinned as-is: connecting pins that are already connected adds a second connection to the pin it is called on,
// while the other pin keeps one. Disconnecting once removes both again.
OutputPin<Numeric> output = _source.CreateOutputPin<Numeric>();
InputPin<Numeric> input = _target.CreateInputPin<Numeric>();
input.ConnectTo(output);
input.ConnectTo(output);
input.ConnectedTo.ShouldBe([output, output]);
input.ConnectedTo.ShouldBe([output]);
output.ConnectedTo.ShouldBe([input]);
input.DisconnectFrom(output);
@@ -215,14 +213,15 @@ public class PinTests
}
[Fact]
public void IsTypeCompatible_MatchesEnums_EvenWhenNotForgiving()
public void IsTypeCompatible_OnlyMatchesASpecificEnumToAnyEnumWhenForgiving()
{
// Pinned as-is: the forgiving enum check has no effect, a specific enum type already counts as an Enum without it
InputPin input = _target.CreateInputPin(typeof(Enum));
OutputPin output = _source.CreateOutputPin(typeof(TestEnum));
input.IsTypeCompatible(typeof(TestEnum), false).ShouldBeTrue();
output.IsTypeCompatible(typeof(Enum), false).ShouldBeTrue();
input.IsTypeCompatible(typeof(TestEnum), false).ShouldBeFalse();
output.IsTypeCompatible(typeof(Enum), false).ShouldBeFalse();
input.IsTypeCompatible(typeof(TestEnum), true).ShouldBeTrue();
output.IsTypeCompatible(typeof(Enum), true).ShouldBeTrue();
}
[Fact]
@@ -390,25 +389,19 @@ public class PinTests
}
[Fact]
public void UntypedOutput_ForAValueType_AcceptsNull()
public void UntypedOutput_ForAValueType_TurnsNullIntoTheDefaultValue()
{
// Pinned as-is: the setter means to turn null into the default value for value types (see its comment), but
// then stores null anyway. A typed input reading the pin gets its default value, an untyped one turns the null
// into the default value itself.
OutputPin output = _source.CreateOutputPin(typeof(Numeric));
output.Value = new Numeric(3);
output.Value = null;
output.Value.ShouldBeNull();
output.Value.ShouldBe(new Numeric(0));
}
[Fact]
public void NewTypedInput_IgnoresItsConnectionUntilItIsReset()
public void NewTypedInput_ReadsItsConnection_LikeAnUntypedInput()
{
// Pinned as-is: a new InputPin<T> counts as evaluated with its default value, so it only reads the pin it is
// connected to after a reset. Running a script resets every pin first, so this only shows outside a script.
// Untyped input pins don't do this.
OutputPin<Numeric> output = _source.CreateOutputPin<Numeric>();
InputPin<Numeric> typed = _target.CreateInputPin<Numeric>();
InputPin untyped = _target.CreateInputPin(typeof(Numeric));
@@ -416,12 +409,9 @@ public class PinTests
untyped.ConnectTo(output);
output.Value = new Numeric(5);
typed.IsEvaluated.ShouldBeTrue();
typed.Value.ShouldBe(new Numeric(0));
untyped.Value.ShouldBe(new Numeric(5));
typed.Reset();
typed.IsEvaluated.ShouldBeFalse();
typed.Value.ShouldBe(new Numeric(5));
untyped.Value.ShouldBe(new Numeric(5));
}
[Fact]