fix(LocalRunnerClient): correct path creating logic in RunnerClient and its implementations

This commit is contained in:
2026-01-11 16:47:14 +08:00
parent cdb6ae9d01
commit abec141e4e
3 changed files with 28 additions and 20 deletions

View File

@@ -104,7 +104,10 @@ public class LocalRunnerClient extends RunnerClient {
this.MCP_SERVER_PATH = buildPathStr(ACTION_PATH, "mcp"); this.MCP_SERVER_PATH = buildPathStr(ACTION_PATH, "mcp");
this.MCP_DESC_PATH = buildPathStr(MCP_SERVER_PATH, "desc"); this.MCP_DESC_PATH = buildPathStr(MCP_SERVER_PATH, "desc");
createPaths(); createPath(TMP_ACTION_PATH);
createPath(DYNAMIC_ACTION_PATH);
createPath(MCP_SERVER_PATH);
createPath(MCP_DESC_PATH);
try { try {
watchService = FileSystems.getDefault().newWatchService(); watchService = FileSystems.getDefault().newWatchService();
@@ -117,17 +120,6 @@ public class LocalRunnerClient extends RunnerClient {
setupShutdownHook(); setupShutdownHook();
} }
private void createPaths() {
try {
Files.createDirectory(Path.of(TMP_ACTION_PATH));
Files.createDirectory(Path.of(DYNAMIC_ACTION_PATH));
Files.createDirectory(Path.of(MCP_SERVER_PATH));
Files.createDirectory(Path.of(MCP_DESC_PATH));
} catch (IOException e) {
throw new ActionInitFailedException("目录创建失败: " + e);
}
}
private void registerCommonMcp() { private void registerCommonMcp() {
val ctx = new WatchContext(Path.of(MCP_SERVER_PATH), watchService); val ctx = new WatchContext(Path.of(MCP_SERVER_PATH), watchService);
val common = new LocalWatchEventProcessor.Common(existedMetaActions, mcpClients, ctx); val common = new LocalWatchEventProcessor.Common(existedMetaActions, mcpClients, ctx);

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
import io.modelcontextprotocol.server.McpStatelessAsyncServer; import io.modelcontextprotocol.server.McpStatelessAsyncServer;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import work.slhaf.partner.core.action.entity.ActionFileMetaData; import work.slhaf.partner.core.action.entity.ActionFileMetaData;
import work.slhaf.partner.core.action.entity.MetaAction; import work.slhaf.partner.core.action.entity.MetaAction;
@@ -55,11 +56,7 @@ public abstract class RunnerClient {
baseActionPath = baseActionPath == null ? DATA : baseActionPath; baseActionPath = baseActionPath == null ? DATA : baseActionPath;
this.ACTION_PATH = buildPathStr(baseActionPath, "action"); this.ACTION_PATH = buildPathStr(baseActionPath, "action");
try { createPath(ACTION_PATH);
Files.createDirectory(Path.of(ACTION_PATH));
} catch (IOException e) {
throw new ActionInitFailedException("目录创建失败: " + ACTION_PATH, e);
}
} }
/** /**
@@ -82,7 +79,18 @@ public abstract class RunnerClient {
public abstract void tmpSerialize(MetaAction tempAction, String code, String codeType) throws IOException; public abstract void tmpSerialize(MetaAction tempAction, String code, String codeType) throws IOException;
public abstract void persistSerialize(MetaActionInfo metaActionInfo, McpData mcpData); public abstract void persistSerialize(MetaActionInfo metaActionInfo, ActionFileMetaData fileMetaData);
protected void createPath(String pathStr) {
val path = Path.of(pathStr);
try {
Files.createDirectory(path);
} catch (IOException e) {
if (!Files.exists(path)) {
throw new ActionInitFailedException("目录创建失败: " + pathStr, e);
}
}
}
/** /**
* 列出执行环境下的系统依赖情况 * 列出执行环境下的系统依赖情况

View File

@@ -7,6 +7,7 @@ import work.slhaf.partner.core.action.entity.MetaAction;
import work.slhaf.partner.core.action.entity.MetaActionType; import work.slhaf.partner.core.action.entity.MetaActionType;
import java.util.Map; import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -16,11 +17,11 @@ public class LocalRunnerClientTest {
@BeforeAll @BeforeAll
static void beforeAll() { static void beforeAll() {
runnerClient = new LocalRunnerClient(new ConcurrentHashMap<>(), Executors.newVirtualThreadPerTaskExecutor(), "/home/slhaf/Projects/IdeaProjects/Projects/Partner/Partner-Main/src/test/java/resources/action/data"); runnerClient = new LocalRunnerClient(new ConcurrentHashMap<>(), Executors.newVirtualThreadPerTaskExecutor(), "/home/slhaf/Projects/IdeaProjects/Projects/Partner/Partner-Main/src/test/java/resources/action");
} }
@Test @Test
void runOrigin() { void testRunOrigin() {
MetaAction metaAction = buildTmpMetaAction(); MetaAction metaAction = buildTmpMetaAction();
RunnerClient.RunnerResponse runnerResponse = runnerClient.doRun(metaAction); RunnerClient.RunnerResponse runnerResponse = runnerClient.doRun(metaAction);
@@ -36,4 +37,11 @@ public class LocalRunnerClientTest {
metaAction.setLocation("/home/slhaf/Projects/IdeaProjects/Projects/Partner/Partner-Main/src/test/java/resources/action/tmp/hello_world.py"); metaAction.setLocation("/home/slhaf/Projects/IdeaProjects/Projects/Partner/Partner-Main/src/test/java/resources/action/tmp/hello_world.py");
return metaAction; return metaAction;
} }
@Test
void testWatch() {
// 直接等待输入然后尝试触发各种文件监听事件即可
Scanner scanner = new Scanner(System.in);
scanner.next();
}
} }