Skip to content

feat: warn on unknown concept metadata keys at load time#116

Merged
QMalcolm merged 2 commits into
mainfrom
qmalcolm--feat-load-time-validation-warnings
May 6, 2026
Merged

feat: warn on unknown concept metadata keys at load time#116
QMalcolm merged 2 commits into
mainfrom
qmalcolm--feat-load-time-validation-warnings

Conversation

@QMalcolm

@QMalcolm QMalcolm commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds custom_metadata_keys to RuleModule / module.toml — the escape hatch for system authors to declare intentional domain keys (display metadata like school, casting_time, etc.) without triggering warnings
  • Loader.load/1 now calls warn_unknown_metadata_keys/3 after building the concept_metadata map; any key not in the allowed set emits a grouped Logger.warning (one per {key, type_id}, listing affected concept IDs)
  • Allowed keys are the union of: structural vocabulary (18 fixed keys the library reads), metadata_contributions from_field / label_filters.filter_field, inventory_rules dynamic field names, and custom_metadata_keys
  • dnd_5e_srd/module.toml gets a custom_metadata_keys list (38 domain keys) built empirically via the integration test; loading the system now produces zero warnings

Closes the "Add load-time validation for metadata keys" todo from the over-configurability cleanup list. Warnings now rather than errors — a future breaking release can elevate them once authors have migrated.

Test plan

  • All 49 existing tests pass
  • New integration test: dnd_5e_srd loads with no unknown metadata key warnings asserts zero log output when loading the full D&D 5e SRD
  • Unit tests for: unknown key warns; structural vocab keys don't warn; metadata_contributions.from_field keys don't warn; custom_metadata_keys suppresses warnings; multi-concept warnings group into one per {key, type_id}

Summary by Bito

  • Added a new module attribute @structural_metadata_keys containing a MapSet of allowed metadata keys for rule system concepts.
  • Introduced warn_unknown_metadata_keys function to log warnings for unknown metadata keys found in concept metadata during loading.
  • Added build_allowed_keys and extract_inventory_rules_keys helper functions to construct the set of allowed metadata keys from rule module and inventory rules.
  • Modified the load function to call warn_unknown_metadata_keys after expanding metadata contributions.

QMalcolm added 2 commits May 5, 2026 22:37
Adds an optional custom_metadata_keys list to RuleModule, populated from
module.toml. This will be used by the load-time metadata key validator to
suppress warnings for domain-specific keys that are intentional but not
part of the library's structural vocabulary.
Previously, typos or undeclared keys in concept TOML silently had no
effect — the library ignored them without any feedback. This made it
easy to author broken config that appeared correct.

Now, `load/1` calls `warn_unknown_metadata_keys/3` after building the
concept_metadata map. Any key not in the allowed set emits a
Logger.warning grouped by {key, type_id} to avoid one warning per
concept. The warning names the system slug and lists the affected
concept IDs (first 5, then "+ N more").

Allowed keys are the union of four sources:
1. The structural vocabulary (@structural_metadata_keys) — the 18 keys
   the library reads by name from concept metadata.
2. metadata_contributions from_field and label_filters.filter_field
   values, which the loader expands into effects at load time.
3. inventory_rules dynamic keys (mode_field, pool_field,
   always_prepared_metadata_key, class_filter_field) — read by the
   evaluator at runtime from the InventoryRules config.
4. custom_metadata_keys declared in module.toml — the escape hatch for
   system authors who use domain-specific metadata keys that the
   library never reads (e.g. display metadata like "school",
   "casting_time", "description").

The dnd_5e_srd custom_metadata_keys list was built empirically by
running the integration test and iterating until zero warnings
remained, rather than enumerating by hand.

Warnings rather than errors to allow a smooth rollout. A future
breaking release can elevate these to errors once authors have had time
to migrate.

@QMalcolm QMalcolm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

✔️

@QMalcolm QMalcolm merged commit dd21271 into main May 6, 2026
5 checks passed
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