Implement backend configuration options and refactor related components

This commit is contained in:
2025-09-02 21:12:14 +02:00
parent d9542ba117
commit 4f6bb6292e
11 changed files with 358 additions and 62 deletions

View File

@@ -4,6 +4,7 @@ import type { ReactNode } from "react";
import { InstancesProvider, useInstances } from "@/contexts/InstancesContext";
import { instancesApi } from "@/lib/api";
import type { Instance } from "@/types/instance";
import { BackendType } from "@/types/instance";
import { AuthProvider } from "../AuthContext";
// Mock the API module
@@ -47,13 +48,13 @@ function TestComponent() {
{/* Action buttons for testing with specific instances */}
<button
onClick={() => createInstance("new-instance", { model: "test.gguf" })}
onClick={() => createInstance("new-instance", { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "test.gguf" } })}
data-testid="create-instance"
>
Create Instance
</button>
<button
onClick={() => updateInstance("instance1", { model: "updated.gguf" })}
onClick={() => updateInstance("instance1", { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "updated.gguf" } })}
data-testid="update-instance"
>
Update Instance
@@ -99,8 +100,8 @@ function renderWithProvider(children: ReactNode) {
describe("InstancesContext", () => {
const mockInstances: Instance[] = [
{ name: "instance1", status: "running", options: { model: "model1.gguf" } },
{ name: "instance2", status: "stopped", options: { model: "model2.gguf" } },
{ name: "instance1", status: "running", options: { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "model1.gguf" } } },
{ name: "instance2", status: "stopped", options: { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "model2.gguf" } } },
];
beforeEach(() => {
@@ -159,7 +160,7 @@ describe("InstancesContext", () => {
const newInstance: Instance = {
name: "new-instance",
status: "stopped",
options: { model: "test.gguf" },
options: { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "test.gguf" } },
};
vi.mocked(instancesApi.create).mockResolvedValue(newInstance);
@@ -174,7 +175,8 @@ describe("InstancesContext", () => {
await waitFor(() => {
expect(instancesApi.create).toHaveBeenCalledWith("new-instance", {
model: "test.gguf",
backend_type: BackendType.LLAMA_SERVER,
backend_options: { model: "test.gguf" }
});
});
@@ -215,7 +217,7 @@ describe("InstancesContext", () => {
const updatedInstance: Instance = {
name: "instance1",
status: "running",
options: { model: "updated.gguf" },
options: { backend_type: BackendType.LLAMA_SERVER, backend_options: { model: "updated.gguf" } },
};
vi.mocked(instancesApi.update).mockResolvedValue(updatedInstance);
@@ -230,7 +232,8 @@ describe("InstancesContext", () => {
await waitFor(() => {
expect(instancesApi.update).toHaveBeenCalledWith("instance1", {
model: "updated.gguf",
backend_type: BackendType.LLAMA_SERVER,
backend_options: { model: "updated.gguf" }
});
});