11package io.modelcontextprotocol.kotlin.sdk.integration.typescript
22
3- import org.junit.jupiter.api.AfterAll
43import org.junit.jupiter.api.BeforeAll
54import java.io.BufferedReader
65import java.io.File
@@ -16,7 +15,11 @@ abstract class TypeScriptTestBase {
1615
1716 companion object {
1817 @JvmStatic
19- protected val sdkDir = File (" src/jvmTest/resources/typescript-sdk" )
18+ private val tempRootDir: File =
19+ java.nio.file.Files .createTempDirectory(" typescript-sdk-" ).toFile().apply { deleteOnExit() }
20+
21+ @JvmStatic
22+ protected val sdkDir: File = File (tempRootDir, " typescript-sdk" )
2023
2124 /* *
2225 * clone TypeScript SDK and install dependencies
@@ -27,7 +30,7 @@ abstract class TypeScriptTestBase {
2730 println (" Cloning TypeScript SDK repository" )
2831 if (! sdkDir.exists()) {
2932 val cloneCommand =
30- " git clone --depth 1 https://github.com/modelcontextprotocol/typescript-sdk.git src/jvmTest/resources/typescript-sdk "
33+ " git clone --depth 1 https://github.com/modelcontextprotocol/typescript-sdk.git ${sdkDir.absolutePath} "
3134 val process = ProcessBuilder ()
3235 .command(" bash" , " -c" , cloneCommand)
3336 .redirectErrorStream(true )
@@ -42,17 +45,11 @@ abstract class TypeScriptTestBase {
4245 executeCommand(" npm install" , sdkDir)
4346 }
4447
45- @JvmStatic
46- @AfterAll
47- fun removeTypeScriptSDK () {
48- sdkDir.deleteRecursively()
49- }
50-
5148 @JvmStatic
5249 protected fun executeCommand (command : String , workingDir : File ): String {
5350 // Prefer running TypeScript via ts-node to avoid npx network delays on CI
5451 val process = ProcessBuilder ()
55- .command(" bash" , " -c" , command)
52+ .command(" bash" , " -c" , " TYPESCRIPT_SDK_DIR=' ${sdkDir.absolutePath} ' $ command" )
5653 .directory(workingDir)
5754 .redirectErrorStream(true )
5855 .start()
@@ -126,7 +123,7 @@ abstract class TypeScriptTestBase {
126123
127124 protected fun executeCommandAllowingFailure (command : String , workingDir : File , timeoutSeconds : Long = 20): String {
128125 val process = ProcessBuilder ()
129- .command(" bash" , " -c" , command)
126+ .command(" bash" , " -c" , " TYPESCRIPT_SDK_DIR=' ${sdkDir.absolutePath} ' $ command" )
130127 .directory(workingDir)
131128 .redirectErrorStream(true )
132129 .start()
0 commit comments