mirror of
https://github.com/eyaltoledano/claude-task-master.git
synced 2026-01-30 06:12:05 +00:00
test(cli): fix and improve LoopCommand tests (#1579)
This commit is contained in:
@@ -389,9 +389,10 @@ describe('LoopCommand', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should check sandbox auth before running', async () => {
|
||||
it('should check sandbox auth when --sandbox flag is provided', async () => {
|
||||
const result = createMockResult();
|
||||
mockLoopRun.mockResolvedValue(result);
|
||||
mockTmCore.loop.checkSandboxAuth.mockReturnValue({ ready: true });
|
||||
|
||||
const execute = (loopCommand as any).execute.bind(loopCommand);
|
||||
await execute({ sandbox: true });
|
||||
@@ -399,8 +400,19 @@ describe('LoopCommand', () => {
|
||||
expect(mockTmCore.loop.checkSandboxAuth).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not check sandbox auth when --sandbox flag is not provided', async () => {
|
||||
const result = createMockResult();
|
||||
mockLoopRun.mockResolvedValue(result);
|
||||
|
||||
const execute = (loopCommand as any).execute.bind(loopCommand);
|
||||
await execute({});
|
||||
|
||||
expect(mockTmCore.loop.checkSandboxAuth).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should run interactive auth when sandbox not ready', async () => {
|
||||
mockTmCore.loop.checkSandboxAuth.mockReturnValue({ ready: false });
|
||||
mockTmCore.loop.runInteractiveAuth.mockReturnValue({ success: true });
|
||||
const result = createMockResult();
|
||||
mockLoopRun.mockResolvedValue(result);
|
||||
|
||||
@@ -410,6 +422,46 @@ describe('LoopCommand', () => {
|
||||
expect(mockTmCore.loop.runInteractiveAuth).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw error when sandbox auth has error', async () => {
|
||||
mockTmCore.loop.checkSandboxAuth.mockReturnValue({
|
||||
error: 'Sandbox auth failed'
|
||||
});
|
||||
|
||||
const execute = (loopCommand as any).execute.bind(loopCommand);
|
||||
|
||||
try {
|
||||
await execute({ sandbox: true });
|
||||
} catch {
|
||||
// Expected - processExitSpy mock throws to simulate process.exit
|
||||
}
|
||||
|
||||
expect(displayError).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ message: 'Sandbox auth failed' }),
|
||||
{ skipExit: true }
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error when interactive auth fails', async () => {
|
||||
mockTmCore.loop.checkSandboxAuth.mockReturnValue({ ready: false });
|
||||
mockTmCore.loop.runInteractiveAuth.mockReturnValue({
|
||||
success: false,
|
||||
error: 'Auth failed'
|
||||
});
|
||||
|
||||
const execute = (loopCommand as any).execute.bind(loopCommand);
|
||||
|
||||
try {
|
||||
await execute({ sandbox: true });
|
||||
} catch {
|
||||
// Expected - processExitSpy mock throws to simulate process.exit
|
||||
}
|
||||
|
||||
expect(displayError).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ message: 'Auth failed' }),
|
||||
{ skipExit: true }
|
||||
);
|
||||
});
|
||||
|
||||
it('should show next task before starting loop', async () => {
|
||||
const result = createMockResult();
|
||||
mockLoopRun.mockResolvedValue(result);
|
||||
|
||||
@@ -147,6 +147,13 @@ describe('loop command', () => {
|
||||
expect(output).toContain('--tag');
|
||||
});
|
||||
|
||||
it('should show --sandbox option in help', () => {
|
||||
const { output, exitCode } = runHelp();
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output).toContain('--sandbox');
|
||||
});
|
||||
|
||||
it('should show --progress-file option in help', () => {
|
||||
const { output, exitCode } = runHelp();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user