Skip to content

refactor(render): inject RenderBase in handlers & expand test suites#1522

Open
sabhi128 wants to merge 4 commits into
OpenCSGs:mainfrom
sabhi128:refactor-handlers-testability
Open

refactor(render): inject RenderBase in handlers & expand test suites#1522
sabhi128 wants to merge 4 commits into
OpenCSGs:mainfrom
sabhi128:refactor-handlers-testability

Conversation

@sabhi128

@sabhi128 sabhi128 commented Jul 2, 2026

Copy link
Copy Markdown

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

Copilot AI review requested due to automatic review settings July 2, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BaseHandlerImpl to call b.renderBaseInstance.RenderTemplate(...) and inject RenderBaseInstance via handler constructors.
  • Update notebook handler rendering to use the injected renderer.
  • Add new backend unit tests for ModelHandlerImpl and new frontend unit tests for ParquetViewer.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.

Comment on lines +1 to +3
import { describe, it, expect, vi, beforeEach } from "vitest";
import { mount } from "@vue/test-utils";
import ParquetViewer from "../../datasets/ParquetViewer.vue";
Comment on lines +77 to +83
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" }
]);
});
@zhendi

zhendi commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

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.

@sabhi128

sabhi128 commented Jul 9, 2026

Copy link
Copy Markdown
Author

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.

@sabhi128

sabhi128 commented Jul 9, 2026

Copy link
Copy Markdown
Author

"Hi there,

I have synced my branch with the latest upstream code and resolved the test failures:

  1. Fixed an async race condition in the Vue test runner by replacing nextTick with flushPromises.
  2. Fixed a type assertion mismatch on the id column to align with the component's stringification behavior.

The tests are now green locally. Please let me know if you need any other changes. Thanks!"

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.

3 participants