fix(CQ-ORCH-9): Deduplicate spawn validation logic
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Remove duplicate validateSpawnRequest from AgentsController. Validation is now handled exclusively by: 1. ValidationPipe + DTO decorators (HTTP layer, class-validator) 2. AgentSpawnerService.validateSpawnRequest (business logic layer) This eliminates the maintenance burden and divergence risk of having identical validation in two places. Controller tests for the removed duplicate validation are also removed since they are fully covered by the service tests and DTO validation decorators. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,6 @@ import { QueueService } from "../../queue/queue.service";
|
||||
import { AgentSpawnerService } from "../../spawner/agent-spawner.service";
|
||||
import { AgentLifecycleService } from "../../spawner/agent-lifecycle.service";
|
||||
import { KillswitchService } from "../../killswitch/killswitch.service";
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
|
||||
describe("AgentsController", () => {
|
||||
@@ -289,80 +288,6 @@ describe("AgentsController", () => {
|
||||
expect(result.agentId).toBe(agentId);
|
||||
});
|
||||
|
||||
it("should throw BadRequestException when taskId is missing", async () => {
|
||||
// Arrange
|
||||
const invalidRequest = {
|
||||
agentType: "worker" as const,
|
||||
context: validRequest.context,
|
||||
} as unknown as typeof validRequest;
|
||||
|
||||
// Act & Assert
|
||||
await expect(controller.spawn(invalidRequest)).rejects.toThrow(BadRequestException);
|
||||
expect(spawnerService.spawnAgent).not.toHaveBeenCalled();
|
||||
expect(queueService.addTask).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw BadRequestException when agentType is invalid", async () => {
|
||||
// Arrange
|
||||
const invalidRequest = {
|
||||
...validRequest,
|
||||
agentType: "invalid" as unknown as "worker",
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
await expect(controller.spawn(invalidRequest)).rejects.toThrow(BadRequestException);
|
||||
expect(spawnerService.spawnAgent).not.toHaveBeenCalled();
|
||||
expect(queueService.addTask).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw BadRequestException when repository is missing", async () => {
|
||||
// Arrange
|
||||
const invalidRequest = {
|
||||
...validRequest,
|
||||
context: {
|
||||
...validRequest.context,
|
||||
repository: "",
|
||||
},
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
await expect(controller.spawn(invalidRequest)).rejects.toThrow(BadRequestException);
|
||||
expect(spawnerService.spawnAgent).not.toHaveBeenCalled();
|
||||
expect(queueService.addTask).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw BadRequestException when branch is missing", async () => {
|
||||
// Arrange
|
||||
const invalidRequest = {
|
||||
...validRequest,
|
||||
context: {
|
||||
...validRequest.context,
|
||||
branch: "",
|
||||
},
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
await expect(controller.spawn(invalidRequest)).rejects.toThrow(BadRequestException);
|
||||
expect(spawnerService.spawnAgent).not.toHaveBeenCalled();
|
||||
expect(queueService.addTask).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw BadRequestException when workItems is empty", async () => {
|
||||
// Arrange
|
||||
const invalidRequest = {
|
||||
...validRequest,
|
||||
context: {
|
||||
...validRequest.context,
|
||||
workItems: [],
|
||||
},
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
await expect(controller.spawn(invalidRequest)).rejects.toThrow(BadRequestException);
|
||||
expect(spawnerService.spawnAgent).not.toHaveBeenCalled();
|
||||
expect(queueService.addTask).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should propagate errors from spawner service", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Spawner failed");
|
||||
|
||||
Reference in New Issue
Block a user