diff --git a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift index 4fe85ea73..a2e7dddbe 100644 --- a/Sources/Testing/ABI/EntryPoints/EntryPoint.swift +++ b/Sources/Testing/ABI/EntryPoints/EntryPoint.swift @@ -57,10 +57,10 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha // Check for experimental console output flag if Environment.flag(named: "SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT") == true { // Use experimental AdvancedConsoleOutputRecorder - var advancedOptions = Event.AdvancedConsoleOutputRecorder.Options() + var advancedOptions = Event.AdvancedConsoleOutputRecorder.Options() advancedOptions.base = .for(.stderr) - let eventRecorder = Event.AdvancedConsoleOutputRecorder(options: advancedOptions) { string in + let eventRecorder = Event.AdvancedConsoleOutputRecorder(options: advancedOptions) { string in try? FileHandle.stderr.write(string) } diff --git a/Sources/Testing/Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift b/Sources/Testing/Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift index 784929993..2f537cb3d 100644 --- a/Sources/Testing/Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift +++ b/Sources/Testing/Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift @@ -14,7 +14,7 @@ extension Event { /// /// This recorder is currently experimental and must be enabled via the /// `SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT` environment variable. - struct AdvancedConsoleOutputRecorder: Sendable { + struct AdvancedConsoleOutputRecorder: Sendable { /// Configuration options for the advanced console output recorder. struct Options: Sendable { /// Base console output recorder options to inherit from. @@ -25,6 +25,15 @@ extension Event { } } + /// Context for storing data across events during test execution. + private struct _Context: Sendable { + /// Storage for test information, keyed by test ID string value. + /// This is needed because ABI.EncodedEvent doesn't contain full test context. + var testStorage: [String: ABI.EncodedTest] = [:] + + // Future storage for result data and other event information can be added here + } + /// The options for this recorder. let options: Options @@ -34,6 +43,12 @@ extension Event { /// The fallback console recorder for standard output. private let _fallbackRecorder: Event.ConsoleOutputRecorder + /// Context storage for test information and results. + private let _context: Locked<_Context> + + /// Human-readable output recorder for generating messages. + private let _humanReadableRecorder: Event.HumanReadableOutputRecorder + /// Initialize the advanced console output recorder. /// /// - Parameters: @@ -43,6 +58,8 @@ extension Event { self.options = options self.write = write self._fallbackRecorder = Event.ConsoleOutputRecorder(options: options.base, writingUsing: write) + self._context = Locked(rawValue: _Context()) + self._humanReadableRecorder = Event.HumanReadableOutputRecorder() } } } @@ -50,14 +67,68 @@ extension Event { extension Event.AdvancedConsoleOutputRecorder { /// Record an event by processing it and generating appropriate output. /// - /// Currently this is a skeleton implementation that delegates to - /// ``Event/ConsoleOutputRecorder``. + /// This implementation converts the Event to ABI.EncodedEvent for internal processing, + /// following the ABI-based architecture for future separation into a harness process. /// /// - Parameters: /// - event: The event to record. /// - eventContext: The context associated with the event. func record(_ event: borrowing Event, in eventContext: borrowing Event.Context) { - // Skeleton implementation: delegate to ConsoleOutputRecorder + // Handle test discovery to populate our test storage + if case .testDiscovered = event.kind, let test = eventContext.test { + let encodedTest = ABI.EncodedTest(encoding: test) + _context.withLock { context in + context.testStorage[encodedTest.id.stringValue] = encodedTest + } + } + + // Generate human-readable messages for the event + let messages = _humanReadableRecorder.record(event, in: eventContext) + + // Convert Event to ABI.EncodedEvent + if let encodedEvent = ABI.EncodedEvent(encoding: event, in: eventContext, messages: messages) { + // Process the ABI event + _processABIEvent(encodedEvent) + } + + // For now, still delegate to the fallback recorder to maintain existing functionality _fallbackRecorder.record(event, in: eventContext) } + + /// Process an ABI.EncodedEvent for advanced console output. + /// + /// This is where the enhanced console logic will be implemented in future PRs. + /// Currently this is a placeholder that demonstrates the ABI conversion. + /// + /// - Parameters: + /// - encodedEvent: The ABI-encoded event to process. + private func _processABIEvent(_ encodedEvent: ABI.EncodedEvent) { + // TODO: Implement enhanced console output logic here + // This will be expanded in subsequent PRs for: + // - Failure summary display + // - Progress bar functionality + // - Hierarchical test result display + + // For now, we just demonstrate that we can access the ABI event data + switch encodedEvent.kind { + case .runStarted: + // Could implement run start logic here + break + case .testStarted: + // Could implement test start logic here + break + case .issueRecorded: + // Could implement issue recording logic here + break + case .testEnded: + // Could implement test end logic here + break + case .runEnded: + // Could implement run end logic here + break + default: + // Handle other event types + break + } + } }