refactor(render): inject RenderBase in handlers & expand test suites#1522
refactor(render): inject RenderBase in handlers & expand test suites#1522sabhi128 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves render-handler testability in the Go backend by injecting the RenderBase renderer into handler implementations (removing reliance on a package-level global), and expands frontend unit test coverage by adding a Vitest suite for ParquetViewer.vue.
Changes:
- Refactor
BaseHandlerImplto callb.renderBaseInstance.RenderTemplate(...)and injectRenderBaseInstancevia handler constructors. - Update notebook handler rendering to use the injected renderer.
- Add new backend unit tests for
ModelHandlerImpland new frontend unit tests forParquetViewer.vue.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/handlers/render/repo.go | Adds renderBaseInstance RenderBase to BaseHandlerImpl and routes template rendering through the injected renderer. |
| internal/handlers/render/codes.go | Injects RenderBaseInstance into CodeHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/datasets.go | Injects RenderBaseInstance into DatasetHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/endpoint.go | Injects RenderBaseInstance into EndpointHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/finetune.go | Injects RenderBaseInstance into FinetuneHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/mcp_server.go | Injects RenderBaseInstance into McpServerHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/models.go | Injects RenderBaseInstance into ModelHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/notebooks.go | Injects RenderBaseInstance and uses it in Show() rendering. |
| internal/handlers/render/skills.go | Injects RenderBaseInstance into SkillHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/spaces.go | Injects RenderBaseInstance into SpaceHandlerImpl via BaseHandlerImpl. |
| internal/handlers/render/models_test.go | Adds mock-based unit tests for model list/detail/new rendering routes. |
| frontend/src/components/tests/datasets/ParquetViewer.spec.js | Adds a Vitest suite covering mount behavior, computed values, and row loading for ParquetViewer.vue. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { mount } from "@vue/test-utils"; | ||
| import ParquetViewer from "../../datasets/ParquetViewer.vue"; |
| it("processes table data correctly", async () => { | ||
| await wrapper.vm.$nextTick(); | ||
| expect(wrapper.vm.tableData).toEqual([ | ||
| { id: 1, text: "First example text", label: "positive" }, | ||
| { id: 2, text: "Second example text", label: "negative" } | ||
| ]); | ||
| }); |
|
Thanks for your contribution. I noticed that the unit tests are currently failing in the CI run. Could you please take a look and push a fix when you have a chance? Let me know once the tests are green so I can proceed with the review. |
Thanks for reviewing. Yeah sure, let me fix it, and then i will make pr again. |
|
"Hi there, I have synced my branch with the latest upstream code and resolved the test failures:
The tests are now green locally. Please let me know if you need any other changes. Thanks!" |
refactor(render): inject RenderBase in handlers & expand test suites
PR Description: Refactor Render Handlers for Testability & Expand Test Suites
Category
Refactoring
Testing / Quality Assurance
Summary of Changes
This PR addresses two main areas:
Frontend Test Suite Expansion: Added unit test coverage for the ParquetViewer.vue dataset component using Vitest.
Go Backend Testability & Mock Testing: Refactored the core repository render handlers to support dependency injection for the RenderBase template renderer. This removes the dependency on the package-level global RenderBaseInstance and allows handlers to be tested in isolation. We added a new unit test suite for the ModelHandler to verify template mapping and parameter routing.
Detailed Component Changes
Frontend
New File: frontend/src/components/tests/datasets/ParquetViewer.spec.js
Tests component mounting, dynamic split/subset dropdown configurations, rows loading using mocked API calls (datasets/.../dataviewer/rows), computed calculations, and layout responsiveness.
Backend
Modified: internal/handlers/render/repo.go
Added renderBaseInstance RenderBase field to the shared BaseHandlerImpl class to allow mocking the template renderer.
Refactored List, Tools, Deploy, New, and renderShow methods to use the new struct field.
Modified Constructors:
Updated constructors in codes.go, datasets.go, endpoint.go, finetune.go, mcp_server.go, models.go, notebooks.go, skills.go, and spaces.go to inject RenderBaseInstance by default.
Updated Show method in notebooks.go to call i.renderBaseInstance.RenderTemplate.
New File: internal/handlers/render/models_test.go
Tests List, Detail, and New endpoints for model page rendering using testify mocks.
Verification & Testing
Frontend
Run the Vitest suite:
bash
cd frontend
yarn test src/components/tests/datasets/ParquetViewer.spec.js
Backend
Run Go tests:
bash
go test -v ./internal/handlers/render/ -run TestModelHandlerImpl