TML-2732: collation-independent storage-sort comparator#721
Conversation
…onicalization-storage-sort storageHash was non-deterministic across hosts with different ICU/collation builds because compareByNameProperty used localeCompare. Replace with a code-unit ternary so ordering is byte-stable regardless of locale. Existing idx_*/uq_* fixture names are lowercase ASCII snake_case, so code-unit order equals locale order for them — fixtures are unaffected. Adds a locale-independence regression test pinning Z < a (code-unit: U+005A < U+0061); a future reversion to localeCompare would fail this case on most locale builds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: wmadden-electric <286902546+wmadden-electric@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughcompareByNameProperty was changed to compare name strings by raw UTF-16 code units via a new compareCodeUnits helper instead of using localeCompare. A Vitest case was added to assert that ChangesCode-unit comparison in string sorting
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/1-framework/0-foundation/contract/test/canonicalization-storage-sort.test.ts (1)
100-102: ⚡ Quick winDrop the inline explanatory block and keep just the test case.
The test name and assertion already capture intent; these comments add noise in a file where concision is preferred.
As per coding guidelines, "
**/*.{ts,tsx,js,jsx}: Don't add comments if avoidable, prefer code that expresses its intent."🤖 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 `@packages/1-framework/0-foundation/contract/test/canonicalization-storage-sort.test.ts` around lines 100 - 102, Remove the three-line explanatory comment block about locale-independence/code-unit order that precedes the test in canonicalization-storage-sort.test.ts and leave only the test case and its assertion; do not change the test name or logic (the test already documents intent), simply delete the inline comment to keep the file concise.
🤖 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.
Nitpick comments:
In
`@packages/1-framework/0-foundation/contract/test/canonicalization-storage-sort.test.ts`:
- Around line 100-102: Remove the three-line explanatory comment block about
locale-independence/code-unit order that precedes the test in
canonicalization-storage-sort.test.ts and leave only the test case and its
assertion; do not change the test name or logic (the test already documents
intent), simply delete the inline comment to keep the file concise.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: f75707a0-5bde-4f74-b490-29bc065cd214
📒 Files selected for processing (2)
packages/1-framework/0-foundation/contract/src/canonicalization-storage-sort.tspackages/1-framework/0-foundation/contract/test/canonicalization-storage-sort.test.ts
size-limit report 📦
|
wmadden
left a comment
There was a problem hiding this comment.
I stand corrected, < is exactly what we should do.
Address review on #721: name the deterministic comparator so its intent reads from the code (not a bare `<`/`>`), and drop the verbose inline comment from the regression test (the test name carries the intent). No behavioural change — still UTF-16 code-unit, collation-independent order. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Will Madden <madden@prisma.io>
Replace
localeComparewith a deterministic code-unit comparator incompareByNameProperty(packages/1-framework/0-foundation/contract/src/canonicalization-storage-sort.ts).Why
storageHashstability must not depend on the host.compareByNamePropertyfeedscreateStorageSort→ the SQL canonicalization hook →canonicalizeContract, so ordering index/unique arrays withlocaleCompare(no locale/options) makes canonical bytes depend on the host's ICU/collation build — two machines with different ICU data could produce a differentstorageHashfor the same contract. This was a verbatim carry-over flagged by CodeRabbit on #631 and deliberately deferred there (that PR had a byte-identical-output invariant; changing the comparator is a hashing-semantics change, so it could not ride along).Change
nameA < nameB ? -1 : nameA > nameB ? 1 : 0. This is the onlylocaleCompareon the canonicalization path.compareByNameProperty({ name: 'Z' }, { name: 'a' }) < 0— code-unit ordersZ(U+005A) beforea(U+0061); locale collation would not, so a reversion tolocaleComparefails the test.Scope / verification (reviewer ~1 min)
pnpm typecheck+ 168/168 package tests +pnpm lintgreen.fixtures:checkis a no-op for this change. (Current names are all lowercase ASCIIsnake_case, where code-unit and locale order coincide anyway.)Refs: TML-2732
🤖 Generated with Claude Code
Summary by CodeRabbit