2026-07-20 11:31:41 +08:00
|
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
2026-07-18 23:36:59 +08:00
|
|
|
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
2026-07-18 20:42:40 +08:00
|
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
|
|
|
|
|
|
import { App } from "./App";
|
2026-07-19 21:37:10 +08:00
|
|
|
|
import type {
|
|
|
|
|
|
ActiveSlotKind,
|
|
|
|
|
|
AssignConnectionSlotRequest,
|
2026-07-20 00:49:15 +08:00
|
|
|
|
ConnectionPolicyStatus,
|
2026-07-19 21:37:10 +08:00
|
|
|
|
ConnectionSlot,
|
|
|
|
|
|
} from "./types/connection";
|
2026-07-18 23:36:59 +08:00
|
|
|
|
import type {
|
|
|
|
|
|
ConnectionProfile,
|
|
|
|
|
|
ConnectionProfileInput,
|
|
|
|
|
|
UpdateConnectionProfileRequest,
|
|
|
|
|
|
} from "./types/profile";
|
2026-07-18 20:42:40 +08:00
|
|
|
|
|
|
|
|
|
|
vi.mock("@tauri-apps/api/core", () => ({
|
|
|
|
|
|
invoke: vi.fn(),
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
2026-07-18 23:36:59 +08:00
|
|
|
|
const bootstrapStatus = {
|
|
|
|
|
|
appVersion: "0.1.0-alpha.0",
|
|
|
|
|
|
platform: "windows",
|
|
|
|
|
|
rustCore: "ready",
|
|
|
|
|
|
protocolVersion: "desktop-v1alpha1",
|
2026-07-19 21:37:10 +08:00
|
|
|
|
databaseSchemaVersion: 3,
|
2026-07-18 23:36:59 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-07-19 21:37:10 +08:00
|
|
|
|
const emptySlots: ConnectionSlot[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
slot: "companion",
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
slot: "operations",
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2026-07-20 00:49:15 +08:00
|
|
|
|
const emptyPolicy: ConnectionPolicyStatus = {
|
|
|
|
|
|
operationsSwitchLocked: false,
|
|
|
|
|
|
activeOperationsTaskCount: 0,
|
|
|
|
|
|
duplicateServerInstanceWarnings: [],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function mockBaseCommands(options?: {
|
|
|
|
|
|
profiles?: ConnectionProfile[];
|
|
|
|
|
|
slots?: ConnectionSlot[];
|
|
|
|
|
|
policy?: ConnectionPolicyStatus;
|
|
|
|
|
|
}) {
|
|
|
|
|
|
const profiles = options?.profiles ?? [];
|
|
|
|
|
|
let slots = options?.slots ?? emptySlots;
|
|
|
|
|
|
let policy = options?.policy ?? emptyPolicy;
|
|
|
|
|
|
|
|
|
|
|
|
vi.mocked(invoke).mockImplementation(async (command, args) => {
|
|
|
|
|
|
if (command === "bootstrap_status") {
|
|
|
|
|
|
return bootstrapStatus;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_profiles") {
|
|
|
|
|
|
return profiles;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_slots") {
|
|
|
|
|
|
return slots;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "connection_policy_status") {
|
|
|
|
|
|
return policy;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "assign_connection_slot") {
|
|
|
|
|
|
const { request } = args as { request: AssignConnectionSlotRequest };
|
|
|
|
|
|
const saved: ConnectionSlot = {
|
|
|
|
|
|
slot: request.slot,
|
|
|
|
|
|
profileId: request.profileId,
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
slots = slots.map((slot) => (slot.slot === request.slot ? saved : slot));
|
|
|
|
|
|
return saved;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "clear_connection_slot") {
|
|
|
|
|
|
const { slot } = args as { slot: ActiveSlotKind };
|
|
|
|
|
|
const saved: ConnectionSlot = {
|
|
|
|
|
|
slot,
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
slots = slots.map((item) => (item.slot === slot ? saved : item));
|
|
|
|
|
|
return saved;
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error(`Unexpected command: ${command}`);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
setPolicy(next: ConnectionPolicyStatus) {
|
|
|
|
|
|
policy = next;
|
|
|
|
|
|
},
|
|
|
|
|
|
getSlots() {
|
|
|
|
|
|
return slots;
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-18 20:42:40 +08:00
|
|
|
|
describe("App", () => {
|
|
|
|
|
|
beforeEach(() => {
|
2026-07-20 00:49:15 +08:00
|
|
|
|
mockBaseCommands();
|
2026-07-18 20:42:40 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("renders the verified Rust bootstrap status", async () => {
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByText("ready")).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument();
|
2026-07-18 23:36:59 +08:00
|
|
|
|
expect(screen.getByText("连接 Profile")).toBeInTheDocument();
|
2026-07-18 20:42:40 +08:00
|
|
|
|
});
|
2026-07-18 22:17:29 +08:00
|
|
|
|
|
|
|
|
|
|
it("rejects an invalid Rust IPC payload", async () => {
|
2026-07-18 23:36:59 +08:00
|
|
|
|
vi.mocked(invoke).mockImplementation(async (command) => {
|
|
|
|
|
|
if (command === "bootstrap_status") {
|
|
|
|
|
|
return {
|
|
|
|
|
|
...bootstrapStatus,
|
|
|
|
|
|
rustCore: "unexpected",
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_profiles") {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
2026-07-19 21:37:10 +08:00
|
|
|
|
if (command === "list_connection_slots") {
|
|
|
|
|
|
return emptySlots;
|
|
|
|
|
|
}
|
2026-07-20 00:49:15 +08:00
|
|
|
|
if (command === "connection_policy_status") {
|
|
|
|
|
|
return emptyPolicy;
|
|
|
|
|
|
}
|
2026-07-18 23:36:59 +08:00
|
|
|
|
throw new Error(`Unexpected command: ${command}`);
|
2026-07-18 22:17:29 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
|
|
|
|
|
|
expect(await screen.findByText(/IPC unavailable:/)).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.queryByText("unexpected")).not.toBeInTheDocument();
|
|
|
|
|
|
});
|
2026-07-18 23:36:59 +08:00
|
|
|
|
|
|
|
|
|
|
it("creates, edits, and deletes non-sensitive profile metadata", async () => {
|
|
|
|
|
|
let profiles: ConnectionProfile[] = [];
|
|
|
|
|
|
vi.mocked(invoke).mockImplementation(async (command, args) => {
|
|
|
|
|
|
if (command === "bootstrap_status") {
|
|
|
|
|
|
return bootstrapStatus;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_profiles") {
|
|
|
|
|
|
return profiles;
|
|
|
|
|
|
}
|
2026-07-19 21:37:10 +08:00
|
|
|
|
if (command === "list_connection_slots") {
|
|
|
|
|
|
return emptySlots;
|
|
|
|
|
|
}
|
2026-07-20 00:49:15 +08:00
|
|
|
|
if (command === "connection_policy_status") {
|
|
|
|
|
|
return emptyPolicy;
|
|
|
|
|
|
}
|
2026-07-18 23:36:59 +08:00
|
|
|
|
if (command === "create_connection_profile") {
|
|
|
|
|
|
const { request } = args as { request: ConnectionProfileInput };
|
|
|
|
|
|
const created: ConnectionProfile = {
|
|
|
|
|
|
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
|
|
|
|
|
...request,
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-18 23:36:59 +08:00
|
|
|
|
createdAt: "2026-07-18T02:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-18T02:00:00Z",
|
|
|
|
|
|
};
|
|
|
|
|
|
profiles = [created];
|
|
|
|
|
|
return created;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "update_connection_profile") {
|
|
|
|
|
|
const { request } = args as {
|
|
|
|
|
|
request: UpdateConnectionProfileRequest;
|
|
|
|
|
|
};
|
|
|
|
|
|
const existing = profiles.find((profile) => profile.id === request.id);
|
|
|
|
|
|
if (!existing) {
|
|
|
|
|
|
throw new Error("Profile not found");
|
|
|
|
|
|
}
|
|
|
|
|
|
const updated: ConnectionProfile = {
|
|
|
|
|
|
...existing,
|
|
|
|
|
|
...request.profile,
|
|
|
|
|
|
updatedAt: "2026-07-18T02:10:00Z",
|
|
|
|
|
|
};
|
|
|
|
|
|
profiles = [updated];
|
|
|
|
|
|
return updated;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "delete_connection_profile") {
|
|
|
|
|
|
const { id } = args as { id: string };
|
|
|
|
|
|
profiles = profiles.filter((profile) => profile.id !== id);
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
throw new Error(`Unexpected command: ${command}`);
|
|
|
|
|
|
});
|
|
|
|
|
|
vi.spyOn(window, "confirm").mockReturnValue(true);
|
|
|
|
|
|
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("显示名称"), {
|
|
|
|
|
|
target: { value: "家庭运维" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("角色"), {
|
|
|
|
|
|
target: { value: "operations" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("REST 基础 URL"), {
|
|
|
|
|
|
target: { value: "https://ops.example.test" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByText("已创建 Profile:家庭运维"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByLabelText("编辑 家庭运维")).toBeEnabled();
|
2026-07-20 00:49:15 +08:00
|
|
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
|
|
|
|
"create_connection_profile",
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
request: expect.objectContaining({
|
|
|
|
|
|
autoConnect: false,
|
|
|
|
|
|
}),
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
2026-07-18 23:36:59 +08:00
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByLabelText("编辑 家庭运维"));
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("显示名称"), {
|
|
|
|
|
|
target: { value: "家庭运维(主)" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "更新 Profile" }));
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByText("已更新 Profile:家庭运维(主)"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
fireEvent.click(screen.getByLabelText("删除 家庭运维(主)"));
|
|
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
|
expect(
|
|
|
|
|
|
screen.getByText("已删除 Profile:家庭运维(主)"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
});
|
|
|
|
|
|
expect(screen.getByText("尚未保存 Profile。")).toBeInTheDocument();
|
|
|
|
|
|
expect(invoke).toHaveBeenCalledWith(
|
|
|
|
|
|
"create_connection_profile",
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
request: expect.not.objectContaining({
|
|
|
|
|
|
token: expect.anything(),
|
|
|
|
|
|
password: expect.anything(),
|
|
|
|
|
|
apiKey: expect.anything(),
|
|
|
|
|
|
}),
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
2026-07-19 21:37:10 +08:00
|
|
|
|
|
|
|
|
|
|
it("assigns different profiles to the two fixed slots", async () => {
|
|
|
|
|
|
const profiles: ConnectionProfile[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
|
|
|
|
|
displayName: "陪伴实例",
|
|
|
|
|
|
role: "companion",
|
|
|
|
|
|
baseUrl: "https://companion.example.test/",
|
|
|
|
|
|
authenticationType: "device-token",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-19 21:37:10 +08:00
|
|
|
|
allowInsecureHttp: false,
|
|
|
|
|
|
autoConnect: false,
|
|
|
|
|
|
createdAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: "f272aef0-0a89-4f98-b950-b2f1f309631b",
|
|
|
|
|
|
displayName: "运维实例",
|
|
|
|
|
|
role: "operations",
|
|
|
|
|
|
baseUrl: "https://operations.example.test/",
|
|
|
|
|
|
authenticationType: "api-key",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-19 21:37:10 +08:00
|
|
|
|
allowInsecureHttp: false,
|
|
|
|
|
|
autoConnect: false,
|
|
|
|
|
|
createdAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2026-07-20 00:49:15 +08:00
|
|
|
|
mockBaseCommands({ profiles });
|
|
|
|
|
|
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.change(await screen.findByLabelText("陪伴 Profile"), {
|
|
|
|
|
|
target: { value: profiles[0].id },
|
|
|
|
|
|
});
|
|
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByText("已将陪伴实例分配到陪伴槽位。"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("运维 Profile"), {
|
|
|
|
|
|
target: { value: profiles[1].id },
|
|
|
|
|
|
});
|
|
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByText("已将运维实例分配到运维槽位。"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
expect(invoke).toHaveBeenCalledWith("assign_connection_slot", {
|
|
|
|
|
|
request: {
|
|
|
|
|
|
slot: "operations",
|
|
|
|
|
|
profileId: profiles[1].id,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("saves auto-connect configuration without activating network sessions", async () => {
|
|
|
|
|
|
let profiles: ConnectionProfile[] = [];
|
2026-07-19 21:37:10 +08:00
|
|
|
|
vi.mocked(invoke).mockImplementation(async (command, args) => {
|
|
|
|
|
|
if (command === "bootstrap_status") {
|
|
|
|
|
|
return bootstrapStatus;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_profiles") {
|
|
|
|
|
|
return profiles;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (command === "list_connection_slots") {
|
2026-07-20 00:49:15 +08:00
|
|
|
|
return emptySlots;
|
2026-07-19 21:37:10 +08:00
|
|
|
|
}
|
2026-07-20 00:49:15 +08:00
|
|
|
|
if (command === "connection_policy_status") {
|
|
|
|
|
|
return emptyPolicy;
|
2026-07-19 21:37:10 +08:00
|
|
|
|
}
|
2026-07-20 00:49:15 +08:00
|
|
|
|
if (command === "create_connection_profile") {
|
|
|
|
|
|
const { request } = args as { request: ConnectionProfileInput };
|
|
|
|
|
|
const created: ConnectionProfile = {
|
|
|
|
|
|
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
|
|
|
|
|
...request,
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-20 00:49:15 +08:00
|
|
|
|
createdAt: "2026-07-19T03:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-19T03:00:00Z",
|
2026-07-19 21:37:10 +08:00
|
|
|
|
};
|
2026-07-20 00:49:15 +08:00
|
|
|
|
profiles = [created];
|
|
|
|
|
|
return created;
|
2026-07-19 21:37:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
throw new Error(`Unexpected command: ${command}`);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
render(<App />);
|
2026-07-20 00:49:15 +08:00
|
|
|
|
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
2026-07-19 21:37:10 +08:00
|
|
|
|
|
2026-07-20 00:49:15 +08:00
|
|
|
|
fireEvent.change(screen.getByLabelText("显示名称"), {
|
|
|
|
|
|
target: { value: "自动陪伴" },
|
2026-07-19 21:37:10 +08:00
|
|
|
|
});
|
2026-07-20 00:49:15 +08:00
|
|
|
|
fireEvent.change(screen.getByLabelText("角色"), {
|
|
|
|
|
|
target: { value: "companion" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("REST 基础 URL"), {
|
|
|
|
|
|
target: { value: "https://companion.example.test" },
|
2026-07-19 21:37:10 +08:00
|
|
|
|
});
|
2026-07-20 00:49:15 +08:00
|
|
|
|
fireEvent.click(
|
|
|
|
|
|
screen.getByLabelText("启动时自动连接(不会在本阶段真正建立网络会话)"),
|
|
|
|
|
|
);
|
|
|
|
|
|
fireEvent.change(screen.getByLabelText("自动连接槽位"), {
|
|
|
|
|
|
target: { value: "companion" },
|
|
|
|
|
|
});
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
|
|
|
|
|
|
2026-07-19 21:37:10 +08:00
|
|
|
|
expect(
|
2026-07-20 00:49:15 +08:00
|
|
|
|
await screen.findByText("已创建 Profile:自动陪伴"),
|
2026-07-19 21:37:10 +08:00
|
|
|
|
).toBeInTheDocument();
|
2026-07-20 00:49:15 +08:00
|
|
|
|
expect(screen.getByText("自动连接:陪伴")).toBeInTheDocument();
|
|
|
|
|
|
expect(invoke).toHaveBeenCalledWith("create_connection_profile", {
|
2026-07-19 21:37:10 +08:00
|
|
|
|
request: {
|
2026-07-20 00:49:15 +08:00
|
|
|
|
displayName: "自动陪伴",
|
|
|
|
|
|
role: "companion",
|
|
|
|
|
|
baseUrl: "https://companion.example.test",
|
|
|
|
|
|
authenticationType: "device-token",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-20 00:49:15 +08:00
|
|
|
|
allowInsecureHttp: false,
|
|
|
|
|
|
autoConnect: true,
|
|
|
|
|
|
autoConnectSlot: "companion",
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("shows duplicate server-instance warnings and locks the operations slot", async () => {
|
|
|
|
|
|
const profiles: ConnectionProfile[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
|
|
|
|
|
displayName: "陪伴实例",
|
|
|
|
|
|
role: "companion",
|
|
|
|
|
|
baseUrl: "https://companion.example.test/",
|
|
|
|
|
|
authenticationType: "device-token",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-20 00:49:15 +08:00
|
|
|
|
allowInsecureHttp: false,
|
|
|
|
|
|
autoConnect: false,
|
|
|
|
|
|
serverInstanceId: "server-shared",
|
|
|
|
|
|
createdAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: "f272aef0-0a89-4f98-b950-b2f1f309631b",
|
|
|
|
|
|
displayName: "运维实例",
|
|
|
|
|
|
role: "operations",
|
|
|
|
|
|
baseUrl: "https://operations.example.test/",
|
|
|
|
|
|
authenticationType: "api-key",
|
2026-07-20 11:31:41 +08:00
|
|
|
|
transportKind: "desktop-v1",
|
2026-07-20 00:49:15 +08:00
|
|
|
|
allowInsecureHttp: false,
|
|
|
|
|
|
autoConnect: false,
|
|
|
|
|
|
serverInstanceId: "server-shared",
|
|
|
|
|
|
createdAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
updatedAt: "2026-07-19T02:00:00Z",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
mockBaseCommands({
|
|
|
|
|
|
profiles,
|
|
|
|
|
|
slots: [
|
|
|
|
|
|
{
|
|
|
|
|
|
slot: "companion",
|
|
|
|
|
|
profileId: profiles[0].id,
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
slot: "operations",
|
|
|
|
|
|
profileId: profiles[1].id,
|
|
|
|
|
|
state: "disconnected",
|
|
|
|
|
|
unreadCount: 0,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
policy: {
|
|
|
|
|
|
operationsSwitchLocked: true,
|
|
|
|
|
|
activeOperationsTaskCount: 1,
|
|
|
|
|
|
duplicateServerInstanceWarnings: [
|
|
|
|
|
|
{
|
|
|
|
|
|
code: "duplicateServerInstance",
|
|
|
|
|
|
serverInstanceId: "server-shared",
|
|
|
|
|
|
profileIds: [profiles[0].id, profiles[1].id],
|
|
|
|
|
|
displayNames: ["陪伴实例", "运维实例"],
|
|
|
|
|
|
message:
|
|
|
|
|
|
"Multiple saved profiles point at the same server instance. Keep them separate and choose deliberately which profile to assign.",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2026-07-19 21:37:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2026-07-20 00:49:15 +08:00
|
|
|
|
|
|
|
|
|
|
render(<App />);
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
await screen.findByLabelText("重复服务器实例提示"),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
expect(
|
|
|
|
|
|
screen.getByText(/服务器实例 server-shared 被多个 Profile 引用/),
|
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
expect(screen.getByLabelText("运维 Profile")).toBeDisabled();
|
|
|
|
|
|
expect(screen.getByLabelText("陪伴 Profile")).toBeEnabled();
|
|
|
|
|
|
expect(
|
|
|
|
|
|
screen.getByText(/运维任务进行中,已锁定运维槽位切换(\s*1 个活动任务)/),
|
|
|
|
|
|
).toBeInTheDocument();
|
2026-07-19 21:37:10 +08:00
|
|
|
|
});
|
2026-07-18 20:42:40 +08:00
|
|
|
|
});
|