Skip to content

refactor(tests): generalise scalar matrix harness off integer-inherent consts#258

Merged
tobyhede merged 2 commits into
eql_v3from
v3-scalar-harness-generalize
Jun 4, 2026
Merged

refactor(tests): generalise scalar matrix harness off integer-inherent consts#258
tobyhede merged 2 commits into
eql_v3from
v3-scalar-harness-generalize

Conversation

@tobyhede
Copy link
Copy Markdown
Contributor

@tobyhede tobyhede commented Jun 3, 2026

Summary

PR 1 of 2 (stacked). Makes the SQLx scalar-matrix harness type-agnostic ahead of the first non-integer scalar, without adding one — so the date type (#256, stacked on this branch) becomes a clean catalog-row-plus-wiring change. Behaviour-preserving for the existing int4 / int2 types.

What changed

Three integer assumptions in the harness are lifted:

  • ScalarType::FIXTURE_VALUES (a const) → fn fixture_values(). A method, so a scalar whose values can't be const-constructed (e.g. a chrono type) can return a borrow of a lazily-built Vec. Integer impls still hand back their eql_scalars::<T>_VALUES const.
  • New min_pivot() / max_pivot() trait methods replace the matrix's direct <T>::MIN / <T>::MAX pivot references, so a scalar without an inherent ::MIN/::MAX const can supply an explicit sentinel.
  • The ORDER BY arms build their WHERE clause from to_sql_literal(zero) instead of a hardcoded > 0, so a non-integer plaintext column typechecks.

The macro emits the new method shape for integer impls; the int4 cargo-expand snapshot is regenerated to track the method-based bodies.

Why behaviour-preserving

For int4 / int2: min_pivot/max_pivot resolve to Self::MIN/Self::MAX, to_sql_literal(0) renders 0 (so WHERE plaintext > 0 is byte-identical), and the generated test names are unchanged — the matrix_tests.txt inventory snapshot does not move.

Verification

  • cargo test -p eql-tests-macros — green
  • cargo check -p eql_tests --tests — clean (the const→fn rename compiles across all ~20 call sites)
  • cargo fmt --check, clippy -D warnings — clean

Full PG matrix runs in CI. PR 2 (eql_v3.date) stacks on this branch.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated internal test infrastructure to improve fixture value and pivot handling within the test suite.

…t consts

Make the SQLx scalar-matrix harness type-agnostic ahead of the first
non-integer scalar, without adding one. Three integer assumptions are lifted:

- `ScalarType::FIXTURE_VALUES` (a `const`) becomes `fn fixture_values()`, so a
  scalar whose values can't be const-constructed can return a borrow of a
  lazily-built `Vec` instead. Integer impls still hand back their
  `eql_scalars::<T>_VALUES` const.
- New `min_pivot()` / `max_pivot()` trait methods replace the matrix's direct
  `<T>::MIN` / `<T>::MAX` pivot references, so a scalar without an inherent
  `::MIN`/`::MAX` const can supply an explicit sentinel.
- The ORDER BY arms build their `WHERE` clause from `to_sql_literal(zero)`
  instead of a hardcoded `> 0`, so a non-integer plaintext column typechecks.

Behaviour-preserving for the existing `int4` / `int2` types: the integer
`min_pivot`/`max_pivot` resolve to `Self::MIN`/`Self::MAX`, `to_sql_literal(0)`
renders `0`, and the generated test names are unchanged. The int4 cargo-expand
snapshot is regenerated to track the method-based bodies.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bdac2ad-096f-49d3-93f0-8da4c3305ffe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v3-scalar-harness-generalize

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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-tests-macros/src/lib.rs`:
- Around line 268-273: The test currently only checks for the substrings
"MIN"/"MAX" which may appear in doc comments; update the assertions to verify
the actual emitted pivot function bodies for min_pivot and max_pivot instead of
loose substrings. Specifically, in the test that inspects out, replace the
out.contains("MIN") and out.contains("MAX") checks with assertions that match a
more precise snippet from the generated functions (e.g., the signature and the
body that returns the inherent bounds for min_pivot and max_pivot) so you
validate the functions min_pivot and max_pivot actually return the expected
bounds; keep the existing checks for "fn fixture_values" and the presence of the
pivot function names.

In `@tests/sqlx/src/scalar_domains.rs`:
- Around line 37-46: The contract for fixture_values() is ambiguous about
ordering but callers (e.g., ordered_numeric_matrix! driven code) depend on a
stable, insertion-consistent ordering and perform positional indexing; update
the trait/docs and implementations so fixture_values() guarantees a
deterministic order matching the fixture insertion order (or explicitly sorted
by a defined key) — modify the fixture_values() implementations for non-integer
scalars to build and return a statically stable slice (e.g., by producing a Vec
once in a deterministic order and leaking or storing it as &'static [Self]) and
update the trait comment for fixture_values() to state that callers may rely on
its ordering (or alternatively have callers sort before positional access if
ordering cannot be guaranteed).
🪄 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: 39aa6b97-4a18-4a3e-8315-f083e656290e

📥 Commits

Reviewing files that changed from the base of the PR and between b45cea6 and b265e43.

📒 Files selected for processing (5)
  • crates/eql-tests-macros/src/lib.rs
  • tests/sqlx/snapshots/int4_expanded.rs
  • tests/sqlx/src/matrix.rs
  • tests/sqlx/src/scalar_domains.rs
  • tests/sqlx/tests/encrypted_domain/family/mutations.rs

Comment thread crates/eql-tests-macros/src/lib.rs Outdated
Comment thread tests/sqlx/src/scalar_domains.rs
- scalar_domains.rs: document fixture_values() stable-order contract
  (callers compare element-wise and index positionally without sorting)
- eql-tests-macros: assert emitted min_pivot/max_pivot bodies instead of
  loose MIN/MAX substrings that also match the doc comment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tobyhede
Copy link
Copy Markdown
Contributor Author

tobyhede commented Jun 3, 2026

Fixes Applied Successfully

Fixed 2 file(s) based on 2 CodeRabbit feedback item(s).

Files modified:

  • tests/sqlx/src/scalar_domains.rs — documented the fixture_values() stable-order contract (callers compare the slice element-wise against the ORDER BY id plaintext column and index positionally [0]/[len/2] without sorting; a lazily-built Vec must preserve fixture insertion order).
  • crates/eql-tests-macros/src/lib.rs — assert the emitted min_pivot/max_pivot function bodies instead of loose MIN/MAX substrings that also match the doc comment.

Commit: 09d1de1

The latest autofix changes are on the v3-scalar-harness-generalize branch.

@tobyhede tobyhede merged commit 750152f into eql_v3 Jun 4, 2026
10 checks passed
@tobyhede tobyhede deleted the v3-scalar-harness-generalize branch June 4, 2026 10:07
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