Feature: OpenAI chat provider coverage
  As a maintainer integrating real provider adapters
  I want unit-level Behave scenarios for the OpenAI chat provider
  So that the placeholder implementation stays documented and regression tested

  @unit @providers @openai
  Scenario: OpenAI provider instantiates ChatOpenAI with provided credentials
    Given I have sample provider domain inputs
    When I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    And I request plan generation from the OpenAI provider
    Then the OpenAI provider should construct ChatOpenAI with api key "sk-unit-test" and model "gpt-4o-mini"
    And the OpenAI provider metadata should report name "openai" and model "gpt-4o-mini"

  @unit @providers @openai
  Scenario: OpenAI provider stubbed response reports metadata
    Given I have sample provider domain inputs
    And I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    When I request plan generation from the OpenAI provider
    Then the OpenAI provider response should contain no generated changes
    And the OpenAI provider response should report the requested model without errors

  @unit @providers @openai
  Scenario: OpenAI provider rejects missing API key
    Given I have sample provider domain inputs
    When I attempt to create an OpenAI chat provider without an API key
    Then the OpenAI provider creation should fail with error "OpenAI API key is required"

  @unit @providers @openai
  Scenario: OpenAI provider forwards optional organization and kwargs
    Given I have sample provider domain inputs
    And I set the OpenAI provider organization "org-test-123"
    And I set the OpenAI provider extra kwargs "temperature=0.35,max_tokens=256"
    When I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    And I request plan generation from the OpenAI provider
    Then the OpenAI provider should construct ChatOpenAI with api key "sk-unit-test" and model "gpt-4o-mini"
    And the OpenAI provider should include organization "org-test-123" in the ChatOpenAI call
    And the OpenAI provider should include kwargs "temperature=0.35,max_tokens=256" in the ChatOpenAI call

  @unit @providers @openai
  Scenario: OpenAI provider reports runtime errors
    Given I have sample provider domain inputs
    And I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    And the plan generation graph raises RuntimeError "deadline reached"
    When I request plan generation from the OpenAI provider
    Then the OpenAI provider response should report error "deadline reached"
    And the OpenAI provider response should contain no generated changes


  @unit @providers @openai
  Scenario: OpenAI provider streaming yields workflow events
    Given I have sample provider domain inputs
    And the plan generation graph returns a generated change for "app/stream.py"
    And the plan generation graph emits streaming nodes "load_context,analyze_requirements,generate_plan,validate"
    And I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    When I stream plan generation from the OpenAI provider
    Then the OpenAI provider streaming events should include nodes "load_context,analyze_requirements,generate_plan,validate"
    And the OpenAI provider streaming result should finish with a response containing 1 generated change

  @unit @providers @openai
  Scenario: OpenAI provider surfaces plan generation errors
    Given I have sample provider domain inputs
    And the plan generation graph raises ValueError "graph exploded"
    And I create an OpenAI chat provider with API key "sk-unit-test" and model "gpt-4o-mini"
    When I request plan generation from the OpenAI provider
    Then the OpenAI provider response should report error "graph exploded"
    And the OpenAI provider response should contain no generated changes

