diff --git a/src/agents/impl/instance-agents-impl.ts b/src/agents/impl/instance-agents-impl.ts index 54a9e17..c30e185 100644 --- a/src/agents/impl/instance-agents-impl.ts +++ b/src/agents/impl/instance-agents-impl.ts @@ -362,6 +362,10 @@ class InstanceAgentsImpl implements InstanceAgentsInternal { if (protoId !== undefined) { if (am === undefined || am.meta.protoId !== undefined) { return protoId; + } else { + throw new RegalError( + "Failed registering the agent's prototype because a bad protoId was already set" + ); } } else { protoId = StaticPrototypeRegistry.getPrototypeIdOrDefault(agent); diff --git a/test/unit/agents.test.ts b/test/unit/agents.test.ts index eb1962c..7ad5787 100644 --- a/test/unit/agents.test.ts +++ b/test/unit/agents.test.ts @@ -1993,6 +1993,16 @@ describe("Agents", function() { RegalError ); }); + + it("Throws a RegalError if an agent's protoId is forced to some value", function() { + Game.init(MD); + const myGame = buildGameInstance(); + + const _d = new Dummy("D1", 1); + _d.meta.protoId = "foo" as any; + + expect(() => myGame.using(_d)).to.throw(RegalError); + }); }); });