Add two BDD scenarios that mock os.walk and the time module so the
outer-loop and inner-file-loop timeout-exceeded branches in
detect_directory_languages() are deterministically exercised. Closes
the diff-coverage gap on src/cleveragents/lsp/discovery.py lines
250-257 (outer-loop timeout warning + break) and 284-291 (inner-loop
timeout warning + break) which the previous DoS protection scenarios
did not reach.
Refs: #7161
The @tdd_issue and @tdd_issue_7161 tags were placed inside the Feature
description body (indented after Feature:), where Behave treats them as
free-text, not tags. The parser fails at the plain-text description line
that follows ("Prevent resource exhaustion...") because it entered the
taggable_statement state after seeing the @-prefixed lines.
Moving both tags to before the Feature: line makes them proper
feature-level tags. All 9 scenarios inherit @tdd_issue via effective_tags,
satisfying the validate_tdd_tags() rule that every @tdd_issue_N scenario
must also carry @tdd_issue. All 9 scenarios now pass.
Refs: #7161
Resolved three blocking review items from pr-review-worker:
1. Added @tdd_issue tag at Feature level to fix unit_tests CI failure
(each scenario has @tdd_issue_7161 which requires @tdd_issue present)
2. Assigned milestone v3.6.0 to align with linked issue #7161
3. Applied ruff format to resolve lint/format violations in discovery.py
Added robust guards to detect_directory_languages() by introducing depth, file count, and timeout controls. Defaults and validations are implemented to prevent resource exhaustion during LSP discovery.
- Added max_depth parameter (default: 50) with validation to ensure a positive integer.
- Added max_files parameter (default: 10,000) with validation to ensure a positive integer.
- Added timeout parameter (default: 30.0 seconds) with validation to ensure a positive float.
- Pass followlinks=False to os.walk() to prevent symlink-based DoS via recursive loops.
- Implemented depth tracking in the traversal loop with early break when max_depth is exceeded.
- Implemented file count tracking with early break when max_files is exceeded.
- Implemented periodic timeout checks during traversal to enforce the overall time limit.
- Added warning logging when traversal is terminated early due to any limit.
- Updated the function docstring to document the new parameters and their defaults.
- Created comprehensive BDD tests in features/lsp_discovery_dos_protection.feature to validate the protections.
ISSUES CLOSED: #7161