Skip to content

fix(data): sweep non-canonical sort key direction: → SortNode's order: (desc silently sorted ascending)#1772

Merged
os-zhuang merged 1 commit into
mainfrom
fix-sortnode-order-key
Jun 12, 2026
Merged

fix(data): sweep non-canonical sort key direction: → SortNode's order: (desc silently sorted ascending)#1772
os-zhuang merged 1 commit into
mainfrom
fix-sortnode-order-key

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Summary

SortNode (packages/spec/src/data/query.zod.ts) takes order: 'asc'|'desc' with default asc. Zod strips the unknown direction: key, so every engine query sorting with direction: 'desc' silently sorted ascending. Same bug class as the plugin-approvals fix that landed in #1769; this sweeps the remaining sites.

Behavior-changing (desc was silently asc)

  • plugin-reports listReports — now genuinely most-recently-updated first
  • plugin-sharing listShares — newest grant first
  • service-job listExecutionsByStatus — "latest run" was returning the oldest run
  • service-queue listFailed — newest DLQ message first

Cosmetic (asc default made behavior accidentally right, key still wrong)

plugin-reports listSchedules, plugin-sharing listRules + share-link messages sort, service-queue claimBatch (×2).

Doc/template sites (schema-verified before changing)

  • cli explain query example — engine FindOptions.sort validates against SortNode[]
  • cli generate list-view template + spec benchmark — used a phantom defaultSort: key (ListViewSchema only has sort: [{field, order}], view.zod.ts:422); benchmark validQuery used sort: which QuerySchema doesn't have → orderBy

Verified-correct, left alone

  • plugin-auth objectql-adapter — sortBy.direction is better-auth's own interface, already translated to canonical {field, order} at both sites
  • graphql.zod.ts defaultSort — separate schema that legitimately uses direction: 'ASC'|'DESC'

Tests

  • All four fake-engine mocks now honor only the canonical order key, with a comment explaining why (mocks honoring both keys is exactly how the approvals bug stayed hidden)
  • One descending-order regression test per package (newest row must come first)
  • Mutation-checked: reverting the service-job fix makes its new regression test fail
  • Suites green: plugin-reports 25, plugin-sharing 55, service-job 26, service-queue 20, cli 268; tsc --noEmit clean on spec

🤖 Generated with Claude Code

…g — sweep to SortNode's order:

SortNode (spec/data/query.zod.ts) takes `order: 'asc'|'desc'` (default asc);
Zod strips an unknown `direction:` key, so every desc sort using it silently
returned ascending. Same bug class fixed in plugin-approvals via #1769.

Behavior-changing (desc was silently asc):
- plugin-reports listReports: most-recently-updated first
- plugin-sharing listShares: newest grant first
- service-job listExecutionsByStatus: "latest run" actually returned the
  OLDEST run
- service-queue listFailed: newest message first

Cosmetic (asc default made behavior accidentally right, key still wrong):
- plugin-reports listSchedules, plugin-sharing listRules,
  share-link-routes messages sort, service-queue claimBatch

Doc/template sites (schema-verified):
- cli explain: query example sort key — FindOptions.sort takes SortNode[]
- cli generate + spec benchmark: list-view template used a phantom
  `defaultSort:` key (ListViewSchema only has `sort: [{field, order}]`);
  benchmark validQuery used `sort:` which QuerySchema doesn't have → orderBy

Left alone: plugin-auth objectql-adapter (better-auth's own sortBy.direction,
already translated to {field, order}); graphql.zod.ts defaultSort
(a separate schema that legitimately uses direction: 'ASC'|'DESC').

Tests: all four fake-engine mocks now honor ONLY the canonical `order` key
(honoring both is how the approvals bug stayed hidden), plus a descending-
order regression test per package; mutation-checked that reverting the
service-job fix fails its new test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Building Building Preview, Comment Jun 12, 2026 7:08am

Request Review

@os-zhuang
os-zhuang merged commit a3ae817 into main Jun 12, 2026
7 of 8 checks passed
@os-zhuang
os-zhuang deleted the fix-sortnode-order-key branch June 12, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant