@tdd_issue @tdd_issue_7501
Feature: TDD Issue #7501 — PlanResult.success derived from result_success column
  As a system operator managing plan lifecycle
  I want PlanResult.success to be derived from the dedicated result_success column
  So that plans with historical build errors are not incorrectly marked as failed

  The root cause is that PlanRepository._to_domain derived PlanResult.success
  from `error_message is None`. Because error_message is shared between the
  build phase and the result phase, a plan that had a build error but later
  succeeded in the apply phase would be incorrectly reconstructed as failed.

  The fix adds a dedicated result_success column to the plans table and updates
  _to_domain to use it. For backward compatibility, when result_success is NULL
  (pre-migration records), the legacy heuristic (error_message is None) is used.

  Background:
    Given a clean in-memory database for plan result success tests
    And a legacy plan repository backed by the database

  Scenario: Plan with result_success=True is reconstructed as success=True
    Given a legacy plan with applied_at set and result_success column True
    When the legacy plan is retrieved from the repository
    Then the retrieved plan result success should be True

  Scenario: Plan with result_success=False is reconstructed as success=False
    Given a legacy plan with applied_at set and result_success column False
    When the legacy plan is retrieved from the repository
    Then the retrieved plan result success should be False

  Scenario: Plan with build error but result_success=True is reconstructed as success=True
    Given a legacy plan with a build error_message and result_success column True
    When the legacy plan is retrieved from the repository
    Then the retrieved plan result success should be True

  Scenario: Plan with NULL result_success falls back to error_message heuristic when no error
    Given a legacy plan with applied_at set and result_success column NULL and no error_message
    When the legacy plan is retrieved from the repository
    Then the retrieved plan result success should be True

  Scenario: Plan with NULL result_success falls back to error_message heuristic when error present
    Given a legacy plan with applied_at set and result_success column NULL and an error_message
    When the legacy plan is retrieved from the repository
    Then the retrieved plan result success should be False
