From dcea6b59d81737d62d6e02a7bb3e37fb83f798d0 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 24 Jun 2025 12:46:00 +0000 Subject: [PATCH 1/4] context: Fix xref api calls Signed-off-by: Arthur Chan --- data_prep/introspector.py | 57 +++++++++++++++++-- .../project_context/context_introspector.py | 22 ++++++- prompts/template_xml/context.txt | 2 - 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/data_prep/introspector.py b/data_prep/introspector.py index 7bb74348a..8818e70fd 100755 --- a/data_prep/introspector.py +++ b/data_prep/introspector.py @@ -254,7 +254,7 @@ def query_introspector_for_tests(project: str) -> list[str]: def query_introspector_for_tests_xref( - project: str, functions: Optional[list[str]]) -> list[str]: + project: str, functions: Optional[list[str]]) -> dict[str, list[Any]]: """Gets the list of functions and xref test files in the target project.""" data = {'project': project} if functions: @@ -263,14 +263,60 @@ def query_introspector_for_tests_xref( resp = _query_introspector(INTROSPECTOR_ORACLE_ALL_TESTS_XREF, data) + details = _get_data(resp, 'details', False) test_files = _get_data(resp, 'test-files-xref', {}) handled = set() result_list = [] + detail_list = [] key_list = test_files.keys() for test_paths in test_files.values(): + # Only dump the details from the test source files + # which are related to the target function calls + if details and isinstance(test_paths, dict): + for test_path, calls in test_paths.items(): + source_code = query_introspector_test_source(project, test_path) + lines = source_code.splitlines() + + # Include details of function calls in test files + for call in calls: + result_lines = [] + start = call.get('call_start', -1) + end = call.get('call_end', -1) + params = call.get('params') + + # Skip invalid data + if start <= 0 or end <= 0 or params is None: + continue + + call_lines = lines[start - 1:end] + + param_list = [] + for param in params: + param_dict = {} + + decl = param.get('decl_line', -1) + start = param.get('init_start', -1) + end = param.get('init_end', -1) + func = param.get('init_func') + + # Skip invalid data + if decl <= 0 or decl >= len(lines): + continue + + result_lines.append(lines[decl - 1]) + if func and start > 0 and end > 0: + result_lines.extend(lines[start - 1:end]) + + result_lines.extend(call_lines) + + detail_list.append(result_lines) + + continue + + # Plain dump of test source files with limited number + # of result lines if details not found for test_path in test_paths: - # Allow limited number of result lines if len(result_list) > 100: break @@ -279,9 +325,9 @@ def query_introspector_for_tests_xref( handled.add(test_path) source_code = query_introspector_test_source(project, test_path) + lines = source_code.splitlines() # Retrieve needed line range in the source file - lines = source_code.splitlines() target_lines = list() for idx, line in enumerate(lines): if any(func.split('::')[-1] in line for func in key_list): @@ -305,7 +351,10 @@ def query_introspector_for_tests_xref( for start, end in ranges: result_list.extend(lines[start:end]) - return result_list + result_dict = {} + result_dict['source'] = result_list + result_dict['details'] = detail_list + return result_dict def query_introspector_for_harness_intrinsics( diff --git a/data_prep/project_context/context_introspector.py b/data_prep/project_context/context_introspector.py index 82444c571..f519be652 100644 --- a/data_prep/project_context/context_introspector.py +++ b/data_prep/project_context/context_introspector.py @@ -187,10 +187,26 @@ def _get_test_xrefs_to_function(self) -> list[str]: if not xrefs: logging.warning( - 'Could not retrieve tests xrefs for project: %s ' - 'function_signature: %s', project, func_name) + 'Could not retrieve xrefs for project: %s ' + 'function_signature: %s', project, func_sig) - return [xref for xref in xrefs if xref.strip()] + source_list = xrefs.get('source') + detail_list = xrefs.get('details') + + if source_list: + source_list.insert(0, '') + source_list.append('') + return [src for src in source_list if src.strip()] + + result = [''] + + for detail in detail_list: + result.append('') + result.extend(detail) + result.append('') + + result.append('') + return result def _get_param_typedef(self) -> list[str]: """Querties FI for param type definitions with type name.""" diff --git a/prompts/template_xml/context.txt b/prompts/template_xml/context.txt index 174b06e74..2ba82e90b 100644 --- a/prompts/template_xml/context.txt +++ b/prompts/template_xml/context.txt @@ -34,7 +34,5 @@ Here is the source code for functions which reference the function being tested: {% if tests_xrefs %} Here is the source code snippet for the tests/examples that reference the function being tested: - {{ tests_xrefs }} - {% endif %} From 33983b51bd9dcccf9e2952f08ca11f4b6df2d307 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 24 Jun 2025 12:53:54 +0000 Subject: [PATCH 2/4] Fix typing Signed-off-by: Arthur Chan --- data_prep/project_context/context_introspector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_prep/project_context/context_introspector.py b/data_prep/project_context/context_introspector.py index f519be652..41a52b4d5 100644 --- a/data_prep/project_context/context_introspector.py +++ b/data_prep/project_context/context_introspector.py @@ -187,8 +187,8 @@ def _get_test_xrefs_to_function(self) -> list[str]: if not xrefs: logging.warning( - 'Could not retrieve xrefs for project: %s ' - 'function_signature: %s', project, func_sig) + 'Could not retrieve tests xrefs for project: %s ' + 'function_signature: %s', project, func_name) source_list = xrefs.get('source') detail_list = xrefs.get('details') From 4d25f0a2078046f35ef65818020effe00d45e9e3 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 24 Jun 2025 12:56:03 +0000 Subject: [PATCH 3/4] Fix formatting Signed-off-by: Arthur Chan --- data_prep/project_context/context_introspector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data_prep/project_context/context_introspector.py b/data_prep/project_context/context_introspector.py index 41a52b4d5..f164a2786 100644 --- a/data_prep/project_context/context_introspector.py +++ b/data_prep/project_context/context_introspector.py @@ -193,6 +193,9 @@ def _get_test_xrefs_to_function(self) -> list[str]: source_list = xrefs.get('source') detail_list = xrefs.get('details') + if not source_list and not detail_list: + return [] + if source_list: source_list.insert(0, '') source_list.append('') From b1014a1a53dcab51b8548a8719c610ec7998c75e Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 24 Jun 2025 13:01:44 +0000 Subject: [PATCH 4/4] Fix formatting Signed-off-by: Arthur Chan --- data_prep/project_context/context_introspector.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data_prep/project_context/context_introspector.py b/data_prep/project_context/context_introspector.py index f164a2786..1a4f5663e 100644 --- a/data_prep/project_context/context_introspector.py +++ b/data_prep/project_context/context_introspector.py @@ -193,14 +193,14 @@ def _get_test_xrefs_to_function(self) -> list[str]: source_list = xrefs.get('source') detail_list = xrefs.get('details') - if not source_list and not detail_list: - return [] - if source_list: source_list.insert(0, '') source_list.append('') return [src for src in source_list if src.strip()] + if not detail_list: + return [] + result = [''] for detail in detail_list: @@ -209,6 +209,7 @@ def _get_test_xrefs_to_function(self) -> list[str]: result.append('') result.append('') + return result def _get_param_typedef(self) -> list[str]: