Skip to content

fix: restore native Arbitrary for StringId, Url, RequestId, Finite - #902

Merged
patroza merged 4 commits into
mainfrom
t3code/stringid-native-arbitrary
Sep 16, 2026
Merged

patroza merged 4 commits into
mainfrom
t3code/stringid-native-arbitrary

Conversation

@patroza

@patroza patroza commented Sep 16, 2026

Copy link
Copy Markdown
Member

Why

Native Arbitrary replaced fast-check toArbitrary. generateFromSchema now draws sampleEffect({ count: 1 }), which is always attempt 0 (edge-biased). StringId lost its nanoid generator, so successive samples collide (UNIQUE PickItems.id in scanner e2e) and look like toString / prototype. Url samples garbage that isURL({ require_tld: false }) happens to accept.

What

  • StringId / prefixedStringId: 21-char nanoid-shaped native generation (old StringIdArb).
  • Url: https://… pattern (old fc.webUrl()).
  • RequestId: generation-only nanoid-shaped samples (decode still accepts looser span ids).
  • Finite: generation-only ±1e6 cap so products stay finite (same class as PositiveNumber).
  • generateFromSchema: jump master seed per call ("${seed}:${n}") like fast-check's shared Random.

Email, PhoneNumber, PositiveNumber/NonNegativeNumber were already constrained.

How

arbitraryConstraint on the existing checks/refines (generation-only; JSON Schema and decode unchanged). Tests cover unique StringId/RequestId, https Urls, and Finite magnitudes.

Remarks

Scanner/configurator stay on 328 until this is versioned (329+), then bump. Configurator ISOCode still needs isPattern(/^[A-Z]{2}$/) locally (scanner already has it).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

generateFromSchema used sampleEffect({ count: 1 }) which always draws
attempt 0. Combined with StringId losing its nanoid toArbitrary, successive
samples collided (UNIQUE PickItems.id). Jump the master seed per call like
fast-check's shared Random, and steer generation: nanoid-shaped StringId,
https URLs, unique RequestIds, Finite ±1e6.
@patroza
patroza marked this pull request as ready for review September 16, 2026 08:55
@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@effect-app/cli

npm i https://pkg.pr.new/effect-app/libs/@effect-app/cli@902

effect-app

npm i https://pkg.pr.new/effect-app/libs/effect-app@902

@effect-app/eslint-codegen-model

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-codegen-model@902

@effect-app/eslint-shared-config

npm i https://pkg.pr.new/effect-app/libs/@effect-app/eslint-shared-config@902

@effect-app/infra

npm i https://pkg.pr.new/effect-app/libs/@effect-app/infra@902

@effect-app/vue

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue@902

@effect-app/vue-components

npm i https://pkg.pr.new/effect-app/libs/@effect-app/vue-components@902

commit: b029e9e

Native replacement for fast-check toArbitrary is a Schema.declare link,
not a regex. JSON stays a branded string (toCodec); Arbitrary generates
Uint8Array(210) then customRandom(urlAlphabet, 21) like StringIdArb.
Native replacement for fast-check toArbitrary is Schema.declare's
toCodecArbitrary link, not a regex. Encoded stays string
(declareConstructor<StringId, string>). Arbitrary generates
Uint8Array(210) then customRandom(urlAlphabet, 21) like StringIdArb.
@patroza

patroza commented Sep 16, 2026

Copy link
Copy Markdown
Member Author

Follow-up: StringId now uses native toCodecArbitrary (the replacement for fast-check toArbitrary) — generate Uint8Array(210) then customRandom(urlAlphabet, 21), same as old StringIdArb. JSON stays a branded string via toCodec / declareConstructor<StringId, string>.

prefixedStringId again maps nanoid then prefix+substring, matching
rc.112 toArbitrary. Tests assert 21-char urlAlphabet ids and foo- prefix.
@patroza
patroza merged commit 459697f into main Sep 16, 2026
6 checks passed
@patroza
patroza deleted the t3code/stringid-native-arbitrary branch September 16, 2026 09:16
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