Resolve role players by object identity (fix wrapper schizophrenia)#37
Merged
Conversation
saturnflyer
force-pushed
the
role-map-identity-split
branch
from
June 24, 2026 17:56
9ba3fd3 to
cad2e45
Compare
saturnflyer
force-pushed
the
role-map-identity-split
branch
from
June 24, 2026 18:10
cad2e45 to
2ba2283
Compare
saturnflyer
added a commit
that referenced
this pull request
Jun 24, 2026
Resolve role players by object identity (fix wrapper schizophrenia) Fixed: Roles applied through a wrapper, such as an interface, can reach the other roles in their context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While I was poking around in here I hit a case where an interface role couldn't reach another role in the context. It raised a NameError even though the other player was sitting right there.
Here's what was going on. When behaviors get applied during a trigger, the role map was having its stored object overwritten with the wrapper. So when something asked "is this object playing a role?", we were comparing the bare object against its wrapper. Those come out equal one direction but not the other (the wrapper forwards == to the object, but the plain object has no idea about the wrapper), and triad's value index does a hash lookup that misses it. It's the old object schizophrenia thing, where a player is really two objects, the domain object and its wrapper.
So I split the two jobs apart. The role map now only holds the actual objects you passed in, which is the identity we care about for "who's playing what". RoleMap keeps track of the applied wrappers separately for the life of a trigger and clears them afterward. role_player? compares by identity against either the assigned object or the applied wrapper, so it no longer leans on == behaving a particular way. Accessors and sibling lookups go through whichever player is current. I also moved that bookkeeping out of the context and into RoleMap, since keeping track of role players is really RoleMap's job and not the context's.
There's a new test that casts a role player whose == always returns false, so it only passes if we're genuinely comparing identity.
A few smaller things came along for the ride: added minitest-mock to the Gemfile (minitest 6 split mock out into its own gem and one of the existing tests requires it), added 4.0 to the CI matrix, and fixed a comment on the interface role type that claimed interface methods can't reach other roles. They can, as long as the object includes Surrounded.