Skip to content

Add consistency checks for dangling references#85591

Open
dumb-kevin wants to merge 1 commit intoCleverRaven:masterfrom
dumb-kevin:improve/check-consistency-refs
Open

Add consistency checks for dangling references#85591
dumb-kevin wants to merge 1 commit intoCleverRaven:masterfrom
dumb-kevin:improve/check-consistency-refs

Conversation

@dumb-kevin
Copy link
Contributor

@dumb-kevin dumb-kevin commented Feb 28, 2026

Summary

Infrastructure "Add consistency checks for dangling references and fix existing ones"

Purpose of change

Various JSON fields that reference other game entities (item IDs, overmap terrains, EOCs, monster types) were not validated during check_consistency(), so typos or stale references after renames would silently break things at runtime. A few such broken references already existed.

Describe the solution

New C++ checks:

  • effect_on_condition.cpp - collect EOC string references during load_inline_eoc, validate they all resolve to real IDs in check_consistency(). Error messages include both the mod source and the JSON file path for easy lookup.
  • item_factory.cpp - validate repairs_like, source_monster, cooks_like, smoking_result, rot_spawn monster/group
  • magic.cpp - warn on summon/spawn_item/summon_monster spells with zero duration and no PERMANENT flag
  • profession.cpp - non-hobby professions with starting CBMs must have a trait that cancels NO_CBM_INSTALLATION (e.g. CBM_Interface)
  • start_location.cpp - validate om_terrain references exist for all match types (exact, type, subtype, prefix, contains)

JSON fixes (items):

  • looks_like pointing at removed power_armor_basic -> combat_exoskeleton_medium (3 files: combat_exoskeleton.json, TEST_DATA/items.json, aftershock exosuit_frame.json)
  • looks_like pointing at removed knife_butcher -> knife_huge (cooking.json)
  • smoking_result: " " hack on mutflesh -> proper "null" (carnivore.json)

JSON fixes (start locations):

  • urban_library changed to PREFIX match to pick up urban_library_* variants
  • MA mod: house_two_story_basement -> house_2story_basement (typo in rename), road entries consolidated to TYPE match
  • Aftershock: removed sloc_crashed_gunship - the terrain afs_crashed_gunship never existed as an overmap terrain (the gunship is a map extra, mx_gunship; the scenario uses that, not an omt)

JSON fixes (EOC dangling references):

  • MindOverMatter: EOC_PORTAL_NULL_AWAKENING -> EOC_MOM_NO_EFFECT (3 places in eoc_selector menus)
  • MindOverMatter: EOC_perk_blood_drinking_heal_hp_check was a cross-mod dependency on BombasticPerks. Replaced with mod_interactions/bombastic_perks/ bridge pattern - no-op base EOC when BombasticPerks isn't loaded, delegates to the real one when it is.
  • Xedra Evolved: removed stale refs to EOC_REDUCE_VAMPVIRUS1 and EOC_REDUCE_VAMPVIRUS2 from EOC_BLOOD_OF_SAINTS_AGAINST_VAMPIRISM caller. These were merged into EOC_REDUCE_VAMPVIRUS in [ Xedra Evolved ] Vampire cure is broken once again  #78774 but the caller wasn't updated. Also fixed shade_hands -> gracken_shade_hands.
  • Innawood: cross-mod EOC references (EOC_on_kill_check_exp etc.) replaced with bridge pattern using mod_interactions/ overrides. Base mod defines no-op stubs, mod_interactions/{bombastic_perks,perk_melee_system,sorcerer}/ files override when those mods are active.
  • Magiclysm: added missing EOC_SUMMON_MUSHROOMS definition (was referenced but never defined)

JSON fixes (spells):

  • Added PERMANENT_ALL_LEVELS to Magiclysm Alchemist summon spell (zero duration without it)
  • Added PERMANENT to MoM electrokinesis spawn_item spell and two Xedra spawn_item spells (Cultivate Goblin Fruit, Seed Bearer)

JSON fixes (professions):

  • Added CBM_Interface to MMA cyborg martial artist and MoM Fifth Sun profession (had starting CBMs but no interface trait)

Build script fix:

  • get_all_mods.py: use add_mods() instead of raw append() when collecting individual mods. The old code skipped dependency resolution and compatibility checks, so mods could be tested without their prerequisites.

Other:

  • flexbuffer_json.h: expose get_root_source_path() on JsonValue (was protected, needed for EOC error context)

New test:

  • recipe_cycle_test.cpp - checks for net-positive craft/uncraft exploits. Two cases: with-provenance (player-crafted items, checks uniform component groups) and without-provenance (world-spawned items, checks front()-based disassembly path).

Describe alternatives you've considered

For cross-mod EOC dependencies (Innawood, MoM psychic vampire), the alternative was to keep inline mod_is_loaded conditions, but that means the referenced EOC string fails validation when the other mod isn't loaded. The mod_interactions/ bridge pattern is already used elsewhere in the codebase and avoids the dangling reference entirely.

For looks_like validation -- currently not enforced. There are ~52 unique broken item looks_like values (27 truly missing IDs, 25 cross-type references like items pointing at furniture). Enforcement is feasible but needs a separate cleanup pass, especially for the cross-type cases that are an intentional pattern for appliances.

Testing

  • Full build (make TILES=1): clean
  • [recipe] test tag: 7060 assertions in 5 test cases, all pass

Additional context

The mod_interactions/ directory loading mechanism (in init.cpp) only loads subdirectory contents when the named mod is also active in the world, so bridge EOCs correctly resolve at load time without hard mod dependencies.

@github-actions github-actions bot added [JSON] Changes (can be) made in JSON Crafting / Construction / Recipes Includes: Uncrafting / Disassembling Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` Scenarios New Scenarios, balancing, bugs with scenarios Mods: Aftershock Anything to do with the Aftershock mod Items: Armor / Clothing Armor and clothing EOC: Effects On Condition Anything concerning Effects On Condition labels Feb 28, 2026
@github-actions github-actions bot added Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Feb 28, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch 6 times, most recently from db58d2c to 2c2bfb5 Compare February 28, 2026 17:19
@github-actions github-actions bot added Mods: Magiclysm Anything to do with the Magiclysm mod Mechanics: Enchantments / Spells Enchantments and spells json-styled JSON lint passed, label assigned by github actions and removed json-styled JSON lint passed, label assigned by github actions labels Feb 28, 2026
@GuardianDll
Copy link
Member

is looks_like needs to be validated? i thought it was used to target id of a texture, ie if we have item foo, which id was renamed to bar, but tileset still used foo, it would correctly pick the texture named "foo"? or something like that? tho it is very questionable pattern, if it is true

The rest LGTM

@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from dca535f to 98292f4 Compare February 28, 2026 18:24
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions and removed json-styled JSON lint passed, label assigned by github actions labels Feb 28, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 9b664aa to be156c6 Compare February 28, 2026 19:00
@github-actions github-actions bot added Map / Mapgen Overmap, Mapgen, Map extras, Map display Items: Food / Vitamins Comestibles and drinks Mods: Xedra Evolved Anything to do with Xedra Evolved Mods: Mind Over Matter labels Feb 28, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from be156c6 to 19c1d9a Compare February 28, 2026 20:15
@github-actions github-actions bot requested a review from Venera3 February 28, 2026 20:15
@github-actions github-actions bot added the Mods: MMA Mythical Martial Arts mod label Feb 28, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @Hymore246

@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 19c1d9a to 2093a41 Compare February 28, 2026 20:43
@github-actions github-actions bot added the Mods: Innawood 🌲 Anything to do with Innawood mod label Feb 28, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @Light-Wave

@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch 2 times, most recently from a3b16ab to 6cf7ca7 Compare March 1, 2026 08:52
@github-actions github-actions bot added Code: Build Issues regarding different builds and build environments [Python] Code made in Python Mods: MA Massachussetts mod. Cata in one state labels Mar 1, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-requesting reviews from non-collaborators: @ZhilkinSerg

@github-actions github-actions bot removed the json-styled JSON lint passed, label assigned by github actions label Mar 1, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 6cf7ca7 to 9095dd8 Compare March 1, 2026 08:57
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Mar 1, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 9095dd8 to 74511ee Compare March 1, 2026 09:36
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 1, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 74511ee to d152b49 Compare March 1, 2026 15:35
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 1, 2026
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from d152b49 to 3727b75 Compare March 1, 2026 20:07
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Mar 2, 2026
"terrain": [ "afs_crashed_escape_pod" ]
},
{
"type": "start_location",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a real start location. Is the issue it shouldn't be a safe location?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went and answered my own question. I didn't make it a terrain because I made it a map update. This makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh also apparently I never submitted my review so that's why you never responded to the question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is resolved, right?

Validate EOC string references, item repairs_like / source_monster /
cooks_like / smoking_result / rot_spawn, summon spells with zero
duration, profession CBM-without-interface, and start_location
om_terrain references.  Fix looks_like pointing at removed
power_armor_basic / knife_butcher, and use PREFIX match for
urban_library variants.  Add recipe cycle test for craft/uncraft
exploits.
@dumb-kevin dumb-kevin force-pushed the improve/check-consistency-refs branch from 3727b75 to 26ad76b Compare March 2, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Build Issues regarding different builds and build environments Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. Crafting / Construction / Recipes Includes: Uncrafting / Disassembling EOC: Effects On Condition Anything concerning Effects On Condition Items: Armor / Clothing Armor and clothing Items: Food / Vitamins Comestibles and drinks [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Mechanics: Enchantments / Spells Enchantments and spells Mods: Aftershock Anything to do with the Aftershock mod Mods: Innawood 🌲 Anything to do with Innawood mod Mods: MA Massachussetts mod. Cata in one state Mods: Magiclysm Anything to do with the Magiclysm mod Mods: Mind Over Matter Mods: MMA Mythical Martial Arts mod Mods: Xedra Evolved Anything to do with Xedra Evolved Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies [Python] Code made in Python Scenarios New Scenarios, balancing, bugs with scenarios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants