Files
automaker/apps/server/tests/unit/services/auto-mode-service.test.ts
Kacper 23ff99d2e2 feat: add comprehensive integration tests for auto-mode-service
- Created git-test-repo helper for managing test git repositories
- Added 13 integration tests covering:
  - Worktree operations (create, error handling, non-worktree mode)
  - Feature execution (status updates, model selection, duplicate prevention)
  - Auto loop (start/stop, pending features, max concurrency, events)
  - Error handling (provider errors, continue after failures)
- Integration tests use real git operations with temporary repos
- All 416 tests passing with 72.65% overall coverage
- Service coverage improved: agent-service 58%, auto-mode-service 44%, feature-loader 66%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 13:34:27 +01:00

72 lines
1.9 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { AutoModeService } from "@/services/auto-mode-service.js";
describe("auto-mode-service.ts", () => {
let service: AutoModeService;
const mockEvents = {
subscribe: vi.fn(),
emit: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
service = new AutoModeService(mockEvents as any);
});
describe("constructor", () => {
it("should initialize with event emitter", () => {
expect(service).toBeDefined();
});
});
describe("startAutoLoop", () => {
it("should throw if auto mode is already running", async () => {
// Start first loop
const promise1 = service.startAutoLoop("/test/project", 3);
// Try to start second loop
await expect(
service.startAutoLoop("/test/project", 3)
).rejects.toThrow("already running");
// Cleanup
await service.stopAutoLoop();
await promise1.catch(() => {});
});
it("should emit auto mode start event", async () => {
const promise = service.startAutoLoop("/test/project", 3);
// Give it time to emit the event
await new Promise((resolve) => setTimeout(resolve, 10));
expect(mockEvents.emit).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
message: expect.stringContaining("Auto mode started"),
})
);
// Cleanup
await service.stopAutoLoop();
await promise.catch(() => {});
});
});
describe("stopAutoLoop", () => {
it("should stop the auto loop", async () => {
const promise = service.startAutoLoop("/test/project", 3);
const runningCount = await service.stopAutoLoop();
expect(runningCount).toBe(0);
await promise.catch(() => {});
});
it("should return 0 when not running", async () => {
const runningCount = await service.stopAutoLoop();
expect(runningCount).toBe(0);
});
});
});