test(cli): fix and improve LoopCommand tests (#1579)

This commit is contained in:
Ralph Khreish
2026-01-15 16:30:31 +01:00
committed by GitHub
parent 87ba3a2a5b
commit 68aac14dae
2 changed files with 60 additions and 1 deletions

View File

@@ -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);

View File

@@ -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();