Skip to content

fix schema arbitrary constraint combiners for BigInt, Date, and BigDecimal#2265

Open
Gabrola wants to merge 2 commits into
Effect-TS:mainfrom
Gabrola:fix/arbitrary-min-max-bounds
Open

fix schema arbitrary constraint combiners for BigInt, Date, and BigDecimal#2265
Gabrola wants to merge 2 commits into
Effect-TS:mainfrom
Gabrola:fix/arbitrary-min-max-bounds

Conversation

@Gabrola
Copy link
Copy Markdown
Contributor

@Gabrola Gabrola commented May 25, 2026

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Summary

Fix schema arbitrary constraint derivation for BigInt, Date, and BigDecimal checks.

  • Merge constraint bounds with type-specific combiners instead of shared number-based reducers.
  • Add BigDecimal arbitrary constraints and generate bigint bounds for each selected decimal scale.
  • Skip BigDecimal scales whose rounded bounds cross before passing constraints to fast-check.
  • Add regression coverage for BigInt, Date context handling, and BigDecimal rescaling.

Why

The previous constraint merging path did not handle non-number bounds reliably, and BigDecimal generation reused decimal bounds without adapting them to the generated scale. That made some valid decimal values effectively unreachable and could produce invalid fast-check bigint ranges for narrow decimal intervals.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

🦋 Changeset detected

Latest commit: 1e05bf2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Gabrola Gabrola marked this pull request as ready for review May 25, 2026 07:34
@Gabrola Gabrola force-pushed the fix/arbitrary-min-max-bounds branch from d9da684 to d6851bc Compare May 25, 2026 07:37
Comment thread packages/effect/src/Schema.ts Outdated
toArbitraryConstraint: {
bigint: {
min: exclusiveMinimum,
minExcluded: true
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fast-check doesn't have minExcluded/maxExcluded on bigints

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you are right, working on a fix that also includes dates and integers: #2266

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gcanti that's perfect, I'll readjust my fix to match

@Gabrola Gabrola force-pushed the fix/arbitrary-min-max-bounds branch 2 times, most recently from dd415ae to 50f729f Compare May 25, 2026 12:14
@Gabrola Gabrola force-pushed the fix/arbitrary-min-max-bounds branch from 50f729f to bd8045e Compare May 25, 2026 12:15
Comment on lines +628 to +637
it("isBetweenBigDecimal", () => {
verifyGeneration(
Schema.BigDecimal.check(
Schema.isBetweenBigDecimal({
minimum: BigDecimal.make(100n, 0),
maximum: BigDecimal.make(200n, 0)
})
)
)
})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one is a little peculiar. Before the fix, fast-check was only generating bigints between -77n and 77n, so this test was just running in an infinite loop

@Gabrola Gabrola changed the title Fix schema arbitrary constraint bounds fix schema arbitrary constraint combiners for BigInt, Date, and BigDecimal May 25, 2026
@Gabrola Gabrola force-pushed the fix/arbitrary-min-max-bounds branch from d5065fc to 1e05bf2 Compare May 25, 2026 12:46
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