Skip to content

ogar-from-ruff: lift Rails enum variant keys in declared order - #373

Merged
AdaWorldAPI merged 1 commit into
mainfrom
ccr-8062bcc7-l7lkz9-o1
Nov 7, 2026
Merged

AdaWorldAPI merged 1 commit into
mainfrom
ccr-8062bcc7-l7lkz9-o1

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Problem

lift_enum (crates/ogar-from-ruff/src/lib.rs) ignored AttrDecl::options, so every Rails enum came out as EnumSource::Static(empty).

Its doc comment blamed the walker for dropping the variant hash, but that is wrong. The ruff_ruby_spo walker keeps every key, its integer, and the source order. For enum :status, { shipped: 3, cancelled: 7 } the hash reaches options through as_hash_options (ruff_ruby_spo/src/walk.rs:449-453). The loss happened in this lift.

Change

lift_enum now puts the variant keys into EnumSource::Static, in declared order.

  • Label = key. This matches ogar-from-schema; no "no label" convention exists.
  • The Rails integer is not put in the label slot. ogar-emitter publishes that slot as variantValue, and the integer is a source-local physical id. Its home is the source's versioned code map in DR, not the class's meaning. A test pins this.
  • A duplicate key is refused. lift_enum returns None, following the crate's Option-returning lift_* convention. Rails itself rejects duplicate enum keys, so such a source is invalid input.
  • The stale doc comment is corrected. The existing test near :1566 stays valid, because its fixture has empty options, and its comment now says so.

The change is in crates/ogar-from-ruff/src/lib.rs only: about 35 non-test lines, mostly doc text. ogar_vocab is unchanged.

Tests

Six new tests. Before the fix, four were red: keeps_variant_keys_in_declared_order, reorder_changes_order_not_key_identity, label_is_the_key_never_the_rails_integer, refuses_duplicate_key. The other two are guards: ordinary attributes are unchanged, and an enum-less class has no enums.

Disable run (after commit). I replaced the assignment with Static(Vec::new()) and asserted the patch applied. Three tests went red: keeps_variant_keys_in_declared_order, label_is_the_key_never_the_rails_integer and reorder_changes_order_not_key_identity. refuses_duplicate_key stayed green, because the duplicate check runs before that line.

Validation

All runs used CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_INCREMENTAL=0.

  • cargo test -p ogar-from-ruff: 89 passed, 0 failed. I re-ran this independently.
  • ogar-vocab and ogar-from-rails (which wraps the same lift) pass.
  • Clippy -D warnings and fmt are clean.
  • ogar-doc-ir, ogar-from-docv1 and ogar-loco pass.
  • ogar-action-handler has 3 tests in ogit_schema_composition that also fail on a clean main worktree (panic in ogit_checkout.rs:23). The likely cause is the missing OGIT checkout. They are not from this change.

Open (not in this PR)

  • Unsupported spellings. The walker returns empty options for dynamic, array and no-argument enums, so the lift cannot tell them apart. They stay a key-less Static, now documented as "variant list not recovered". An explicit marker needs either an EnumSource variant or a walker change (ruff PR-R1); that is a vocabulary decision.
  • Kwarg form. enum status: {...} produces no declaration at all in the walker. That is a ruff fix (PR-R1).

Part of the OGAR × DR × DT64 semantic-continuity plan (producer fidelity, PR-O1).


Generated by Claude Code

lift_enum ignored AttrDecl options and returned Static(empty) although the
ruby walker keeps the variant hash. Keys now land in the key slot in source
order; the label is the key (no label is declared in Rails source; matches
ogar-from-schema); the Rails integer stays out of the label slot because the
emitter publishes it as variantValue. A duplicate key is refused (None).
Empty options (array form, constant, no argument) stay key-less and are
documented as 'not recovered'. Corrected the stale doc comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c87a0926-98e1-40be-8f25-26545991b430
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T23:12:03.979284Z 070ef95 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@AdaWorldAPI
AdaWorldAPI merged commit 5fe3b63 into main Nov 7, 2026
4 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.

2 participants