refactor(api): inject server dependencies in tests

This commit is contained in:
2026-04-21 13:30:52 +00:00
parent 9608540792
commit d6b4c0def1
2 changed files with 31 additions and 27 deletions
+10 -3
View File
@@ -17,6 +17,12 @@ import { ModelLoader } from '../models/loader.ts';
import { GpuDetector } from '../hardware/gpu-detector.ts';
import { ClusterHandler } from './handlers/cluster.ts';
interface IApiServerOptions {
gpuDetector?: GpuDetector;
router?: ApiRouter;
clusterHandler?: ClusterHandler;
}
/**
* API Server for ModelGrid
*/
@@ -42,15 +48,16 @@ export class ApiServer {
modelRegistry: ModelRegistry,
modelLoader: ModelLoader,
clusterCoordinator: ClusterCoordinator,
options: IApiServerOptions = {},
) {
this.config = config;
this.containerManager = containerManager;
this.modelRegistry = modelRegistry;
this.gpuDetector = new GpuDetector();
this.gpuDetector = options.gpuDetector || new GpuDetector();
this.modelLoader = modelLoader;
this.clusterCoordinator = clusterCoordinator;
this.clusterHandler = new ClusterHandler(clusterCoordinator);
this.router = new ApiRouter(
this.clusterHandler = options.clusterHandler || new ClusterHandler(clusterCoordinator);
this.router = options.router || new ApiRouter(
containerManager,
modelRegistry,
this.modelLoader,