Interface robustness repairing method and device, equipment and medium

By generating robustness test cases and automated tests, and determining repair strategies based on defect types, we realize automated repair of defect interfaces in the target code, solving the problem of excessive R&D costs caused by manual modification of interface robustness, and improving development efficiency and interface robustness.

CN119938113APending Publication Date: 2025-05-06CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411697990.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

In the prior art, technicians are required to manually modify the interface robustness, resulting in excessive R&D costs.

Method used

By obtaining object code and interface documents, generating robust test cases, automating tests and generating interface defect reports, determining repair policies based on defect types, and automatically repairing defect interfaces in the object code.

Benefits of technology

It realizes automatic repair of defective interfaces in the target code, improves the development efficiency of R&D personnel, and ensures the robustness of the interface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119938113A_ABST
    Figure CN119938113A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software development, and discloses an interface robustness repairing method and device, equipment and a medium, the method comprises the following steps: obtaining a target code and an interface document submitted by a user, the interface document comprising robustness requirements corresponding to each interface in the target code; generating a robustness test case according to the robustness requirement corresponding to each interface; the target code is automatically tested based on the robustness test case, an interface defect report of the target code is generated, and the interface defect report comprises a defect interface and a corresponding defect type; according to the method and device for repairing the target code, after the target code is tested, the specific repairing strategy is determined according to the defect type corresponding to the defect interface so as to repair the target code, the defect repairing strategy of the corresponding defect interface is determined based on the defect type, and the target code is repaired according to the defect repairing strategy. The development efficiency of research and development personnel can be effectively improved, and the workload is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to an interface robustness repair method, device, equipment and medium. Background Art

[0002] With the development of Internet technology, modern Web services are becoming more and more complex. A service may contain hundreds or even thousands of HTTP interfaces, each of which may have multiple parameters and return values. This complexity makes it increasingly difficult to manually test and fix the robustness of interfaces. At the same time, due to the increase in the number of Internet users, the scale of services is also expanding, and modern Internet users have higher and higher expectations for services. They want services to respond quickly, be stable and reliable, and be secure. This means that even a small robustness issue may affect a large number of users and cause serious business losses. Moreover, with the continuous development of network attack methods, the robustness issues of HTTP interfaces may be maliciously exploited, leading to security issues.

[0003] Currently, after the robustness of the interface is tested through some automated test cases, technicians are usually required to make manual modifications. As the requirements for interface robustness become higher and higher, the need to repair interfaces with robustness defects is becoming more and more urgent, which leads to excessively high overall R&D costs. Summary of the invention

[0004] In view of this, the present invention provides an interface robustness repair method, apparatus, computer equipment and storage medium to solve the problem of excessively high R&D costs caused by the need for technicians to manually modify interface robustness issues.

[0005] In a first aspect, the present invention provides a method for repairing interface robustness, the method comprising:

[0006] Obtaining the target code and interface document submitted by the user, wherein the interface document includes: robustness requirements corresponding to each interface in the target code;

[0007] Generate robustness test cases according to the robustness requirements corresponding to each of the interfaces;

[0008] Performing automated testing on the target code based on the robustness test case to generate an interface defect report of the target code, wherein the interface defect report includes: a defective interface and a corresponding defect type;

[0009] A defect repair strategy corresponding to the defective interface is determined based on the defect type, and the target code is repaired according to the defect repair strategy.

[0010] The method provided in this aspect generates corresponding test cases through the robustness requirements corresponding to each interface involved in the target code, so as to test the defective interfaces and specific defect types with robustness defects in the target code, and determine the corresponding repair strategies based on the defect types of each defective interface, thereby realizing automatic repair of the defective interfaces in the target code, which can effectively improve the development efficiency of R&D personnel while ensuring the robustness of the interface.

[0011] In an optional implementation, determining a defect repair strategy corresponding to the defective interface based on the defect type includes:

[0012] For each defective interface, locating a defect code corresponding to the defective interface in the target code;

[0013] Calling a code analysis tool to analyze the defect code and defect type corresponding to the defect interface, and determining the defect cause corresponding to the defect type;

[0014] A defect repair strategy corresponding to the defect cause is matched in a preset repair strategy library.

[0015] This implementation method locates the defect code corresponding to each defective interface and calls the code analysis tool to perform a comprehensive analysis of the defect code and defect type, thereby clarifying the specific defect cause of the defective interface, and matching the corresponding defect repair strategy in the defect policy library to ensure the matching accuracy of the defect repair strategy and the subsequent defect repair effect.

[0016] In an optional implementation, repairing the target code according to the defect repair strategy includes:

[0017] For each defective interface, generating a corresponding repair code based on the defect repair strategy corresponding to the defective interface;

[0018] The defective code of the defective interface in the target code is replaced by the repair code.

[0019] In this implementation, corresponding repair codes are generated through defect repair strategies corresponding to each defective interface, and the defective code in the target code is replaced, so that defect repair of the defective interface can be completed efficiently and accurately.

[0020] In an optional implementation, generating a robustness test case according to the robustness requirements corresponding to each interface includes:

[0021] According to the robustness requirements of each interface, match the standard test cases corresponding to each interface in the test case library;

[0022] The corresponding standard test cases are adjusted according to the interface parameter information corresponding to each interface to generate robustness test cases corresponding to each interface.

[0023] In this implementation, by matching standard test cases in a test case library and adjusting them in combination with actual interface parameter information, test cases can be obtained quickly and efficiently for subsequent automated testing.

[0024] In an optional implementation, the automated testing of the target code based on the robustness test case includes:

[0025] Integrate and deploy the target code into a test environment, wherein the test environment includes: a plurality of defect testing tools;

[0026] In the test environment, a defect testing tool is called based on the robustness test case to perform automated testing on the target code.

[0027] This implementation method can ensure the robustness defect testing effect by integrating and deploying the target code into the test environment, thereby calling the test tools in the environment to perform automated testing on the target code, thereby accurately identifying the defective interfaces in the target code.

[0028] In an optional implementation, the method further includes:

[0029] Deploy the repaired target code to a test environment, perform defect verification testing, and obtain current defect information corresponding to the repaired target code;

[0030] Determining code replacement information in a repair process based on the repair code in the repaired target code;

[0031] A robustness repair report corresponding to the repaired target code is generated according to the current defect information and the code replacement information.

[0032] This implementation method performs a secondary test on the repaired code to determine the current defects in the repaired code, and generates a robustness repair report based on the code replacement information during the repair process, so that the staff can understand the specific repair status of the code and make corresponding decisions.

[0033] In an optional implementation, after obtaining the robustness repair report corresponding to the repaired target code, the method further includes:

[0034] Outputting the robustness repair report to the user;

[0035] Obtaining the audit information of each repair code in the repaired target code input by the user;

[0036] Based on the audit information, it is determined whether the repair code is effective, and the effective repair code is formally merged into the target code to obtain the target code with the repair completed.

[0037] In this implementation mode, the user inputs the review information for each repair code to determine whether the repair is effective, and then merges the effective repair code into the target code to ensure the availability of the repaired target code finally obtained.

[0038] In a second aspect, the present invention provides an interface robustness repair device, the device comprising:

[0039] The target code acquisition module is used to acquire the target code and interface documents submitted by the user, wherein the interface documents include: the robustness requirements corresponding to each interface in the target code;

[0040] A test case generation module, used to generate robustness test cases according to the robustness requirements corresponding to each interface;

[0041] A test report generation module, used to perform automated testing on the target code based on the robustness test case, and generate an interface defect report of the target code, wherein the interface defect report includes: a defective interface and a corresponding defect type;

[0042] A defect interface repair module is used to determine a defect repair strategy corresponding to the defect interface based on the defect type, and repair the target code according to the defect repair strategy.

[0043] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the interface robustness repair method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0044] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the interface robustness repair method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0046] Figure 1 is a flow chart of a method for repairing interface robustness according to an embodiment of the present invention;

[0047] Figure 2 is a flow chart of another method for repairing the robustness of an interface according to an embodiment of the present invention;

[0048] Figure 3 is an example diagram of the architecture of a robust defect repair system according to an embodiment of the present invention;

[0049] Figure 4 is an example diagram of a process for performing robustness defect repair on a target code according to an embodiment of the present invention;

[0050] Figure 5 is a structural block diagram of an interface robustness repair device according to an embodiment of the present invention;

[0051] Figure 6 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0053] With the development of Internet technology, modern Web services are becoming more and more complex. A service may contain hundreds or even thousands of HTTP interfaces, each of which may have multiple parameters and return values. This complexity makes it increasingly difficult to manually test and fix the robustness of interfaces. At the same time, due to the increase in the number of Internet users, the scale of services is also expanding, and modern Internet users have higher and higher expectations for services. They want services to respond quickly, be stable and reliable, and be secure. This means that even a small robustness issue may affect a large number of users and cause serious business losses. Moreover, with the continuous development of network attack methods, the robustness issues of HTTP interfaces may be maliciously exploited, leading to security issues.

[0054] Currently, after the robustness of the interface is tested through some automated test cases, technicians are usually required to make manual modifications. As the requirements for interface robustness become higher and higher, the need to repair interfaces with robustness defects is becoming more and more urgent, which leads to excessively high overall R&D costs.

[0055] To this end, an embodiment of the present invention provides an interface robustness repair method, which generates corresponding test cases through the robustness requirements corresponding to each interface involved in the target code to test the defective interfaces and specific defect types with robustness defects in the target code, and determines the corresponding repair strategy based on the defect type of each defective interface, thereby realizing automatic repair of the defective interfaces in the target code, which can effectively improve the development efficiency of R&D personnel while ensuring the robustness of the interface.

[0056] According to an embodiment of the present invention, an embodiment of an interface robustness repair method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0057] In this embodiment, a method for repairing the robustness of an interface is provided, which can be applied to a test platform for testing code to perform robustness testing on the interface in the code. Figure 1 is a flow chart of a method for repairing interface robustness according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0058] Step S101, obtaining the target code and interface document submitted by the user, the interface document including: robustness requirements corresponding to each interface in the target code.

[0059] After the R&D personnel complete the code development of a service, the target code corresponding to the service will involve multiple interfaces, each of which will involve multiple parameters and return values. In the actual application of the service, it is necessary to ensure that the interface has a certain robustness.

[0060] Robustness can be understood as the degree to which a system can still perform normally under abnormal input or abnormal external environment. When programming, we often set certain specifications, that is, input some data and output these data after processing, but sometimes users input some illegal data, which may cause the program to do some unexpected behavior and cause the program to terminate illegally. Therefore, in order to enable the program to still accurately and unambiguously display comprehensive error information to the user in this case to help debug, the robustness of the program is very important.

[0061] Therefore, in order to test and repair the robustness of the interface later, R&D personnel need to organize the interfaces involved in the code, clarify the robustness requirements of each interface in the target code, that is, the degree of robustness each interface needs to have, organize these robustness requirements into interface documents, and submit them to the test platform together with the target code for subsequent robustness testing.

[0062] Step S102, generating robustness test cases according to the robustness requirements corresponding to each interface.

[0063] Before testing the target code submitted by the user, it is necessary to automatically generate robustness test cases for the target code based on the robustness requirements of each interface involved in the target code in the interface document submitted by the user. For the automatic generation of robustness test cases, for example, the corresponding test cases can be matched in a pre-written test case library, and adaptive adjustments can be made in combination with the actual parameters of each interface in the target code to obtain test cases for testing the robustness of the interfaces in the target code. For the automatic generation of test cases, they can be set in combination with actual test requirements in specific application scenarios. The above method is only an exemplary implementation method and is not limited here.

[0064] Step S103, performing automated testing on the target code based on robustness test cases, and generating an interface defect report of the target code, wherein the interface defect report includes: defective interfaces and corresponding defect types.

[0065] After obtaining the test cases, the target code can be automatically tested through specific robustness test cases. In the process of robustness testing of each interface, the actual response of each interface will be used to determine whether there are defects and the specific defect types. For example, the defect types may include: parameter verification defects, error handling defects, concurrency processing defects, etc. The specific defect types can be set and tested in combination with actual experience. After the target code is tested, the defect types corresponding to each defective interface in the target code will be sorted out to generate an interface defect report corresponding to the target code, which includes each defective interface in the target code and the corresponding defect type.

[0066] In this step S104, a defect repair strategy corresponding to the defective interface is determined based on the defect type, and the target code is repaired according to the defect repair strategy.

[0067] For the test platform that performs target code testing, it has a pre-set repair strategy library inside, which is used to match corresponding defect repair strategies according to various defect types, so as to execute the corresponding defect repair strategy to repair the code corresponding to the defective interface in the target code to make it meet the robustness requirements.

[0068] Exemplarily, for a defective interface in the code, the test platform can use an internal code analysis tool to analyze the code related to the defective interface in the target code, and determine the cause of the defect based on the specific defect type. It then searches the internal policy library for a repair strategy to resolve the defect and executes it to generate qualified code to modify and replace the code related to the defective interface, thereby repairing the defective interface in the target code.

[0069] The interface robustness repair method provided in this embodiment generates corresponding test cases through the robustness requirements corresponding to each interface involved in the target code, so as to test the defective interfaces and specific defect types with robustness defects in the target code, and determine the corresponding repair strategy based on the defect type of each defective interface, thereby realizing automatic repair of the defective interfaces in the target code, which can effectively improve the development efficiency of R&D personnel while ensuring the robustness of the interface.

[0070] According to an embodiment of the present invention, another embodiment of an interface robustness repair method is provided, which can be applied to a test platform for testing code to perform robustness testing on interfaces in the code. Figure 2 is a flow chart of another method for repairing interface robustness according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0071] Step S201, obtaining the target code and interface document submitted by the user, the interface document including: the robustness requirements corresponding to each interface in the target code. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0072] Step S202: Generate robustness test cases according to the robustness requirements corresponding to each interface.

[0073] Specifically, in step S202, it includes:

[0074] Step S202-1, according to the robustness requirements corresponding to each interface, match the standard test cases corresponding to each interface in the test case library.

[0075] Step S202-2, adjusting the standard test cases corresponding to the interface parameter information corresponding to each interface, and generating robustness test cases corresponding to each interface.

[0076] It can be understood that before testing, the test cases required for various robustness requirements are sorted out in advance, and a test case library is built. When generating test cases, they can be matched in the test case library according to the robustness requirements corresponding to each interface in the interface document of the target code. The robustness requirements in the specific interface document can include descriptive information such as the parameters and work content corresponding to each interface, as well as the degree of robustness required to be met in the actual business scenario. Based on this information, the corresponding standard test cases can be matched for each interface in the test case library.

[0077] Then, the matched standard test cases are adaptively adjusted according to the interface parameter information of each interface to obtain the robustness test cases corresponding to each interface. The test cases corresponding to each interface are combined to construct the robustness test cases for the target code as a whole for subsequent robustness testing.

[0078] Step S203, performing automated testing on the target code based on robustness test cases, and generating an interface defect report of the target code, wherein the interface defect report includes: defective interfaces and corresponding defect types.

[0079] Specifically, in step S203, the target code is automatically tested based on the robustness test case, including:

[0080] Step S203-1, integrating and deploying the target code into a test environment, where the test environment includes: a plurality of defect testing tools.

[0081] Step S203-2: In a test environment, a defect testing tool is called based on a robustness test case to perform automated testing on the target code.

[0082] It can be understood that after obtaining the test cases for testing, you can start testing the target code. First, you need to integrate the target code and deploy it to the test environment. In the test environment, you have the relevant test tools needed for testing, such as log analysis tools, general rule monitoring tools and other commonly used test tools.

[0083] During the testing process in the test environment, the target code can be automatically tested according to the specific test requirements in the test case and the test process calling related tools, and the specific test results can be summarized to obtain a robustness test report for the target code, including: defective interfaces with robustness defects in the target code, and specific defect types.

[0084] Step S204: determining a defect repair strategy corresponding to the defective interface based on the defect type.

[0085] Specifically, in step S204, it includes:

[0086] Step S204 - 1 , for each defective interface, locate the defective code corresponding to the defective interface in the target code.

[0087] Step S204 - 2 , calling a code analysis tool to analyze the defect code and defect type corresponding to the defect interface, and determining the defect cause corresponding to the defect type.

[0088] Step S204-3, matching the defect repair strategy corresponding to the defect cause in the preset repair strategy library.

[0089] When repairing a defective interface, you first need to locate the code location corresponding to the defective interface in the target code and determine the defective code related to the defective interface. For example, you can use the built-in code static scanning work to scan the target code as a whole to determine the defective code corresponding to the defective interface.

[0090] Then, the code analysis tool is called to analyze the defective code in combination with the specific defect type of the defective interface to determine the specific cause of the defect. For example, the defect type of a certain interface is a parameter verification defect. After analyzing the relevant defective code of the interface through the code analysis tool, it can be determined that the cause of the defect is the lack of parameter verification.

[0091] For example, the function of an interface is to receive an age parameter and return a message. The code of this interface is as follows:

[0092] @app.route(' / api / greet',methods=['GET'])

[0093] def greet():

[0094] age = request.args.get('age')

[0095] return f"Hello, you are{age}years old."

[0096] In this example, the interface does not verify the age parameter. If the age parameter is not a number or is a negative number, the returned message is meaningless. This means that the specific cause of the defect is the lack of parameter verification.

[0097] After determining the specific cause of the defect in the defective interface, you can look up the repair strategy corresponding to the defect cause in the pre-written response strategy library, and adjust the test platform to the corresponding repair mode to execute the specific repair strategy and perform the corresponding defect repair.

[0098] Step S205: repair the target code according to the defect repair strategy.

[0099] Specifically, step S205 includes:

[0100] Step S205 - 1 : for each defective interface, generate a corresponding repair code based on the defect repair strategy corresponding to the defective interface.

[0101] Step S205-2, replacing the defective code of the defective interface in the target code with the repair code.

[0102] Specifically, after matching the specific repair strategy corresponding to the defective interface, the test platform can execute the corresponding test strategy to generate repair code. The repair code can be understood as qualified code that can avoid defects compared to the defective code of the defective interface. For the repair strategy, it can be understood that the repair process for a certain defect cause determined by a pre-written rule engine or decision tree is used to guide the test platform or test tool to execute corresponding steps. When generating repair code, it can be generated based on a specific repair strategy. Exemplarily, the repair strategy can include a series of operations based on the abstract syntax tree, as follows.

[0103] Exemplarily, the process of generating the repair code mainly includes the following steps:

[0104] First, the original defective code is parsed and converted into an abstract syntax tree (AST). Taking the above-mentioned missing parameter check as an example, in the process of generating the repair code, the original code of the corresponding interface is parsed to obtain an AST representing the function definition, parameter acquisition, return statement, etc.

[0105] For the lack of parameter verification, it is necessary to add a parameter verification step in the original code, that is, to add a judgment statement. Therefore, after obtaining the AST, it is necessary to traverse the AST to find the location where the if statement needs to be added. The specific logic of this part needs to be sorted out in advance by R&D personnel and the corresponding execution program needs to be written. For example, the following code can be used to find the location of parameter acquisition and if judgment, as follows:

[0106]

[0107]

[0108] By executing the above program, you can determine the specific statement location where you need to add a check, and then create a corresponding if statement node in the AST to perform field check. Taking Python as an example, you can use the ast module to create and modify AST. Specifically for the above example, you can use ast.If to create a new if statement node.

[0109] The constructor of ast.If accepts three parameters: test, body, and orelse. test is an expression node representing the condition of the if statement. body is a list of statement nodes representing the body of the if statement. orelse is a list of statement nodes representing the else branch of the if statement.

[0110] When creating the if statement node, other AST nodes are also used, such as ast.BoolOp, ast.Or, ast.UnaryOp, ast.Not, ast.Call, ast.Attribute, ast.Name, ast.Load, ast.Compare, ast.Lt, ast.Num, ast.Return, ast.Dict, ast.Str, etc. These nodes represent different grammatical structures, such as Boolean operations, unary operations, function calls, attribute access, variable names, load operations, comparison operations, less than operations, numbers, return statements, dictionaries, strings, etc.

[0111] Finally, the AST is modified and a new AST traversal is performed. A new if statement node position has been confirmed. A new code node is inserted and inserted into the body list of the function definition node using the list.insert method. This actually modifies the AST. The modified AST is converted into code to obtain the specific final repair code.

[0112] After obtaining the repair code corresponding to the defective interface, the defective code in the target code is replaced with the repair code to complete the repair of a certain defective interface, and so on, the repair of each defective interface in the target code is performed.

[0113] Furthermore, after repairing the target code according to the defect repair strategy, the method further includes:

[0114] Step S206, performing verification test on the repaired target code and generating a robustness repair report.

[0115] Specifically, in step S206, it includes:

[0116] Step S206 - 1 , deploying the repaired target code to a test environment, performing a defect verification test, and obtaining current defect information corresponding to the repaired target code.

[0117] Step S206-2: determining code replacement information in the repair process based on the repair code in the repaired target code.

[0118] Step S206-3: Generate a robustness repair report corresponding to the repaired target code according to the current defect information and code replacement information.

[0119] It can be understood that after completing the defect repair of the target code, the repaired code can be tested again to determine the specific repair situation. The repaired target code needs to be integrated and deployed to the test environment again to perform defect verification testing to determine whether the interface that was previously tested as defective still has defects, and at the same time test whether the modified target code introduces new defects. According to the actual test situation of the modified target code, its current defect information is determined, that is, which interfaces currently have robustness defects.

[0120] At the same time, according to the specific code replacement situation in the above repair process, determine which specific codes have been replaced in the repair process, and organize the codes before and after the replacement to obtain the code replacement information of the repair process, including which specific codes have been replaced and the code changes before and after the replacement.

[0121] A robustness repair report is generated based on the current defect information of the repaired target code and the specific code replacement status, so that the staff can understand the current robustness issues of the code and which specific codes have been replaced, so as to facilitate further processing by the staff model.

[0122] Furthermore, after obtaining the robustness repair report corresponding to the repaired target code, the method further includes:

[0123] Step S207, obtaining the user's review information on the repair code and determining the effective code.

[0124] Specifically, step S207 includes:

[0125] Step S207-1: output the robustness repair report to the user.

[0126] Step S207-2, obtaining the review information for each repair code in the repaired target code input by the user.

[0127] Step S207-3, based on the audit information, determine whether the repair code is effective, and formally merge the effective repair code into the target code to obtain the repaired target code.

[0128] It can be understood that after obtaining the robustness repair report after the secondary test of the repaired target code, the report can be output to the staff to enable them to understand the actual repair status of the current target code, that is, whether there are still defective interfaces and which specific codes have been replaced.

[0129] The staff can determine whether to agree to replace certain defective codes based on the specific circumstances in the robustness repair report. For example, for replacement codes that have been repaired and do not have defects, the staff can determine whether to agree to the corresponding repair method based on global considerations. If they agree, they can enter the effectiveness information to formally incorporate the corresponding repair code into the target code; if they disagree, for example, if they believe that certain replacement codes will cause problems with the overall logic, they can reject the corresponding repair and make manual adjustments. In addition, for interfaces that still have problems after replacing the repair code, the staff can manually repair them. After the specific review information entered by the user, the officially effective code can be determined, and the user's manual modifications can be accepted to achieve robustness repair of the target code.

[0130] The interface robustness repair method provided by the embodiment of the present invention generates corresponding test cases through the robustness requirements corresponding to each interface involved in the target code, so as to test the defective interfaces and specific defect types with robustness defects in the target code, locate the defective codes corresponding to each defective interface, and call the code analysis tool to perform a comprehensive analysis on the defective codes and defect types, so as to clarify the specific defect causes of the defective interfaces, match the corresponding defect repair strategies in the defect strategy library, ensure the matching accuracy of the defect repair strategies and the subsequent defect repair effects, thereby realizing the automatic repair of the defective interfaces in the target code, which can effectively improve the development efficiency of R&D personnel and ensure the robustness of the interfaces.

[0131] In order to facilitate understanding of the above method embodiment, an example diagram of the architecture of a robust defect repair system is provided according to an embodiment of the present invention, as shown in FIG. Figure 3 As shown. Can be applied Figure 3 The robustness defect testing and repairing system shown is used to implement robustness defect repairing of target code.

[0132] First, for Figure 3 The repair system shown can be understood as a test platform, which has pre-set test tools and repair tools, as well as written rule bases and information bases. The system mainly includes: defect identification module, defect location module, repair strategy module, repair execution module, continuous integration module, feedback module. The specific functions of each module are as follows:

[0133] Defect identification module: Identify robustness defects of interfaces through automated testing, log analysis, exception monitoring, and other means.

[0134] Defect location module: Once a specific defect list is available, the causes of the defects need to be automatically located through log analysis, code scanning, and other means, and the errors need to be classified.

[0135] Repair strategy module: Generates repair strategies based on each type of defect using rule engines or decision tree technology.

[0136] Repair execution module: responsible for executing repair strategies and repairing problems.

[0137] Continuous integration module: After fixing the defects, you need to run the test again to verify the repair effect. After the repair results are manually reviewed by the feedback platform, the repair code is automatically merged into the official use branch.

[0138] Feedback module: collects the test results of the repair and the actual code changes, conducts manual review, cleans up unapproved changes, and feeds back to the problem identification module and the repair strategy module so that they can do better next time. Accept the approved changes and merge them into the official use branch.

[0139] When testing and robustness repairing the target code of the R&D personnel based on the above-mentioned robustness defect testing and repairing system, the specific repair process is as follows Figure 4 As shown, Figure 4 An example flow chart of robust defect repair for target code is provided according to an embodiment of the present invention.

[0140] First, R&D personnel provide detailed interface documents according to requirements; the defect identification module generates robustness test cases according to robustness requirements; at the same time, the target code submitted by R&D personnel is obtained, triggering continuous integration deployment to the automated repair environment for automated testing.

[0141] After completing the automated testing in the automated repair environment, the robustness defects of the HTTP interface in the code are identified through log analysis, general rule monitoring, etc., and a robustness defect report is generated.

[0142] According to the robustness defect list generated in the previous step, log analysis, code scanning and other means are performed one by one to locate the cause of the defect and implement defect location classification. According to the classified defects, corresponding repair strategies are generated one by one and the repair defect strategies are executed.

[0143] After completing the automated defect repair, the repaired target code is continuously integrated and deployed to the repair verification environment, and full-process automated testing is performed to verify the defect repair status to ensure that the expected defects are repaired and no new defects are introduced. The test results are generated and synchronized to the feedback platform.

[0144] Obtain the manual review of the repair results and repair code by the developer on the feedback platform. The staff can click to merge the repair code that has passed the test to make it officially effective and complete the automated repair process. Reject the repair code that has failed the test and discard it. At the same time, adjust the defect identification, defect location, defect repair strategy and other links in the above steps to avoid similar ineffective repair solutions in the future.

[0145] In addition, you can also accept approved patches issued by staff to upgrade the repair system and improve the repair effect.

[0146] For the repair strategy module in the above-mentioned robustness defect testing and repair system, relevant repair strategies for the following defect types can be pre-set.

[0147] (1) Parameter verification: Ensure that the interface can correctly handle various types of parameters, including invalid parameters, missing parameters, parameters of the wrong type, etc. Use the parameter verification library to perform parameter verification and return useful error information when the parameters are wrong.

[0148] (2) Error handling: Ensure that the interface can correctly handle various errors, including internal errors, external errors, user errors, etc. Use error handling middleware to capture errors and return useful error information when errors occur.

[0149] (3) Concurrency processing: Ensure that the interface can correctly handle concurrent requests, including high concurrency, concurrency conflicts, etc. Use concurrency control mechanisms such as locks and semaphores to prevent concurrency conflicts.

[0150] (4) Performance optimization: Ensure that the interface can maintain stable performance under high load, including response time, throughput, etc. Use performance analysis tools to identify performance bottlenecks and optimize them.

[0151] (5) Timeout handling: Ensure that the interface can correctly handle timeouts, including request timeouts, response timeouts, etc. Set a reasonable timeout period and return useful error information when a timeout occurs.

[0152] (6) Service degradation and circuit breaking: Ensure that the interface can perform service degradation and circuit breaking when service problems occur to ensure system stability. Use the service degradation and circuit breaking framework to automatically perform service degradation and circuit breaking when service problems occur.

[0153] (7) Data error: According to the interface documentation, clarify the valid range of the parameter, and set it to the boundary value of the range when the parameter is out of range. Clarify the type of the parameter, and try to convert it to the correct type when the parameter type is incorrect.

[0154] When the above-mentioned robustness defect testing and repairing system performs defect repair, the repair is mainly achieved by generating repair code and replacing it. The whole process can be divided into three steps, namely, defect location classification, defect repair strategy generation and defect repair strategy execution.

[0155] When locating and classifying defects, we first identify common defects based on the interface robustness automated testing. The generated test report will provide the specific interface with defects and the specific defect type. For example, the automated test will identify that the interface ' / api / greet' has a parameter verification defect.

[0156] Then use the code static scanning tool to locate the source code function location of the ' / api / greet' interface.

[0157] Finally, code analysis is performed to match the identified problems to predefined error patterns. In this example, the tool may match the problem to the error pattern of "missing parameter validation".

[0158] When the defect repair strategy is generated, after confirming the error pattern of "missing parameter verification", the "parameter automatic verification" repair pattern will be matched and the repair code will be automatically generated.

[0159] The following are the specific steps to fix the defect based on the example of missing parameter verification:

[0160] 1. Code parsing: Parse the original code and convert it into an abstract syntax tree (AST). In this example, the tool will parse the original code and get an AST that represents function definitions, parameter acquisition, return statements, etc.

[0161] 2. AST traversal: traverse the AST to find the location where the if statement needs to be added. This involves some complex logic, such as finding the function definition node, and then finding the parameter acquisition code in the function body. Specifically, the code for finding the parameter acquisition location can refer to the code involved in the above-mentioned related embodiments, which will not be repeated here.

[0162] 3. New if statement generation: Creation of abstract syntax tree (AST). In Python, you can use the ast module to create and modify AST. In this example, we use ast.If to create a new if statement node.

[0163] The constructor of a.ast.If accepts three parameters: test, body, and orelse. test is an expression node representing the condition of the if statement. body is a list of statement nodes representing the body of the if statement. orelse is a list of statement nodes representing the else branch of the if statement.

[0164] b. When creating the if statement node, other AST nodes are also used, such as ast.BoolOp, ast.Or, ast.UnaryOp, ast.Not, ast.Call, ast.Attribute, ast.Name, ast.Load, ast.Compare, ast.Lt, ast.Num, ast.Return, ast.Dict, ast.Str, etc. These nodes represent different grammatical structures, such as Boolean operations, unary operations, function calls, attribute access, variable names, load operations, comparison operations, less than operations, numbers, return statements, dictionaries, strings, etc.

[0165] 4. AST modification: The AST traversal in step 2 has confirmed the insertion of a new if statement node position. Insert a new code node and use the list.insert method to insert it into the body list of the function definition node. This actually modifies the AST.

[0166] 5. Convert the modified AST back to code: Use the astor.to_source function to convert the modified AST back to source code (modified code). astor is a third-party library that provides a method to convert AST back to source code. Example: new_code = astor.to_source(tree).

[0167] Finally, the execution of the defect repair strategy mainly includes generating repair code that has been automatically generated according to the defect, replacing the original function with the repaired code, and executing the repair strategy. After the code replacement is completed, the code static scanning tool can be called to confirm that the new code does not introduce new defects, and the execution of the defect repair strategy is completed, and the problem is fixed.

[0168] The above method embodiment can realize automatic repair of interface defects. Traditional repair methods usually require development engineers to locate problems and manually repair and verify, but the present invention can automatically identify and repair problems, which not only improves the repair efficiency, but also reduces the error rate.

[0169] At the same time, it has good scalability: it can be applied to any HTTP interface, not just specific interfaces or services. This makes it very scalable and can cope with a variety of different scenarios and needs. And it uses a comprehensive knowledge base and rule base, as well as a more intelligent decision-making mechanism, which can cover all HTTP interfaces, not just the parts that can be covered by manual testing.

[0170] During the test process, repairs can be made in real time without waiting for manual intervention. This allows problems to be fixed as soon as possible, shortening the research and testing cycle. In addition, a powerful monitoring and feedback mechanism and a more flexible repair strategy are adopted. This can be done continuously rather than once. This allows the robustness of the interface to be maintained even after code changes or environmental changes.

[0171] Extract general rules for HTTP interfaces and generate robustness defect repair strategies applicable to all HTTP interfaces. It is precisely because of these general strategies that this patent can be comprehensive and scalable, applicable to all interfaces, rather than specific interfaces or services. In the repair process, rule engines or decision trees are used preferentially for defect location (such as Python's AST), and more complex defects are not limited to the use of machine learning for policy execution. This makes the method provided by the present invention intelligent. In addition, a good feedback mechanism is established to generate defect repair reports and manually review the repair code to avoid deeper problems introduced by automated repairs. For rejected repair plans, defect identification and defect location are optimized in a timely manner, and a defect strategy module is generated. This makes the method provided by the embodiment of the present invention sustainable and universal.

[0172] In this embodiment, an interface robustness repair device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0173] This embodiment provides an interface robustness repair device, such as Figure 5 As shown, including:

[0174] The target code acquisition module 401 is used to acquire the target code and interface document submitted by the user. The interface document includes: the robustness requirements corresponding to each interface in the target code.

[0175] The test case generation module 402 is used to generate robustness test cases according to the robustness requirements corresponding to each interface.

[0176] The test report generation module 403 is used to perform automated testing on the target code based on robustness test cases and generate an interface defect report of the target code. The interface defect report includes: defective interfaces and corresponding defect types.

[0177] The defective interface repair module 404 is used to determine a defect repair strategy corresponding to the defective interface based on the defect type, and repair the target code according to the defect repair strategy.

[0178] In some optional implementations, the defective interface repairing module 404, when determining a defect repairing strategy corresponding to the defective interface based on the defect type, includes:

[0179] For each defective interface, locate the defective code corresponding to the defective interface in the target code;

[0180] Call the code analysis tool to analyze the defect code and defect type corresponding to the defect interface, and determine the defect cause corresponding to the defect type;

[0181] Match the defect repair strategy corresponding to the defect cause in the preset repair strategy library.

[0182] In some optional implementations, the defect interface repair module 404, when repairing the target code according to the defect repair strategy, includes:

[0183] For each defective interface, generate corresponding repair code based on the defect repair strategy corresponding to the defective interface;

[0184] Replace the defective code of the defective interface in the target code with the repair code.

[0185] In some optional implementations, the test case generation module 402, when generating robustness test cases according to the robustness requirements corresponding to each interface, includes:

[0186] According to the robustness requirements of each interface, match the standard test cases corresponding to each interface in the test case library;

[0187] Adjust the standard test cases corresponding to the interface parameter information of each interface to generate the robustness test cases corresponding to each interface.

[0188] In some optional implementations, the test report generation module 403, when performing automated testing on the target code based on the robustness test case, includes:

[0189] Integrate and deploy the target code into the test environment, which includes: multiple defect testing tools;

[0190] In the test environment, the defect testing tool is called based on the robustness test cases to perform automated testing on the target code.

[0191] In some optional implementations, the apparatus further includes: a repair report generation module, configured to deploy the repaired target code to a test environment, perform defect verification testing, and obtain current defect information corresponding to the repaired target code;

[0192] Determine code replacement information in a repair process based on the repair code in the repaired target code;

[0193] Generate a robustness repair report corresponding to the repaired target code based on the current defect information and code replacement information.

[0194] In some optional implementations, the repair report generation module is further used to output the robustness repair report to the user;

[0195] Obtaining the audit information of each repair code in the repaired target code input by the user;

[0196] Based on the audit information, determine whether the repair code is effective, and formally merge the effective repair code into the target code to obtain the target code with the repair completed.

[0197] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0198] The interface robustness repair device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0199] The embodiment of the present invention also provides a computer device having the above Figure 5 Interface robustness fix shown.

[0200] See also Figure 6 , Figure 6 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 6 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 6 A processor 10 is taken as an example.

[0201] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0202] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0203] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0204] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0205] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.

[0206] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0207] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0208] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for repairing interface robustness, characterized in that: The method comprises: Obtaining the target code and interface document submitted by the user, wherein the interface document includes: robustness requirements corresponding to each interface in the target code; Generate robustness test cases according to the robustness requirements corresponding to each of the interfaces; Performing automated testing on the target code based on the robustness test case to generate an interface defect report of the target code, wherein the interface defect report includes: a defective interface and a corresponding defect type; A defect repair strategy corresponding to the defective interface is determined based on the defect type, and the target code is repaired according to the defect repair strategy.

2. The method according to claim 1, characterized in that The determining of a defect repair strategy corresponding to the defective interface based on the defect type includes: For each defective interface, locating a defect code corresponding to the defective interface in the target code; Calling a code analysis tool to analyze the defect code and defect type corresponding to the defect interface, and determining the defect cause corresponding to the defect type; A defect repair strategy corresponding to the defect cause is matched in a preset repair strategy library.

3. The method according to claim 2, characterized in that The repairing the target code according to the defect repair strategy includes: For each defective interface, generating a corresponding repair code based on the defect repair strategy corresponding to the defective interface; The defective code of the defective interface in the target code is replaced by the repair code.

4. The method according to claim 1, characterized in that: Generating robustness test cases according to the robustness requirements corresponding to the various interfaces includes: According to the robustness requirements of each interface, match the standard test cases corresponding to each interface in the test case library; The corresponding standard test cases are adjusted according to the interface parameter information corresponding to each interface to generate robustness test cases corresponding to each interface.

5. The method according to claim 1, characterized in that The automated testing of the target code based on the robustness test case includes: Integrate and deploy the target code into a test environment, wherein the test environment includes: a plurality of defect testing tools; In the test environment, a defect testing tool is called based on the robustness test case to perform automated testing on the target code.

6. The method according to claim 3, characterized in that The method further comprises: Deploy the repaired target code to a test environment, perform defect verification testing, and obtain current defect information corresponding to the repaired target code; Determining code replacement information in a repair process based on the repair code in the repaired target code; A robustness repair report corresponding to the repaired target code is generated according to the current defect information and the code replacement information.

7. The method according to claim 6, characterized in that After obtaining the robustness repair report corresponding to the repaired target code, the method further includes: Outputting the robustness repair report to the user; Obtaining the audit information of each repair code in the repaired target code input by the user; Based on the audit information, it is determined whether the repair code is effective, and the effective repair code is formally merged into the target code to obtain the target code with the repair completed.

8. An interface robustness repair device, characterized in that: The device comprises: The target code acquisition module is used to acquire the target code and interface documents submitted by the user, wherein the interface documents include: the robustness requirements corresponding to each interface in the target code; A test case generation module, used to generate robustness test cases according to the robustness requirements corresponding to each interface; A test report generation module, used to perform automated testing on the target code based on the robustness test case, and generate an interface defect report of the target code, wherein the interface defect report includes: a defective interface and a corresponding defect type; A defect interface repair module is used to determine a defect repair strategy corresponding to the defect interface based on the defect type, and repair the target code according to the defect repair strategy.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the interface robustness repair method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the interface robustness repair method according to any one of claims 1 to 7.