From ed838317cc4052c73d11c2b8219da7f4a4adef33 Mon Sep 17 00:00:00 2001 From: r0ny123 <49360849+r0ny123@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:36:13 +0530 Subject: [PATCH 1/2] Select a sample's matching jobs by their sample id arguments queryJobs kept a job if its rendered parameters contained the sample id as "(id)", "(id,", ",id," or ",id)". Job.parameters joins the arguments with ", ", so the last two forms never matched, and a sample that was not a job's first argument was missed: getMatchesForSampleVs(5, 12) was found for sample 5 but not for sample 12. Jobs are now matched on Job.sample_ids, the sample id arguments of each method, as the server's sample_ids selector reads them. A threshold that happens to equal the sample id does not count, which matching every argument would have allowed. Job.sample_ids does not know the getMatchesForSampleVsGroup jobs of a cross compare, so their first argument is checked directly, as the text test did. A job whose arguments do not have the shape of its method is skipped instead of failing the whole query. --- CHANGELOG.md | 3 ++ mcrit_plugin/core/McritInterface.py | 27 ++++++++------ tests/core/test_mcrit_interface.py | 55 +++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b2505..d77a547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,9 @@ Ninja applies to that plugin only. ### Fixed +- Get Match Result missed the jobs in which the sample is not the first argument, such as a + sample-vs-sample comparison started from the other sample or a cross compare that includes it. + Jobs are now selected by their sample id arguments instead of by matching the job's text. - The bundled MCRIT client's `modifyFamily`, `modifySample`, `requestMatchesForMappedBinary` and `requestMatchesForUnmappedBinary` raised `TypeError` on every call: they passed the request body positionally to the client's request wrappers, which take it only by keyword. diff --git a/mcrit_plugin/core/McritInterface.py b/mcrit_plugin/core/McritInterface.py index 8329fbf..203bf2b 100644 --- a/mcrit_plugin/core/McritInterface.py +++ b/mcrit_plugin/core/McritInterface.py @@ -15,6 +15,21 @@ _SMDA_IMPORT_ERROR = None +def _isMatchingJobOfSample(job, sample_id): + """Whether a matching job compares the sample, read from the job's sample id arguments like the + server's sample_ids selector; its thresholds are arguments too and must not count.""" + if "Matches" not in (job.method or ""): + return False + try: + # the per-sample jobs of a cross compare; Job.sample_ids does not know them + if job.method == "getMatchesForSampleVsGroup": + return int(job.arguments[0]) == sample_id + return sample_id in job.sample_ids + except (TypeError, ValueError, IndexError, KeyError, AttributeError): + # a job whose arguments do not have the shape its method has concerns no sample + return False + + class McritInterface(object): def __init__(self, parent, backend): if Disassembler is None: @@ -201,17 +216,7 @@ def queryJobs(self, sample_id=None): return None # check if we already have a match report for the sample id if sample_id is not None: - jobs = [ - job - for job in jobs - if "Matches" in job.parameters - and ( - "(" + str(sample_id) + ")" in job.parameters - or "(" + str(sample_id) + "," in job.parameters - or "," + str(sample_id) + "," in job.parameters - or "," + str(sample_id) + ")" in job.parameters - ) - ] + jobs = [job for job in jobs if _isMatchingJobOfSample(job, sample_id)] if jobs: self.parent.local_widget.updateActivityInfo("Success! Fetched Jobs.") else: diff --git a/tests/core/test_mcrit_interface.py b/tests/core/test_mcrit_interface.py index c893154..33bccc1 100644 --- a/tests/core/test_mcrit_interface.py +++ b/tests/core/test_mcrit_interface.py @@ -1,5 +1,6 @@ """Tests for the McritInterface logic that runs without a disassembler or an MCRIT server.""" +import json import threading from types import SimpleNamespace from unittest.mock import MagicMock @@ -8,6 +9,7 @@ import requests from mcrit_plugin.core.McritInterface import McritInterface +from mcrit_plugin.core.minimcrit.queue.LocalQueue import Job class _FakeBinaryInfo: @@ -159,6 +161,12 @@ def test_leaves_a_dict_the_ui_is_iterating_unchanged(self): assert interface.parent.matched_function_entries == {1: old_entry, 7: old_entry} +def _job(method, *arguments): + """A queue Job as the server describes it: the method and its arguments by position.""" + params = {str(index): argument for index, argument in enumerate(arguments)} + return Job({"payload": {"method": method, "params": json.dumps(params)}}, None) + + class TestServerErrors: def test_a_rejected_upload_reports_failure_without_a_traceback(self, capsys): interface = _make_interface() @@ -178,20 +186,53 @@ def test_a_rejected_job_query_reports_failure(self): def test_jobs_of_a_sample_are_narrowed_by_the_server_and_checked_exactly(self): interface = _make_interface() - - def job(parameters): - return SimpleNamespace(parameters=parameters) - - wanted = job("getMatchesForSample(23, 2)") + wanted = _job("getMatchesForSample", 23, 2) interface.mcrit_client.getQueueData.return_value = [ wanted, - job("getMatchesForSample(230, 2)"), - job("updateMinHashesForSample(23)"), + _job("getMatchesForSample", 230, 2), + _job("updateMinHashesForSample", 23), ] assert interface.queryJobs(sample_id=23) == [wanted] interface.mcrit_client.getQueueData.assert_called_once_with(filter="23") + def test_a_sample_compared_second_finds_the_comparison(self): + interface = _make_interface() + versus = _job("getMatchesForSampleVs", 5, 12, 50) + interface.mcrit_client.getQueueData.return_value = [versus] + + assert interface.queryJobs(sample_id=5) == [versus] + assert interface.queryJobs(sample_id=12) == [versus] + + def test_a_threshold_equal_to_the_sample_id_does_not_count(self): + interface = _make_interface() + # getMatchesForSample(sample_id, minhash_threshold, pichash_size, ...) + interface.mcrit_client.getQueueData.return_value = [ + _job("getMatchesForSample", 0, 50, 10, 1, 50, 1000) + ] + + assert interface.queryJobs(sample_id=50) == [] + assert interface.queryJobs(sample_id=10) == [] + + def test_cross_compares_find_each_of_their_samples(self): + interface = _make_interface() + cross = _job("combineMatchesToCross", {"3": "job-a", "7": "job-b"}) + per_sample = _job("getMatchesForSampleVsGroup", 3, [7]) + interface.mcrit_client.getQueueData.return_value = [cross, per_sample] + + assert interface.queryJobs(sample_id=3) == [cross, per_sample] + assert interface.queryJobs(sample_id=7) == [cross] + + def test_a_job_with_arguments_of_another_shape_is_skipped(self): + interface = _make_interface() + wanted = _job("getMatchesForSample", 4) + interface.mcrit_client.getQueueData.return_value = [ + _job("getMatchesForSample", "not a sample id"), + wanted, + ] + + assert interface.queryJobs(sample_id=4) == [wanted] + class TestRemoteInformation: def test_the_lists_are_downloaded_once_by_whoever_asks_first(self): From 53bfba0d319f9d13f3bf9795d068225bdbdb43b3 Mon Sep 17 00:00:00 2001 From: r0ny123 <49360849+r0ny123@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:41:26 +0530 Subject: [PATCH 2/2] Leave a cross compare's combined result out of the result chooser Selecting jobs by Job.sample_ids also found combineMatchesToCross jobs, whose sample ids are the keys of their first argument; the text test never matched them. Their result is the cross-compare matrix, not a matching report, so MatchingResult.fromDict fails on it ("info" is missing) and the chooser reported "Result query failed". After a cross compare that job is also the newest finished one, which the chooser preselects. Those jobs are skipped again; the per-sample getMatchesForSampleVsGroup jobs of a cross compare stay selectable. The tests now build jobs as the server stores them, with the knobs as named parameters after the positional sample ids. --- CHANGELOG.md | 4 ++-- mcrit_plugin/core/McritInterface.py | 3 ++- tests/core/test_mcrit_interface.py | 16 ++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d77a547..c26aa48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,8 +106,8 @@ Ninja applies to that plugin only. ### Fixed - Get Match Result missed the jobs in which the sample is not the first argument, such as a - sample-vs-sample comparison started from the other sample or a cross compare that includes it. - Jobs are now selected by their sample id arguments instead of by matching the job's text. + sample-vs-sample comparison started from the other sample. Jobs are now selected by their sample + id arguments instead of by matching the job's text. - The bundled MCRIT client's `modifyFamily`, `modifySample`, `requestMatchesForMappedBinary` and `requestMatchesForUnmappedBinary` raised `TypeError` on every call: they passed the request body positionally to the client's request wrappers, which take it only by keyword. diff --git a/mcrit_plugin/core/McritInterface.py b/mcrit_plugin/core/McritInterface.py index 203bf2b..cd6bdc3 100644 --- a/mcrit_plugin/core/McritInterface.py +++ b/mcrit_plugin/core/McritInterface.py @@ -18,7 +18,8 @@ def _isMatchingJobOfSample(job, sample_id): """Whether a matching job compares the sample, read from the job's sample id arguments like the server's sample_ids selector; its thresholds are arguments too and must not count.""" - if "Matches" not in (job.method or ""): + # a cross compare's combined result is no matching report, so the result chooser cannot load it + if "Matches" not in (job.method or "") or job.method == "combineMatchesToCross": return False try: # the per-sample jobs of a cross compare; Job.sample_ids does not know them diff --git a/tests/core/test_mcrit_interface.py b/tests/core/test_mcrit_interface.py index 33bccc1..d29a60d 100644 --- a/tests/core/test_mcrit_interface.py +++ b/tests/core/test_mcrit_interface.py @@ -161,9 +161,10 @@ def test_leaves_a_dict_the_ui_is_iterating_unchanged(self): assert interface.parent.matched_function_entries == {1: old_entry, 7: old_entry} -def _job(method, *arguments): - """A queue Job as the server describes it: the method and its arguments by position.""" +def _job(method, *arguments, **named): + """A queue Job as the server stores it: the sample ids by position, the knobs by name.""" params = {str(index): argument for index, argument in enumerate(arguments)} + params.update(named) return Job({"payload": {"method": method, "params": json.dumps(params)}}, None) @@ -198,7 +199,7 @@ def test_jobs_of_a_sample_are_narrowed_by_the_server_and_checked_exactly(self): def test_a_sample_compared_second_finds_the_comparison(self): interface = _make_interface() - versus = _job("getMatchesForSampleVs", 5, 12, 50) + versus = _job("getMatchesForSampleVs", 5, 12, minhash_threshold=50) interface.mcrit_client.getQueueData.return_value = [versus] assert interface.queryJobs(sample_id=5) == [versus] @@ -206,22 +207,21 @@ def test_a_sample_compared_second_finds_the_comparison(self): def test_a_threshold_equal_to_the_sample_id_does_not_count(self): interface = _make_interface() - # getMatchesForSample(sample_id, minhash_threshold, pichash_size, ...) interface.mcrit_client.getQueueData.return_value = [ - _job("getMatchesForSample", 0, 50, 10, 1, 50, 1000) + _job("getMatchesForSample", 0, minhash_threshold=50, pichash_size=10, shortlist_size=50) ] assert interface.queryJobs(sample_id=50) == [] assert interface.queryJobs(sample_id=10) == [] - def test_cross_compares_find_each_of_their_samples(self): + def test_a_cross_compare_offers_its_per_sample_jobs_not_its_combined_result(self): interface = _make_interface() cross = _job("combineMatchesToCross", {"3": "job-a", "7": "job-b"}) per_sample = _job("getMatchesForSampleVsGroup", 3, [7]) interface.mcrit_client.getQueueData.return_value = [cross, per_sample] - assert interface.queryJobs(sample_id=3) == [cross, per_sample] - assert interface.queryJobs(sample_id=7) == [cross] + assert interface.queryJobs(sample_id=3) == [per_sample] + assert interface.queryJobs(sample_id=7) == [] def test_a_job_with_arguments_of_another_shape_is_skipped(self): interface = _make_interface()