Influencing link generation method, device and storage medium
By identifying the API interface functions of the modified functions and the entry point functions of the target functional modules, the impact chain is automatically generated, which solves the problem of accuracy in evaluating the call chain after code modification in agile development, improves the efficiency and accuracy of evaluation, and reduces the risk of going live.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING 58 INFORMATION TTECH CO LTD
- Filing Date
- 2024-12-27
- Publication Date
- 2026-06-26
AI Technical Summary
In agile development environments, existing technologies struggle to quickly and comprehensively assess the impact of code modifications on call chains, especially in complex cluster deployment projects. They often overlook subtle cross-cluster call chains, leading to insufficient accuracy in assessing the scope of test impact.
By identifying the API interface functions corresponding to the changed functions, the target functional modules that have dependencies on them are determined. Starting from the entry point function of the target functional module, the impact chain is generated layer by layer downwards. The distributed version control system and abstract syntax tree are used to analyze code changes. Combined with the project knowledge base and large language model, the impact chain is automatically generated.
It enables precise generation of impact chains for code changes, ensuring that every potential impact point is fully considered and verified, reducing post-launch risks, and improving generation efficiency and assessment accuracy.
Smart Images

Figure CN119883913B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, device and storage medium for generating topological links. Background Technology
[0002] In agile development environments, enterprises face the demands of rapid iteration and frequent deployments, along with frequent cross-project collaborations, making the assessment of test impact scope particularly critical. Current methods primarily rely on technical personnel manually tracing changes layer by layer, ultimately determining the affected call chains through human judgment. However, this approach is slow and often overlooks subtle call chains, failing to provide a comprehensive understanding of all call chains affected by code modifications. Summary of the Invention
[0003] This invention provides an impact link generation method, device, and storage medium, which can accurately generate impact links corresponding to test code.
[0004] In a first aspect, embodiments of the present invention provide a method for influencing link generation, the method comprising:
[0005] In response to the test code link generation request, retrieve the development branch commit record corresponding to the test code;
[0006] Based on the development branch commit history, determine the changed functions in the test code;
[0007] Determine the API interface function corresponding to the change function, and the API interface function is called by other functional modules outside the functional module where the change function is located;
[0008] Identify the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module. The target functional module is a functional module other than the functional module where the change function is located.
[0009] Based on the change function, the API interface function, and the entry point function, the impact chain corresponding to the test code is generated.
[0010] Secondly, embodiments of the present invention provide an influence link generation apparatus, the apparatus comprising:
[0011] The acquisition module is used to retrieve the development branch commit records corresponding to the test code in response to the test code's link generation request;
[0012] The first determining module is used to determine the changed functions in the test code based on the development branch commit records;
[0013] The second determining module is used to determine the API interface function corresponding to the change function, and the API interface function is called by other functional modules outside the functional module where the change function is located.
[0014] The third determining module is used to determine the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module. The target functional module is a functional module other than the functional module where the change function is located.
[0015] The generation module is used to generate the impact chain corresponding to the test code based on the change function, the API interface function, and the entry point function.
[0016] Thirdly, embodiments of the present invention provide an electronic device, including: a memory, a processor, and a communication interface; wherein, the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the influence link generation method as described in the first aspect.
[0017] Fourthly, embodiments of the present invention provide a non-transitory machine-readable storage medium storing executable code, which, when executed by a processor of a transmission device, enables the processor to at least implement the influence link generation method as described in the first aspect.
[0018] Fifthly, embodiments of the present invention provide a computer program product, the computer program product including a computer program or instructions, which, when executed by a processor, cause the processor to implement the influence link generation method as described in the first aspect above.
[0019] In the impact chain generation scheme provided in this embodiment of the invention, an impact chain can be generated for modified test code during the development phase to determine the impact of the test code on cross-cluster functional modules. Specifically, in response to the link generation request of the test code, the development branch commit record corresponding to the test code is obtained, and the modified function in the test code is determined based on the development branch commit record. Then, the API interface function corresponding to the modified function is determined, wherein the API interface function is called by other functional modules outside the functional module where the modified function is located. Next, the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module are determined. The target functional module is a functional module other than the functional module where the modified function is located. Finally, the impact chain corresponding to the test code is generated based on the modified function, the API interface function, and the entry point function.
[0020] In the above scheme, by identifying the API interface functions exposed by the changed function, and finding the target functional modules that depend on these API interface functions, all external call points that may be affected by the change can be identified based on the API interface functions. This provides a comprehensive understanding of the cross-cluster call situation of the changed function, allowing for the identification of subtle call chains. Furthermore, based on the changed function, the API interface functions, and the entry point functions corresponding to the target functional modules, the impact chain corresponding to the test code can be generated more accurately, ensuring that every potential impact point of the change is fully considered and verified, reducing post-deployment risks. Moreover, when generating the impact chain, the API interface functions corresponding to the changed function in the test code can be identified first to obtain the outermost function of the functional module containing the changed function. This allows for the rapid identification of target functional modules that depend on the API interface functions and their corresponding entry point functions, accelerating the efficiency of impact chain generation. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart of an influence link generation method provided in an embodiment of the present invention;
[0023] Figure 2 A flowchart for determining the API interface function corresponding to the change function is provided in an embodiment of the present invention;
[0024] Figure 3 A flowchart for determining the entry point function corresponding to a target functional module is provided in an embodiment of the present invention;
[0025] Figure 4 A flowchart illustrating the impact chain for generating test code is provided in this embodiment of the invention.
[0026] Figure 5 A flowchart of another method for influencing link generation provided in an embodiment of the present invention;
[0027] Figure 6 This is an application diagram of an influence link generation method provided by an embodiment of the present invention;
[0028] Figure 7 A flowchart for determining the entry layer function is provided in an embodiment of the present invention;
[0029] Figure 8This is a schematic diagram of the structure of an influence link generation device provided in an embodiment of the present invention;
[0030] Figure 9 To and Figure 8 The illustrated embodiment provides a schematic diagram of the electronic device corresponding to the influence link generation device. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation.
[0033] In agile development environments, enterprises face the demands of rapid iteration and frequent deployments, along with frequent cross-project collaborations, making the assessment of test impact scope particularly critical. Existing solutions primarily involve technical personnel manually tracing changes layer by layer, ultimately determining the affected call chains through human judgment. However, this approach is slow, and for complex cluster deployments, the call chains are intricate and variable, with many call chains having unclear cross-cluster usage. This method often overlooks these subtle call chains, affecting the final generated impact chain and consequently the accuracy of the test impact scope assessment.
[0034] To address the aforementioned technical issues, this invention provides a solution for automatically generating the impact chain corresponding to changed code, eliminating the need for manual generation. Specifically, by identifying the API interface function corresponding to the changed code and determining the target functional modules that depend on the API function, all external call points potentially affected by the change can be identified. Then, starting from the entry point function corresponding to the target functional module, the search proceeds layer by layer downwards according to function reference relationships to sequentially determine the dependent functions that depend on the changed function. This allows for a more accurate generation of the impact chain corresponding to the changed code. Furthermore, based on the generated impact chain corresponding to the changed code, the scope of the change code's impact on cross-cluster projects can be accurately assessed.
[0035] Some embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0036] Figure 1A flowchart of an influence link generation method provided in an embodiment of the present invention, such as Figure 1 As shown, specifically, the method may include the following steps:
[0037] 101. In response to the test code's link generation request, retrieve the development branch commit record corresponding to the test code.
[0038] 102. Based on the development branch commit history, identify the changed functions in the test code.
[0039] 103. Determine the API interface function corresponding to the modified function. The API interface function is available for other functional modules outside the functional module where the modified function is located to call.
[0040] 104. Identify the target functional modules that have dependencies on the API interface functions, as well as the entry point functions corresponding to the target functional modules. The target functional modules are functional modules other than the functional modules where the change functions are located.
[0041] 105. Based on the changed functions, API interface functions, and entry point functions, generate the impact chain corresponding to the test code.
[0042] In software development, distributed version control systems can be used to clone code from a remote repository to generate a local codebase. Modifications can then be made to the main branch within the local repository to change, delete, or add specific features to the existing live code. To track code changes, each modification and commit is recorded for the corresponding development branch.
[0043] Upon receiving a link generation request triggered by the test code, the system responds by retrieving the corresponding development branch commit history based on the version number of the test code carried in the request. This development branch commit history details the time, author, commit information, and specific code changes for each commit. By analyzing this commit history, the system can identify the modified code within the test code and the corresponding modified functions.
[0044] A test code may contain multiple change functions, and the generation process of the impact link corresponding to each change function is roughly the same. For ease of description, the following only uses one change function as an example to illustrate its specific implementation process.
[0045] In one optional implementation, the process of determining the modified functions in the test code can be as follows: First, obtain the commit record of the main branch corresponding to the test code, compare the commit record of the development branch corresponding to the test code with the commit record of the main branch corresponding to the test code to determine the changes in the test code, and then determine the modified functions in the test code based on the changes.
[0046] The main branch commit history details the changes to the project's core code. By using the difference comparison command, you can compare the development branch commit history with the main branch commit history to identify the change files corresponding to the test code, as well as the changes and their corresponding line numbers within those change files.
[0047] After obtaining the line number corresponding to the changed content, we can determine the specific function corresponding to the changed content by combining the file structure of the changed file. For ease of description, this function is called the change function.
[0048] This involves obtaining the first abstract syntax tree (BST) corresponding to the test code, using the BST to parse the change file, and obtaining the line number corresponding to each function in the change file. Based on the line number of each function in the change file and the line number of the changed content, the changed function corresponding to the changed content can be determined.
[0049] For example, if you use `git diff` to determine that lines 100-150 of the modified file have changed, and combine this with the Java abstract syntax tree corresponding to the test code, you can identify that function A in the modified file is located in lines 99-160. Therefore, you can determine that the modified function is function A.
[0050] In one optional embodiment, the specific implementation process of obtaining the first abstract syntax tree corresponding to the test code may include: dividing the test code into multiple lexical units; and organizing the multiple lexical units into a first abstract syntax tree according to the syntax rules of the test code.
[0051] Once the modified function in the test code is identified, the corresponding API interface function is determined. The API interface function is called by other functional modules outside the module containing the modified function. In other words, the API interface function is the outermost entry point function of the module containing the modified function and is typically exposed to other functional modules.
[0052] In practical applications, the outermost call entry function is where the modified function is first called in the program, marking the starting point of the modified function's execution flow. Analyzing from the outermost call entry function avoids blindly searching for the influence path of the modified function throughout the entire program, which helps improve analysis efficiency, speeds up the generation of influence chains, and reduces unnecessary workload.
[0053] Next, the dependencies between the modification function and other functions can be identified through the API interface functions. Specifically, the target functional modules that have dependencies on the API interface functions and their corresponding entry point functions are determined. The target functional modules are functional modules other than the functional module where the modification function is located.
[0054] In practical applications, when a function in a development project is modified, this function may be relatively low-level and affect many call chains (i.e., multiple functions call this function). In complex iterative scenarios, the parts of the call chain affected by this modified function are often overlooked, leading to deployment risks. Therefore, to comprehensively understand the actual cross-cluster call behavior of the modified function, all target functional modules that depend on the API interface function can be identified to determine all external call points that may be affected by the change. This allows for the discovery of call chains that are not easily detected.
[0055] In one alternative embodiment, the target functional modules that depend on the API interface function can be identified by analyzing the project's dependent projects. Once the modified function, the corresponding API interface function, and the entry point function corresponding to the target functional module are determined, the upper and lower level functions corresponding to each function can be determined based on the function reference relationships between each function, thereby generating the impact chain corresponding to the test code.
[0056] In this embodiment of the invention, by identifying the API interface functions exposed by the changed function, target functional modules that depend on the API interface functions are located. This allows for the identification of all external call points potentially affected by the change, providing a comprehensive understanding of the cross-cluster call behavior of the changed function. This helps identify subtle call chains. Furthermore, based on the changed function, the API interface functions, and the entry point functions corresponding to the target functional modules, the impact chain corresponding to the test code can be accurately generated. This ensures that every potential impact point of the change is fully considered and verified, reducing post-deployment risks. Moreover, when generating the impact chain, the API interface functions corresponding to the changed function in the test code can be determined first, thus obtaining the outermost function of the functional module containing the changed function. This allows for the rapid identification of target functional modules that depend on the API interface functions and their corresponding entry point functions, accelerating the generation efficiency of the impact chain.
[0057] The following embodiments provide a detailed description of one possible implementation of the API interface function corresponding to the change function in the above embodiments.
[0058] Figure 2 A flowchart for determining the API interface function corresponding to the change function is provided in an embodiment of the present invention, such as... Figure 2As shown, specifically, the method may include the following steps:
[0059] 201. Based on the reference relationships corresponding to the modified function, determine the parent function corresponding to the modified function.
[0060] 202. Identify whether the upper-level function carries an external call identifier.
[0061] 203. If the upper-level function carries the aforementioned external call identifier, then the upper-level function is identified as the API interface function corresponding to the change function.
[0062] 204. If the upper-level function does not carry an external call identifier, then start from the function being modified and search upwards layer by layer until the top-level function carrying the external call identifier is found.
[0063] 205. The top-level function carrying the external call identifier is identified as the API interface function corresponding to the modified function.
[0064] Before determining the API interface function corresponding to the modified function, the modification file to which the modified function belongs can be analyzed according to syntax and semantics to parse out the function name, function implementation, input parameters, return value and function reference relationship of each function in the modification file.
[0065] Function reference relationships include how a function is called by other functions and how a function calls other functions. In other words, the reference relationship corresponding to a modified function refers to which function references the modified function and which function the modified function references.
[0066] Once the reference relationships of the modified function are determined, the corresponding parent function can be identified based on these relationships. Then, it's checked whether this parent function carries an external call identifier. This external call identifier can be an RPC identifier, message receiving entry identifier, scheduled task identifier, gateway identifier, task forwarding service identifier, etc.
[0067] If an external call identifier is identified in the upper-level function, it means that the upper-level function is the outermost call entry function exposed to other functional modules for calling. In this case, the upper-level function can be identified as the API interface function corresponding to the change function.
[0068] If the upper-level function is found to not carry an external call identifier, it means that the upper-level function is not the outermost call entry function. In this case, we can start from the modified function and search upwards layer by layer until we find the topmost function that carries an external call identifier. The topmost function found is then identified as the API interface function corresponding to the modified function.
[0069] For example, suppose the changed function is function A. Function A references function D; function D is referenced by functions A and B; function D references function C; function C is referenced by function D; function C references function E; and function C carries an RPC identifier. We can start from function A and search upwards layer by layer until we find its parent function, function D. Since function D does not carry an external call identifier, we continue searching upwards from function D until we find its parent function, function C. We then identify that function C carries an external call identifier. The search ends there, and function C is identified as the API interface function corresponding to the changed function.
[0070] In this embodiment of the invention, the upper-level function corresponding to the changed function is determined based on the reference relationship corresponding to the changed function, and it is identified whether the upper-level function carries an external call identifier. If the upper-level function carries the external call identifier, the upper-level function is determined to be the API interface function corresponding to the changed function. If the upper-level function does not carry an external call identifier, the search is performed layer by layer upwards from the changed function until the top-level function carrying the external call identifier is found. In this way, the API interface function corresponding to the changed function can be accurately identified, and then all target functional modules that have a dependency relationship with the changed function can be accurately found based on the API interface function.
[0071] When identifying target functional modules that depend on API interface functions, the dependency can be determined based on the service call file or the pom.xml file. The target functional module is defined as a functional module other than the one containing the modified function; that is, the target functional module is the external calling module.
[0072] In an optional embodiment, a pre-trained code similarity recognition model can also be used to identify target functional modules that have dependencies on API interface functions. The code similarity recognition model can be pre-trained to identify target functional modules that have dependencies on API interface functions. The code similarity recognition model can be generated by training a neural network module.
[0073] In addition, a project knowledge base can be built. When using code similarity recognition models to identify target functional modules that have dependencies on API interface functions, the project knowledge base can be used in conjunction with this approach to improve the accuracy of the recognition results.
[0074] The project knowledge base includes code files, project design documents, project history, reasons for technology selection, project change log, detailed descriptions of each functional module, the file structure of the code files, function signature information for each function, and detailed descriptions of each function. The code files can include source code and test code.
[0075] Furthermore, automated scripts can be used to collect, organize, and update information in the knowledge base. For example, the latest function reference relationships can be extracted from the code repository regularly and stored in the database; or the relevant documentation can be automatically updated whenever there is a new commit.
[0076] Before inputting the API interface function corresponding to the change function and the reference relationships and function signatures of the functional modules corresponding to multiple projects into the code similarity recognition model, we can first determine the keywords corresponding to the API interface function. Based on the keywords, we can match the background knowledge that matches the keywords from the project knowledge base. Then, we input the background knowledge, API interface function, reference relationships and function signatures of the functional modules corresponding to multiple projects into the code similarity recognition model to output the target functional modules that have a dependency relationship with the API interface function.
[0077] In another optional embodiment, a project knowledge base can be combined with a large language model to identify target functional modules that have dependencies on API interface functions. Specifically, firstly, keywords corresponding to API interface functions are determined, and background knowledge matching these keywords is retrieved from the project knowledge base. Then, the API interface functions, the reference relationships between functional modules across multiple projects, function signatures, and background knowledge are transformed into a language form that the large language model can understand, resulting in transformed language text. Next, task description information corresponding to the large language model is generated, and the task description information and language text are input into the large language model to guide it in selecting target functional modules that have dependencies on API functions from multiple functional modules.
[0078] Once the target functional module that has a dependency relationship with the API interface function corresponding to the change function is identified, the entry point function corresponding to the target functional module can be determined. Then, based on the entry point function, the upper-level call chain can be determined to accurately generate the complete impact chain.
[0079] The following examples illustrate in detail the specific implementation process of determining the entry point function corresponding to the target functional module and generating the influencing link.
[0080] Figure 3 A flowchart for determining the entry point function corresponding to a target functional module is provided in an embodiment of the present invention, such as... Figure 3As shown, specifically, the method may include the following steps:
[0081] 301. Parse the source code of the target functional module to construct the second abstract syntax tree corresponding to the target functional module.
[0082] 302. Based on the second abstract syntax tree, extract the code structure corresponding to the target functional module. The code structure includes detailed information about each class, each method, and each attribute in the source code.
[0083] 303. Based on the code structure and external call identifiers, determine the entry point function corresponding to the target functional module.
[0084] In the process of parsing the target functional module, the source code corresponding to the target functional module can be retrieved first, and the overall structure of the project corresponding to the target functional module can be parsed. Based on the overall structure of the project, the second abstract syntax tree corresponding to the target functional module can be constructed.
[0085] Next, based on the second abstract syntax tree, the code structure corresponding to the target functional module is extracted. The code structure includes detailed information about each class, each method, and each attribute in the source code. Then, based on the code structure and external call identifiers, the entry point function corresponding to the target functional module is determined.
[0086] The target functional module may consist of multiple code files. A second abstract syntax tree can be used to parse the file structure of each code file within the target functional module. This file structure includes function information, class information, class attribute information, and function body information for each function. Furthermore, based on the file structure of each code file, the internal and external dependencies of each function in that code file are parsed out. Based on the internal and external dependencies of each function in each code file, as well as the external call identifier, the entry point function corresponding to the target functional module is determined.
[0087] In this embodiment of the invention, by combining the second abstract syntax tree corresponding to the target functional module, the code structure corresponding to the target functional module is extracted, and then the entry point function corresponding to the target functional module can be accurately determined based on the code structure and external call identifier.
[0088] Figure 4 A flowchart illustrating the impact chain for generating test code, as provided in this embodiment of the invention, is shown below. Figure 4 As shown, specifically, the method may include the following steps:
[0089] 401. Determine the reference function corresponding to the entry point function.
[0090] 402. Compare the code similarity between API interface functions and referenced functions to determine whether the API interface functions and referenced functions are the same function.
[0091] 403. If the API interface function and the reference function are the same function, then starting from the entry point function, search downwards layer by layer according to the function reference relationship to determine the dependent functions that have a dependency relationship with the entry point function.
[0092] 404. Based on the change function, API interface function, entry point function, and dependent functions, generate the impact chain corresponding to the test code.
[0093] To ensure accurate generation of the impact chain corresponding to the test code, when generating the impact chain for the changed function, it can be further determined whether the API interface function and the entry point function corresponding to the target functional module refer to the same function. That is, it further determines whether the target functional module calls the API interface function in actual application.
[0094] In practice, the first step is to identify the referenced function by the entry point function. Then, the code similarity between the API interface function and the referenced function is compared to determine whether they are the same function.
[0095] In one optional embodiment, the specific implementation process of comparing the code similarity between the API interface function and the reference entry point function to determine whether the API interface function and the reference entry point function are the same function may include: obtaining a first function signature corresponding to the API interface function and a second function signature corresponding to the reference entry point function; performing vectorization processing on the first function signature and the second function signature respectively to obtain a first vectorized representation corresponding to the first function signature and a second vectorized representation corresponding to the second function signature; comparing the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the reference entry point function are the same function.
[0096] Specifically, the Jaccard similarity coefficients of the API interface function and the referenced function can be determined based on the first and second vectorized representations; if the Jaccard similarity coefficients meet a preset threshold, then the API interface function and the referenced function are determined to be the same function.
[0097] Once it is determined that the API interface function and the referenced function are the same function, then starting from that entry point function, the search can proceed layer by layer downwards according to the function reference relationship to identify the dependent functions that have a dependency relationship with the entry point function.
[0098] Next, based on function reference relationships, modified functions, API interface functions, entry point functions, and dependent functions, the impact chain corresponding to the test code is generated.
[0099] In this embodiment of the invention, before generating the impact chain based on the entry point function, the code similarity between the API interface function and the reference function corresponding to the entry point is compared to determine whether the API interface function and the reference function are the same function. It is then determined whether the target functional module actually calls the API interface function. Finally, the dependent functions are found based on the entry point function. This can generate the impact chain corresponding to the test code more accurately. Figure 5 A flowchart of another method for influencing link generation provided in an embodiment of the present invention, such as... Figure 5 As shown, specifically, the method may include the following steps:
[0100] 501. In response to the test code's link generation request, retrieve the development branch commit record corresponding to the test code.
[0101] 502. Based on the development branch commit history, identify several changed functions in the test code.
[0102] 503. Select the target change function from multiple change functions. The target change function is the core function or the function that modifies the risk point.
[0103] 504. Determine the API interface function corresponding to the target change function.
[0104] 505. Identify the target functional modules that have dependencies on the API interface functions, as well as the entry point functions corresponding to the target functional modules.
[0105] 506. Based on the target change function, API interface function, and entry point function, generate the impact chain corresponding to the test code.
[0106] Upon receiving a request to generate a test code commit history, the system responds by retrieving the commit history of the development branch corresponding to the test code. Based on this commit history, it identifies several modified functions within the test code.
[0107] In practical applications, many changed functions will not have any impact on the system, or the changed functions do not have any risk points for modification. Therefore, when generating the impact chain corresponding to the test code, some changed functions can be filtered out, and only those core functions or functions with modification risks that have an important impact on the system or process can be focused on, making the analysis process more efficient.
[0108] In practice, the target change function is selected from multiple change functions; this target function is either a core function or a function with a high risk of modification. Next, the corresponding API interface function is determined. Then, the target functional modules that have dependencies on the API interface function and their corresponding entry point functions are identified. Finally, based on the target change function, the API interface function, and the entry point function, the impact chain corresponding to the test code is generated.
[0109] In this embodiment of the invention, by filtering out a portion of the modified functions and only generating impact links for core functions or functions with modified risk points, key risk points can be quickly identified, thereby improving the efficiency of impact link generation.
[0110] For ease of understanding, please refer to the appendix. Figure 6 and attached Figure 7 The following example illustrates the process of generating the impact chain for the test code in the specific application scenario described above. First, the test code-related code is cloned using `git` to generate a local code repository, which includes the code files corresponding to the development branch and the master branch. Upon receiving the request to generate the impact chain for the test code, `git diff` is used to obtain the commit history of the development branch and the master branch. Based on these commit history, the development branch and the master branch are compared to determine the changed files and which lines within those files have been modified.
[0111] Next, the collection classes in these change files are parsed to determine which functions are included in the change file and the call relationships between them. Specifically, the change file can be parsed using the Java tree corresponding to the test code to determine how many functions are included, the function name, implementation, input parameters, return value, and line number information of each function. This information, combined with the line numbers corresponding to the changes identified by `git diff` and the line numbers of each function parsed from the Java tree, determines the modified functions.
[0112] Then, following the syntax rules, extract the set of changed functions from each change file, and record the file name or file identifier to which the function belongs. Based on the function description (function identifier, function description information, etc.), the set of changed functions to be analyzed can be determined. This set can be filtered based on whether the changed function is a core function, or whether it represents a risky modification. Alternatively, tools or machines can be used to perform this filtering operation to determine whether a changed function is a core function or a risky modification function.
[0113] Next, based on the project's functionality and configuration information, it is determined whether each modified function is a core function or a potential point of risk. For example, in a payment scenario, payment-related functions would be considered potential risk functions. After filtering out the target modified functions from multiple functions, the outermost call entry function (API interface function) is automatically located based on the target modified function.
[0114] Then, based on the reference relationships corresponding to the parsed variable functions, we determine who references the variable function and who the variable function references, thus identifying the parent function corresponding to the variable function. Based on the reference relationships corresponding to the parent functions, we determine the parent function corresponding to the parent function. We determine each parent function in turn. When the outermost function we find has an RPC identifier, we have found the outermost calling function and identify it as the API interface function corresponding to the variable function.
[0115] Next, analyze the project's dependencies. Based on the service call collection file or pom.xml file, determine the dependent projects corresponding to the changed functions, pull the dependent projects corresponding to the changed functions, and parse the overall project structure to extract the complete code structure corresponding to the project. Specifically, the code structure corresponding to each code file in the dependent projects can be parsed using the Java syntax tree, including function information, class information, class attribute information, and function body information.
[0116] Based on the code structure of each code file, the overall internal and external dependencies of each code file in the dependent project are analyzed. Based on the analyzed internal and external dependencies, as well as the external call identifier, the API interface function corresponding to the modified function is determined. Furthermore, the special identifier of the RPC call can be identified by the cluster RPC identifier and the external call identifier, thus determining the API interface function corresponding to the modified function.
[0117] Furthermore, a unified project identifier management system can be established. A unique identifier can be assigned to multiple dependent cluster projects, and based on the identifier, complete function information (including: function name, input parameters, return value, function package path) and function call relationships can be obtained for each cluster.
[0118] Based on the API interface function corresponding to the target change function and the set of dependent projects, determine whether the entry layer function of the dependent projects calls the API interface function. This can be done by comparing the code similarity between the referenced function corresponding to the entry layer function and the API interface function to determine if the API interface function and the referenced function corresponding to the entry layer function in the dependent projects are the same function, thus determining whether a dependency relationship exists between the dependent project and the API interface function in the current situation.
[0119] Among them, such as Figure 7As shown, for the target change function, firstly, all dependent projects that have dependencies on the target change function are retrieved, namely project A, project B, and project C. Projects A, B, and C are parsed, and through syntactic and semantic analysis, the Java package path, member variables, method implementations, class information, etc., corresponding to each code file in each project are determined. Then, based on this information, the function execution chain in the code file can be obtained. Based on the function execution chain, the execution entry point is determined, that is, the entry-level function corresponding to each dependent project.
[0120] To determine if two functions are the same, the vectorized representations of the referenced functions called by the API interface function and the entry layer function are compared. If they are the same function, a dependency relationship exists. Based on the entry layer function and the function reference relationship, the top-level chain is determined. Information such as function name, return value, formal parameters, and path is extracted for each function in the chain, and the function signature is determined based on this information. Then, based on each function, a complete dependency chain is determined, and based on the dependency chain, the entry layer function, and the target change function, a complete execution chain is determined. This execution chain is the impact chain corresponding to the test code. In this way, the cross-cluster impact range of the change function corresponding to the change code in the test code can be evaluated based on the automatically output impact chain.
[0121] The embodiments of the present invention can be applied not only to the above-mentioned application scenarios, but also to many different application scenarios. The specific implementation methods can be referred to the methods in the above-mentioned application scenarios, and will not be described in detail here.
[0122] The detailed execution process can be found in the descriptions of the other embodiments mentioned above, and will not be repeated here.
[0123] After obtaining the complete impact chain in the above embodiments, the obtained impact chain can also be displayed on the interface so that staff can intuitively see the impact chain corresponding to the test code, and then assess the scope of the impact of the change on cross-cluster calls.
[0124] Figure 8 This is a schematic diagram of the structure of an influence link generation device provided in an embodiment of the present invention, as shown below. Figure 8 As shown, the device includes: an acquisition module 11, a first determination module 12, a second determination module 13, a third determination module 14, and a generation module 15.
[0125] The acquisition module 11 is used to obtain the development branch commit record corresponding to the test code in response to the link generation request of the test code.
[0126] The first determination module 12 is used to determine the changed functions in the test code based on the development branch commit records.
[0127] The second determining module 13 is used to determine the API interface function corresponding to the change function, and the API interface function is called by other functional modules outside the functional module where the change function is located.
[0128] The third determining module 14 is used to determine the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module. The target functional module is a functional module other than the functional module where the change function is located.
[0129] The generation module 15 is used to generate the impact chain corresponding to the test code based on the change function, the API interface function, and the entry point function.
[0130] Optionally, the generation module 15 is specifically used for: determining the reference function corresponding to the entry point function; comparing the code similarity between the API interface function and the reference function to determine whether the API interface function and the reference function are the same function; if the API interface function and the reference function are the same function, then starting from the entry point function, searching downwards layer by layer according to the function reference relationship, and sequentially determining the dependent functions that have a dependency relationship with the entry point function; generating the impact chain corresponding to the test code based on the change function, the API interface function, the entry point function, and the dependent functions.
[0131] Optionally, the generation module 15 is specifically used to: obtain a first function signature corresponding to the API interface function and a second function signature corresponding to the reference function; perform vectorization processing on the first function signature and the second function signature respectively to obtain a first vectorized representation corresponding to the first function signature and a second vectorized representation corresponding to the second function signature; compare the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the reference function are the same function.
[0132] Optionally, the generation module 15 is specifically used to: determine the Jaccard similarity coefficient between the API interface function and the reference function based on the first vectorized representation and the second vectorized representation; if the Jaccard similarity coefficient meets a preset threshold, then determine that the API interface function and the reference function are the same function.
[0133] Optionally, the first determining module 12 is specifically used to: obtain the main branch commit record corresponding to the test code; compare the development branch record and the main branch commit record to determine the changes in the test code; and determine the modified functions in the test code based on the changes.
[0134] Optionally, the first determining module 12 is specifically used to: use a difference comparison command to compare the development branch record and the main branch commit record to determine the change file corresponding to the test code; and determine the changed content in the change file and the line number corresponding to the changed content.
[0135] Optionally, the first determining module 12 is specifically used to: obtain a first abstract syntax tree corresponding to the test code; use the first abstract syntax tree to parse the change file and obtain the line number corresponding to each function in the change file; and determine the change function corresponding to the change content based on the line number corresponding to each function in the change file and the line number corresponding to the change content.
[0136] Optionally, the first determining module 12 is specifically used to: divide the test code into multiple lexical units; and organize the multiple lexical units into a first abstract syntax tree according to the syntax rules of the test code.
[0137] Optionally, the second determining module 13 is specifically used to: determine the upper-level function corresponding to the changed function based on the reference relationship corresponding to the changed function; identify whether the upper-level function carries an external call identifier; if the upper-level function carries the external call identifier, then determine the upper-level function as the API interface function corresponding to the changed function; if the upper-level function does not carry the external call identifier, then start from the changed function and search upwards layer by layer until the topmost function carrying the external call identifier is found; determine the topmost function carrying the external call identifier as the API interface function corresponding to the changed function.
[0138] Optionally, the third determining module 14 is specifically used for: determining a target functional module that has a dependency relationship with the API interface function based on the service call file; parsing the source code of the target functional module to construct a second abstract syntax tree corresponding to the target functional module; extracting the code structure corresponding to the target functional module based on the second abstract syntax tree, the code structure including detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code; and determining the entry point function corresponding to the target functional module based on the code structure and the external call identifier.
[0139] Figure 8 The apparatus shown can execute the influence link generation method provided in the foregoing embodiments. For details of the execution process and technical effects, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0140] In one possible design, the above Figure 8 The structure of the link generation device shown can be implemented as an electronic device, such as... Figure 9 As shown, the electronic device may include: a processor 21, a memory 22, and a communication interface 23. The memory 22 stores executable code, which, when executed by the processor 21, enables the processor 21 to at least implement the influence link generation method provided in the foregoing embodiments.
[0141] In addition, embodiments of the present invention provide a non-transitory machine-readable storage medium storing executable code, which, when executed by a processor of an electronic device, enables the processor to at least implement the influence link generation method provided in the foregoing embodiments.
[0142] In addition, embodiments of the present invention provide a computer program product. This computer program product includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is able to perform the above-described functions. Figure 1-7 The steps or functions of the method shown.
[0143] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separate. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0144] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of a necessary general-purpose hardware platform, or by a combination of hardware and software. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a computer product. The present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for influencing link generation, characterized in that, include: In response to the test code link generation request, retrieve the development branch commit record corresponding to the test code; Based on the development branch commit history, determine the changed functions in the test code; Starting from the modified function, search upwards layer by layer for the topmost function carrying the external call identifier, and determine the topmost function as the API interface function corresponding to the modified function. The API interface function is called by other functional modules outside the functional module where the modified function is located. Identify the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module. The target functional module is a functional module other than the functional module where the change function is located. Based on the change function, the API interface function, and the entry point function, the impact chain corresponding to the test code is generated.
2. The method according to claim 1, characterized in that, The step of generating the impact chain corresponding to the test code based on the change function, the API interface function, and the entry point function includes: Determine the reference function corresponding to the entry point function; Compare the code similarity between the API interface function and the referenced function to determine whether the API interface function and the referenced function are the same function; If the API interface function and the referenced function are the same function, then starting from the entry point function, search downwards layer by layer according to the function reference relationship to determine the dependent functions that have a dependency relationship with the entry point function in turn; Based on the change function, the API interface function, the entry point function, and the dependency function, the impact chain corresponding to the test code is generated.
3. The method according to claim 2, characterized in that, The step of comparing the code similarity between the API interface function and the referenced function to determine whether the API interface function and the referenced function are the same function includes: Obtain the first function signature corresponding to the API interface function and the second function signature corresponding to the reference function; The first function signature and the second function signature are vectorized respectively to obtain a first vectorized representation of the first function signature and a second vectorized representation of the second function signature; The similarity between the first vectorized representation and the second vectorized representation is compared to determine whether the API interface function and the reference function are the same function.
4. The method according to claim 3, characterized in that, The step of comparing the similarity between the first vectorized representation and the second vectorized representation to determine whether the API interface function and the reference function are the same function includes: Based on the first vectorized representation and the second vectorized representation, determine the Jaccard similarity coefficient between the API interface function and the reference function; If the Jaccard similarity coefficient meets a preset threshold, then the API interface function and the reference function are determined to be the same function.
5. The method according to claim 1, characterized in that, The step of determining the modified functions in the test code based on the development branch commit history includes: Retrieve the main branch commit history corresponding to the test code; Compare the commit history of the development branch with the commit history of the main branch to determine the changes in the test code; Based on the changes, determine the modified functions in the test code.
6. The method according to claim 5, characterized in that, The comparison of the development branch commit history and the main branch commit history to determine the changes in the test code includes: Use the difference comparison command to compare the commit history of the development branch and the commit history of the main branch to determine the change file corresponding to the test code; Determine the changes in the change file and the corresponding line numbers.
7. The method according to claim 6, characterized in that, The step of determining the modified function in the test code based on the changes includes: Obtain the first abstract syntax tree corresponding to the test code; Using the first abstract syntax tree, the modified file is parsed to obtain the line number corresponding to each function in the modified file; Based on the line number corresponding to each function in the change file and the line number corresponding to the changed content, the change function corresponding to the changed content is determined.
8. The method according to claim 7, characterized in that, Obtaining the first abstract syntax tree corresponding to the test code includes: The test code is divided into multiple lexical units; Based on the syntax rules of the test code, the multiple lexical units are organized into a first abstract syntax tree.
9. The method according to claim 1, characterized in that, The step of searching upwards from the modified function, layer by layer, for the topmost function carrying the external call identifier, and identifying the topmost function as the API interface function corresponding to the modified function, includes: Based on the reference relationship corresponding to the modified function, determine the upper-level function corresponding to the modified function; Identify whether the upper-level function carries an external call identifier. If the upper-level function carries the external call identifier, then the upper-level function is identified as the API interface function corresponding to the modified function. If the upper-level function does not carry the external call identifier, then start from the modified function and search upwards layer by layer until the topmost function carrying the external call identifier is found; The top-level function carrying the external call identifier is identified as the API interface function corresponding to the modified function.
10. The method according to claim 1, characterized in that, The process of determining the target functional module that has a dependency relationship with the API interface function and the entry point function corresponding to the target functional module includes: Based on the service call file, identify the target functional modules that have dependencies on the API interface functions; The source code of the target functional module is parsed to construct the second abstract syntax tree corresponding to the target functional module; Based on the second abstract syntax tree, the code structure corresponding to the target functional module is extracted. The code structure includes detailed information of each class, detailed information of each method, and detailed information of each attribute in the source code. Based on the code structure and external call identifier, determine the entry point function corresponding to the target functional module.
11. An electronic device, characterized in that, include: The system includes a memory, a processor, and a communication interface; wherein the memory stores executable code, which, when executed by the processor, causes the processor to perform the influence link generation method as described in any one of claims 1 to 10.
12. A non-transitory machine-readable storage medium, characterized in that, The non-transitory machine-readable storage medium stores executable code that, when executed by a processor of an electronic device, causes the processor to perform the influence link generation method as described in any one of claims 1 to 10.