forked from cleveragents/cleveragents-core
a6f3bd3841
This commit adds JSON/YAML schemas, Python stubs, fixture examples, and comprehensive test coverage for data contracts across all modules (auth, AI models, contexts, plans, orgs, etc.). Implements automated validation through Behave and
136 lines
4.3 KiB
Python
136 lines
4.3 KiB
Python
"""Step definitions for discovery module tests."""
|
|
|
|
from behave import given, then, when
|
|
|
|
from cleveragents.discovery.cli_inventory import CLIInventoryExtractor, main
|
|
|
|
|
|
@when("I import the discovery module")
|
|
def step_import_discovery_module(context):
|
|
"""Import the discovery module."""
|
|
try:
|
|
import cleveragents.discovery
|
|
|
|
context.discovery_module = cleveragents.discovery
|
|
context.import_success = True
|
|
except ImportError as e:
|
|
context.import_error = e
|
|
context.import_success = False
|
|
|
|
|
|
@then("it should have CLIInventoryExtractor available")
|
|
def step_check_cli_extractor_available(context):
|
|
"""Check CLIInventoryExtractor is available."""
|
|
assert context.import_success, (
|
|
f"Import failed: {getattr(context, 'import_error', 'Unknown')}"
|
|
)
|
|
assert hasattr(context.discovery_module, "CLIInventoryExtractor")
|
|
|
|
|
|
@when("I run the discovery CLI inventory main")
|
|
def step_run_discovery_main(context):
|
|
"""Run the main function from cli_inventory."""
|
|
try:
|
|
context.main_result = main()
|
|
context.main_success = True
|
|
except Exception as e:
|
|
context.main_error = e
|
|
context.main_success = False
|
|
|
|
|
|
@then("it should extract and save the inventory")
|
|
def step_check_main_extraction(context):
|
|
"""Check that main extracted and saved inventory."""
|
|
assert context.main_success, (
|
|
f"Main failed: {getattr(context, 'main_error', 'Unknown')}"
|
|
)
|
|
assert context.main_result is not None
|
|
assert "statistics" in context.main_result
|
|
assert context.main_result["statistics"]["total_commands"] > 0
|
|
|
|
|
|
@given("a CLI inventory extractor instance")
|
|
def step_create_extractor_instance(context):
|
|
"""Create a CLI inventory extractor instance."""
|
|
context.extractor = CLIInventoryExtractor()
|
|
|
|
|
|
@when('I convert "{var_name}" to command name')
|
|
def step_convert_var_to_command(context, var_name):
|
|
"""Convert Go variable name to command name."""
|
|
context.converted_name = context.extractor._var_to_cmd_name(var_name)
|
|
|
|
|
|
@then('the converted name should be "{expected}"')
|
|
def step_check_converted_name(context, expected):
|
|
"""Check the converted name matches expected."""
|
|
assert context.converted_name == expected, (
|
|
f"Expected '{expected}', got '{context.converted_name}'"
|
|
)
|
|
|
|
|
|
@when("I build the command hierarchy")
|
|
def step_build_hierarchy(context):
|
|
"""Build the command hierarchy."""
|
|
# Extract commands first
|
|
context.extractor.extract_all()
|
|
context.hierarchy = context.extractor._build_command_hierarchy()
|
|
|
|
|
|
@then("it should return a hierarchical structure")
|
|
def step_check_hierarchy(context):
|
|
"""Check hierarchy structure."""
|
|
assert context.hierarchy is not None
|
|
assert "root" in context.hierarchy
|
|
assert "subcommands" in context.hierarchy["root"]
|
|
|
|
|
|
@when("I gather statistics about extracted commands")
|
|
def step_gather_statistics(context):
|
|
"""Gather statistics."""
|
|
# Extract commands first
|
|
context.extractor.extract_all()
|
|
context.statistics = context.extractor._gather_statistics()
|
|
|
|
|
|
@then("statistics should include total_commands")
|
|
def step_check_stats_total(context):
|
|
"""Check total_commands in statistics."""
|
|
assert "total_commands" in context.statistics
|
|
|
|
|
|
@then("statistics should include commands_with_aliases")
|
|
def step_check_stats_aliases(context):
|
|
"""Check commands_with_aliases in statistics."""
|
|
assert "commands_with_aliases" in context.statistics
|
|
|
|
|
|
@then("statistics should include commands_with_flags")
|
|
def step_check_stats_flags(context):
|
|
"""Check commands_with_flags in statistics."""
|
|
assert "commands_with_flags" in context.statistics
|
|
|
|
|
|
@when("I extract additional metadata")
|
|
def step_extract_metadata(context):
|
|
"""Extract additional metadata."""
|
|
context.metadata = context.extractor._extract_additional_metadata()
|
|
|
|
|
|
@then("metadata should include repl_commands")
|
|
def step_check_metadata_repl(context):
|
|
"""Check repl_commands in metadata."""
|
|
assert "repl_commands" in context.metadata
|
|
|
|
|
|
@then("metadata should include shortcuts")
|
|
def step_check_metadata_shortcuts(context):
|
|
"""Check shortcuts in metadata."""
|
|
assert "shortcuts" in context.metadata
|
|
|
|
|
|
@then("metadata should include environment_variables")
|
|
def step_check_metadata_env(context):
|
|
"""Check environment_variables in metadata."""
|
|
assert "environment_variables" in context.metadata
|