@mock_only
Feature: Behave-parallel conditional log replay
  The parallel behave runner should only replay captured stdout/stderr
  for worker chunks that failed, errored, or crashed.  Passing chunks
  must suppress their captured output to reduce CI noise.

  # ---- _chunk_has_failures helper ----

  Scenario: chunk_has_failures returns False for all-passing summary
    Given behave_parallel a summary with 3 passed features and 5 passed scenarios
    When behave_parallel I check chunk_has_failures
    Then behave_parallel chunk_has_failures should return false

  Scenario: chunk_has_failures returns True when features have failures
    Given behave_parallel a summary with 1 failed feature
    When behave_parallel I check chunk_has_failures
    Then behave_parallel chunk_has_failures should return true

  Scenario: chunk_has_failures returns True when features have errors
    Given behave_parallel a summary with 1 errored feature
    When behave_parallel I check chunk_has_failures
    Then behave_parallel chunk_has_failures should return true

  Scenario: chunk_has_failures returns True when scenarios have failures
    Given behave_parallel a summary with 1 failed scenario
    When behave_parallel I check chunk_has_failures
    Then behave_parallel chunk_has_failures should return true

  Scenario: chunk_has_failures returns True when scenarios have errors
    Given behave_parallel a summary with 1 errored scenario
    When behave_parallel I check chunk_has_failures
    Then behave_parallel chunk_has_failures should return true

  # ---- _chunk_no_scenarios_ran helper ----

  Scenario: chunk_no_scenarios_ran returns True for empty summary
    Given behave_parallel an empty summary
    When behave_parallel I check chunk_no_scenarios_ran
    Then behave_parallel chunk_no_scenarios_ran should return true

  Scenario: chunk_no_scenarios_ran returns False when scenarios passed
    Given behave_parallel a summary with 3 passed features and 5 passed scenarios
    When behave_parallel I check chunk_no_scenarios_ran
    Then behave_parallel chunk_no_scenarios_ran should return false

  Scenario: chunk_no_scenarios_ran returns False when all scenarios are skipped
    Given behave_parallel a summary with all scenarios skipped
    When behave_parallel I check chunk_no_scenarios_ran
    Then behave_parallel chunk_no_scenarios_ran should return false

  # ---- Conditional log replay integration ----

  Scenario: Passing chunk output is suppressed in parallel aggregation
    Given behave_parallel a worker result with passing summary and captured stdout "PASS OUTPUT"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stdout should not contain "PASS OUTPUT"

  Scenario: Failed chunk output is replayed in parallel aggregation
    Given behave_parallel a worker result with failed summary and captured stdout "FAIL OUTPUT"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stdout should contain "FAIL OUTPUT"

  Scenario: Crashed worker output is replayed in parallel aggregation
    Given behave_parallel a worker result with crashed summary and captured stderr "WORKER CRASH"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stderr should contain "WORKER CRASH"

  Scenario: Pure empty summary chunk triggers log replay via no-scenarios-ran path
    Given behave_parallel a worker result with empty summary and captured stderr "EMPTY CRASH"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stderr should contain "EMPTY CRASH"

  Scenario: Failed chunk stderr is replayed in parallel aggregation
    Given behave_parallel a worker result with failed summary and captured stderr "FAIL STDERR"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stderr should contain "FAIL STDERR"

  Scenario: Mixed results replay only failed chunks
    Given behave_parallel worker results with one passing and one failing chunk
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stdout should contain "FAILING CHUNK"
    And behave_parallel the aggregated stdout should not contain "PASSING CHUNK"

  Scenario: TDD-inverted chunk suppresses output when worker_failed but summary is passing
    Given behave_parallel a worker result where worker_failed is true but summary is passing with stdout "TDD OUTPUT"
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated stdout should not contain "TDD OUTPUT"

  # ---- Worker exception handling ----

  Scenario: Worker exception returns failed summary with traceback
    Given behave_parallel a worker payload that will raise an exception
    When behave_parallel I invoke the worker
    Then behave_parallel the worker result should indicate failure
    And behave_parallel the worker stderr should contain "WORKER CRASH:"
    And behave_parallel the worker summary should have features errors equal to 1

  Scenario: Partial worker crash alongside passing workers produces summary with failures
    Given behave_parallel worker results with one crashed chunk and one passing chunk
    When behave_parallel I aggregate the worker results
    Then behave_parallel the aggregated summary should have failures
