@tdd_issue @tdd_issue_8232
Feature: TDD Bug #8232 — _resolve_profile_for_plan silently falls back to manual
  As a developer
  I want _resolve_profile_for_plan to raise a clear error for unknown profiles
  So that custom automation profiles are never silently replaced with 'manual'

  Per the v3.5.0 acceptance criterion:
  "Automation profile resolution precedence correct (plan > action > global)"

  The bug: when a plan's automation_profile.profile_name is a custom name
  not present in BUILTIN_PROFILES, the old code silently returned
  BUILTIN_PROFILES["manual"] instead of raising an error.

  The fix: raise ValidationError for unknown profile names and log the
  resolved profile name at debug level.

  Background:
    Given rp8232 a fresh PlanLifecycleService for profile resolution testing

  Scenario: Built-in profile resolves correctly without fallback
    Given rp8232 a plan with automation_profile "full-auto"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "full-auto"
    And rp8232 no ValidationError should have been raised

  Scenario: Plan with no automation_profile resolves to manual
    Given rp8232 a plan with no automation_profile set
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "manual"
    And rp8232 no ValidationError should have been raised

  Scenario: Custom profile name raises ValidationError instead of silent fallback
    Given rp8232 a plan with automation_profile "semi-auto"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 a ValidationError should be raised
    And rp8232 the error message should mention "semi-auto"
    And rp8232 the error message should list available built-in profiles

  Scenario: Another custom profile name raises ValidationError
    Given rp8232 a plan with automation_profile "acme/strict"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 a ValidationError should be raised
    And rp8232 the error message should mention "acme/strict"

  Scenario: All built-in profiles resolve without error
    Given rp8232 a plan with automation_profile "manual"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "manual"
    And rp8232 no ValidationError should have been raised

  Scenario: Built-in profile "ci" resolves correctly
    Given rp8232 a plan with automation_profile "ci"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "ci"
    And rp8232 no ValidationError should have been raised

  Scenario: Built-in profile "auto" resolves correctly
    Given rp8232 a plan with automation_profile "auto"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "auto"
    And rp8232 no ValidationError should have been raised

  Scenario: Resolved profile name is logged at debug level
    Given rp8232 a plan with automation_profile "trusted"
    When rp8232 _resolve_profile_for_plan is called on the plan
    Then rp8232 the resolved profile name should be "trusted"
    And rp8232 the debug log should record the resolved profile name "trusted"
