Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -53,6 +54,10 @@ class ArthasMcpJavaSdkIT {

private static final String TARGET_METHOD_PATTERN = "hotMethod";

private static final String UPLOAD_FILE_NAME = "mcp-upload-it.class";

private static final String UPLOAD_FILE_CONTENT = "mcp-upload-it-content";

private static final List<String> EXPECTED_TOOL_NAMES = Arrays.asList(
"classloader",
"dashboard",
Expand Down Expand Up @@ -80,6 +85,7 @@ class ArthasMcpJavaSdkIT {
"thread",
"trace",
"tt",
"upload_file",
"version",
"vmoption",
"vmtool",
Expand Down Expand Up @@ -184,6 +190,20 @@ private static void assertToolSideEffects(String toolName, Environment env, Stri
return;
}

if ("upload_file".equals(toolName)) {
JsonNode node = OBJECT_MAPPER.readTree(body);
assertThat(node.path("status").asText()).isEqualTo("completed");
assertThat(node.path("fileName").asText()).isEqualTo(UPLOAD_FILE_NAME);
assertThat(node.path("reused").asBoolean()).isFalse();

Path uploadedFile = Paths.get(node.path("targetPath").asText());
assertThat(uploadedFile).isRegularFile();
assertThat(uploadedFile.getFileName().toString()).isEqualTo(UPLOAD_FILE_NAME);
assertThat(Files.readAllBytes(uploadedFile))
.containsExactly(UPLOAD_FILE_CONTENT.getBytes(StandardCharsets.UTF_8));
return;
}

if (isStreamableTool(toolName)) {
JsonNode node = OBJECT_MAPPER.readTree(body);
if (node != null && node.isObject()) {
Expand Down Expand Up @@ -268,6 +288,13 @@ private static Map<String, Object> createArgumentsForTool(String toolName, Envir
return args;
}

if ("upload_file".equals(toolName)) {
args.put("fileName", UPLOAD_FILE_NAME);
args.put("contentBase64", Base64.getEncoder().encodeToString(
UPLOAD_FILE_CONTENT.getBytes(StandardCharsets.UTF_8)));
return args;
}

if ("retransform".equals(toolName) || "redefine".equals(toolName)) {
args.put("classFilePaths", env.targetClassFile.toString());
return args;
Expand Down
Loading
Loading