Feature: Plan Service Coverage Boost Round 2
  Additional scenarios targeting uncovered lines in plan_service.py:
  auto_debug_build exception path with contexts (851, 853),
  auto_debug_build successful fix branch (922-935),
  apply_changes generic exception handler (1036),
  and _coerce_change_list defensive guard (1413-1416).

  Background:
    Given I have a plan service configured for r2 coverage testing

  Scenario: auto_debug_build formats code context from contexts with content
    Given the current plan has contexts with file content
    And build_plan raises an exception on every attempt
    And the auto debug agent returns an unsuccessful fix
    When I call auto_debug_build
    Then the auto_debug_build should return failure with the build error

  Scenario: auto_debug_build applies a successful fix and retries the build
    Given the current plan has contexts with file content
    And build_plan fails on the first attempt then succeeds
    And the auto debug agent returns a successful fix
    When I call auto_debug_build
    Then the auto_debug_build should return success
    And the plan prompt should contain the auto-debug fix description

  Scenario: auto_debug_build applies a successful fix when plan has no prompt
    Given the current plan has no prompt set
    And build_plan fails on the first attempt then succeeds
    And the auto debug agent returns a successful fix
    When I call auto_debug_build
    Then the auto_debug_build should return success

  Scenario: apply_changes raises PlanError on generic filesystem exception
    Given the current plan has a pending CREATE change with a poison path
    When I call apply_changes and expect an error
    Then the apply error should be a PlanError with operation value in details

  Scenario: _coerce_change_list raises PlanError for an invalid dict entry
    When I call _coerce_change_list with a dict that fails Change validation
    Then a PlanError should be raised about unable to parse streamed change entry

  Scenario: auto_debug_build with contexts that have no content are filtered
    Given the current plan has contexts where some lack content
    And build_plan raises an exception on every attempt
    And the auto debug agent returns an unsuccessful fix
    When I call auto_debug_build
    Then the auto_debug_build should return failure with the build error
