Skip to content

copy Omicron's sort order for mock API items#3033

Open
charliepark wants to merge 14 commits intomainfrom
sort_mock_api_items
Open

copy Omicron's sort order for mock API items#3033
charliepark wants to merge 14 commits intomainfrom
sort_mock_api_items

Conversation

@charliepark
Copy link
Contributor

This PR copies the Omicron API's sorting in the mock API, so Console results more accurately reflect what a user would see on an actual rack.

Closes #2776


Changes Made

  1. Updated mock-api/msw/util.ts
  • Added a sortItems() function that implements sorting for all sort modes:
    • name_ascending / name_descending - sorts alphabetically by name
    • id_ascending - sorts lexicographically by ID (UUID)
    • time_and_id_ascending / time_and_id_descending - sorts by timestamp, then by ID
  • Updated the paginated() function to:
    • Accept a sortBy parameter in the query options
    • Apply default sorting matching Omicron's behavior:
      • name_ascending for items with a name field (most common)
      • id_ascending for items without a name field
    • Sort items before paginating
  1. Updated mock-api/msw/util.spec.ts
  • Fixed the pagination test to expect lexicographically sorted results, matching how UUIDs are actually compared in Rust

Key Findings from Omicron Analysis

Based on the Omicron source code (https://github.com/uuid-rs/uuid):

  • UUIDs in Rust use lexicographic byte-by-byte comparison because the Ord trait is derived for Uuid(Bytes), which wraps a [u8; 16] array
  • Arrays in Rust compare element-by-element from left to right
  • This means my implementation using localeCompare() in JavaScript correctly matches Omicron's UUID sorting behavior

The mock API now properly sorts results by default, matching Omicron's pagination behavior where:

  • Most endpoints default to name_ascending (alphabetical by name)
  • Endpoints without names default to id_ascending (lexicographic by UUID)
  • Time-based sorting is only used when explicitly requested

Sources:

@vercel
Copy link

vercel bot commented Feb 5, 2026

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

Project Deployment Actions Updated (UTC)
console Ready Ready Preview Feb 6, 2026 9:08pm

Request Review

@charliepark
Copy link
Contributor Author

Can't say I love this, but I think this is just a quirk of the names we've given them and lexicographical ordering.
Screenshot 2026-02-06 at 10 41 29 AM

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.

Update the mock API to alphabetize paginated list queries

2 participants