From aceca8b5dfc8edd378ee9ff891bccb0f94c69f31 Mon Sep 17 00:00:00 2001 From: gigagamerchaddhruv-spec Date: Wed, 14 Oct 2026 20:18:20 +0530 Subject: feat: launch Bubomb - native macOS menu bar utility ('Configure the boom') --- Tests/BubombCoreTests/SequenceExecutorTests.swift | 98 +++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Tests/BubombCoreTests/SequenceExecutorTests.swift (limited to 'Tests/BubombCoreTests/SequenceExecutorTests.swift') diff --git a/Tests/BubombCoreTests/SequenceExecutorTests.swift b/Tests/BubombCoreTests/SequenceExecutorTests.swift new file mode 100644 index 0000000..63af939 --- /dev/null +++ b/Tests/BubombCoreTests/SequenceExecutorTests.swift @@ -0,0 +1,98 @@ +#if canImport(XCTest) +import XCTest +#endif +import Foundation +import BubombCore + +final class SequenceExecutorTests: XCTestCase { + func testSuccessfulSequentialExecution() async throws { + let step1 = SequenceStep( + name: "Step 1", + action: .runCommand(command: "echo 'first'", workingDirectory: nil, timeoutSeconds: 5) + ) + let step2 = SequenceStep( + name: "Step 2", + action: .runCommand(command: "echo 'second'", workingDirectory: nil, timeoutSeconds: 5) + ) + + let config = SequenceConfig(steps: [step1, step2], stopOnError: true) + let executor = SequenceExecutor() + + let tracker = StepTracker() + let result = try await executor.execute(config: config) { step, total, name in + tracker.record(step: step, total: total, name: name) + } + + XCTAssertEqual(result.exitCode, 0) + XCTAssertTrue(result.stdout.contains("first")) + XCTAssertTrue(result.stdout.contains("second")) + let calls = tracker.getCalls() + XCTAssertEqual(calls.count, 2) + XCTAssertEqual(calls[0].0, 1) + XCTAssertEqual(calls[1].0, 2) + } + + func testSequenceStopsOnErrorWhenConfigured() async { + let step1 = SequenceStep( + name: "Failing Step", + action: .runCommand(command: "exit 12", workingDirectory: nil, timeoutSeconds: 5) + ) + let step2 = SequenceStep( + name: "Should Not Run", + action: .runCommand(command: "echo 'unreachable'", workingDirectory: nil, timeoutSeconds: 5) + ) + + let config = SequenceConfig(steps: [step1, step2], stopOnError: true) + let executor = SequenceExecutor() + + do { + _ = try await executor.execute(config: config) + XCTFail("Should have thrown stepFailed error") + } catch let error as ExecutionError { + if case .stepFailed(let index, let name, _) = error { + XCTAssertEqual(index, 0) + XCTAssertEqual(name, "Failing Step") + } else { + XCTFail("Unexpected error: \(error)") + } + } catch { + XCTFail("Unexpected non-ExecutionError: \(error)") + } + } + + func testSequenceContinuesOnErrorWhenConfigured() async throws { + let step1 = SequenceStep( + name: "Ignored Failure", + action: .runCommand(command: "exit 5", workingDirectory: nil, timeoutSeconds: 5) + ) + let step2 = SequenceStep( + name: "Subsequent Step", + action: .runCommand(command: "echo 'recovered'", workingDirectory: nil, timeoutSeconds: 5) + ) + + let config = SequenceConfig(steps: [step1, step2], stopOnError: false) + let executor = SequenceExecutor() + + let result = try await executor.execute(config: config) + XCTAssertEqual(result.exitCode, 0) + XCTAssertTrue(result.stdout.contains("recovered")) + XCTAssertTrue(result.stderr.contains("Step 1 failed")) + } +} + +private final class StepTracker: @unchecked Sendable { + private var calls: [(Int, Int, String)] = [] + private let lock = NSLock() + + func record(step: Int, total: Int, name: String) { + lock.lock() + calls.append((step, total, name)) + lock.unlock() + } + + func getCalls() -> [(Int, Int, String)] { + lock.lock() + defer { lock.unlock() } + return calls + } +} -- cgit v1.2.3