UNPKG

@iservu-inc/adf-cli

Version:

CLI tool for AgentDevFramework - AI-assisted development framework with multi-provider AI support

163 lines (123 loc) 5.94 kB
const fs = require('fs-extra'); const path = require('path'); const SessionManager = require('../lib/frameworks/session-manager'); const ProgressTracker = require('../lib/frameworks/progress-tracker'); const TEST_PROJECT_PATH = path.join(__dirname, 'test-project'); const TEST_SESSIONS_DIR = path.join(TEST_PROJECT_PATH, '.adf', 'sessions'); describe('SessionManager', () => { beforeEach(async () => { // Clean up test project directory await fs.remove(TEST_PROJECT_PATH); await fs.ensureDir(TEST_PROJECT_PATH); }); afterEach(async () => { // Clean up after tests await fs.remove(TEST_PROJECT_PATH); }); describe('listSessions', () => { it('should return empty array when no sessions exist', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); const sessions = await manager.listSessions(); expect(sessions).toEqual([]); }); it('should list all sessions with progress files', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create test sessions const session1Path = path.join(TEST_SESSIONS_DIR, 'session-1'); const session2Path = path.join(TEST_SESSIONS_DIR, 'session-2'); await fs.ensureDir(session1Path); await fs.ensureDir(session2Path); // Create progress trackers const tracker1 = new ProgressTracker(session1Path, 5, 'rapid'); await tracker1.initialize(); const tracker2 = new ProgressTracker(session2Path, 10, 'balanced'); await tracker2.initialize(); const sessions = await manager.listSessions(); expect(sessions.length).toBe(2); expect(sessions[0].sessionId).toBe('session-1'); expect(sessions[1].sessionId).toBe('session-2'); expect(sessions[0].progress.framework).toBe('rapid'); expect(sessions[1].progress.framework).toBe('balanced'); }); it('should skip directories without progress files', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create session with progress const session1Path = path.join(TEST_SESSIONS_DIR, 'session-1'); await fs.ensureDir(session1Path); const tracker1 = new ProgressTracker(session1Path, 5, 'rapid'); await tracker1.initialize(); // Create directory without progress file const session2Path = path.join(TEST_SESSIONS_DIR, 'session-2'); await fs.ensureDir(session2Path); const sessions = await manager.listSessions(); expect(sessions.length).toBe(1); expect(sessions[0].sessionId).toBe('session-1'); }); }); describe('getResumableSessions', () => { it('should return only in-progress resumable sessions', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create in-progress session const session1Path = path.join(TEST_SESSIONS_DIR, 'session-1'); await fs.ensureDir(session1Path); const tracker1 = new ProgressTracker(session1Path, 5, 'rapid'); await tracker1.initialize(); await tracker1.startBlock(1, 'Block 1'); // Create completed session const session2Path = path.join(TEST_SESSIONS_DIR, 'session-2'); await fs.ensureDir(session2Path); const tracker2 = new ProgressTracker(session2Path, 5, 'rapid'); await tracker2.initialize(); await tracker2.complete(); const resumable = await manager.getResumableSessions(); expect(resumable.length).toBe(1); expect(resumable[0].sessionId).toBe('session-1'); expect(resumable[0].progress.status).toBe('in-progress'); expect(resumable[0].progress.canResume).toBe(true); }); it('should return empty array when no resumable sessions', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create completed session const sessionPath = path.join(TEST_SESSIONS_DIR, 'session-1'); await fs.ensureDir(sessionPath); const tracker = new ProgressTracker(sessionPath, 5, 'rapid'); await tracker.initialize(); await tracker.complete(); const resumable = await manager.getResumableSessions(); expect(resumable).toEqual([]); }); }); describe('deleteSession', () => { it('should delete session directory', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create session const sessionPath = path.join(TEST_SESSIONS_DIR, 'session-1'); await fs.ensureDir(sessionPath); const tracker = new ProgressTracker(sessionPath, 5, 'rapid'); await tracker.initialize(); expect(await fs.pathExists(sessionPath)).toBe(true); await manager.deleteSession('session-1'); expect(await fs.pathExists(sessionPath)).toBe(false); }); }); describe('deleteAllSessions', () => { it('should delete all sessions and recreate directory', async () => { const manager = new SessionManager(TEST_PROJECT_PATH); // Create multiple sessions const session1Path = path.join(TEST_SESSIONS_DIR, 'session-1'); const session2Path = path.join(TEST_SESSIONS_DIR, 'session-2'); await fs.ensureDir(session1Path); await fs.ensureDir(session2Path); const tracker1 = new ProgressTracker(session1Path, 5, 'rapid'); await tracker1.initialize(); const tracker2 = new ProgressTracker(session2Path, 5, 'rapid'); await tracker2.initialize(); expect(await fs.pathExists(session1Path)).toBe(true); expect(await fs.pathExists(session2Path)).toBe(true); await manager.deleteAllSessions(); expect(await fs.pathExists(session1Path)).toBe(false); expect(await fs.pathExists(session2Path)).toBe(false); expect(await fs.pathExists(TEST_SESSIONS_DIR)).toBe(true); // Directory should still exist }); }); });