Repository navigation
fix(codegen): sort schema snapshot keys by code unit, not locale - #188
Conversation
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
|
Warning Review limit reached
Next review available in: 15 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (1)
WalkthroughSchema snapshot generation now uses locale-independent code-unit sorting for record keys and migration IDs, producing byte-stable JSON while retaining declaration order for fields, indexes, and relations. ChangesSchema snapshot determinism
Estimated code review effort: 2 (Simple) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
`.lunora-schema.json` is a COMMITTED file whose whole purpose is to be byte-stable so drift detection is meaningful. It sorted table names and migration ids with `localeCompare`, which resolves against the runtime's default locale and ICU version — so two developers, or a developer and CI, or one machine either side of a Node upgrade, could regenerate the same schema and produce different bytes. That surfaces as a spurious diff and a false drift signal, which is exactly what the sort was there to prevent. Sorts by UTF-16 code unit instead, which is locale-independent. No committed snapshot changes: all 9 in-repo `.lunora-schema.json` files were checked object-by-object (191 objects) and no key ordering differs between the two comparators — their names are all lowercase ASCII, where ICU collation and code-unit order agree. So no fixture regeneration. Field / index / relation keys are deliberately left in declaration order and are now documented as such; they were never locale-sorted. Found while auditing `@lunora/replica`, which had the same bug in two places (see #185). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Each case scaffolds a whole project, parses its schema and function modules through `runCodegen` (a real TypeScript parse), and runs the wrangler validator — far more work than a unit test, against the shared 10s local budget (CI gets 30s). On an unloaded machine the heaviest case takes ~6.4s of that 10s, thin enough that running anything else concurrently tips it over. It failed that way twice during an unrelated audit and passed on re-run, while CI stayed green — a flake that costs a full re-run to diagnose each time. Scoped to this suite rather than raising the global default, so genuinely hung unit tests elsewhere still fail fast. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
8585afc to
b3919a6
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The two follow-ups flagged during the benchmark/perf audit in #185, which were out of scope there. Independent of that PR — this branches off
alphadirectly.1.
codegen— schema snapshot ordering was locale-dependentpackages/codegen/src/schema-drift.tssorted table names and migration ids withlocaleCompare. That resolves against the runtime's default locale and ICU version, so it is not stable across machines — which defeats the entire point, since.lunora-schema.jsonis a committed file and the sort exists specifically to make it byte-stable.The failure mode: two developers, or a developer and CI, or one machine either side of a Node upgrade, regenerate the same schema and get different bytes. That reads as a spurious diff and a false drift signal.
Now sorted by UTF-16 code unit, which is locale-independent. Same bug class as the two instances fixed in
@lunora/replicain #185 — this was the third, in a different package.No committed snapshot changes. I checked all 9 in-repo
.lunora-schema.jsonfiles object-by-object (191 objects) and no key ordering differs between the two comparators: every table and migration name is lowercase ASCII, where ICU collation and code-unit order agree. So no fixture regeneration, and the diff is confined to source plus a test.The new test uses fixtures where the two orderings genuinely disagree (
Berries/_hidden/apples, andA_one/b_two), so a regression to a locale-aware comparator flips it. Without that, a test using ordinary lowercase names would pass under either comparator and guard nothing.Field / index / relation keys are left in declaration order — they were never locale-sorted, and that is now documented rather than left ambiguous.
2.
cli— the init smoke suite runs against too tight a timeoutEach case scaffolds a whole project, parses its schema and function modules through
runCodegen(a real TypeScript parse), and runs the wrangler validator. That is far more work than a unit test, and it lands against the shared 10s local budget (tools/get-vitest-config.ts; CI gets 30s).On an unloaded machine the heaviest case takes ~6.4s of that 10s — thin enough that running anything else concurrently tips it over. It failed exactly that way twice during the #185 audit and passed on re-run, while CI stayed green. Each occurrence costs a full re-run to diagnose.
Scoped to this suite via
describe(name, { timeout }, fn)rather than raising the global default, so genuinely hung unit tests elsewhere still fail fast.Worth noting for anyone who saw my earlier description of this: the suite is offline — it scaffolds via
--fromagainst the local templates root, not giget. The cost is CPU, not network.Verification
codegen864 tests,cli684 tests, types clean, zero eslint errors. Affected run green across 6 projects.🤖 Generated with Claude Code
Summary by CodeRabbit