fix(cli): make model outputs JSON-safe - #2135
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe changes add a shared JSON-safe route-output projection. Model configuration and runtime model routes use it to remove undefined and private fields. CLI diagnostics now distinguish route-contract failures from JSON-value failures. ChangesJSON-safe model outputs
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
zerob13
left a comment
There was a problem hiding this comment.
The current behavior is covered and CI is green, but both DTO helpers duplicate the canonical route schemas and create avoidable field-drift risk. Details are inline.
There was a problem hiding this comment.
Pull request overview
This PR fixes CLI failures for model list and model config-get by ensuring route outputs are projected into JSON-safe values (notably removing explicitly-undefined optional fields) before they reach the CLI’s strict JsonValueSchema boundary. It introduces a reusable projection helper, applies it to the affected model routes, and adds regression tests that cover both JSON-safety and redaction.
Changes:
- Added
projectJsonRouteOutputto normalize contract-valid outputs into JSON-safe values (omitting explicitundefinedkeys). - Applied JSON-safe projection to
models.listRuntime,models.getPublicConfig, andmodels.setPublicConfigoutputs. - Strengthened CLI boundary logging with bounded Zod validation metadata and added targeted regression tests for JSON-invalid-but-schema-valid outputs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/main/routes/routeRegistry.ts |
Adds projectJsonRouteOutput helper to project contract outputs through JSON serialization to omit explicit undefined. |
src/main/provider/routes.ts |
Uses projectJsonRouteOutput for models.listRuntime to prevent undefined from reaching CLI JSON validation. |
src/main/cli/providerModelAdminRoutes.ts |
Uses projectJsonRouteOutput for public model config get/set responses to ensure JSON-safe sparse configs and redaction. |
src/main/cli/server.ts |
Improves fail-closed output validation with stage-aware, bounded error metadata logging. |
test/main/routes/routeRegistry.test.ts |
Adds unit test for projection removing private/unknown values before serialization and dropping undefined optionals. |
test/main/provider/routes.test.ts |
Adds coverage ensuring runtime model lists are JSON-safe and do not leak internal fields across providers. |
test/main/cli/server.test.ts |
Adds regression test for schema-valid but non-JSON route output and verifies logs don’t include dynamic record keys. |
test/main/cli/providerModelAdminRoutes.test.ts |
Adds coverage for sparse public configs (including nested undefined) being returned as redacted JSON-safe values for get/set. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
models.listRuntime.models.getPublicConfigandmodels.setPublicConfig.undefinedproperties, including nested image, video, and TTS options.Root Cause
Zod preserves optional properties when the input explicitly contains those properties with an
undefinedvalue.The affected model routes passed their domain schemas, but their parsed results then failed
JsonValueSchemavalidation in the CLI server becauseundefinedis not a valid JSON value. As a result,model listandmodel config-getreturnedinternal_error.Compatibility
Testing
undefined.Validation completed:
pnpm run format:checkpnpm run i18npnpm run lintpnpm run typecheckFixes #2120
Summary by CodeRabbit
Bug Fixes
Tests