Turn-Around Threshold
The harvester turns for home on one condition. In the original tutorial it is this line of role.harvester.js:
if(creep.store.getFreeCapacity() > 0) {The creep keeps harvesting while any free space remains, so it turns around completely full. Find the same condition in the port — it is in harness/role.harvester.ts, the port’s counterpart of the tutorial file. The spec holds the role and the body; this threshold sits in the harness in both worlds.
This challenge moves the threshold through the pipeline. Both gates accept it, the room slows down anyway. We’ll need a test to make sure the behavior does not get changed.
In
harness/role.harvester.ts, change the condition to turn around at half-full:if (creep.store.getFreeCapacity() > creep.store.getCapacity() / 2) {rm -rf .server-data, then,nix run .#deploy-local. Both gates pass. The threshold is a number, and a different number is still well-typed.Run
nix run .#itest. It passes. Watch the room: the creep turns for home early and the spawn fills in smaller bites. Every check said yes to a colony that slowed down.
Where tests come from
Every gate passed, and the colony’s rhythm changed anyway. Paradox verified the spec’s named properties. tsc checked types, and the edited line still compares numbers and yields a boolean — the value of the threshold sits outside the type system’s view. And itest passed: it counts transfers with rc === 0 and asserts a delivery happened — the amount delivered is outside its view. The threshold’s effect on the world was covered by no test at all.
The suite lives in tests/integration.nix: it deploys, spawns, and checks the harvest loop by reading Memory.trace latches — a machine reading the same world you watched in the panel. Open it and find the check that counted your transfers.
Write the test
Look at a trace entry from the console:
JSON.stringify(Memory.trace)Each entry is
{ t, action, rc }— it doesn’t say how much the creep was carrying. Add anamountfield:harness/memory.d.ts: addamount: numberto the trace entry type.harness/role.harvester.ts: add a requiredamountparameter torecordTrace, push it with the entry, and passcreep.store.energyat all four call sites.- In the same function, add
last.amount === amountto the duplicate check, so entries that differ only in amount are kept.
Deploy. Old entries keep their old shape; watch a creep spawned after the deploy. Each delivery now prints
{ ..., "amount": 26 }.In
tests/integration.nix, the probe ispollDeliveryTrace. Its counting loop is theforEachthat counts entries withaction === "transfer"andrc === 0. Add your assertion on the recorded amount there:if (e.action === "transfer" && e.rc === 0 && e.amount === 50) n += 1;50 is a full load for this creep.
Run
nix run .#itestwith the half-full threshold still deployed: the test fails — deliveries are on record, none of them full. Restore the old condition, deploy, and run it again — it passes. A test that has never failed hasn’t witnessed anything yet; this one has.
Back to Let’s Play Screeps.