test: cover master agent evolution entry wiring

This commit is contained in:
kris
2026-04-16 06:02:27 +08:00
parent 363f732e29
commit 4bedf75dc2
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package com.hyzq.boss;
import static org.junit.Assert.assertEquals;
import android.content.Intent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 34)
public class MainActivityMeEntryNavigationTest {
@Test
public void masterAgentPromptMeEntryOpensPromptActivityForMasterAgent() {
MainActivity activity = Robolectric.buildActivity(MainActivity.class).setup().get();
ReflectionHelpers.callInstanceMethod(
activity,
"openMeEntry",
ReflectionHelpers.ClassParameter.from(String.class, "master_agent_prompt")
);
Intent started = Shadows.shadowOf(activity).getNextStartedActivity();
assertEquals(MasterAgentPromptActivity.class.getName(), started.getComponent().getClassName());
assertEquals("master-agent", started.getStringExtra(MasterAgentPromptActivity.EXTRA_PROJECT_ID));
assertEquals("主 Agent", started.getStringExtra(MasterAgentPromptActivity.EXTRA_PROJECT_NAME));
}
@Test
public void masterAgentEvolutionMeEntryOpensEvolutionActivity() {
MainActivity activity = Robolectric.buildActivity(MainActivity.class).setup().get();
ReflectionHelpers.callInstanceMethod(
activity,
"openMeEntry",
ReflectionHelpers.ClassParameter.from(String.class, "master_agent_evolution")
);
Intent started = Shadows.shadowOf(activity).getNextStartedActivity();
assertEquals(MasterAgentEvolutionActivity.class.getName(), started.getComponent().getClassName());
}
}

View File

@@ -52,3 +52,21 @@ test("me page exposes master agent evolution entry", async () => {
assert.match(source, /href="\/me\/master-agent\/evolution"/, "expected me page to link evolution page");
assert.match(source, /title="主 Agent 自动进化"/, "expected me page to show evolution menu title");
});
test("master agent evolution page renders admin-aware dashboard shell", async () => {
const pageSource = await readSource("src/app/me/master-agent/evolution/page.tsx");
const clientSource = await readSource("src/components/master-agent-evolution-client.tsx");
assert.match(pageSource, /getMasterAgentEvolutionDashboard/, "expected page to load evolution dashboard server-side");
assert.match(pageSource, /session\.role === "highest_admin"/, "expected page to gate admin actions by role");
assert.match(pageSource, /<MasterAgentEvolutionClient/, "expected page to render evolution client");
assert.match(clientSource, /待处理提案/, "expected dashboard to expose pending proposals");
assert.match(clientSource, /最近信号/, "expected dashboard to expose recent signals");
assert.match(clientSource, /已生效规则/, "expected dashboard to expose applied rules");
assert.match(clientSource, /\/api\/v1\/master-agent\/evolution\/config/, "expected mode switch API to be wired");
assert.match(
clientSource,
/\/api\/v1\/master-agent\/evolution\/proposals\/\$\{proposalId\}\/\$\{action\}/,
"expected proposal review API to be wired",
);
});