feat: move global takeover into master-agent menu

This commit is contained in:
kris
2026-04-05 08:52:21 +08:00
parent 2a5962f767
commit 7cc33d391b
7 changed files with 228 additions and 51 deletions

View File

@@ -54,8 +54,7 @@ public class MasterAgentPromptActivityTest {
.put("userPrompt", new JSONObject().put("content", "用户私有主提示词"))
.put("projectControls", new JSONObject()
.put("promptOverride", "当前对话提示词")
.put("backendOverride", "claw-runtime")
.put("globalTakeoverEnabled", true));
.put("backendOverride", "claw-runtime"));
ReflectionHelpers.callInstanceMethod(
activity,
@@ -69,7 +68,6 @@ public class MasterAgentPromptActivityTest {
assertTrue(viewTreeContainsText(content, "用户私有主提示词"));
assertTrue(viewTreeContainsText(content, "当前对话提示词"));
assertTrue(viewTreeContainsText(content, "执行后端"));
assertTrue(viewTreeContainsText(content, "全局主 Agent 协同接管"));
assertTrue(viewTreeContainsText(content, "合成预览"));
}
@@ -286,17 +284,6 @@ public class MasterAgentPromptActivityTest {
// JVM 单测不需要落 Android 侧身份缓存。
}
@Override
public ApiResponse updateProjectTakeoverSettings(String projectId, Boolean takeoverEnabled, Boolean globalTakeoverEnabled) {
try {
return new ApiResponse(
200,
new JSONObject().put("ok", true)
);
} catch (Exception error) {
throw new IllegalStateException(error);
}
}
}
private static final class InMemorySharedPreferences implements android.content.SharedPreferences {

View File

@@ -0,0 +1,65 @@
package com.hyzq.boss;
import static org.junit.Assert.assertTrue;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 34)
public class MasterAgentTakeoverActivityTest {
@Test
public void renderTakeoverSettingsShowsStandaloneGlobalTakeoverSection() throws Exception {
MasterAgentTakeoverActivity activity = Robolectric
.buildActivity(
MasterAgentTakeoverActivity.class,
new Intent()
.putExtra(MasterAgentTakeoverActivity.EXTRA_PROJECT_ID, "master-agent")
.putExtra(MasterAgentTakeoverActivity.EXTRA_PROJECT_NAME, "主 Agent")
)
.setup()
.get();
JSONObject payload = new JSONObject()
.put("controls", new JSONObject().put("globalTakeoverEnabled", true));
ReflectionHelpers.callInstanceMethod(
activity,
"renderTakeoverSettings",
ReflectionHelpers.ClassParameter.from(JSONObject.class, payload)
);
View content = activity.findViewById(R.id.screen_content);
assertTrue(viewTreeContainsText(content, "全局主 Agent 协同接管"));
assertTrue(viewTreeContainsText(content, "线程会话默认跟随全局协同推进"));
}
private static boolean viewTreeContainsText(View root, String expectedText) {
if (root instanceof TextView) {
CharSequence text = ((TextView) root).getText();
if (text != null && text.toString().contains(expectedText)) {
return true;
}
}
if (!(root instanceof ViewGroup)) {
return false;
}
ViewGroup group = (ViewGroup) root;
for (int index = 0; index < group.getChildCount(); index += 1) {
if (viewTreeContainsText(group.getChildAt(index), expectedText)) {
return true;
}
}
return false;
}
}

View File

@@ -44,10 +44,11 @@ public class ProjectDetailActivityMasterAgentMenuTest {
assertMenuItem(listView, 0, "模型");
assertMenuItem(listView, 1, "推理强度");
assertMenuItem(listView, 2, "提示词");
assertMenuItem(listView, 3, "记忆");
assertMenuItem(listView, 4, "会话信息");
assertMenuItem(listView, 5, "刷新");
assertMenuItem(listView, 2, "全局接管");
assertMenuItem(listView, 3, "提示词");
assertMenuItem(listView, 4, "记忆");
assertMenuItem(listView, 5, "会话信息");
assertMenuItem(listView, 6, "刷新");
}
@Test