Skip to content

Freeze era definition structs - #27

Merged
sugi merged 1 commit into
masterfrom
freeze-era-defs
Jul 13, 2026
Merged

sugi merged 1 commit into
masterfrom
freeze-era-defs

Conversation

@sugi

@sugi sugi commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to a Copilot review comment on #24: the ERA_DEFS / ERA_NORTH_DEFS arrays were frozen but the Era structs inside were not, so a caller mutating an era returned by Utils.find_era or ERA_BY_NAME could corrupt process-wide era definitions. This freezes the structs at definition time (including the ad-hoc 皇紀/西暦 entries), which covers every lookup path without adding per-call copies on the conversion hot path.

The ERA_JD_LOOKUP builder keeps working as-is since it dups entries before adjusting them (dup of a frozen struct is unfrozen); this also stays correct if #24 (which removes that builder) merges in either order.

Test plan

  • TDD: new spec asserting all era definition structs and find_era results are frozen, confirmed failing first
  • bundle exec rspec: 66 examples, 0 failures; RuboCop: no offenses

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q1Pf4Mrtd7zB8Lrjc499t9

The containing arrays were frozen but the Era structs inside were
not, so a caller mutating an era returned by find_era or ERA_BY_NAME
could corrupt process-wide state. Freeze them at definition time;
this covers every lookup path without per-call copies.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q1Pf4Mrtd7zB8Lrjc499t9

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that era definitions and individual Era objects are frozen to prevent unintended modifications. Specifically, it freezes the Era instances assigned to ERA_BY_NAME in lib/wareki/common.rb, freezes each Era object inside the definition arrays in lib/wareki/era_def.rb, and adds a unit test in spec/utils_spec.rb to verify that these definitions are indeed frozen. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@sugi
sugi merged commit d7d09ec into master Jul 13, 2026
9 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