From 8e1af6f5ad98ed22e3b32e76e9303cc19643b506 Mon Sep 17 00:00:00 2001 From: nightcityblade Date: Fri, 14 Aug 2026 11:18:08 +0800 Subject: [PATCH] fix(cli): honor page size for filtered cleanup Signed-off-by: nightcityblade --- .../rosetta_cli/commands/cleanup_command.py | 4 +-- src/rosetta-cli/tests/test_cleanup_command.py | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/rosetta-cli/tests/test_cleanup_command.py diff --git a/src/rosetta-cli/rosetta_cli/commands/cleanup_command.py b/src/rosetta-cli/rosetta_cli/commands/cleanup_command.py index 7b5b8127c..f013ee1ff 100644 --- a/src/rosetta-cli/rosetta_cli/commands/cleanup_command.py +++ b/src/rosetta-cli/rosetta_cli/commands/cleanup_command.py @@ -94,13 +94,13 @@ def _get_filtered_documents( # Filter by tags (metadata condition) tags_list = self._parse_tags(args.tags) filtered_documents = document_service.filter_documents_by_tags( - dataset, tags_list + dataset, tags_list, limit=self.config.page_size ) print(f"\nFiltered {len(filtered_documents)} document(s) with tags: {', '.join(tags_list)}\n") elif args.prefix: # Filter by prefix filtered_documents = document_service.filter_documents_by_prefix( - dataset, args.prefix + dataset, args.prefix, limit=self.config.page_size ) print(f"\nFiltered {len(filtered_documents)} document(s) matching prefix '{args.prefix}'\n") else: diff --git a/src/rosetta-cli/tests/test_cleanup_command.py b/src/rosetta-cli/tests/test_cleanup_command.py new file mode 100644 index 000000000..f05a46bb3 --- /dev/null +++ b/src/rosetta-cli/tests/test_cleanup_command.py @@ -0,0 +1,36 @@ +from argparse import Namespace +from types import SimpleNamespace +from unittest.mock import Mock + +import pytest +from rosetta_cli.commands.cleanup_command import CleanupCommand + + +@pytest.mark.parametrize( + ("args", "method_name", "filter_value"), + [ + ( + Namespace(tags="one,two", prefix=None), + "filter_documents_by_tags", + ["one", "two"], + ), + (Namespace(tags=None, prefix="guide-"), "filter_documents_by_prefix", "guide-"), + ], +) +def test_filtered_cleanup_uses_configured_page_size( + monkeypatch, args, method_name, filter_value +): + document_service = Mock() + getattr(document_service, method_name).return_value = [] + monkeypatch.setattr( + "rosetta_cli.commands.cleanup_command.DocumentService", + lambda client: document_service, + ) + command = CleanupCommand(SimpleNamespace(), SimpleNamespace(page_size=2048)) + dataset = SimpleNamespace() + + command._get_filtered_documents(dataset, SimpleNamespace(), args) + + getattr(document_service, method_name).assert_called_once_with( + dataset, filter_value, limit=2048 + )