refactor(eql-scalars): split lib.rs into definitions + impl/test modules#266
Conversation
The crate's single lib.rs had grown to 1215 lines, ~55% of it tests, with each enum's definition interleaved with its impl block. Reorganise for readability so the catalog reads top-to-bottom: - lib.rs (~240 lines) keeps the *definitions* — the six type defs, the two crate-internal macros (fixtures!, int_values!), and all catalog data (ORDERED_INT_DOMAINS, INT*_FIXTURES, INT4/INT2/INT8/DATE, CATALOG, INT*_VALUES). - Inherent impls move to sibling modules: kind.rs (BoundedIntKind, ScalarKind), term.rs (Term), fixture.rs (Fixture), spec.rs (ScalarSpec). Methods travel with their types, so no re-exports are needed. - The 7 unit-test modules move verbatim into tests.rs (#[cfg(test)] mod tests), kept as one group because rust_tests spans multiple types; use super::* becomes use crate::*. Pure code-move, zero behaviour change. Public API surface of the crate is unchanged. Verified: cargo test -p eql-scalars (40 pass), codegen:parity (byte-for-byte identical int4 golden), test:crates clippy -D warnings clean, eql-codegen/eql-tests-macros build unchanged.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/eql-scalars/src/tests.rs (1)
606-625: 💤 Low valueOutdated comment: CATALOG now includes DATE.
The comment on line 607 states "CATALOG is int-only, so the
Strpath is otherwise unexercised", butDATEis now in the catalog withFixture::Date(...)variants that do exercise theDistinctKey::Strarm infixture_values_are_distinct_by_resolved_number.📝 Suggested comment update
#[test] fn distinct_key_separates_string_fixtures() { - // CATALOG is int-only, so the `Str` path is otherwise unexercised. + // Exercises the `Str` path for string-backed variants beyond DATE (which is + // in the catalog but only uses Date fixtures). assert_eq!(🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/eql-scalars/src/tests.rs` around lines 606 - 625, Update the outdated test comment in the distinct_key_separates_string_fixtures test: remove or reword the sentence "CATALOG is int-only, so the `Str` path is otherwise unexercised" to reflect that CATALOG now includes DATE and that Fixture::Date variants exercise the DistinctKey::Str arm (see fixture_values_are_distinct_by_resolved_number and DistinctKey::Str). Ensure the comment accurately describes current coverage (e.g., note DATE exercises the Str path) or drop the claim entirely so the test comment matches the code behavior in distinct_key_separates_string_fixtures and related fixtures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/eql-scalars/src/kind.rs`:
- Around line 89-99: The docstring for ScalarKind::rust_type incorrectly claims
the returned strings are "Rust type name[s] as they appear in generated source"
while Numeric/Text/Jsonb return "numeric"/"text"/"jsonb" and are not used by
codegen; update the ScalarKind::rust_type documentation to accurately state its
behavior (e.g., that it returns canonical Rust type names only for
I16/I32/I64/Date and returns SQL/type-identifiers or placeholders for
Numeric/Text/Jsonb), and mention the only call sites
(crates/eql-scalars/src/tests.rs) if helpful; alternatively, if you prefer
functional change, either remove/merge the unused variants from ScalarKind or
change rust_type to return Option<&'static str> for only codegen-supported
variants—apply the chosen change to ScalarKind::rust_type and update any tests
that rely on its current return values.
---
Nitpick comments:
In `@crates/eql-scalars/src/tests.rs`:
- Around line 606-625: Update the outdated test comment in the
distinct_key_separates_string_fixtures test: remove or reword the sentence
"CATALOG is int-only, so the `Str` path is otherwise unexercised" to reflect
that CATALOG now includes DATE and that Fixture::Date variants exercise the
DistinctKey::Str arm (see fixture_values_are_distinct_by_resolved_number and
DistinctKey::Str). Ensure the comment accurately describes current coverage
(e.g., note DATE exercises the Str path) or drop the claim entirely so the test
comment matches the code behavior in distinct_key_separates_string_fixtures and
related fixtures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0346b025-8b01-4f9b-a22e-1e89b430f602
📒 Files selected for processing (6)
crates/eql-scalars/src/fixture.rscrates/eql-scalars/src/kind.rscrates/eql-scalars/src/lib.rscrates/eql-scalars/src/spec.rscrates/eql-scalars/src/term.rscrates/eql-scalars/src/tests.rs
The docstring claimed all returned strings are Rust type names as they appear in generated source, but Numeric/Text/Jsonb return SQL tokens (numeric/text/jsonb) and have no generated surface. Clarify that only I16/I32/I64/Date return canonical Rust type names and the rest are placeholders, and note the sole call site (tests.rs).
refactor(eql-scalars): split lib.rs into definitions + impl/test modules
What
crates/eql-scalars/src/lib.rshad grown to 1215 lines — ~55% of it tests, with each enum's definition interleaved with itsimplblock. This reorganises the crate so the catalog reads top-to-bottom, per the stated ideal: definitions at the top level for simple access; implementation and tests in modules.Pure code-move, zero behaviour change. The crate's public API surface is unchanged.
Layout
lib.rs(1215 → ~240 lines) now holds only the definitions:BoundedIntKind,ScalarKind,Term,Fixture,DomainSpec,ScalarSpec)fixtures!,int_values!)ORDERED_INT_DOMAINS,INT*_FIXTURES,INT4/INT2/INT8/DATE,CATALOG,INT*_VALUES)Inherent
implblocks move to sibling modules (methods travel with their types — no re-exports needed):kind.rsBoundedIntKind,ScalarKindterm.rsTerm(both blocks)fixture.rsFixturespec.rsScalarSpecThe 7 unit-test modules move verbatim into
tests.rs(#[cfg(test)] mod tests), kept as one group becauserust_testsspans multiple types;use super::*→use crate::*. Test names are preserved (now under thetests::path).Why these choices
pub useneeded, public paths (eql_scalars::{CATALOG, INT4_VALUES, …}) unchanged, soeql-codegen/eql-tests-macros/tests/sqlxcompile without edits.lib.rs(crate-internal, not#[macro_export]) so they precede their use sites;tests.rsseesfixtures!by textual scoping (mod tests;is declared after the macro).rust_testsexercisesBoundedIntKind+ScalarKind+Fixture+ScalarSpecand would otherwise fragment.Verification
cargo test -p eql-scalarsmise run test:codegenmise run codegen:paritymise run test:crates(clippy-D warnings)eql-codegen/eql-tests-macrosbuildmise run test:matrix:inventoryThe byte-for-byte parity pass is the definitive proof this is behaviour-preserving.
Scope
Diff touches
crates/eql-scalars/src/only:lib.rs(−963/+39) + 5 new module files.Summary by CodeRabbit
Refactor
Tests