Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def get_recommendations(
scored_projects.sort(key=lambda item: (-item["score"], int(item["project"].get("id", 0))))

selected_projects = (
scored_projects
scored_projects[:MAX_RESULTS]
if max_results is None
else scored_projects[:max_results])

Expand Down
15 changes: 15 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ def test_get_recommendations_max_three():
assert len(results.get("recommendations", [])) <= 3, f"Expected at most 3 results, got {len(results.get('recommendations', []))}"


def test_get_recommendations_default_cap_applies():
"""MAX_RESULTS must be honored as the default cap when max_results is None."""
capped = get_recommendations("python", "Beginner", "Web", "Low")
assert len(capped.get("recommendations", [])) <= 3, (
f"Expected default cap of 3, got {len(capped.get('recommendations', []))}"
)

uncapped = get_recommendations(
"python", "Beginner", "Web", "Low", max_results=100
)
assert len(uncapped.get("recommendations", [])) > 3, (
"Explicit max_results should override the default cap"
)


def test_get_recommendations_result_format():
"""Each returned project must be a dict with at least a title and id."""
results = get_recommendations("Python", "Beginner", "Data", "Low")
Expand Down
Loading