Skip to content

Commit 7136fcc

Browse files
committed
♻️ Add OpenAIIntegrationTest Extension
Extension encapsulates the logic for determining if an OpenAI test should be skipped.
1 parent 903df59 commit 7136fcc

File tree

13 files changed

+105
-51
lines changed

13 files changed

+105
-51
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ python -m site
5858

5959
You need to be able to run [Docker](https://www.docker.com/) for some tests. Make sure you have it installed and have the necessary permissions to run with your user.
6060

61+
#### OpenAI Integration Tests
62+
63+
Some tests integrate with the OpenAI platform. To run these tests, configure an OpenAI key in the Gradle
64+
property `codemodderOpenAIKey`. When no API key is configured, the tests will be skipped.
65+
66+
You can add the Gradle property to your `~/.gradle/gradle.properties` file:
67+
68+
```properties
69+
codemodderOpenAIKey=your-openai-key
70+
```
71+
6172
### Run the Core Codemods
6273
You can download and run the latest release from this repository in order to run the core codemods as a CLI:
6374

core-codemods/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("io.codemodder.runner")
44
id("io.codemodder.maven-publish")
55
id("io.codemodder.core-codemods-docs")
6+
id("io.codemodder.openai")
67
`jvm-test-suite`
78
}
89

@@ -30,12 +31,12 @@ dependencies {
3031
implementation(libs.dom4j)
3132
implementation(libs.commons.jexl)
3233
implementation(libs.tuples)
34+
testImplementation(testFixtures(project(":plugins:codemodder-plugin-llm")))
3335
testImplementation(testlibs.bundles.junit.jupiter)
3436
testImplementation(testlibs.bundles.hamcrest)
3537
testImplementation(testlibs.assertj)
3638
testImplementation(testlibs.mockito)
3739
testImplementation(project(":framework:codemodder-testutils"))
38-
testImplementation(project(":framework:codemodder-testutils-llm"))
3940
testRuntimeOnly(testlibs.junit.jupiter.engine)
4041
testImplementation(testlibs.jgit)
4142
testImplementation(testlibs.assertj)

core-codemods/src/test/java/io/codemodder/codemods/LogFailedLoginCodemodTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package io.codemodder.codemods;
22

3+
import io.codemodder.plugins.llm.test.LLMVerifyingCodemodTestMixin;
4+
import io.codemodder.plugins.llm.test.OpenAIIntegrationTest;
35
import io.codemodder.testutils.Metadata;
4-
import io.codemodder.testutils.llm.LLMVerifyingCodemodTestMixin;
5-
import org.junit.jupiter.api.condition.EnabledIf;
66

77
@Metadata(
88
codemodType = LogFailedLoginCodemod.class,
99
testResourceDir = "log-failed-login",
1010
dependencies = {})
11-
@EnabledIf("io.codemodder.testutils.llm.CodemodderOpenAIKeys#isAvailable")
11+
@OpenAIIntegrationTest
1212
public final class LogFailedLoginCodemodTest implements LLMVerifyingCodemodTestMixin {
1313

1414
@Override

core-codemods/src/test/java/io/codemodder/codemods/SensitiveDataLoggingCodemodTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package io.codemodder.codemods;
22

3+
import io.codemodder.plugins.llm.test.LLMVerifyingCodemodTestMixin;
4+
import io.codemodder.plugins.llm.test.OpenAIIntegrationTest;
35
import io.codemodder.testutils.Metadata;
4-
import io.codemodder.testutils.llm.LLMVerifyingCodemodTestMixin;
5-
import org.junit.jupiter.api.condition.EnabledIf;
66

77
@Metadata(
88
codemodType = SensitiveDataLoggingCodemod.class,
99
testResourceDir = "sensitive-data-logging",
1010
dependencies = {})
11-
@EnabledIf("io.codemodder.testutils.llm.CodemodderOpenAIKeys#isAvailable")
11+
@OpenAIIntegrationTest
1212
final class SensitiveDataLoggingCodemodTest implements LLMVerifyingCodemodTestMixin {
1313

1414
@Override

framework/codemodder-testutils-llm/build.gradle.kts

Lines changed: 0 additions & 14 deletions
This file was deleted.

framework/codemodder-testutils-llm/src/main/java/io/codemodder/testutils/llm/CodemodderOpenAIKeys.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
`java-test-fixtures`
3+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id("io.codemodder.java")
3+
`jvm-test-suite`
4+
}
5+
6+
testing {
7+
suites {
8+
@Suppress("UnstableApiUsage")
9+
val test by getting(JvmTestSuite::class) {
10+
useJUnitJupiter()
11+
targets {
12+
all {
13+
testTask {
14+
val openAIKey = project.findProperty("codemodderOpenAIKey") as String?
15+
openAIKey?.let {
16+
environment("CODEMODDER_OPENAI_API_KEY", it)
17+
}
18+
}
19+
}
20+
}
21+
}
22+
}
23+
}

plugins/codemodder-plugin-llm/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("io.codemodder.java-library")
3+
id("io.codemodder.java-test-fixtures")
34
id("io.codemodder.maven-publish")
45
}
56

@@ -12,6 +13,10 @@ dependencies {
1213
}
1314
implementation("com.google.inject:guice:5.1.0")
1415

16+
testFixturesApi(testlibs.junit.jupiter.api)
17+
testFixturesApi(project(":framework:codemodder-testutils"))
18+
testFixturesImplementation(testlibs.bundles.hamcrest)
19+
1520
testImplementation(testlibs.bundles.junit.jupiter)
1621
testImplementation(testlibs.bundles.hamcrest)
1722
testImplementation(testlibs.assertj)

framework/codemodder-testutils-llm/src/main/java/io/codemodder/testutils/llm/LLMVerifyingCodemodTestMixin.java renamed to plugins/codemodder-plugin-llm/src/testFixtures/java/io/codemodder/plugins/llm/test/LLMVerifyingCodemodTestMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.codemodder.testutils.llm;
1+
package io.codemodder.plugins.llm.test;
22

33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.is;

0 commit comments

Comments
 (0)