AI Quality Gate
Written on by jt
A software solution should alway be in flux, that's why this blog is all about the topic Quality Gate and AI. The question of maintenance, continous development and operation is top priority. Through various approaches (team organisation and company-mindset, to name a few), people try to keep the delivery cycle as short as possible. Such dynamics only work when a high degree of automation an transparency is available. An important part of this is the Quality Gate.
The meaning of Quality Gate
At the quality gate, the approval of the next project steps is clearly determined in advance based on quality criteria. How can the quality of code be assessed in this context? In general, a lot of "Clean Code" techniques revolve around the following question: How to write code in a team of developers that keeps the training period of new members to a minimum? Aside from static code analysis (complexity, bug heuristic, and so on) - Keyword Sonarqube) comes to mind, code review is a viable solution.
Who is responsible for quality control?
Code review enabled the transfer of know-how from senior developers to new team members.
More often than not, this takes a lot of time. As such, software architects should primarily take care of this task.
Let's get to the topic of deployment pipelines. Those tend to look as follows:
- Write & commit code
- Trigger build (Unit tests, acceptance tests, integration tests, an so on)
- Quality Gate (Clean code standards, security, licencing, an so on)
The code review only takes place after these steps.
The role of AI
Let's try out a Code Completion interface by OpenAI, that can support code quality checkes. Our example project has 2 different methods, one in Typescript and one in Java. The Typescript-function does a simple addition:
function add(x, y) { return x + y;}
The Java-class is garbled nonsense, with untelligible naming conventions:
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SomeClass {
static boolean sA(final String s) {
String bKram = s;
String sFe = fo(bKram);
return bKram.equals(sFe);
}
static String fo(String bKram) {
List<String> faef = Stream.of(bKram).map(c-> c).collect(Collectors.toList());
StringBuilder dram = new StringBuilder(bKram).reverse();
if(Objects.nonNull(faef)) {
return dram.toString();
}
return null;
}
Let's give this a shot:
const question = "Can you write Unit Test for this Code : ";
We'll use the createCompletion
API by OpenAI
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: question + fileContents,
temperature: 0,
max_tokens: 3600,
});
Here we are:
@Test
public void testSA() {
String s = "test";
assertTrue(SomeClass.sA(s));
}
@Test
public void testFo() {
String s = "test";
assertEquals("tset", SomeClass.fo(s));
}
We're still not quite sure what the class is supposed to do, but the functionality has been squeezed out in seconds.
The same can be done for our Typescript-function:
describe('add function', () => {
it('should add two numbers', () => {
expect(add(1, 2)).toEqual(3);
});
});
Handing the Java-function over to ChatGPT, the AI was quick to find out that the unintelligible function actually checks whether or not the parameter is a palindrome. As such, the AI did comprehend the goal of the function:
AI Quality Gate
Let's get back to topic and analyze the use of AI for Quality Gate. Can AI be used to generate unit tests for new code?
Concise methods with little side effects are very likely interpretable and testable by AI.
Conversely, this means that AI can act as a filter to highlight areas that are relevant for code review.
By adding AI to our pipeline, it will look as follows:
- Write & commit code
- Trigger build (Unit tests, acceptance tests, integration tests and so on)
- AI code review
- Quality Gate (Clean code standarts, security licences, and so on.)
This way, AI can be integrated into deployment pipelines as well as be applied to security aspects with regard to the written code increasing the stability, maintainability and the quality of the delivered software. The most important result achieved by the use of AI in regard of Quality Gate however is the productivity increase during the development cycle.