Extract getTopLevelVariants for testable top-level oneOf rendering#31226
Extract getTopLevelVariants for testable top-level oneOf rendering#31226superhighfives wants to merge 1 commit into
Conversation
Move getTopLevelVariants and the SchemaVariant type from SchemaDisplay.astro into src/util/model-schema.ts (alongside detectApiModes), and add unit tests that lock in correct rendering of titled top-level oneOf model schemas. Behavior is unchanged. This prepares the AI catalog model-detail pages to render the faithful top-level oneOf the catalog API will emit for variable-schema models (AIG-1175), where each request-format branch carries a title (e.g. "Chat Completions" / "Responses"). Tests verify detectApiModes does not hijack that shape and getTopLevelVariants surfaces the variant titles for both input and output.
Review✅ No style-guide issues found in commit CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
There was a problem hiding this comment.
Pull request overview
This PR extracts the top-level oneOf/anyOf variant-tab detection (getTopLevelVariants + SchemaVariant) out of SchemaDisplay.astro into the shared src/util/model-schema.ts, and adds Node Vitest coverage to lock in the intended behavior for titled top-level oneOf model schemas (request-format branches like “Chat Completions” vs “Responses”). This supports upcoming AI Gateway catalog schema shapes while preserving current rendering behavior.
Changes:
- Moved
getTopLevelVariantsandSchemaVariantfromSchemaDisplay.astrointosrc/util/model-schema.ts(alongsidedetectApiModes). - Updated
SchemaDisplay.astroto import and use the extracted utility. - Added
src/util/model-schema.node.test.tswith coverage for both the “no API-mode hijack” case and genuine Workers AI mode-splitting cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/util/model-schema.ts |
Adds exported SchemaVariant and getTopLevelVariants utility for top-level titled oneOf/anyOf variant selection. |
src/util/model-schema.node.test.ts |
Introduces unit tests covering request-format top-level oneOf behavior and ensuring detectApiModes still splits real sync/batch and sync/streaming shapes. |
src/components/models/SchemaDisplay.astro |
Replaces in-file helper/type with an import from ~/util/model-schema and keeps rendering logic unchanged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Clean behavior-preserving refactor. No issues found.
Summary: Extracts getTopLevelVariants and the SchemaVariant type from SchemaDisplay.astro into src/util/model-schema.ts, adds 10 unit tests locking in correct rendering of titled top-level oneOf schemas. pnpm run check and pnpm vitest run both pass cleanly.
Labels applied: docs engine, engineering
|
Done. Here's what I found: Labels applied: PR assessment: This is a clean, behavior-preserving refactor. No issues found.
Action taken: Approved PR #31226 with a summary review comment. |
|
Preview URL: https://de663634.preview.developers.cloudflare.com |
What
Extracts
getTopLevelVariants(and theSchemaVarianttype) fromSchemaDisplay.astrointosrc/util/model-schema.ts, alongsidedetectApiModes, and adds unit tests that lock in correct rendering of titled top-leveloneOfmodel schemas.Behavior is unchanged — this is a behavior-preserving refactor plus tests. No rendering or detection logic is modified, and no
catalog-modelsdata is touched.Why
The AI Gateway catalog API will start emitting a faithful top-level
oneOffor variable-schema models (multi-format models like the GPT-5 and Gemini families) — see ai-gateway-infra MR !462. Each request-format branch carries a human-readabletitle(e.g. "Chat Completions" / "Responses").The docs already render this shape correctly:
detectApiModesdoes not hijack it (norequests/binary signals → single mode → falls through), andSchemaDisplay'sgetTopLevelVariantssurfaces the titled branches into the variant selector. This PR proves that behavior with tests and makes the gate unit-testable, so the rendering is protected for whenever the data lands.Tests
New
src/util/model-schema.node.test.ts(10 tests):detectApiModesreturnsundefinedfor the titled request-formatoneOf(no API-mode hijack), input and output.detectApiModesstill correctly splits genuine Workers AI sync/batch and sync/streaming schemas (refactor doesn't weaken real behavior).getTopLevelVariantssurfaces the "Chat Completions" / "Responses" titles for both sides; returnsnullfor flat / untitled / single-branch schemas.Local: vitest Node project 10/10 new + no regressions;
astro check0 errors; eslint 0 errors on touched files.Sequencing
Safe to merge independently — behavior-preserving. The actual
catalog-models/*.jsondata refresh (which makes the variant selector appear on real model pages) is a separate change, gated on !462 being deployed and promoted to production.Refs AIG-1175.