73 lines
3.4 KiB
TypeScript
73 lines
3.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
async function readSource(relativePath: string) {
|
|
return readFile(new URL(`../${relativePath}`, import.meta.url), "utf8");
|
|
}
|
|
|
|
test("ai accounts page refreshes when AI account state changes", async () => {
|
|
const source = await readSource("src/app/me/ai-accounts/page.tsx");
|
|
|
|
assert.match(source, /import \{ RealtimeRefresh \}/, "expected ai accounts page to import RealtimeRefresh");
|
|
assert.match(source, /<RealtimeRefresh/, "expected ai accounts page to render RealtimeRefresh");
|
|
assert.match(
|
|
source,
|
|
/events=\{\["ai_accounts\.updated"\]\}/,
|
|
"expected ai accounts page to refresh on ai_accounts.updated",
|
|
);
|
|
});
|
|
|
|
test("storage page refreshes when storage config changes", async () => {
|
|
const source = await readSource("src/app/me/storage/page.tsx");
|
|
|
|
assert.match(source, /import \{ RealtimeRefresh \}/, "expected storage page to import RealtimeRefresh");
|
|
assert.match(source, /<RealtimeRefresh/, "expected storage page to render RealtimeRefresh");
|
|
assert.match(
|
|
source,
|
|
/events=\{\["storage\.updated"\]\}/,
|
|
"expected storage page to refresh on storage.updated",
|
|
);
|
|
});
|
|
|
|
test("master agent settings pages refresh when master agent config changes", async () => {
|
|
for (const relativePath of [
|
|
"src/app/me/master-agent/page.tsx",
|
|
"src/app/me/master-agent/takeover/page.tsx",
|
|
"src/app/me/master-agent/evolution/page.tsx",
|
|
]) {
|
|
const source = await readSource(relativePath);
|
|
assert.match(source, /import \{ RealtimeRefresh \}/, `expected ${relativePath} to import RealtimeRefresh`);
|
|
assert.match(source, /<RealtimeRefresh/, `expected ${relativePath} to render RealtimeRefresh`);
|
|
assert.match(
|
|
source,
|
|
/events=\{\["master_agent\.settings\.updated"\]\}/,
|
|
`expected ${relativePath} to refresh on master_agent.settings.updated`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test("me page exposes master agent evolution entry", async () => {
|
|
const source = await readSource("src/app/me/page.tsx");
|
|
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",
|
|
);
|
|
});
|