Files
temp/features/steps/project_config_model_steps.py

314 lines
12 KiB
Python

"""Step definitions for project configuration model tests (B1.5, B1.6)."""
from __future__ import annotations
from behave import given, then
from behave.runner import Context
from cleveragents.domain.models.core.project import ContextConfig, ValidationConfig
# ValidationConfig Steps (B1.5)
@given("a default ValidationConfig")
def step_default_validation_config(context: Context) -> None:
"""Create a ValidationConfig with all defaults."""
context.validation_config = ValidationConfig()
@given(
'a ValidationConfig with test "{test}" lint "{lint}" typecheck "{typecheck}" build "{build}"'
)
def step_validation_config_all_commands(
context: Context, test: str, lint: str, typecheck: str, build: str
) -> None:
"""Create a ValidationConfig with all standard commands."""
context.validation_config = ValidationConfig(
test_command=test,
lint_command=lint,
type_check_command=typecheck,
build_command=build,
)
@given('a ValidationConfig with custom commands "{commands_str}"')
def step_validation_config_custom_commands(context: Context, commands_str: str) -> None:
"""Create a ValidationConfig with custom commands parsed from key=value pairs."""
custom = {}
for pair in commands_str.split(","):
key, value = pair.strip().split("=", 1)
custom[key.strip()] = value.strip()
context.validation_config = ValidationConfig(custom_commands=custom)
@given("a ValidationConfig with timeout {timeout:d}")
def step_validation_config_timeout(context: Context, timeout: int) -> None:
"""Create a ValidationConfig with custom timeout."""
context.validation_config = ValidationConfig(timeout_seconds=timeout)
@given("a ValidationConfig with fail_on_lint_error false")
def step_validation_config_no_lint_fail(context: Context) -> None:
"""Create a ValidationConfig with fail_on_lint_error disabled."""
context.validation_config = ValidationConfig(fail_on_lint_error=False)
@given('a ValidationConfig with test "{test}" and custom commands "{commands_str}"')
def step_validation_config_test_and_custom(
context: Context, test: str, commands_str: str
) -> None:
"""Create a ValidationConfig with test command and custom commands."""
custom = {}
for pair in commands_str.split(","):
key, value = pair.strip().split("=", 1)
custom[key.strip()] = value.strip()
context.validation_config = ValidationConfig(
test_command=test, custom_commands=custom
)
# ValidationConfig field assertions
@then("the validation test_command should be none")
def step_check_test_command_none(context: Context) -> None:
"""Verify test_command is None."""
assert context.validation_config.test_command is None
@then('the validation test_command should be "{expected}"')
def step_check_test_command(context: Context, expected: str) -> None:
"""Verify test_command value."""
assert context.validation_config.test_command == expected, (
f"Expected '{expected}', got '{context.validation_config.test_command}'"
)
@then("the validation lint_command should be none")
def step_check_lint_command_none(context: Context) -> None:
"""Verify lint_command is None."""
assert context.validation_config.lint_command is None
@then('the validation lint_command should be "{expected}"')
def step_check_lint_command(context: Context, expected: str) -> None:
"""Verify lint_command value."""
assert context.validation_config.lint_command == expected, (
f"Expected '{expected}', got '{context.validation_config.lint_command}'"
)
@then("the validation type_check_command should be none")
def step_check_typecheck_command_none(context: Context) -> None:
"""Verify type_check_command is None."""
assert context.validation_config.type_check_command is None
@then('the validation type_check_command should be "{expected}"')
def step_check_typecheck_command(context: Context, expected: str) -> None:
"""Verify type_check_command value."""
assert context.validation_config.type_check_command == expected, (
f"Expected '{expected}', got '{context.validation_config.type_check_command}'"
)
@then("the validation build_command should be none")
def step_check_build_command_none(context: Context) -> None:
"""Verify build_command is None."""
assert context.validation_config.build_command is None
@then('the validation build_command should be "{expected}"')
def step_check_build_command(context: Context, expected: str) -> None:
"""Verify build_command value."""
assert context.validation_config.build_command == expected, (
f"Expected '{expected}', got '{context.validation_config.build_command}'"
)
@then("the validation custom_commands should be empty")
def step_check_custom_commands_empty(context: Context) -> None:
"""Verify custom_commands is empty dict."""
assert context.validation_config.custom_commands == {}
@then('the validation custom_commands should contain "{key}" with value "{value}"')
def step_check_custom_command(context: Context, key: str, value: str) -> None:
"""Verify custom_commands contains expected key-value pair."""
assert key in context.validation_config.custom_commands, (
f"Expected key '{key}' in custom_commands"
)
assert context.validation_config.custom_commands[key] == value, (
f"Expected custom_commands['{key}'] = '{value}', "
f"got '{context.validation_config.custom_commands[key]}'"
)
@then("the validation timeout_seconds should be {expected:d}")
def step_check_timeout(context: Context, expected: int) -> None:
"""Verify timeout_seconds value."""
assert context.validation_config.timeout_seconds == expected
@then("the validation fail_on_lint_error should be true")
def step_check_fail_on_lint_true(context: Context) -> None:
"""Verify fail_on_lint_error is True."""
assert context.validation_config.fail_on_lint_error is True
@then("the validation fail_on_lint_error should be false")
def step_check_fail_on_lint_false(context: Context) -> None:
"""Verify fail_on_lint_error is False."""
assert context.validation_config.fail_on_lint_error is False
# ValidationConfig method assertions
@then('get_all_commands should include "{key}" with value "{value}"')
def step_check_get_all_commands_key(context: Context, key: str, value: str) -> None:
"""Verify get_all_commands includes expected key-value pair."""
commands = context.validation_config.get_all_commands()
assert key in commands, (
f"Expected key '{key}' in get_all_commands(), got {commands}"
)
assert commands[key] == value, (
f"Expected commands['{key}'] = '{value}', got '{commands[key]}'"
)
@then("get_all_commands should be empty")
def step_check_get_all_commands_empty(context: Context) -> None:
"""Verify get_all_commands returns empty dict."""
commands = context.validation_config.get_all_commands()
assert commands == {}, f"Expected empty dict, got {commands}"
@then("has_any_validation should be true")
def step_check_has_validation_true(context: Context) -> None:
"""Verify has_any_validation returns True."""
assert context.validation_config.has_any_validation() is True
@then("has_any_validation should be false")
def step_check_has_validation_false(context: Context) -> None:
"""Verify has_any_validation returns False."""
assert context.validation_config.has_any_validation() is False
# ContextConfig Steps (B1.6)
@given("a default ContextConfig")
def step_default_context_config(context: Context) -> None:
"""Create a ContextConfig with all defaults."""
context.context_config = ContextConfig()
@given('a ContextConfig with ignore patterns "{patterns}"')
def step_context_config_ignore_patterns(context: Context, patterns: str) -> None:
"""Create a ContextConfig with custom ignore patterns."""
pattern_list = [p.strip() for p in patterns.split(",")]
context.context_config = ContextConfig(ignore_patterns=pattern_list)
@given('a ContextConfig with include patterns "{patterns}"')
def step_context_config_include_patterns(context: Context, patterns: str) -> None:
"""Create a ContextConfig with include patterns."""
pattern_list = [p.strip() for p in patterns.split(",")]
context.context_config = ContextConfig(include_patterns=pattern_list)
@given("a ContextConfig with max_file_size {size:d}")
def step_context_config_max_file_size(context: Context, size: int) -> None:
"""Create a ContextConfig with custom max_file_size."""
context.context_config = ContextConfig(max_file_size=size)
@given('a ContextConfig with indexing_strategy "{strategy}"')
def step_context_config_indexing_strategy(context: Context, strategy: str) -> None:
"""Create a ContextConfig with custom indexing strategy."""
context.context_config = ContextConfig(indexing_strategy=strategy)
@given('a ContextConfig with chunking_policy "{policy}"')
def step_context_config_chunking_policy(context: Context, policy: str) -> None:
"""Create a ContextConfig with custom chunking policy."""
context.context_config = ContextConfig(chunking_policy=policy)
@given("a ContextConfig with chunk_size {size:d}")
def step_context_config_chunk_size(context: Context, size: int) -> None:
"""Create a ContextConfig with custom chunk size."""
context.context_config = ContextConfig(chunk_size=size)
# ContextConfig field assertions
@then("the context max_file_size should be {expected:d}")
def step_check_max_file_size(context: Context, expected: int) -> None:
"""Verify max_file_size value."""
assert context.context_config.max_file_size == expected
@then("the context max_files should be {expected:d}")
def step_check_max_files(context: Context, expected: int) -> None:
"""Verify max_files value."""
assert context.context_config.max_files == expected
@then('the context indexing_strategy should be "{expected}"')
def step_check_indexing_strategy(context: Context, expected: str) -> None:
"""Verify indexing_strategy value."""
assert context.context_config.indexing_strategy == expected
@then('the context chunking_policy should be "{expected}"')
def step_check_chunking_policy(context: Context, expected: str) -> None:
"""Verify chunking_policy value."""
assert context.context_config.chunking_policy == expected
@then("the context chunk_size should be {expected:d}")
def step_check_chunk_size(context: Context, expected: int) -> None:
"""Verify chunk_size value."""
assert context.context_config.chunk_size == expected
@then("the context include_patterns should be none")
def step_check_include_patterns_none(context: Context) -> None:
"""Verify include_patterns is None."""
assert context.context_config.include_patterns is None
@then('the context ignore_patterns should contain "{pattern}"')
def step_check_ignore_pattern(context: Context, pattern: str) -> None:
"""Verify ignore_patterns contains expected pattern."""
assert pattern in context.context_config.ignore_patterns, (
f"Expected '{pattern}' in ignore_patterns, "
f"got {context.context_config.ignore_patterns}"
)
@then('the context include_patterns should contain "{pattern}"')
def step_check_include_pattern(context: Context, pattern: str) -> None:
"""Verify include_patterns contains expected pattern."""
assert context.context_config.include_patterns is not None, (
"include_patterns is None"
)
assert pattern in context.context_config.include_patterns, (
f"Expected '{pattern}' in include_patterns, "
f"got {context.context_config.include_patterns}"
)
@then('the context ignore_patterns should not contain duplicate "{pattern}"')
def step_check_no_duplicate_ignore_pattern(context: Context, pattern: str) -> None:
"""Verify ignore_patterns does not contain duplicates of the given pattern."""
count = context.context_config.ignore_patterns.count(pattern)
assert count == 1, (
f"Expected exactly 1 occurrence of '{pattern}' in ignore_patterns, "
f"found {count}: {context.context_config.ignore_patterns}"
)