Add construction graph test (#10760)

This commit is contained in:
Leon Friedrich
2022-08-22 12:45:25 +12:00
committed by GitHub
parent ff37e69c0a
commit 87d753e910
2 changed files with 51 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
using System.Threading.Tasks;
using Content.Server.Construction.Components;
using Content.Server.Stack;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Construction.Steps;
using Content.Shared.Prototypes;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
@@ -109,5 +112,48 @@ namespace Content.IntegrationTests.Tests.Construction
}
await pairTracker.CleanReturnAsync();
}
[Test]
public async Task TestStackPrototypeSteps()
{
// People often mistakenly use the prototype-step rather than a material-step, resulting in a whole stack
// being consumed. This checks that if something uses a prototype step, that the relevant prototype does not
// have a stack component.
//
// If, for whatever reason, that is ever required, then this test should probably just support an ignore
// list. Though the test should then also checks that it accepts both the full-stack and single-sheet
// prototypes.
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings { NoClient = true });
var server = pairTracker.Pair.Server;
var protoMan = server.ResolveDependency<IPrototypeManager>();
var stackName = server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(StackComponent));
Assert.Multiple(() =>
{
// quadruple for loop nesting, what fun.
foreach (var protoGraph in protoMan.EnumeratePrototypes<ConstructionGraphPrototype>())
{
foreach (var node in protoGraph.Nodes.Values)
{
foreach (var edge in node.Edges)
{
foreach (var step in edge.Steps)
{
if (step is not PrototypeConstructionGraphStep protoStep)
continue;
var protoEnt = protoMan.Index<EntityPrototype>(protoStep.Prototype);
Assert.False(protoEnt.Components.ContainsKey(stackName),
$"Construction graph {protoGraph.ID} uses a prototype-step that consumes a stackable entity {protoEnt.ID}");
}
}
}
}
});
await pairTracker.CleanReturnAsync();
}
}
}

View File

@@ -1,11 +1,14 @@
using Content.Shared.Examine;
using Content.Shared.Examine;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Construction.Steps
{
[DataDefinition]
public sealed class PrototypeConstructionGraphStep : ArbitraryInsertConstructionGraphStep
{
[DataField("prototype")] public string Prototype { get; } = string.Empty;
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>), required:true)]
public string Prototype { get; } = string.Empty;
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)
{