@server @langgraph-platform
Feature: LangGraph Platform RemoteGraph Integration
  As a server-mode deployment
  I want to manage actor graphs via LangGraph Platform RemoteGraph
  So that actor execution can be delegated to the platform

  # -----------------------------------------------------------------------
  # RemoteGraphConfig validation
  # -----------------------------------------------------------------------

  Scenario: RemoteGraphConfig accepts valid HTTPS platform URL
    When I create a basic RemoteGraphConfig with graph_id "strategy-actor" and platform_url "https://langgraph.example.com"
    Then the config graph_id should be "strategy-actor"
    And the config platform_url should be "https://langgraph.example.com"
    And the config api_key_env should be "LANGGRAPH_API_KEY"
    And the config timeout should be 60.0

  Scenario: RemoteGraphConfig accepts valid HTTP platform URL
    When I create a basic RemoteGraphConfig with graph_id "execution-actor" and platform_url "http://localhost:8123"
    Then the config graph_id should be "execution-actor"
    And the config platform_url should be "http://localhost:8123"

  Scenario: RemoteGraphConfig accepts custom api_key_env
    When I create a RemoteGraphConfig with custom api_key_env "MY_API_KEY"
    Then the config api_key_env should be "MY_API_KEY"

  Scenario: RemoteGraphConfig accepts custom timeout
    When I create a RemoteGraphConfig with custom timeout 120.0
    Then the config timeout should be 120.0

  Scenario: RemoteGraphConfig rejects empty graph_id
    When I try to create a RemoteGraphConfig with empty graph_id
    Then a remote graph config validation error should be raised

  Scenario: RemoteGraphConfig rejects empty platform_url
    When I try to create a RemoteGraphConfig with empty platform_url
    Then a remote graph config validation error should be raised

  Scenario: RemoteGraphConfig rejects non-HTTP platform_url
    When I try to create a RemoteGraphConfig with platform_url "ftp://langgraph.example.com"
    Then a remote graph config validation error should be raised

  Scenario: RemoteGraphConfig rejects non-positive timeout
    When I try to create a RemoteGraphConfig with timeout 0
    Then a remote graph config validation error should be raised

  Scenario: RemoteGraphConfig is frozen
    When I create a basic RemoteGraphConfig with graph_id "actor" and platform_url "https://langgraph.example.com"
    Then the remote graph config should be immutable

  # -----------------------------------------------------------------------
  # RemoteGraphManager — not configured (no platform URL)
  # -----------------------------------------------------------------------

  Scenario: RemoteGraphManager is not available when no platform URL given
    Given a RemoteGraphManager with no platform URL
    Then the manager should not be available
    And the manager platform_url should be None

  Scenario: RemoteGraphManager register_graph raises when not configured
    Given a RemoteGraphManager with no platform URL
    When I try to register a graph on the unconfigured manager
    Then a RemoteGraphNotAvailableError should be raised

  Scenario: RemoteGraphManager list_graphs raises when not configured
    Given a RemoteGraphManager with no platform URL
    When I try to list graphs on the unconfigured manager
    Then a RemoteGraphNotAvailableError should be raised

  Scenario: RemoteGraphManager invoke raises when not configured
    Given a RemoteGraphManager with no platform URL
    When I try to invoke a graph on the unconfigured manager
    Then a RemoteGraphNotAvailableError should be raised

  Scenario: RemoteGraphManager health_check returns False when not configured
    Given a RemoteGraphManager with no platform URL
    When I call health_check on the unconfigured manager
    Then the health check result should be False

  # -----------------------------------------------------------------------
  # RemoteGraphManager — configured (with platform URL)
  # -----------------------------------------------------------------------

  Scenario: RemoteGraphManager is available when platform URL is given
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    Then the manager should be available
    And the manager platform_url should be "https://langgraph.example.com"

  Scenario: RemoteGraphManager can register a graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I register a graph with id "strategy-actor"
    Then the graph "strategy-actor" should be registered

  Scenario: RemoteGraphManager list_graphs returns registered graph IDs
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I register graphs with ids "alpha" and "beta"
    Then list_graphs should return "alpha" and "beta" in sorted order

  Scenario: RemoteGraphManager get_graph_config returns registered config
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I register a graph with id "execution-actor"
    Then get_graph_config for "execution-actor" should return the config

  Scenario: RemoteGraphManager get_graph_config raises for unknown graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I try to get config for unregistered graph "unknown-actor"
    Then a KeyError should be raised for the unknown graph

  Scenario: RemoteGraphManager unregister_graph removes a graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I register then unregister graph "temp-actor"
    Then the graph "temp-actor" should not be registered

  Scenario: RemoteGraphManager unregister_graph raises for unknown graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I try to unregister an unknown graph "ghost-actor"
    Then a KeyError should be raised for the unregistered graph

  Scenario: RemoteGraphManager invoke raises RemoteGraphNotAvailableError for registered graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I register a graph with id "strategy-actor"
    And I try to invoke the registered graph "strategy-actor"
    Then a RemoteGraphNotAvailableError should be raised for the stub invocation

  Scenario: RemoteGraphManager invoke raises KeyError for unregistered graph
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I try to invoke unregistered graph "missing-actor"
    Then a KeyError should be raised for the missing graph invocation

  Scenario: RemoteGraphManager health_check returns False for stub
    Given a RemoteGraphManager with platform URL "https://langgraph.example.com"
    When I call health_check on the configured manager
    Then the health check result should be False

  # -----------------------------------------------------------------------
  # PostgreSQL connection utilities
  # -----------------------------------------------------------------------

  Scenario: PostgreSQLConnectionConfig accepts valid parameters
    When I create a PostgreSQLConnectionConfig with host "db.example.com" database "cleveragents" username "app" password "secret"
    Then the pg config host should be "db.example.com"
    And the pg config database should be "cleveragents"
    And the pg config username should be "app"
    And the pg config port should be 5432
    And the pg config ssl_mode should be "prefer"

  Scenario: PostgreSQLConnectionConfig accepts custom port
    When I create a PostgreSQLConnectionConfig with host "db.example.com" database "cleveragents" username "app" password "secret" port 5433
    Then the pg config port should be 5433

  Scenario: PostgreSQLConnectionConfig to_url returns async URL by default
    When I create a PostgreSQLConnectionConfig with host "db.example.com" database "cleveragents" username "app" password "secret"
    Then the pg config async URL should start with "postgresql+asyncpg://"

  Scenario: PostgreSQLConnectionConfig to_url returns sync URL when requested
    When I create a PostgreSQLConnectionConfig with host "db.example.com" database "cleveragents" username "app" password "secret"
    Then the pg config sync URL should start with "postgresql://"

  Scenario: PostgreSQLConnectionConfig rejects empty host
    When I try to create a PostgreSQLConnectionConfig with empty host
    Then a pg config validation error should be raised

  Scenario: PostgreSQLConnectionConfig rejects invalid port
    When I try to create a PostgreSQLConnectionConfig with port 0
    Then a pg config validation error should be raised

  Scenario: PostgreSQLConnectionConfig rejects negative pool_size
    When I try to create a PostgreSQLConnectionConfig with pool_size 0
    Then a pg config validation error should be raised

  Scenario: build_postgresql_url returns async URL
    When I call build_postgresql_url with host "db.example.com" database "mydb" username "user" password "pass"
    Then the built URL should start with "postgresql+asyncpg://"
    And the built URL should contain "db.example.com"
    And the built URL should contain "mydb"

  Scenario: build_postgresql_url returns sync URL when async_driver is False
    When I call build_postgresql_url with async_driver False
    Then the built URL should start with "postgresql://"

  Scenario: is_postgresql_url returns True for postgresql URL
    When I check if "postgresql://user:pass@host/db" is a PostgreSQL URL
    Then the pg url check result should be True

  Scenario: is_postgresql_url returns True for postgresql+asyncpg URL
    When I check if "postgresql+asyncpg://user:pass@host/db" is a PostgreSQL URL
    Then the pg url check result should be True

  Scenario: is_postgresql_url returns False for sqlite URL
    When I check if "sqlite:///path/to/db.sqlite" is a PostgreSQL URL
    Then the pg url check result should be False

  Scenario: is_postgresql_url returns False for empty string
    When I check if "" is a PostgreSQL URL
    Then the pg url check result should be False
