- Add MAX_CONCURRENT_AGENTS configuration (default: 20) - Check current agent count before spawning - Reject spawn requests with 429 Too Many Requests when limit reached - Add comprehensive tests for limit enforcement Refs #338
113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { orchestratorConfig } from "./orchestrator.config";
|
|
|
|
describe("orchestratorConfig", () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...originalEnv };
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
describe("sandbox.enabled", () => {
|
|
it("should be enabled by default when SANDBOX_ENABLED is not set", () => {
|
|
delete process.env.SANDBOX_ENABLED;
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.sandbox.enabled).toBe(true);
|
|
});
|
|
|
|
it("should be enabled when SANDBOX_ENABLED is set to 'true'", () => {
|
|
process.env.SANDBOX_ENABLED = "true";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.sandbox.enabled).toBe(true);
|
|
});
|
|
|
|
it("should be disabled only when SANDBOX_ENABLED is explicitly set to 'false'", () => {
|
|
process.env.SANDBOX_ENABLED = "false";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.sandbox.enabled).toBe(false);
|
|
});
|
|
|
|
it("should be enabled for any other value of SANDBOX_ENABLED", () => {
|
|
process.env.SANDBOX_ENABLED = "yes";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.sandbox.enabled).toBe(true);
|
|
});
|
|
|
|
it("should be enabled when SANDBOX_ENABLED is empty string", () => {
|
|
process.env.SANDBOX_ENABLED = "";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.sandbox.enabled).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("other config values", () => {
|
|
it("should use default port when ORCHESTRATOR_PORT is not set", () => {
|
|
delete process.env.ORCHESTRATOR_PORT;
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.port).toBe(3001);
|
|
});
|
|
|
|
it("should use provided port when ORCHESTRATOR_PORT is set", () => {
|
|
process.env.ORCHESTRATOR_PORT = "4000";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.port).toBe(4000);
|
|
});
|
|
|
|
it("should use default valkey config when not set", () => {
|
|
delete process.env.VALKEY_HOST;
|
|
delete process.env.VALKEY_PORT;
|
|
delete process.env.VALKEY_URL;
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.valkey.host).toBe("localhost");
|
|
expect(config.valkey.port).toBe(6379);
|
|
expect(config.valkey.url).toBe("redis://localhost:6379");
|
|
});
|
|
});
|
|
|
|
describe("spawner config", () => {
|
|
it("should use default maxConcurrentAgents of 20 when not set", () => {
|
|
delete process.env.MAX_CONCURRENT_AGENTS;
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.spawner.maxConcurrentAgents).toBe(20);
|
|
});
|
|
|
|
it("should use provided maxConcurrentAgents when MAX_CONCURRENT_AGENTS is set", () => {
|
|
process.env.MAX_CONCURRENT_AGENTS = "50";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.spawner.maxConcurrentAgents).toBe(50);
|
|
});
|
|
|
|
it("should handle MAX_CONCURRENT_AGENTS of 10", () => {
|
|
process.env.MAX_CONCURRENT_AGENTS = "10";
|
|
|
|
const config = orchestratorConfig();
|
|
|
|
expect(config.spawner.maxConcurrentAgents).toBe(10);
|
|
});
|
|
});
|
|
});
|