Code check method and related device
By introducing AI analysis capabilities of language models into the code inspector, the problem that code inspectors developed using DSL cannot cover subjective and flexible issues is solved, achieving more efficient and accurate code inspection.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2026-04-02
AI Technical Summary
Code inspectors developed based on domain-specific languages (DSLs) struggle to cover issues that are subjectively described, vague, or involve flexible and varied scenarios, resulting in insufficient inspection efficiency and accuracy.
By introducing artificial intelligence analysis capabilities such as language models and combining them with DSL code inspection rules, the code inspection process is optimized by constructing language model prompts to infer whether the code has the characteristics of natural language description and combining the results of logical combination.
It improves the efficiency and accuracy of code inspection, effectively covers subjective and flexible scenarios, and meets the high-efficiency response requirements of complex query scenarios.
Smart Images

Figure CN2025089838_02042026_PF_FP_ABST
Abstract
Description
Code inspection method and related device
[0001] The present application claims priority from the Chinese patent application No. 202411357011.5 filed on September 26, 2024, and entitled "A code inspection method and related device", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0002] The present application relates to the technical field of code development and testing, and in particular to a code inspection method, a testing platform, a computing device cluster, a computer readable storage medium, and a computer program product. BACKGROUND
[0003] In recent years, with the rise of technologies such as mobile Internet, cloud computing, artificial intelligence (AI), and the like, the scale and complexity of software continue to expand, and the pressure on software security assurance is also increasing. Among numerous security assurance technologies, static analysis technology can analyze the characteristics of code itself without running the software, thereby discovering possible problems in the software at a lower running cost.
[0004] A typical application of static analysis technology is a code inspector. The code inspector aims to automatically check possible problems in the inspected code and feed back to the developer so as to fix the problems before actually running the code. Compared with software, the development of the code inspector is more difficult. The developer not only needs to be an experienced code developer, but also needs to be familiar with the underlying framework of the code inspector, the specific structure of the inspected code, and the programming language characteristics, and the like. To improve the development efficiency and reduce the development threshold, some new code inspectors design corresponding domain-specific languages (DSL) to assist in the development of the code inspector, so that the developer does not need to be proficient in complex underlying frameworks to develop the code inspector.
[0005] However, the code inspector developed based on the DSL is subject to the capability boundary of the code inspector and can only perform code inspection based on a certain predefined rule, such as code inspection based on a certain specific syntax structure or code inspection based on a certain specific data flow relationship, and it is difficult to check scenes with subjective or flexible standards. SUMMARY
[0006] The application provides a code inspection method, which introduces an AI analysis capability such as a language model on the basis of a code inspector to solve the problem that a code inspector developed based on a DSL cannot cover subjective, ambiguous, or flexible and variable scenarios. The application also provides a test platform, a computing device cluster, a computer readable storage medium, and a computer program product corresponding to the above method.
[0007] In a first aspect, the application provides a code inspection method. The method can be applied to a test platform. The test platform is a platform for testing code. The test platform can be a software system, which can be an independent software system, for example, an independent component, which can be deployed in a cloud environment or a local integrated development environment as a value-added service of a code inspector. Alternatively, the test platform can also be integrated with other software, for example, the test platform can be an extended component of the code inspector, which is provided to the customer together with the code inspector and the engine. In some possible implementation manners, the test platform can also be an independent hardware system, which can be a computing device cluster with code inspection capability. The hardware system runs and executes the code inspection method of the application.
[0008] Specifically, the test platform can obtain the code to be inspected and receive a DSL code inspection rule written by a user based on a domain-specific language (DSL). The DSL code inspection rule is used to perform code inspection on the code to be inspected. When the DSL code inspection rule includes a first type of DSL code inspection rule, the test platform can construct a prompt for a language model according to the first type of DSL code inspection rule. The first type of code inspection rule indicates whether the code to be inspected has a feature described using natural language. Then the test platform can call the language model to infer whether the code to be inspected has the feature described using natural language according to the prompt, and obtain a calling result. Next, the test platform can present a checking result generated according to the calling result of the language model to the user. The checking result is used to indicate whether the code to be inspected has the feature described using natural language.
[0009] The method supports a user to use natural language to describe a feature to be checked when writing a DSL code checking rule, for example, a subjective feature, so that when receiving a DSL code checking rule written by the user based on the DSL and indicating whether the inspected code has the feature described by the natural language, a prompt of the language model can be constructed according to the DSL code checking rule of the type, and then the language model is called according to the prompt to infer whether the inspected code has the feature described by the natural language, and a final checking result can be obtained based on a calling result of the language model. The method introduces an AI analysis capability such as a language model to solve the problem that a code checker developed based on a DSL cannot cover subjective, ambiguous or flexible and changeable scene description based on the original code checker developed based on the DSL, and meanwhile, the checking capability of the code checker is used to guarantee the efficiency and accuracy of the checking.
[0010] In some possible implementation manners, the feature described by the natural language includes a first feature described by the natural language and a second feature described by the natural language, and the DSL code checking rule of the first type indicates whether the inspected code has the first feature described by the natural language and / or whether the inspected code has the second feature described by the natural language. Accordingly, the test platform can construct a first prompt of the language model according to the DSL code checking rule of the first type, and construct a second prompt of the language model according to the DSL code checking rule of the first type. The test platform can also combine the first calling result and the second calling result to obtain the checking result.
[0011] The method can reduce the difficulty of the query by decomposing a complex query scene including a plurality of features described by the natural language, for example, into a plurality of simple queries, and then combining the query results, so that the complex query scene can also be responded to efficiently and the business requirement is met.
[0012] In some possible implementation manners, the test platform can combine the first calling result and the second calling result by using at least one of logical AND, logical OR and logical NOT to obtain the checking result. For example, the test platform can determine the connection logic of the first calling result and the second calling result according to the connection logic of the DSL code checking rule of the first type, and then combine the first calling result and the second calling result according to the connection logic to schedule the final checking result. The method can determine the connection logic of the calling results by combining the connection logic of the DSL code checking rule of the first type, and combine the calling results based on the connection logic, so that the accuracy of the final checking result can be guaranteed.
[0013] In some possible implementation manners, the characteristic described using the natural language includes a first characteristic described using the natural language and a second characteristic described using the natural language. The first type of DSL code checking rule indicates checking whether the inspected code has the first characteristic described using the natural language and / or has the second characteristic described using the natural language. Accordingly, the test platform can construct a first prompt of the language model according to the first type of DSL code checking rule, and construct a second prompt of the language model according to the first type of DSL code checking rule. The test platform can also combine the first prompt and the second prompt to obtain a combined prompt.
[0014] The method reduces the number of invocations of the language model and improves the code checking efficiency by combining the prompts of the language model before AI filtering using the language model, and invoking the language model using the combined prompts.
[0015] In some possible implementation manners, when the DSL code checking rule includes a second type of DSL code checking rule, the test platform can also obtain a query statement according to the second type of DSL code checking rule, and then query a code database corresponding to the inspected code according to the query statement to obtain a candidate code snippet. Accordingly, the test platform can invoke the language model to reason whether the candidate code snippet has the characteristic described using the natural language according to the prompt, and obtain an invocation result.
[0016] The method reduces the number of invocations of the language model and improves the code checking efficiency by combining the prompts of the language model before AI filtering using the language model, and invoking the language model using the combined prompts.
[0017] In some possible implementation manners, the test platform can receive a storage path of the inspected code configured by a user, and obtain the inspected code according to the storage path. In this way, code checking can be performed on a specified inspected code according to a user demand.
[0018] In some possible implementation manners, the test platform can also present a target code snippet in the inspected code to the user in response to a jump operation of the user on the checking result. The target code snippet can be a code snippet associated with the checking result. The method supports the user to check whether the target code snippet has the characteristic described using the natural language, thereby improving the accuracy of the code checking.
[0019] In a second aspect, a test platform is provided. The test platform includes:
[0020] an interaction module, configured to obtain an inspected code;
[0021] The interaction module is further configured to receive a DSL code inspection rule written by a user based on a domain-specific language (DSL), the DSL code inspection rule being used for code inspection on the inspected code;
[0022] The conversion module is configured to, when the DSL code inspection rule comprises a first type of DSL code inspection rule, construct a prompt for a language model according to the first type of DSL code inspection rule, the first type of code inspection rule indicating inspection on whether the inspected code has a feature described using a natural language;
[0023] The language model calling module is configured to call the language model to infer whether the inspected code has the feature described using the natural language according to the prompt, and obtain a calling result;
[0024] The interaction module is further configured to present an inspection result of the inspected code to the user, the inspection result being generated according to the calling result of the language model, and the inspection result being used to indicate whether the inspected code has the feature described using the natural language.
[0025] In some possible implementation manners, the feature described using the natural language comprises a first feature described using the natural language and a second feature described using the natural language, and the first type of DSL code inspection rule indicates inspection on whether the inspected code has the first feature described using the natural language and / or whether the inspected code has the second feature described using the natural language;
[0026] The conversion module is specifically configured to:
[0027] construct a first prompt for the language model according to the first type of DSL code inspection rule, and construct a second prompt for the language model according to the first type of DSL code inspection rule;
[0028] The language model calling module is specifically configured to:
[0029] call the language model to infer whether the inspected code has the first feature described using the natural language according to the first prompt, and obtain a first calling result;
[0030] call the language model to infer whether the inspected code has the second feature described using the natural language according to the second prompt, and obtain a second calling result;
[0031] The test platform further comprises:
[0032] The combination module is configured to combine the first calling result and the second calling result to obtain the inspection result.
[0033] In some possible implementation manners, the combination module is specifically used for:
[0034] The first calling result and the second calling result are combined by at least one of logical AND, logical OR, and logical NOT to obtain the checking result.
[0035] In some possible implementation manners, the natural language description-based feature includes a first natural language description-based feature and a second natural language description-based feature, and the first type of DSL code checking rule indicates checking whether the subject code has the first natural language description-based feature and / or has the second natural language description-based feature;
[0036] The conversion module is specifically used for:
[0037] The first prompt of the language model is constructed according to the first type of DSL code checking rule, and the second prompt of the language model is constructed according to the first type of DSL code checking rule;
[0038] The test platform further includes:
[0039] The combination module is configured to combine the first prompt and the second prompt to obtain a combined prompt.
[0040] In some possible implementation manners, the test platform further includes:
[0041] The parsing module is configured to, when the DSL code checking rule includes a second type of DSL code checking rule, obtain a query statement according to the second type of DSL code checking rule.
[0042] The code database query module is configured to query a code database corresponding to the subject code according to the query statement to obtain a candidate code snippet.
[0043] The language model calling module is specifically used for:
[0044] The language model is called to infer, according to the prompt, whether the candidate code snippet has the natural language description-based feature, to obtain a calling result.
[0045] In some possible implementation manners, the interaction module is specifically used for:
[0046] The storage path of the subject code configured by a user is received.
[0047] The subject code is obtained according to the storage path.
[0048] In some possible implementation manners, the interaction module is further used for:
[0049] In response to the jump operation of the user on the inspection result, a target code segment in the code under test is presented to the user.
[0050] In a third aspect, the present application provides a computing device cluster. The computing device cluster comprises at least one computing device, and the at least one computing device comprises at least one processor and at least one memory. The at least one processor and the at least one memory are in communication with each other. The at least one processor is configured to execute instructions stored in the at least one memory, so that the computing device or the computing device cluster performs the code inspection method according to the first aspect or any implementation manner of the first aspect.
[0051] In a fourth aspect, the present application provides a computer readable storage medium, and the computer readable storage medium stores instructions. The instructions instruct the computing device or the computing device cluster to perform the code inspection method according to the first aspect or any implementation manner of the first aspect.
[0052] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computing device or a computing device cluster, cause the computing device or the computing device cluster to perform the code inspection method according to the first aspect or any implementation manner of the first aspect.
[0053] On the basis of the implementation manners of the above aspects, the present application can be further combined to provide more implementation manners. BRIEF DESCRIPTION OF DRAWINGS
[0054] In order to more clearly illustrate the technical method of the present application, the required drawings will be briefly introduced as follows.
[0055] FIG. 1 is a schematic diagram of an inspection process of a DSL-based code inspector according to the present application;
[0056] FIG. 2 is a schematic diagram of an architecture of a test platform according to the present application;
[0057] FIG. 3 is a flowchart of a code inspection method according to the present application;
[0058] FIG. 4 is an interface diagram of an interactive interface according to the present application;
[0059] FIG. 5 is a schematic diagram of an application scenario of a code inspection method according to the present application;
[0060] FIG. 6 is a schematic diagram of an application scenario of another code inspection method according to the present application;
[0061] FIG. 7 is a structural diagram of a computing device according to the present application;
[0062] FIG. 8 is a structural diagram of a computing device cluster according to the present application;
[0063] FIG. 9 is a structural diagram of another computing device cluster provided by the present application;
[0064] FIG. 10 is a structural diagram of still another computing device cluster provided by the present application. DETAILED DESCRIPTION
[0065] The terms "first", "second", etc. in the embodiments of the present application are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with "first", "second", etc. can explicitly or implicitly include one or more of the features.
[0066] First, some technical terms involved in the embodiments of the present application are introduced.
[0067] A code inspector, or simply an inspector, is a functional module of a static analysis tool for detecting potential problems in code based on certain rules. The code inspector can feed back the detected potential problems to the developer, so as to fix the problems before actually running the code. The code inspector has high customizability, and the developer of the code inspector can develop various code inspectors according to the needs, for checking certain specific problems.
[0068] A domain specific language (DSL) is a computer language specially designed for a specific application field. For example, the DSL can be HyperText Markup Language (HTML) for displaying web pages, or Maven for compiling configurations. The DSL can also be used to assist in developing a code inspector, so that the developer can develop the code inspector without mastering complex underlying frameworks.
[0069] The inspection process of the DSL-based code inspector is shown in FIG. 1. The user prepares the code to be inspected (e.g., the code to be checked), and the code to be inspected can be stored in the form of a code database after being parsed. On the other hand, the user writes a custom DSL code inspection rule, which is a code inspection rule defined according to the DSL syntax. The DSL code inspection rule can be converted into a DSL inspector (generally a database query statement), and finally a database query is performed on the code database based on the DSL inspector to obtain the final code inspection result.
[0070] However, the code checker developed based on the DSL is subject to the capability boundary of the code checker, and can only perform code checking based on some predefined rules, such as code checking based on some specific syntax structure or code checking based on some specific data flow relationship. For scenes in which the checking standard is subjective or flexible, it is difficult for the customized code checker developed based on the DSL to cover. For example, the customized code checker can check "functions with function names of no more than 10 characters", "functions with function names not in camelCase", but it is difficult to check "functions with bad function names" because the checking standard is subjective and the checking standard varies with specific circumstances.
[0071] Therefore, the present application provides a code checking method. The method can be executed by a test platform. The test platform is a platform for testing code. The test platform can be a software system, which can be an independent software system, for example, an independent component, which can be deployed in a cloud environment or a local integrated development environment (IDE) as a value-added service of a code checker. Alternatively, the test platform can also be integrated with other software, for example, the test platform can be an extended component of the code checker, which is provided to the customer together with the code checker and the engine. In some possible implementation manners, the test platform can also be an independent hardware system, which can be a cluster of computing devices with code checking capability. The hardware system runs and executes the code checking method of the present application.
[0072] Specifically, the test platform obtains the code under test, receives a DSL code checking rule written by a user based on a DSL, and the DSL code checking rule is used to perform code checking on the code under test. When the DSL code checking rule includes a first type of DSL code checking rule, the test platform constructs a prompt of a language model (LM) according to the first type of DSL code checking rule. The first type of code snippet indicates whether the code under test has a feature described using natural language. The test platform can call the language model according to the prompt to infer whether the code under test has the feature described using natural language, and obtain a calling result. Then the test platform can present the user with a checking result of the code under test. The checking result is generated according to the calling result of the language model, and the checking result is used to indicate whether the code under test has the feature described using natural language.
[0073] The method introduces an artificial intelligence (AI) analysis capability such as a language model on the basis of the original code checker developed based on the DSL to solve problems that cannot be covered by the code checker developed based on the DSL, such as subjective, ambiguous, or flexible and changeable scenes. Moreover, the method also supports using the checking capability of the code checker to ensure the efficiency and accuracy of the checking.
[0074] In order to make the technical solutions of the present application clearer and easier to understand, the system architecture of the present application is introduced below in combination with the drawings.
[0075] Referring to a schematic diagram of an architecture of a test platform 20 shown in FIG. 2, the test platform 20 includes a code checking layer 206, an analysis layer 204, and a user layer 202 from bottom to top. The code checking layer 206 provides the most bottom code database query and language model calling capability. The analysis layer 204 processes the input that should be handed over to the lower layer (such as the code checking layer 206) and parses the output provided by the lower layer. Specifically, the analysis layer 204 provides DSL code checking rule parsing and AI analysis capability, provides the code database query statement or language model calling parameter required by the code checking layer 206, and the analysis layer 204 can also combine the AI analysis capability or AI analysis result to parse the output of the language model. The user layer provides a direct user interface (UI), and the interactive interface is used to support the user to write the DSL code checking rule and provide the analysis layer 204 for parsing, and display the checking result provided by the analysis layer 204.
[0076] The test platform 20 is introduced below from the perspective of functional modularization.
[0077] The test platform 20 includes an interactive module 2022, a conversion module 2042, and a language model calling module 2062. Further, the test platform 20 can also include a combination module 2044, a parsing module 2046, and a code database query module 2064. The interactive module 2022 can be a module in the user layer 202, the conversion module 2042, the combination module 2044, and the parsing module 2046 can be modules in the analysis layer 204, and the language model calling module 2062 and the code database query module 2064 can be modules in the code checking layer 206. Each module is described in detail below.
[0078] The interaction module 2022 is configured to obtain the subject code and receive a DSL code inspection rule written by a user based on the DSL. The DSL code inspection rule is used for code inspection on the subject code. The interaction module 2022 is provided with an interaction interface, and receives the DSL code inspection rule written by the user through the interaction interface. The DSL code inspection rule can include a first type of DSL code inspection rule, and the first type of DSL code inspection rule is used to indicate whether the subject code has a feature described using natural language. For example, the first type of DSL code inspection rule can be AI(f, "is an external call function"), which is used to check whether the subject code includes an external call function. For the convenience of description, the above-mentioned first type of DSL code inspection rule can also be referred to as an AI predicate in some cases. The AI predicate indicates that a language model (such as an AI large model) checks whether the subject code has a feature described using natural language. The DSL code inspection rule (or AI predicate) written by the user also supports logical connections, such as connections through "and", "or", "not" and the like. For example, the AI predicate A "function name is good" and the AI predicate B "function can be a command line call entry" written by the user can be connected through the "and" logic, thereby being used to check the function name is good and the function can be a command line call entry.
[0079] Further, the DSL code inspection rule can also include a second type of DSL code inspection rule. The second type of DSL code inspection rule is used for code inspection by matching a code database. In some examples, the second type of DSL code inspection rule can not include a feature described using natural language. The second type of DSL code inspection rule can perform code inspection based on a specific syntax structure or a specific data flow relationship. For example, the second type of code snippet can be f.name contain "control". The second type of DSL code inspection rule is used to check all functions whose names contain "control".
[0080] The conversion module 2042 is configured to construct a prompt of a language model according to the DSL code inspection rule of the first type when the DSL code inspection rule comprises the DSL code inspection rule of the first type. The language model can be a large language model (LLM), including but not limited to a generative pre-trained transformer (GPT) model. The LLM can also be referred to as a large language model or a large model. In some examples, the LLM can also be a small language model (or simply referred to as a small model). The conversion module 2042 can convert the DSL code inspection rule (or AI predicate) of the first type to obtain a calling parameter of the language model, which comprises an input parameter of the language model. The input parameter of the language model can comprise a prompt (or prompt text) of the language model.
[0081] The language model calling module 2062 is configured to call the language model to infer whether the inspected code has the feature described in the natural language according to the prompt, and obtain a calling result. Specifically, the language model calling module 2062 can input the prompt as an input parameter of the language model, or call the language model to infer whether the inspected code has the feature described in the natural language according to the language model, and obtain a calling result. The calling result can be an inference result of the language model.
[0082] The interaction module 2022 is further configured to present the inspection result of the inspected code to the user. The inspection result is generated according to the calling result of the language model. For example, the inspection result can be generated according to different calling results of the language model. The above inspection result is used to indicate whether the inspected code has the feature described in the natural language. For another example, the inspection result can be generated according to the calling result of the language model and a database query result of the code inspector developed based on the DSL. Based on this, the inspection result is also used to indicate whether the inspected code has an inspection item inspected by the code inspector.
[0083] The following is illustrated by examples of different invocation results of the language model. In some possible implementation manners, the characteristics using natural language description include a first characteristic using natural language description and a second characteristic using natural language description. The first type of DSL code checking rule indicates checking whether the inspected code has the first characteristic using natural language description and / or has the second characteristic using natural language description. Accordingly, the conversion module 2042 can construct a first prompt of the language model according to the first type of DSL code checking rule, and construct a second prompt of the language model according to the first type of DSL code checking rule. Accordingly, the language model invocation module 2062 can invoke the language model to infer whether the inspected code has the first characteristic using natural language description according to the first prompt, and obtain a first invocation result. The language model invocation module 2062 invokes the language model to infer whether the inspected code has the second characteristic using natural language description according to the second prompt, and obtains a second invocation result. The combination module 2044 is configured to combine the first invocation result and the second invocation result to obtain a checking result. The combination module 2044 can combine the first invocation result and the second invocation result by at least one of logical AND, logical OR, and logical NOT to obtain the checking result.
[0084] It should be noted that the combination module 2044 can also be used to combine the prompts of the AI predicate or the AI predicate conversion. For example, the combination module 2044 can combine the first prompt of the language model constructed according to the first type of DSL code checking rule and the second prompt of the language model constructed according to the first type of DSL code checking rule to obtain a combined prompt.
[0085] Further, the DSL code checking rule can also include a second type of DSL code checking rule. The second type of DSL code checking rule is used for code checking by matching a code database. The parsing module 2046 is configured to obtain a query statement according to the second type of DSL code checking rule for code checking by matching the code database. The code database query module 2064 is configured to query the code database corresponding to the inspected code according to the query statement to obtain a candidate code snippet. Accordingly, the language model invocation module 2062 can invoke the language model to infer whether the candidate code snippet has the characteristic using natural language description according to the prompt, and obtain an invocation result. In this way, the AI analysis can be performed on the filtered code snippet (the candidate code snippet) after the inspected code is filtered based on the DSL code checking rule, the number of invocations of the language model is reduced, the code checking efficiency is ensured, and the accurate search based on the code structure matching and the fuzzy search based on the language model can be reflected in the final checking result. The combination of the above two methods can make the checking effect closer to the user's intention while ensuring the efficiency and accuracy.
[0086] Based on the foregoing test platform, the application further provides a code checking method. The code checking method of the application is described below with reference to the accompanying drawings.
[0087] Referring to a flowchart of a code checking method shown in FIG. 3, the method includes the following steps:
[0088] S302, the test platform 20 acquires the code under test.
[0089] The code under test refers to the code that needs to be checked. The code under test can be the code written by the user through the code editor, or the code downloaded by the user from the open source platform. For example, the test platform 20 receives the code written by the user through the code editor, and when the user triggers the code checking operation, the test platform 20 can determine the code written by the user as the code under test. The test platform 20 can receive the storage path of the code under test configured by the user, and acquire the code under test according to the storage path. For another example, the test platform 20 can actively acquire the code downloaded by the user from the open source platform from the download content storage path based on the security policy, to perform code checking on the code, thereby ensuring security. It should be noted that in some cases, for example, when the security policy level is low, the test platform 20 can also acquire the code downloaded by the user from the open source platform from the download content storage path when the user triggers the code checking operation on the downloaded code, to perform code checking on the code.
[0090] It should be noted that the code under test can be all the codes of the code repository, or a specified code in the code repository. The specified code can be configured by the user. Specifically, the test platform 20 can provide an interactive interface, and the user can trigger code checking through the interactive interface. Referring to a schematic diagram of an interactive interface shown in FIG. 4, the interactive interface 400 can include a checking control 402, and when the user triggers the code checking operation by clicking the checking control 402, the interactive interface 400 can display a code under test configuration window 404, which can include configuration controls of different types of codes. In this example, the code under test configuration window 404 can include a type configuration control 4042 and a code configuration control 4044 corresponding to the type, in addition, the code under test configuration window can also include a third-party library configuration control 4046. When the user completes the configuration, the user can click a confirm control 4048 to submit the storage path of the code under test. The test platform 20 can acquire the code under test according to the storage path.
[0091] S304, the test platform 20 parses the code under test to obtain a code database.
[0092] Specifically, the test platform 20 can parse the subject code through a syntax analyzer to obtain an Abstract Syntax Tree (AST). The AST is an abstract representation of the syntax structure of the source code, and represents the syntax structure of the subject code in a tree form. Each node in the AST represents a syntax structure in the subject code. The syntax structure can be a function, a variable, etc. The test platform 20 can store the AST in a code database, so as to facilitate subsequent code checking based on the code database.
[0093] The above S304 is an optional step of the embodiments of the present application. The code checking method of the present application can also not perform the above S304. For example, when the test platform 20 turns off the precise query or the rule-based query, the test platform 20 can not perform the above S304.
[0094] S306, the test platform 20 receives a DSL code checking rule written by a user based on the DSL.
[0095] The DSL is a computer language specially designed for a specific application field. In the present application, the DSL can be a computer language specially designed for code checking. Considering the difficulty of writing code checking rules, the DSL can usually be a declarative language. For example, the DSL can be a Structured Query Language (SQL).
[0096] Correspondingly, the DSL code checking rule can be a code checking rule written according to the DSL syntax. The DSL code checking rule is used to perform code checking on the subject code. Different from the traditional DSL code checking rule, the DSL code checking rule of the present application supports checking a feature described using a natural language. In other words, when writing the DSL code checking rule, the feature to be checked can be described using a natural language, so as to make up for the deficiency of the traditional DSL code checking rule that it is difficult to check a scene with a standard bias, subjectivity or flexibility.
[0097] In a specific implementation, the test platform 20 receives the DSL code inspection rule written by the user in the DSL, and further, the user can add a feature described in natural language when writing the DSL code inspection rule, to indicate whether the code under test has the feature described in natural language by using the language model to inspect the code under test. The feature described in natural language usually needs to be analyzed by using an AI analysis capability such as a natural language model, and therefore, the feature described in natural language can also be referred to as an AI predicate. It should be noted that the test platform 20 can also logically connect the AI predicates, for example, processing one or more AI predicates by using the "not" logic, or connecting multiple AI predicates by using the "and" logic or the "or" logic. It should be noted that the "and" logic, the "or" logic, and the "not" logic can be used independently or in combination.
[0098] As shown in FIG. 4, the interactive interface 400 further includes a rule writing window 406, and the test platform 20 can receive the DSL code inspection rule written by the user through the rule writing window 406.
[0099] S308, the test platform 20 identifies the DSL code inspection rule, and obtains the first type of DSL code inspection rule and the second type of DSL code inspection rule.
[0100] Specifically, the test platform 20 identifies whether the DSL code inspection rule includes natural language, so as to classify the DSL code inspection rule according to whether the natural language is used. The DSL code inspection rule described in natural language is the first type of DSL code inspection rule, and the first type of DSL code inspection rule indicates whether the code under test has the feature described in natural language. The DSL code inspection rule not described in natural language is the second type of DSL code inspection rule. The test platform 20 can extract the first type of DSL code inspection rule and the second type of DSL code inspection rule according to the identification result.
[0101] It should be noted that the DSL code inspection rule can also not include the first type of DSL code inspection rule, or not include the second type of DSL code inspection rule. When the DSL code inspection rule does not include the first type of DSL code inspection rule, S314 to S318 can not be performed; when the DSL code inspection rule does not include the second type of DSL code inspection rule, S310 and S312 can not be performed.
[0102] In addition, the above S308 is an optional step of the embodiments of the present application, and the code inspection method of the present application can also not perform the above S308. For example, when the DSL code inspection rule includes only one type of DSL code inspection rule, S308 can not be performed.
[0103] S310, the test platform 20 obtains a query statement according to the second type of DSL code inspection rule.
[0104] Specifically, the test platform 20 can construct a query statement corresponding to the code database according to the second type of DSL code inspection rule. For example, when the code database is a graph database, the test platform 20 can convert the second type of code snippet into a graph database query statement, which is used to query the code database in the form of a graph database. Wherein, the graph database query statement is only one implementation of the query statement, and in actual application, the test platform 20 can also query the code database through other ways.
[0105] S312, the test platform 20 queries the code database corresponding to the inspected code according to the query statement, and obtains a candidate code snippet.
[0106] Specifically, the test platform 20 can generate a query plan according to the query statement, and then query the code database corresponding to the inspected code according to the query plan, so as to obtain the candidate code snippet. The candidate code snippet can be a code snippet matched with the second type of DSL code inspection rule. For example, the second type of DSL code inspection rule is f.name contain“control”, and the candidate code snippet can be a function whose name includes control.
[0107] S314, the test platform 20 constructs a prompt of the language model according to the first type of DSL code inspection rule.
[0108] Specifically, the test platform 20 can provide a prompt template of the language model, and then fill the prompt template of the language model according to the first type of DSL code inspection rule, so as to obtain the prompt of the language model. Wherein, the first type of DSL code inspection rule is used to indicate whether the inspected code has a feature described by natural language. The prompt template of the language model can include placeholders of different fields, such as placeholders of features to be checked. The test platform 20 can fill the feature described by natural language into the position indicated by the corresponding placeholder in the prompt template according to the first type of DSL code inspection rule. Further, the prompt template can also include output format or return value. The test platform 20 can also fill the output format or return value in the prompt template according to the first type of DSL code inspection rule.
[0109] Wherein, the test platform 20 can also fill the detection object such as the candidate code snippet into the prompt template, so as to filter the candidate code snippet through the language model, so as to determine whether the candidate code snippet has the feature described by natural language.
[0110] S316, the test platform 20 calls the language model according to the prompt of the language model to infer whether the candidate code snippet has the characteristic described using natural language, and obtains a calling result.
[0111] Specifically, the test platform 20 can take the prompt of the language model as an input parameter, generate a calling request of the language model, and then send the calling request, so as to infer whether the candidate code snippet has the characteristic described using natural language through the language model.
[0112] It should be noted that the test platform 20 can also call the language model according to the prompt of the language model to infer whether the inspected code has the characteristic described using natural language. For example, when the test platform 20 does not perform accurate matching based on the code checking rule, the test platform 20 can call the language model according to the prompt of the language model, directly infer whether the inspected code has the characteristic described using natural language, and obtain a calling result.
[0113] S318, the test platform 20 combines the calling results to obtain a checking result.
[0114] When the characteristic described using natural language includes multiple characteristics, or the AI predicate includes multiple predicates, the test platform 20 can call the language model to infer for each characteristic described using natural language or each predicate, thereby obtaining multiple calling results. Then, the test platform 20 can combine the multiple calling results to obtain a final checking result.
[0115] For ease of understanding, it is exemplarily described that the characteristic described using natural language includes a first characteristic described using natural language and a second characteristic described using natural language. The first type of DSL code checking rule indicates to check whether the inspected code has the first characteristic described using natural language and / or has the second characteristic described using natural language. The first characteristic described using natural language and the second characteristic described using natural language can be logically connected, for example, connected through “and” logic, “or” logic, or “not” logic. In some examples, the first characteristic described using natural language and the second characteristic described using natural language are connected through “and” logic, and the first type of DSL code checking rule can indicate to check whether the inspected code has the first characteristic described using natural language and the second characteristic described using natural language. For another example, the first characteristic described using natural language and the second characteristic described using natural language are connected through “or” logic and “not” logic, and the first type of DSL code checking rule can indicate to check whether the inspected code has the first characteristic described using natural language or does not have the second characteristic described using natural language.
[0116] Correspondingly, the test platform 20 can construct a first prompt of the language model according to the first type of DSL code inspection rule, and construct a second prompt of the language model according to the first type of DSL code inspection rule. Each prompt can be regarded as an AI filter for filtering candidate code snippets through the language model. The test platform 20 invokes the language model according to the first prompt to infer whether the inspected code has a first property described using natural language, obtains a first invocation result, and invokes the language model according to the second prompt to infer whether the inspected code has a second property described using natural language, and obtains a second invocation result. The test platform 20 combines the first invocation result and the second invocation result to obtain an inspection result. The test platform 20 can combine the first invocation result and the second invocation result by at least one of logical AND, logical OR, and logical NOT to obtain the inspection result.
[0117] It should be noted that the test platform 20 can determine the connection logic of the first invocation result and the second invocation result according to the connection logic of the first property described using natural language and the second property described using natural language in the first type of DSL code inspection rule. Generally, the connection logic of the first invocation result and the second invocation result is consistent with the connection logic of the first property described using natural language and the second property described using natural language.
[0118] The above S318 is an optional step of the embodiments of the present application, and the code inspection method of the present application can also not perform S318. For example, when the DSL code inspection rule includes an AI predicate, S318 can not be performed, and the invocation result of the language model can be the final inspection result.
[0119] S320, the test platform 20 presents the inspection result of the inspected code to the user.
[0120] The test platform 20 can present the inspection result of the inspected code to the user through a user interface. In some possible implementation manners, the test platform 20 also supports the user to confirm the inspection result to ensure the accuracy of the inspection result. Specifically, the test platform 20 can present a target code snippet in the inspected code to the user in response to a jump operation of the user on the inspection result. The target code snippet can be a code snippet associated with the inspection result. In this way, the user can verify whether the target code snippet has the property described using natural language, thereby improving the accuracy of code inspection.
[0121] In some possible implementation manners, the user interface can be the interactive interface 400 shown in FIG. 4, and the interactive interface 400 further includes a result display window 408. The result display window 408 can include a problem display area 4082, and the problem display area 4082 can include the inspection result of the inspected code.
[0122] Based on the above description, it can be known that the code inspection method of the present application supports users to use natural language to describe the characteristics to be inspected when writing DSL code inspection rules. Therefore, when receiving a DSL code inspection rule written by a user based on DSL, indicating whether the inspected code has the characteristics described using natural language, the language model prompt can be constructed according to the type of DSL code inspection rule, and then the language model is called according to the prompt to infer whether the inspected code has the characteristics described using natural language. Based on the calling result of the language model, the final inspection result can be obtained. The method introduces AI analysis capabilities such as language models on the basis of the original code inspector developed based on DSL to solve the problem that the code inspector developed based on DSL cannot cover the description of subjective, ambiguous or flexible and variable scenarios. At the same time, the inspection capability of the code inspector is used to ensure the efficiency and accuracy of the inspection.
[0123] In order to make the technical solutions of the present application more clear and easy to understand, the code inspection method of the present application will be introduced in combination with some specific scenarios.
[0124] Referring to a code inspection method application scenario diagram shown in FIG. 5, in this application scenario, the user wants to detect a function whose name contains "test" and is an external call. For this purpose, the following DSL code inspection rule is written:
[0125] The above DSL code inspection rule includes an AI predicate for checking whether the inspected code has the characteristics described using natural language. The characteristics can be "an external call function".
[0126] In this scenario, the test platform 20 first extracts the second type of DSL code inspection rule from the DSL code inspection rule, for example, "f.name contain"test", converts the above second type of DSL code inspection rule into a graph database query statement, and then queries the graph database corresponding to the inspected code to obtain at least one candidate code segment. FIG. 4 illustrates an example including N candidate code segments.
[0127] The test platform 20 extracts the first type of DSL code inspection rule from the DSL code inspection rule, and the first type of DSL code inspection rule includes an AI predicate. The first type of DSL code inspection rule can be "AI(f,"is an external call function")". The test platform 20 can parse the first type of DSL code inspection rule or the AI predicate into a call to the language model.
[0128] In specific implementation, the test platform 20 can fill in the prompt template according to the AI predicate to obtain the prompt of the language model. In this scenario, the prompt template is as follows:
[0129] where monadic means unary, in this example for making one language model call, and %s is a placeholder.
[0130] The prompt filled in the prompt template is as follows:
[0131] The test platform 20 can input the candidate code snippet into the language model, for example, the LLM, and filter the candidate code snippet according to the calling result of the language model. For example, the test platform 20 can retain the functions whose answers of the language model are "yes", so as to obtain the functions in the code under test whose names contain "test" and are externally called.
[0132] The method first matches the syntax structure of the code under test through an efficient graph database query, avoiding calling the language model on the full code repository; then calls the language model on the candidate code snippet whose syntax structure has matched the user's requirements, reducing the number of language model calls and ensuring efficiency, while allowing the final inspection result to reflect the precise search based on code structure matching and the fuzzy search based on the language model.
[0133] FIG. 5 illustrates a simple inspection including a single AI predicate in the DSL code inspection rule, and the following introduces a complex inspection including multiple AI predicates.
[0134] Referring to FIG. 6, another application scenario of the code inspection method is shown. In this application scenario, the user wants to detect a function whose name contains "control" and is externally called, and in addition, the function needs to have "simple and clear calling interface" or "detailed document annotation". For this purpose, the user writes the following DSL code inspection rule:
[0135] The above DSL code inspection rule includes three AI predicates, which are logically connected through "and" logic and "or" logic. Among them, "simple and clear calling interface" and "detailed document annotation" are logically connected through "or" logic, and the connection result of "or" logic and "is an externally called function" are logically connected through "and" logic.
[0136] The detailed processing procedure of the code inspection is as follows: first, the test platform 20 extracts a second type of DSL code inspection rule from the DSL code inspection rule, for example, "f.name contain" control ", converts the second type of DSL code inspection rule into a graph database query statement, and then queries the graph database corresponding to the code under test to obtain at least one candidate code snippet. FIG. 5 illustrates an example including N candidate code snippets.
[0137] Then, the test platform 20 extracts a first type of DSL code inspection rule from the DSL code inspection rule, and the first type of DSL code inspection rule includes three AI predicates. The test platform 20 can parse the AI predicate into a call to the language model.
[0138] Wherein, the test platform 20 can first filter the candidate code snippets based on the call to the language model converted from "is an externally called function". Specifically, the test platform 20 can construct a prompt for the language model according to "is an externally called function", and call the language model based on the prompt for the language model, as follows:
[0139] In this example, it is assumed that the language model filters N candidate code snippets to obtain M AI calls.
[0140] Then, the test platform 20 can perform a second filtering on the filtering results of the first filtering, thereby filtering out functions that are "simple and clear in calling interface" or "have detailed document comments". Wherein, the test platform 20 can call the language model twice for the functions that are "externally called", and take the union of the call results to obtain the final inspection result.
[0141] Wherein, the code for judging "simple and clear in calling interface" is as follows:
[0142] The code for judging "have detailed document comments" is as follows:
[0143] This method parses the AI predicate, calls the language model for reasoning based on the prompt obtained from the parsing result, combines the call results according to the connection logic of the AI predicate written by the user, and obtains the final inspection result.
[0144] Based on the foregoing code inspection method, the present application further provides a test platform 20. As shown in FIG. 2, the test platform 20 includes:
[0145] The interaction module 2022 is configured to obtain the code under test.
[0146] The interaction module 2022 is further configured to receive a DSL code inspection rule written by a user based on a domain-specific language (DSL), the DSL code inspection rule being used for code inspection on the subject code;
[0147] The conversion module 2042 is configured to, when the DSL code inspection rule comprises a first type of DSL code inspection rule, construct a prompt of a language model according to the first type of DSL code inspection rule, the first type of code inspection rule indicating inspection on whether the subject code has a feature described using a natural language;
[0148] The language model calling module 2062 is configured to call the language model to infer, according to the prompt, whether the subject code has the feature described using the natural language, and obtain a calling result;
[0149] The interaction module 2022 is further configured to present, to the user, an inspection result of the subject code, the inspection result being generated according to the calling result of the language model, and the inspection result being used to indicate whether the subject code has the feature described using the natural language.
[0150] Exemplarily, the above interaction module 2022, conversion module 2042, and language model calling module 2062 can be implemented by hardware, or can be implemented by software.
[0151] When implemented by software, the interaction module 2022, the conversion module 2042, and the language model calling module 2062 can be an application program running on a computing device, such as a computing engine, etc. The above application program can also be virtualized to provide a virtualized service to users. The virtualized service can include a virtual machine (VM) service, a bare metal server (BMS) service, or a container service. Among them, the VM service can be a service that provides a VM for users to use on demand by virtualizing a VM resource pool on multiple physical hosts through a virtualization technology. The BMS service is a service that provides a BMS for users to use on demand by virtualizing a BMS resource pool on multiple physical hosts. The container service is a service that provides a container for users to use on demand by virtualizing a container resource pool on multiple physical hosts. The VM is a virtual computer simulated, that is, a logical computer. The BMS is a high-performance computing service that can be elastically scaled, and the computing performance is no different from that of a traditional physical machine, and has the characteristics of secure physical isolation. The container is a kernel virtualization technology that can provide lightweight virtualization to achieve the purpose of isolating user space, processes, and resources. It should be understood that the VM service, the BMS service, and the container service in the above virtualized service are only specific examples. In actual application, the virtualized service can also be other lightweight or heavyweight virtualized services, which are not limited here.
[0152] When implemented by hardware, the interaction module 2022, the conversion module 2042, and the language model calling module 2062 can include at least one computing device, such as a server, etc. Alternatively, the interaction module 2022, the conversion module 2042, and the language model calling module 2062 can also be devices implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), etc. Among them, the above PLD can be implemented by a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0153] In some possible implementation, the characteristics described using natural language include a first characteristic described using natural language and a second characteristic described using natural language, and the first type of DSL code inspection rule indicates to check whether the inspected code has the first characteristic described using natural language and / or has the second characteristic described using natural language.
[0154] Correspondingly, the conversion module 2042 is specifically configured to:
[0155] construct a first prompt of the language model according to the first type of DSL code inspection rule, and construct a second prompt of the language model according to the first type of DSL code inspection rule;
[0156] The language model calling module 2062 is specifically configured to:
[0157] call the language model to infer whether the inspected code has the first characteristic described using natural language according to the first prompt, and obtain a first calling result;
[0158] call the language model to infer whether the inspected code has the second characteristic described using natural language according to the second prompt, and obtain a second calling result;
[0159] The test platform 20 further includes:
[0160] The combination module 2044 is configured to combine the first calling result and the second calling result to obtain the inspection result.
[0161] Similar to the interaction module 2022, the conversion module 2042, and the language model calling module 2062, the combination module 2044 can be implemented by hardware, or can be implemented by software. When implemented by software, the combination module 2044 can be an application program running on a computing device. The above-mentioned application program can also be provided to users in the form of a virtualization service such as a VM service, a BMS service, or a container service. When implemented by hardware, the combination module 2044 can include at least one computing device such as a server. Alternatively, the combination module 2044 can also be a device implemented by ASIC or PLD, etc.
[0162] In some possible implementation, the combination module 2044 is specifically configured to:
[0163] combine the first calling result and the second calling result by at least one of AND logic, OR logic, and NOT logic to obtain the inspection result.
[0164] In some possible implementation manners, the characteristic described using the natural language includes a first characteristic described using the natural language and a second characteristic described using the natural language, and the first type of DSL code inspection rule indicates checking whether the inspected code has the first characteristic described using the natural language and / or has the second characteristic described using the natural language.
[0165] The conversion module 2042 is specifically configured to:
[0166] construct a first prompt of the language model according to the first type of DSL code inspection rule, and construct a second prompt of the language model according to the first type of DSL code inspection rule;
[0167] The test platform 20 further includes:
[0168] The combination module 2044 is configured to combine the first prompt and the second prompt to obtain a combined prompt.
[0169] In some possible implementation manners, the test platform 20 further includes:
[0170] The parsing module 2046 is configured to, when the DSL code inspection rule includes a second type of DSL code inspection rule, obtain a query statement according to the second type of DSL code inspection rule.
[0171] The code database query module 2064 is configured to query a code database corresponding to the inspected code according to the query statement to obtain a candidate code snippet.
[0172] The language model calling module 2062 is specifically configured to:
[0173] call the language model to infer whether the candidate code snippet has the characteristic described using the natural language according to the prompt, and obtain a calling result.
[0174] The parsing module 2046 and the code database query module 2064 can be implemented by hardware, or can be implemented by software. When implemented by software, the parsing module 2046 and the code database query module 2064 can be an application program running on a computing device. The above application program can also be provided to a user in a virtualization service such as a VM service, a BMS service or a container service. When implemented by hardware, the parsing module 2046 and the code database query module 2064 can include at least one computing device such as a server. Alternatively, the parsing module 2046 and the code database query module 2064 can also be a device implemented by an ASIC or a PLD.
[0175] In some possible implementation manners, the interaction module 2022 is specifically configured to:
[0176] receive a storage path of the inspected code configured by the user.
[0177] According to the storage path, the inspected code is acquired.
[0178] In some possible implementation manners, the interaction module 2022 is further configured to:
[0179] In response to a jump operation of the user on the inspection result, the target code segment in the inspected code is presented to the user.
[0180] The application further provides a computing device 700. As shown in FIG. 7, the computing device 700 includes a bus 702, a processor 704, a memory 706, and a communication interface 708. The processor 704, the memory 706, and the communication interface 708 communicate through the bus 702. The computing device 700 can be a server or a terminal device. It should be understood that the number of processors and memories in the computing device 700 is not limited in the application.
[0181] The bus 702 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one line is used in FIG. 7, but it does not mean that there is only one bus or only one type of bus. The bus 702 can include a path for transmitting information between various components (for example, the memory 706, the processor 704, and the communication interface 708) of the computing device 700.
[0182] The processor 704 can include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP), etc.
[0183] The memory 706 can include volatile memory, such as random access memory (RAM) including a cache area for the temporary storage of data. The memory 706 also can include non-volatile memory, such as read only memory (ROM), floppy, flexible, or hard disk drive (HDD), or solid-state drive (SSD) to store information, such as data files, computer readable instructions, and the like. The memory 706 can store program instructions, such as code checking method, which are executable by the processor 704. Specifically, the memory 706 can store instructions for the test platform 20 to perform the code checking method. For example, the memory 706 can store instructions for implementing the functions of the interaction module 2022, the conversion module 2042, and the language model calling module 2062. Further, the memory 706 can store instructions for implementing the functions of the combination module 2044, the parsing module 2046, and the code database querying module 2064.
[0184] The communication interface 708 enables communication among the computing device 700 and other devices or communication networks using, for example, but not limited to, a transceiver, such as a network interface card, a Bluetooth® module, a wireless transceiver, and the like.
[0185] The embodiments of the present disclosure also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device, such as a desktop computer, a notebook computer, or a smart phone.
[0186] As shown in FIG. 8, the computing device cluster includes at least one computing device 700. The memory 706 in one or more computing devices 700 in the computing device cluster can store the same instructions for the test platform 20 to perform the code checking method.
[0187] In some possible implementations, one or more computing devices 700 in the computing device cluster can also be used to execute part of the instructions for the test platform 20 to perform the code checking method. In other words, the combination of one or more computing devices 700 can collectively execute the instructions for the test platform 20 to perform the code checking method.
[0188] It should be noted that the memory 706 in different computing devices 700 in the computing device cluster can store different instructions for performing part of the functions of the test platform 20.
[0189] Figure 9 illustrates one possible implementation. As shown in Figure 9, two computing devices 700A and 700B are connected through the communication interface 708. The memory in the computing device 700A has instructions stored thereon for performing the functions of the interaction module 2022, the conversion module 2042. The memory in the computing device 700B has instructions stored thereon for performing the functions of the language model invocation module 2062. Further, the memory in the computing device 700A can also have instructions stored thereon for performing the functions of the combination module 2044, the parsing module 2046, and the memory in the computing device 700B can also have instructions stored thereon for performing the functions of the code database query module 2064. In other words, the memories 706 in the computing devices 700A and 700B collectively store the instructions for the test platform 20 to perform the code inspection method.
[0190] The manner in which the computing devices in the cluster are connected as shown in Figure 9 can be such that the code inspection method provided herein requires more resources for language model inference. Thus, it is contemplated that the interaction module 2022, the conversion module 2042 are executed by the computing device 700A, and the functions implemented by the language model invocation module 2062 are executed by the computing device 700B.
[0191] It should be appreciated that the functions of the computing device 700A as shown in Figure 9 can also be accomplished by multiple computing devices 700. Similarly, the functions of the computing device 700B can also be accomplished by multiple computing devices 700.
[0192] In some possible implementations, one or more of the computing devices in the cluster can be connected through a network. The network can be a wide area network, a local area network, or the like. Figure 10 illustrates one possible implementation. As shown in Figure 10, two computing devices 700C and 700D are connected through a network. Specifically, the computing devices are connected to the network through the communication interface in each of the computing devices. In this class of possible implementations, the memory 706 in the computing device 700C has instructions stored thereon for performing the functions of the interaction module 2022, the conversion module 2042. Meanwhile, the memory 706 in the computing device 700D has instructions stored thereon for performing the functions of the language model invocation module 2062. Further, the memory in the computing device 700C can also have instructions stored thereon for performing the functions of the combination module 2044, the parsing module 2046, and the memory in the computing device 700D can also have instructions stored thereon for performing the functions of the code database query module 2064.
[0193] The connection between the computing device cluster shown in FIG. 10 can be that the code inspection method provided in the present application requires a large amount of resource inference to determine whether the code under test has the characteristics described using natural language, and therefore the function implemented by the language model calling module 2062 is executed by an independent computing device, for example, the computing device 700D.
[0194] It should be understood that the functions of the computing device 700C shown in FIG. 10 can also be completed by multiple computing devices 700. Similarly, the functions of the computing device 700D can also be completed by multiple computing devices 700.
[0195] The embodiments of the present application also provide a computer readable storage medium. The computer readable storage medium can be any available medium or data storage device that can be accessed by a computing device or a data center containing one or more available media. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk), etc. The computer readable storage medium includes instructions that instruct the computing device to execute the code inspection method applied to the test platform 20 described above.
[0196] The embodiments of the present application also provide a computer program product containing instructions. The computer program product can be software or a program product containing instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute the code inspection method described above.
[0197] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the protection scope of the technical solutions of the embodiments of the present application.
Claims
1. A code inspection method, characterized by, The method comprises: acquiring a code under test; receiving a DSL code inspection rule written by a user based on a domain-specific language (DSL), the DSL code inspection rule being used for code inspection on the code under test; when the DSL code inspection rule comprises a first type of DSL code inspection rule, constructing a prompt for a language model according to the first type of DSL code inspection rule, the first type of code inspection rule indicating to check whether the code under test has a feature described using a natural language; instructing the language model to reason whether the code under test has the feature described using the natural language according to the prompt, and obtaining a calling result; presenting an inspection result of the code under test to the user, the inspection result being generated according to the calling result of the language model, and the inspection result being used to indicate whether the code under test has the feature described using the natural language.
2. The method of claim 1, wherein, The feature described using the natural language comprises a first feature described using a natural language and a second feature described using a natural language, and the first type of DSL code inspection rule indicates to check whether the code under test has the first feature described using the natural language and / or has the second feature described using the natural language. The constructing of the prompt for the language model according to the first type of DSL code inspection rule comprises: constructing a first prompt for the language model according to the first type of DSL code inspection rule, and constructing a second prompt for the language model according to the first type of DSL code inspection rule. The instructing of the language model to reason whether the code under test has the feature described using the natural language according to the prompt, and the obtaining of the calling result, comprise: instructing the language model to reason whether the code under test has the first feature described using the natural language according to the first prompt, and obtaining a first calling result; instructing the language model to reason whether the code under test has the second feature described using the natural language according to the second prompt, and obtaining a second calling result. The method further comprises: combining the first calling result and the second calling result to obtain the inspection result.
3. The method of claim 2, wherein, The combining of the first calling result and the second calling result to obtain the inspection result comprises: combining the first calling result and the second calling result by at least one of AND logic, OR logic, and NOT logic to obtain the inspection result.
4. The method of claim 1, wherein, The feature described using the natural language comprises a first feature described using a natural language and a second feature described using a natural language, and the first type of DSL code inspection rule indicates to check whether the code under test has the first feature described using the natural language and / or has the second feature described using the natural language. The constructing of the prompt for the language model according to the first type of DSL code inspection rule comprises: constructing a first prompt for the language model according to the first type of DSL code inspection rule, and constructing a second prompt for the language model according to the first type of DSL code inspection rule. combine the first prompt and the second prompt to obtain a combined prompt.
5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: when the DSL code inspection rule includes a second type of DSL code inspection rule, obtaining a query statement according to the second type of DSL code inspection rule; querying a code database corresponding to the inspected code according to the query statement to obtain a candidate code snippet; the calling the language model to infer whether the inspected code has the characteristic described in natural language according to the prompt includes: calling the language model to infer whether the candidate code snippet has the characteristic described in natural language according to the prompt.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: receiving a storage path of the inspected code configured by a user; obtaining the inspected code according to the storage path.
7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: in response to a jump operation of the user on the inspection result, presenting a target code snippet in the inspected code to the user.
8. A test platform characterized by, The test platform includes: an interaction module configured to obtain an inspected code; the interaction module is further configured to receive a DSL code inspection rule written by a user based on a domain-specific language (DSL), the DSL code inspection rule being used for code inspection on the inspected code; a conversion module configured to, when the DSL code inspection rule includes a first type of DSL code inspection rule, construct a prompt of a language model according to the first type of DSL code inspection rule, the first type of code inspection rule indicating whether to check whether the inspected code has a characteristic described in natural language; a language model calling module configured to call the language model to infer whether the inspected code has the characteristic described in natural language according to the prompt, and obtain a calling result; the interaction module is further configured to present an inspection result of the inspected code to the user, the inspection result being generated according to the calling result of the language model, and the inspection result being used to indicate whether the inspected code has the characteristic described in natural language.
9. The test platform of claim 8, wherein, The characteristic described in natural language includes a first characteristic described in natural language and a second characteristic described in natural language, and the first type of DSL code inspection rule indicates whether to check whether the inspected code has the first characteristic described in natural language and / or whether the inspected code has the second characteristic described in natural language; The conversion module is specifically configured to: construct a first prompt of a language model according to the first type of DSL code inspection rule, and construct a second prompt of the language model according to the first type of DSL code inspection rule; The language model calling module is specifically configured to: call the language model to infer whether the inspected code has the first characteristic described in natural language according to the first prompt, and obtain a first calling result; call the language model to infer whether the inspected code has the second characteristic described in natural language according to the second prompt, and obtain a second calling result; The test platform further includes: A combination module configured to combine the first invocation result and the second invocation result to obtain the inspection result.
10. The test platform of claim 9, wherein, The combination module is specifically configured to: combine the first invocation result and the second invocation result by at least one of AND logic, OR logic, and NOT logic to obtain the inspection result.
11. The test platform of claim 8, wherein, The natural language description-based features include a first natural language description-based feature and a second natural language description-based feature, and the first type of DSL code inspection rule indicates to inspect whether the subject code has the first natural language description-based feature and / or has the second natural language description-based feature; The conversion module is specifically configured to: construct a first hint of a language model according to the first type of DSL code inspection rule, and construct a second hint of the language model according to the first type of DSL code inspection rule; The test platform further includes: a combination module configured to combine the first hint and the second hint to obtain a combined hint.
12. The test platform of any one of claims 8 to 11, wherein, The test platform further includes: a parsing module configured to, when the DSL code inspection rule includes a second type of DSL code inspection rule, obtain a query statement according to the second type of DSL code inspection rule; a code database query module configured to query a code database corresponding to the subject code according to the query statement to obtain a candidate code snippet; The language model invocation module is specifically configured to: invoke the language model to infer whether the candidate code snippet has the natural language description-based feature according to the hint to obtain an invocation result.
13. The test platform of any one of claims 8 to 12, wherein, The interaction module is specifically configured to: receive a storage path of the subject code configured by a user; obtain the subject code according to the storage path.
14. The test platform of any one of claims 8 to 13, wherein, The interaction module is further configured to: present a target code snippet in the subject code to the user in response to a jump operation of the user on the inspection result.
15. A cluster of computing devices, characterized in that, The computing device cluster includes at least one computing device including at least one processor and at least one memory, and the at least one memory stores computer readable instructions; the at least one processor executes the computer readable instructions, so that the computing device cluster executes the code inspection method in any one of claims 1 to 7.
16. A computer readable storage medium characterized by: including computer readable instructions; the computer readable instructions are used to implement the code inspection method in any one of claims 1 to 7.
17. A computer program product, characterised in that, including computer readable instructions; the computer readable instructions are used to implement the code inspection method in any one of claims 1 to 7.