mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
fix(runner): repair MetaAction related logic in McpMetaRegistry and tests
This commit is contained in:
@@ -99,7 +99,7 @@ public class McpMetaRegistry implements AutoCloseable {
|
||||
}
|
||||
MetaActionInfo info = existedMetaActions.get(actionKey);
|
||||
if (info != null) {
|
||||
resetMetaActionInfo(info);
|
||||
existedMetaActions.put(actionKey, resetMetaActionInfo(info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,18 +172,18 @@ public class McpMetaRegistry implements AutoCloseable {
|
||||
return root.toFile().listFiles();
|
||||
}
|
||||
|
||||
private void resetMetaActionInfo(@NotNull MetaActionInfo info) {
|
||||
info.setIo(false);
|
||||
if (info.getTags() != null) {
|
||||
info.getTags().clear();
|
||||
}
|
||||
if (info.getPreActions() != null) {
|
||||
info.getPreActions().clear();
|
||||
}
|
||||
if (info.getPostActions() != null) {
|
||||
info.getPostActions().clear();
|
||||
}
|
||||
info.setStrictDependencies(false);
|
||||
private MetaActionInfo resetMetaActionInfo(@NotNull MetaActionInfo info) {
|
||||
return new MetaActionInfo(
|
||||
false,
|
||||
info.getLauncher(),
|
||||
copyParams(info.getParams()),
|
||||
info.getDescription(),
|
||||
new LinkedHashSet<>(),
|
||||
new LinkedHashSet<>(),
|
||||
new LinkedHashSet<>(),
|
||||
false,
|
||||
copyResponseSchema(info.getResponseSchema())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,22 +192,32 @@ public class McpMetaRegistry implements AutoCloseable {
|
||||
}
|
||||
|
||||
private MetaActionInfo buildToolMetaActionInfo(McpSchema.Tool tool) {
|
||||
MetaActionInfo info = new MetaActionInfo();
|
||||
info.setDescription(tool.description());
|
||||
Map<String, Object> outputSchema = tool.outputSchema();
|
||||
info.setResponseSchema(outputSchema == null ? JSONObject.of() : JSONObject.from(outputSchema));
|
||||
info.setParams(tool.inputSchema().properties());
|
||||
|
||||
boolean io = false;
|
||||
Set<String> preActions = new LinkedHashSet<>();
|
||||
Set<String> postActions = new LinkedHashSet<>();
|
||||
boolean strictDependencies = false;
|
||||
Set<String> tags = new LinkedHashSet<>();
|
||||
Map<String, Object> meta = tool.meta();
|
||||
if (meta != null) {
|
||||
JSONObject metaJson = JSONObject.from(meta);
|
||||
info.setIo(Boolean.TRUE.equals(metaJson.getBoolean("io")));
|
||||
info.setPreActions(metaJson.getList("pre", String.class));
|
||||
info.setPostActions(metaJson.getList("post", String.class));
|
||||
info.setStrictDependencies(Boolean.TRUE.equals(metaJson.getBoolean("strict")));
|
||||
info.setTags(metaJson.getList("tag", String.class));
|
||||
io = Boolean.TRUE.equals(metaJson.getBoolean("io"));
|
||||
preActions = toOrderedSet(metaJson.getList("pre", String.class));
|
||||
postActions = toOrderedSet(metaJson.getList("post", String.class));
|
||||
strictDependencies = Boolean.TRUE.equals(metaJson.getBoolean("strict"));
|
||||
tags = toOrderedSet(metaJson.getList("tag", String.class));
|
||||
}
|
||||
return info;
|
||||
return new MetaActionInfo(
|
||||
io,
|
||||
null,
|
||||
copyParams(tool.inputSchema().properties()),
|
||||
tool.description(),
|
||||
tags,
|
||||
preActions,
|
||||
postActions,
|
||||
strictDependencies,
|
||||
outputSchema == null ? JSONObject.of() : JSONObject.from(outputSchema)
|
||||
);
|
||||
}
|
||||
|
||||
private MetaActionInfo mergeWithOriginal(String actionKey, MetaActionInfo override) {
|
||||
@@ -219,15 +229,33 @@ public class McpMetaRegistry implements AutoCloseable {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
MetaActionInfo copy = new MetaActionInfo();
|
||||
copy.setIo(source.isIo());
|
||||
copy.setParams(source.getParams() == null ? null : new HashMap<>(source.getParams()));
|
||||
copy.setDescription(source.getDescription());
|
||||
copy.setTags(source.getTags() == null ? new ArrayList<>() : new ArrayList<>(source.getTags()));
|
||||
copy.setPreActions(source.getPreActions() == null ? new ArrayList<>() : new ArrayList<>(source.getPreActions()));
|
||||
copy.setPostActions(source.getPostActions() == null ? new ArrayList<>() : new ArrayList<>(source.getPostActions()));
|
||||
copy.setStrictDependencies(source.isStrictDependencies());
|
||||
copy.setResponseSchema(source.getResponseSchema() == null ? JSONObject.of() : JSONObject.from(source.getResponseSchema()));
|
||||
return copy;
|
||||
return new MetaActionInfo(
|
||||
source.getIo(),
|
||||
source.getLauncher(),
|
||||
copyParams(source.getParams()),
|
||||
source.getDescription(),
|
||||
toOrderedSet(source.getTags()),
|
||||
toOrderedSet(source.getPreActions()),
|
||||
toOrderedSet(source.getPostActions()),
|
||||
source.getStrictDependencies(),
|
||||
copyResponseSchema(source.getResponseSchema())
|
||||
);
|
||||
}
|
||||
|
||||
private <T> LinkedHashSet<T> toOrderedSet(Collection<T> source) {
|
||||
return source == null ? new LinkedHashSet<>() : new LinkedHashSet<>(source);
|
||||
}
|
||||
|
||||
private Map<String, String> copyParams(Map<String, ?> params) {
|
||||
if (params == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> copied = new LinkedHashMap<>();
|
||||
params.forEach((key, value) -> copied.put(key, value == null ? null : String.valueOf(value)));
|
||||
return copied;
|
||||
}
|
||||
|
||||
private JSONObject copyResponseSchema(JSONObject responseSchema) {
|
||||
return responseSchema == null ? JSONObject.of() : JSONObject.from(responseSchema);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package work.slhaf.partner.core.action.runner;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -142,15 +143,17 @@ public class LocalRunnerClientTest {
|
||||
}
|
||||
|
||||
static MetaActionInfo buildMetaActionInfo(String description) {
|
||||
MetaActionInfo info = new MetaActionInfo();
|
||||
info.setIo(true);
|
||||
info.setParams(new HashMap<>());
|
||||
info.setDescription(description);
|
||||
info.setTags(new ArrayList<>(List.of("tag")));
|
||||
info.setPreActions(new ArrayList<>(List.of("pre")));
|
||||
info.setPostActions(new ArrayList<>(List.of("post")));
|
||||
info.setStrictDependencies(true);
|
||||
return info;
|
||||
return new MetaActionInfo(
|
||||
true,
|
||||
null,
|
||||
new HashMap<>(),
|
||||
description,
|
||||
new LinkedHashSet<>(List.of("tag")),
|
||||
new LinkedHashSet<>(List.of("pre")),
|
||||
new LinkedHashSet<>(List.of("post")),
|
||||
true,
|
||||
new JSONObject()
|
||||
);
|
||||
}
|
||||
|
||||
static String buildCommonMcpConfig(String... serverEntries) {
|
||||
@@ -181,6 +184,7 @@ public class LocalRunnerClientTest {
|
||||
MetaAction metaAction = new MetaAction(
|
||||
name,
|
||||
false,
|
||||
null,
|
||||
type,
|
||||
location
|
||||
);
|
||||
@@ -402,8 +406,8 @@ public class LocalRunnerClientTest {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertEquals("v1", info.getDescription());
|
||||
Assertions.assertTrue(info.isIo());
|
||||
Assertions.assertTrue(info.isStrictDependencies());
|
||||
Assertions.assertTrue(info.getIo());
|
||||
Assertions.assertTrue(info.getStrictDependencies());
|
||||
Assertions.assertFalse(info.getTags().isEmpty());
|
||||
|
||||
writeDescMcpJson(descDir, actionKey, "v2");
|
||||
@@ -419,16 +423,16 @@ public class LocalRunnerClientTest {
|
||||
waitForCondition(() -> {
|
||||
MetaActionInfo current = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
return current != null
|
||||
&& !current.isIo()
|
||||
&& !current.isStrictDependencies()
|
||||
&& !current.getIo()
|
||||
&& !current.getStrictDependencies()
|
||||
&& current.getTags().isEmpty()
|
||||
&& current.getPreActions().isEmpty()
|
||||
&& current.getPostActions().isEmpty();
|
||||
}, 2000);
|
||||
info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertFalse(info.isIo());
|
||||
Assertions.assertFalse(info.isStrictDependencies());
|
||||
Assertions.assertFalse(info.getIo());
|
||||
Assertions.assertFalse(info.getStrictDependencies());
|
||||
Assertions.assertTrue(info.getTags().isEmpty());
|
||||
Assertions.assertTrue(info.getPreActions().isEmpty());
|
||||
Assertions.assertTrue(info.getPostActions().isEmpty());
|
||||
@@ -453,16 +457,16 @@ public class LocalRunnerClientTest {
|
||||
waitForCondition(() -> {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
return info != null
|
||||
&& !info.isIo()
|
||||
&& !info.isStrictDependencies()
|
||||
&& !info.getIo()
|
||||
&& !info.getStrictDependencies()
|
||||
&& info.getTags().isEmpty()
|
||||
&& info.getPreActions().isEmpty()
|
||||
&& info.getPostActions().isEmpty();
|
||||
}, 2000);
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertFalse(info.isIo());
|
||||
Assertions.assertFalse(info.isStrictDependencies());
|
||||
Assertions.assertFalse(info.getIo());
|
||||
Assertions.assertFalse(info.getStrictDependencies());
|
||||
Assertions.assertTrue(info.getTags().isEmpty());
|
||||
Assertions.assertTrue(info.getPreActions().isEmpty());
|
||||
Assertions.assertTrue(info.getPostActions().isEmpty());
|
||||
@@ -475,8 +479,8 @@ public class LocalRunnerClientTest {
|
||||
info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertEquals("fixed", info.getDescription());
|
||||
Assertions.assertTrue(info.isIo());
|
||||
Assertions.assertTrue(info.isStrictDependencies());
|
||||
Assertions.assertTrue(info.getIo());
|
||||
Assertions.assertTrue(info.getStrictDependencies());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
@@ -501,7 +505,7 @@ public class LocalRunnerClientTest {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertEquals("base", info.getDescription());
|
||||
Assertions.assertTrue(info.isIo());
|
||||
Assertions.assertTrue(info.getIo());
|
||||
Assertions.assertEquals(1, existedMetaActions.size());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
@@ -545,16 +549,16 @@ public class LocalRunnerClientTest {
|
||||
waitForCondition(() -> {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
return info != null
|
||||
&& !info.isIo()
|
||||
&& !info.isStrictDependencies()
|
||||
&& !info.getIo()
|
||||
&& !info.getStrictDependencies()
|
||||
&& info.getTags().isEmpty()
|
||||
&& info.getPreActions().isEmpty()
|
||||
&& info.getPostActions().isEmpty();
|
||||
}, 2000);
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
Assertions.assertNotNull(info);
|
||||
Assertions.assertFalse(info.isIo());
|
||||
Assertions.assertFalse(info.isStrictDependencies());
|
||||
Assertions.assertFalse(info.getIo());
|
||||
Assertions.assertFalse(info.getStrictDependencies());
|
||||
Assertions.assertTrue(info.getTags().isEmpty());
|
||||
Assertions.assertTrue(info.getPreActions().isEmpty());
|
||||
Assertions.assertTrue(info.getPostActions().isEmpty());
|
||||
@@ -585,8 +589,8 @@ public class LocalRunnerClientTest {
|
||||
waitForCondition(() -> {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
return info != null
|
||||
&& !info.isIo()
|
||||
&& !info.isStrictDependencies()
|
||||
&& !info.getIo()
|
||||
&& !info.getStrictDependencies()
|
||||
&& info.getTags().isEmpty()
|
||||
&& info.getPreActions().isEmpty()
|
||||
&& info.getPostActions().isEmpty();
|
||||
@@ -628,8 +632,8 @@ public class LocalRunnerClientTest {
|
||||
waitForCondition(() -> {
|
||||
MetaActionInfo info = getMetaActionInfo(existedMetaActions, actionKey);
|
||||
return info != null
|
||||
&& !info.isIo()
|
||||
&& !info.isStrictDependencies()
|
||||
&& !info.getIo()
|
||||
&& !info.getStrictDependencies()
|
||||
&& info.getTags().isEmpty()
|
||||
&& info.getPreActions().isEmpty()
|
||||
&& info.getPostActions().isEmpty();
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package work.slhaf.partner.core.action.runner;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import work.slhaf.partner.core.action.entity.ActionFileMetaData;
|
||||
import work.slhaf.partner.core.action.entity.MetaAction;
|
||||
import work.slhaf.partner.core.action.entity.MetaActionInfo;
|
||||
@@ -36,10 +34,5 @@ public class RunnerClientTest {
|
||||
public void persistSerialize(MetaActionInfo metaActionInfo, ActionFileMetaData fileMetaData) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject listSysDependencies() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package work.slhaf.partner.module.modules.action.builtin;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import work.slhaf.partner.core.action.ActionCapability;
|
||||
@@ -12,6 +13,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -34,10 +36,17 @@ class BuiltinActionRegistryTest {
|
||||
}
|
||||
|
||||
private static MetaActionInfo buildMetaActionInfo(String description) {
|
||||
MetaActionInfo info = new MetaActionInfo();
|
||||
info.setDescription(description);
|
||||
info.setParams(new HashMap<>());
|
||||
return info;
|
||||
return new MetaActionInfo(
|
||||
false,
|
||||
null,
|
||||
new HashMap<>(),
|
||||
description,
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
false,
|
||||
new JSONObject()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.*;
|
||||
@@ -77,12 +78,17 @@ class ActionExecutorTest {
|
||||
lenient().when(memoryCapability.getActivatedSlices()).thenReturn(Collections.emptyList());
|
||||
lenient().when(actionCapability.putPhaserRecord(any(Phaser.class), any(ExecutableAction.class)))
|
||||
.thenAnswer(inv -> new PhaserRecord(inv.getArgument(0), inv.getArgument(1)));
|
||||
lenient().when(actionCapability.loadMetaActionInfo(anyString())).thenAnswer(inv -> {
|
||||
MetaActionInfo info = new MetaActionInfo();
|
||||
info.setDescription("desc");
|
||||
info.setParams(Collections.emptyMap());
|
||||
return info;
|
||||
});
|
||||
lenient().when(actionCapability.loadMetaActionInfo(anyString())).thenAnswer(inv -> new MetaActionInfo(
|
||||
false,
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
"desc",
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
false,
|
||||
new JSONObject()
|
||||
));
|
||||
CorrectorResult correctorResult = new CorrectorResult();
|
||||
correctorResult.setMetaInterventionList(Collections.emptyList());
|
||||
lenient().when(actionCorrector.execute(any())).thenReturn(correctorResult);
|
||||
@@ -385,6 +391,7 @@ class ActionExecutorTest {
|
||||
return new MetaAction(
|
||||
name,
|
||||
io,
|
||||
null,
|
||||
MetaAction.Type.ORIGIN,
|
||||
"location"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user