using FluentAssertions; using FreeCode.Tools; using FreeCode.Tests.Unit.Helpers; using Xunit; namespace FreeCode.Tests.Unit.Tools; public sealed class BashToolTests { private readonly BashTool _sut = new(); [Fact] public async Task ExecuteAsync_EchoCommand_ReturnsOutput() { var context = TestHelper.CreateContext(); var result = await _sut.ExecuteAsync(new BashToolInput("echo"), context); result.IsError.Should().BeFalse(); result.Data.Stdout.Should().NotBeNull(); result.Data.ExitCode.Should().Be(0); } [Theory] [InlineData("ls -la", true)] [InlineData("rm file.txt", false)] public void IsReadOnly_ClassifiesCommandsCorrectly(string command, bool expected) { _sut.IsReadOnly(new BashToolInput(command)).Should().Be(expected); } [Fact] public async Task ExecuteAsync_WithShortTimeout_InterruptsProcess() { var context = TestHelper.CreateContext(); var result = await _sut.ExecuteAsync(new BashToolInput("sleep 1", timeout: 25), context); result.Data.Interrupted.Should().BeTrue(); result.Data.ExitCode.Should().NotBe(0); } [Fact] public async Task ExecuteAsync_InBackground_ReturnsBackgroundTaskId() { var context = TestHelper.CreateContext(); var result = await _sut.ExecuteAsync(new BashToolInput("sleep 1", runInBackground: true), context); result.IsError.Should().BeFalse(); result.Data.BackgroundTaskId.Should().NotBeNullOrWhiteSpace(); } }