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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"requests>=2.32",
"loguru>=0.7",
"pydantic",
"revengai>=3.114.2",
"revengai>=3.123.0",
"libbs>=2.16.5",
]

Expand Down
20 changes: 10 additions & 10 deletions reai_toolkit/app/components/dialogs/matching_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from revengai.models import (
BinarySearchResult,
CollectionSearchResult,
CollectionListItemBody,
FunctionMatch,
MatchedFunction,
)
Expand Down Expand Up @@ -154,8 +154,8 @@ def __init__(
self.ui.searchFunctions.textEdited.connect(self._update_functions_table)

# ----------------- Collections state -----------------
# Internal multi-selection: key -> (name, scope, owner, model, created)
self._selected_collections: dict[str, CollectionSearchResult] = {}
# Internal multi-selection: key -> (name, scope, owner, size, created)
self._selected_collections: dict[str, CollectionListItemBody] = {}
self._collectionsDebounce = QtCore.QTimer(self)
self._collectionsDebounce.setSingleShot(True)
self._collectionsDebounce.timeout.connect(self._performCollectionsSearch)
Expand Down Expand Up @@ -390,7 +390,7 @@ def _onCollectionsEdited(self, _text: str):
def _performCollectionsSearch(self):
query = self.ui.editCollections.text().strip()

response: GenericApiReturn[List[CollectionSearchResult]] = (
response: GenericApiReturn[List[CollectionListItemBody]] = (
self.matching_service.search_collections(text_input=query)
)

Expand All @@ -405,7 +405,7 @@ def _performCollectionsSearch(self):
self._fillCollectionsPopup(query=query, rows=response.data)

def _initCollectionsHeader(self):
labels = ["Select", "Collection", "Scope", "Owner", "Model", "Created"]
labels = ["Select", "Collection", "Scope", "Owner", "Size", "Created"]

view = self.ui.collectionsPopupView
view.setHeaderHidden(False)
Expand All @@ -423,7 +423,7 @@ def _initCollectionsHeader(self):
else:
hdr.setSectionResizeMode(i, QtWidgets.QHeaderView.Stretch)

def _fillCollectionsPopup(self, query: str, rows: list[CollectionSearchResult]):
def _fillCollectionsPopup(self, query: str, rows: list[CollectionListItemBody]):
view = self.ui.collectionsPopupView
view.blockSignals(True)
view.clear()
Expand All @@ -449,10 +449,10 @@ def _fillCollectionsPopup(self, query: str, rows: list[CollectionSearchResult]):
[
"",
tup.collection_name,
tup.scope,
tup.owned_by,
tup.model_name,
tup.created_at.isoformat(),
tup.collection_scope,
tup.collection_owner,
str(tup.collection_size),
tup.creation.isoformat(),
]
)
it.setFlags(
Expand Down
25 changes: 10 additions & 15 deletions reai_toolkit/app/services/matching/matching_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from loguru import logger
from revengai import (
BinarySearchResult,
CollectionSearchResult,
CollectionListItemBody,
CollectionsApi,
Configuration,
FunctionMapping,
FunctionMatch,
Expand Down Expand Up @@ -57,27 +58,21 @@ def function_id_to_local_name(self, function_id: int) -> Optional[str]:
name = self.demangle(idc.get_func_name(vaddr))
return name

def _search_collections(self, text_input: str) -> List[CollectionSearchResult]:
def _search_collections(self, text_input: str) -> List[CollectionListItemBody]:
with self.yield_api_client(sdk_config=self.sdk_config) as api_client:
search_client = SearchApi(api_client)

return_list: List[CollectionSearchResult] = []
collections_client = CollectionsApi(api_client)

response = search_client.search_collections(
model_name=self.netstore_service.get_model_name(),
partial_collection_name=text_input,
page_size=10,
page=1,
response = collections_client.v3_list_collections(
search_term=text_input or None,
limit=50,
offset=0,
)

return_list.extend(response.data.results)

return return_list
pass
return response.results or []

def search_collections(
self, text_input: str
) -> GenericApiReturn[List[CollectionSearchResult]]:
) -> GenericApiReturn[List[CollectionListItemBody]]:
response = self.api_request_returning(
lambda: self._search_collections(text_input)
)
Expand Down
23 changes: 15 additions & 8 deletions tests/unit/matching/test_matching_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def search_api(mocker):
return api_inst


@pytest.fixture
def collections_api(mocker):
mocker.patch.object(MatchingService, "yield_api_client")
api_class = mocker.patch.object(svc_mod, "CollectionsApi")
api_inst = MagicMock()
api_class.return_value = api_inst
return api_inst


@pytest.fixture
def core_api(mocker):
mocker.patch.object(MatchingService, "yield_api_client")
Expand Down Expand Up @@ -78,23 +87,21 @@ def _matches(matches=None) -> GetMatchesOutputBody:
)


def test_search_collections_returns_results(service, search_api):
def test_search_collections_returns_results(service, collections_api):
results = [MagicMock(), MagicMock()]
search_api.search_collections.return_value = MagicMock(
data=MagicMock(results=results)
)
collections_api.v3_list_collections.return_value = MagicMock(results=results)

out = service.search_collections("libc")

assert out.success is True
assert out.data == results
search_api.search_collections.assert_called_once_with(
model_name="binnet-0.1", partial_collection_name="libc", page_size=10, page=1
collections_api.v3_list_collections.assert_called_once_with(
search_term="libc", limit=50, offset=0
)


def test_search_collections_failure_returns_empty_success(service, search_api):
search_api.search_collections.side_effect = RuntimeError("boom")
def test_search_collections_failure_returns_empty_success(service, collections_api):
collections_api.v3_list_collections.side_effect = RuntimeError("boom")

out = service.search_collections("libc")

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/matching/test_sdk_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from revengai import (
BinarySearchResult,
CollectionSearchResult,
CollectionListItemBody,
FunctionMapping,
FunctionMatch,
GetMatchesOutputBody,
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_search_result_fields():
BinarySearchResult.model_fields
)
assert {"collection_id", "collection_name"} <= set(
CollectionSearchResult.model_fields
CollectionListItemBody.model_fields
)


Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading