import { describe, expect, test } from 'bun:test'; import { skipIntegration } from '../test-utils/integration-guard'; import { isAnsibleInventoryAvailable, isAnsibleLintAvailable, isAnsiblePlaybookAvailable, validateInventory, validatePlaybookSyntax, validateWithAnsibleLint, } from './validation'; describe('Ansible Tool Availability', () => { test('checks if ansible-lint is available', () => { const available = isAnsibleLintAvailable(); expect(typeof available).toBe('boolean'); // Note: May be false in environments without ansible-lint }); test('checks if ansible-playbook is available', () => { const available = isAnsiblePlaybookAvailable(); expect(typeof available).toBe('boolean'); }); test('checks if ansible-inventory is available', () => { const available = isAnsibleInventoryAvailable(); expect(typeof available).toBe('boolean'); }); }); describe('validateWithAnsibleLint', () => { test('returns error when path does not exist', async () => { const result = await validateWithAnsibleLint('/nonexistent/path'); expect(result.success).toBe(false); // Could be either missing path or missing ansible-lint expect(result.error).toBeDefined(); }); test('returns error when playbook.yml not found', async () => { const result = await validateWithAnsibleLint('/tmp'); expect(result.success).toBe(false); // Could be either missing playbook or missing ansible-lint expect(result.error).toBeDefined(); }); test('returns error when ansible-lint not installed', async () => { if (!isAnsibleLintAvailable()) { const result = await validateWithAnsibleLint('/tmp'); expect(result.success).toBe(false); expect(result.error).toContain('ansible-lint command not found'); } else { // If ansible-lint IS installed, test passes (can't test "not installed" case) expect(true).toBe(true); } }); }); describe('validatePlaybookSyntax', () => { test.skipIf(skipIntegration({ tools: ['ansible'] }))( 'returns error when playbook does not exist', async () => { const result = await validatePlaybookSyntax('/nonexistent/playbook.yml', '/tmp'); expect(result.success).toBe(false); expect(result.error).toContain('Playbook not found'); }, ); test.skipIf(skipIntegration({ tools: ['ansible'] }))( 'returns error when inventory does not exist', async () => { const result = await validatePlaybookSyntax('/tmp/playbook.yml', '/nonexistent/inventory'); expect(result.success).toBe(false); expect(result.error).toContain('not found'); }, ); test('returns error when ansible-playbook not installed', async () => { if (!isAnsiblePlaybookAvailable()) { const result = await validatePlaybookSyntax('/tmp/playbook.yml', '/tmp'); expect(result.success).toBe(false); expect(result.error).toContain('ansible-playbook command not found'); } }); }); describe('validateInventory', () => { test.skipIf(skipIntegration({ tools: ['ansible'] }))( 'returns error when inventory does not exist', async () => { const result = await validateInventory('/nonexistent/inventory'); expect(result.success).toBe(false); expect(result.error).toContain('Inventory not found'); }, ); test('returns error when ansible-inventory not installed', async () => { if (!isAnsibleInventoryAvailable()) { const result = await validateInventory('/tmp'); expect(result.success).toBe(false); expect(result.error).toContain('ansible-inventory command not found'); } }); });