From 153acb7f644d755c45533b7c5311e3ffa47e8973 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 18 Sep 2026 05:31:09 -0400 Subject: fix: harden engine across casino, economy, concurrency, security, and content --- internal/item/store.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'internal/item/store.go') diff --git a/internal/item/store.go b/internal/item/store.go index e50e6e9..12aa729 100644 --- a/internal/item/store.go +++ b/internal/item/store.go @@ -2,6 +2,7 @@ package item import ( "fmt" + "log" "os" "path/filepath" "sync" @@ -44,6 +45,7 @@ func (s *ItemStore) Load(id string) (*ItemDef, error) { if err := yaml.Unmarshal(data, &def); err != nil { return nil, fmt.Errorf("parse item %s: %w", id, err) } + warnDeclaredIDMismatch("item", path, id, def.ID) def.ID = id s.cache[id] = &def return &def, nil @@ -63,6 +65,7 @@ func (s *ItemStore) LoadAll() ([]*ItemDef, error) { if err := yaml.Unmarshal(data, &def); err != nil { return fmt.Errorf("parse item %s: %w", id, err) } + warnDeclaredIDMismatch("item", path, id, def.ID) def.ID = id s.cache[id] = &def defs = append(defs, &def) @@ -71,6 +74,17 @@ func (s *ItemStore) LoadAll() ([]*ItemDef, error) { return defs, err } +// warnDeclaredIDMismatch logs when a data file declares an id: that disagrees +// with its filename. IDs come from the filename (def.ID = id above), so the +// declared value is silently ignored at runtime; without this warning an author +// sees no sign that the id they wrote is dead. +func warnDeclaredIDMismatch(kind, path, filenameID, declaredID string) { + if declaredID != "" && declaredID != filenameID { + log.Printf("%s %s: file declares id %q but is loaded as %q; the filename is authoritative and the declared id is ignored", + kind, path, declaredID, filenameID) + } +} + // PathIndex returns a copy of the id→path index, safe to iterate concurrently. func (s *ItemStore) PathIndex() map[string]string { s.mu.Lock() -- cgit v1.2.3