RecyclerLoopTest: check all materials, simplify test. (#44967)

* ReclaimerLoopTest: check every material

* Remove unused stuff

* constant Recycler, no GameScrounger dependency

* talked myself out of it

* o kurwa

* Tweak comments, convert asserts to assumes, remove return

Signed-off-by: Connor Huffine <chuffine@gmail.com>

---------

Signed-off-by: Connor Huffine <chuffine@gmail.com>
Co-authored-by: Connor Huffine <chuffine@gmail.com>
This commit is contained in:
Whatstone 2026-07-27 21:15:35 -04:00 • committed by GitHub
parent db6bb99ed2
commit d9943c9753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 56 deletions

View file

@ -2,13 +2,9 @@ using Content.IntegrationTests.Fixtures.Attributes;
using Content.IntegrationTests.Tests.Interaction;
using Content.IntegrationTests.Utility;
using Content.Server.Materials;
using Content.Server.Spawners.Components;
using Content.Shared.Materials;
using Content.Shared.Sprite;
using Content.Shared.Whitelist;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using System.Collections.Generic;
namespace Content.IntegrationTests.Tests.Materials;
@ -19,15 +15,13 @@ namespace Content.IntegrationTests.Tests.Materials;
[TestOf(typeof(MaterialReclaimerComponent))]
public sealed class ReclaimerLoopTest : InteractionTest
{
//ProtoIDs we need
// ProtoIDs we need
private static readonly EntProtoId ApcId = "APCBasic";
private static readonly EntProtoId FloorTileId = "FloorTileItemSteelCheckerDark";
private static readonly EntProtoId FloorTileId = "FloorTileItemSteel";
private static readonly string[] Reclaimers = GameDataScrounger.EntitiesWithComponent("MaterialReclaimer");
[SidedDependency(Side.Server)] private readonly SharedMaterialReclaimerSystem _materialReclaimerSystem = null!;
[SidedDependency(Side.Server)] private readonly EntityWhitelistSystem _entityWhitelistSystem = null!;
[SidedDependency(Side.Server)] private readonly IComponentFactory _compFactory = null!;
[Test]
[TestCaseSource(nameof(Reclaimers))]
@ -37,78 +31,46 @@ public sealed class ReclaimerLoopTest : InteractionTest
[TrackingIssue("https://github.com/space-wizards/space-station-14/issues/39691")]
public async Task MaterialSpawnLoopTest(string reclaimerId)
{
//Spawn the reclaimer
// Spawn the reclaimer
await SpawnTarget(reclaimerId, PlayerCoords);
Assert.That(STarget, Is.Not.Null, "STarget was null, did the reclaimer spawn correctly?");
Assume.That(STarget, Is.Not.Null, "STarget was null, did the reclaimer spawn correctly?");
var reclaimComp = Comp<MaterialReclaimerComponent>(Target);
//If the reclaimer can produce materials
var reclaimsMaterials = reclaimComp.ReclaimMaterials;
//if the reclaimer has reclaimsMaterials and is able to produce materials
//go through all recyclable items, compile a HashSet of producible materials
HashSet<ProtoId<MaterialPrototype>> producibleMaterials = []; //If reclaimMaterials is false, this will stay empty
if (reclaimsMaterials)
{
foreach (var proto in ProtoMan.EnumeratePrototypes<EntityPrototype>())
{
//we don't care about items that don't recycle into anything physical
if (!proto.HasComp<PhysicalCompositionComponent>(_compFactory))
continue;
//spawners and random items mess things up quickly, avoid them too
if (proto.HasComp<RandomSpriteComponent>(_compFactory) || proto.HasComp<EntityTableSpawnerComponent>(_compFactory))
continue;
var currentScrap = await Spawn(proto.ID);
var currentScrapUid = ToServer(currentScrap);
var currentScrapCompositionComp = Comp<PhysicalCompositionComponent>(currentScrap);
//If it's on the whitelist for the reclaimer, and not on its blacklist.
if (_entityWhitelistSystem.CheckBoth(currentScrapUid, reclaimComp.Blacklist, reclaimComp.Whitelist))
{
//for each material it produces, add it to the HashSet
foreach (var (mat, _) in currentScrapCompositionComp.MaterialComposition)
{
ProtoId<MaterialPrototype> matAsProto = ProtoMan.Index<MaterialPrototype>(mat);
producibleMaterials.Add(matAsProto);
}
}
await Delete(currentScrapUid);
}
}
// Power the reclaimer
await SpawnEntity(ApcId, SEntMan.GetCoordinates(TargetCoords));
await RunTicks(1);
//Set reclaimer to enabled
// Set reclaimer to enabled
await Server.WaitPost(() =>
{
_materialReclaimerSystem.SetReclaimerEnabled((EntityUid)STarget, true);
});
//Assert that reclaimer enabled
Assert.That(reclaimComp.Enabled, "The reclaimer did not get or stay enabled");
// Check that reclaimer enabled
Assume.That(reclaimComp.Enabled, "The reclaimer did not get or stay enabled");
//put a floor tile down
// Put a floor tile down
await InteractUsing(FloorTileId);
// Reclaimer can't reclaim materials? Job's done.
if (!reclaimComp.ReclaimMaterials)
Assert.Ignore("Cannot reclaim materials");
using (Assert.EnterMultipleScope())
{
//For each producible Material, assert that it is not recyclable (and would thus cause a recycling loop)
foreach (ProtoId<MaterialPrototype> material in producibleMaterials)
// For each material, assert that it is not recyclable (and would thus cause a recycling loop)
foreach (var material in ProtoMan.EnumeratePrototypes<MaterialPrototype>())
{
var matStack = ProtoMan.Index(material).StackEntity;
var matStack = material.StackEntity;
Assert.That(
matStack,
Is.Not.Null,
$"The material, {material}, did not have a stackentity associated with it. You may need to add a stackEntity to its Reagents/Materials yml file.");
$"The material, {material.ID}, did not have a stackentity associated with it. You may need to add a stackEntity to its Reagents/Materials yml file.");
var matInHands = await PlaceInHands(matStack);
var matInHandsUid = ToServer(matInHands);
//Assert we're holding material
// Assert we're holding material
Assert.That(
HandSys.GetActiveItem((SPlayer, Hands)),
Is.EqualTo(matInHandsUid),
@ -116,7 +78,7 @@ public sealed class ReclaimerLoopTest : InteractionTest
await Interact();
//Assert Hands not empty
// Assert Hands not empty
Assert.That(
HandSys.GetActiveItem((SPlayer, Hands)),
Is.Not.Null,

View file

@ -113,6 +113,7 @@
- type: material
id: Bones
stackEntity: MaterialBones1
name: materials-bones
unit: materials-unit-piece
icon: { sprite: Objects/Materials/materials.rsi, state: bones }