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_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 {
watchService = FileSystems.getDefault().newWatchService();
@@ -117,17 +120,6 @@ public class LocalRunnerClient extends RunnerClient {
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() {
val ctx = new WatchContext(Path.of(MCP_SERVER_PATH), watchService);
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 lombok.Data;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.jetbrains.annotations.Nullable;
import work.slhaf.partner.core.action.entity.ActionFileMetaData;
import work.slhaf.partner.core.action.entity.MetaAction;
@@ -55,11 +56,7 @@ public abstract class RunnerClient {
baseActionPath = baseActionPath == null ? DATA : baseActionPath;
this.ACTION_PATH = buildPathStr(baseActionPath, "action");
try {
Files.createDirectory(Path.of(ACTION_PATH));
} catch (IOException e) {
throw new ActionInitFailedException("目录创建失败: " + ACTION_PATH, e);
}
createPath(ACTION_PATH);
}
/**
@@ -82,7 +79,18 @@ public abstract class RunnerClient {
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 java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
@@ -16,11 +17,11 @@ public class LocalRunnerClientTest {
@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
void runOrigin() {
void testRunOrigin() {
MetaAction metaAction = buildTmpMetaAction();
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");
return metaAction;
}
@Test
void testWatch() {
// 直接等待输入然后尝试触发各种文件监听事件即可
Scanner scanner = new Scanner(System.in);
scanner.next();
}
}