Skip to content

Resolve role players by object identity (fix wrapper schizophrenia)#37

Merged
saturnflyer merged 3 commits into
masterfrom
role-map-identity-split
Jun 24, 2026
Merged

Resolve role players by object identity (fix wrapper schizophrenia)#37
saturnflyer merged 3 commits into
masterfrom
role-map-identity-split

Conversation

@saturnflyer

@saturnflyer saturnflyer commented Jun 24, 2026

Copy link
Copy Markdown
Owner

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.

@saturnflyer
saturnflyer force-pushed the role-map-identity-split branch from 9ba3fd3 to cad2e45 Compare June 24, 2026 17:56
@saturnflyer
saturnflyer force-pushed the role-map-identity-split branch from cad2e45 to 2ba2283 Compare June 24, 2026 18:10
@saturnflyer
saturnflyer merged commit 6212fde into master Jun 24, 2026
4 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant