吸收数字员工产物访问治理

This commit is contained in:
baiyanyun
2026-06-10 10:00:34 +08:00
parent cc36d8dcaf
commit 362f397e37
18 changed files with 1016 additions and 166 deletions

View File

@@ -5,6 +5,10 @@ const mockStateService = vi.hoisted(() => ({
recordManagedServiceAction: vi.fn(),
}));
const mockArtifactAccess = vi.hoisted(() => ({
accessDigitalEmployeeArtifact: vi.fn(),
}));
const mockServiceManager = vi.hoisted(() => ({
createServiceManager: vi.fn(),
startFileServer: vi.fn(),
@@ -97,6 +101,10 @@ vi.mock("../services/digitalEmployee/skillCatalogService", () => ({
setDigitalEmployeeSkillEnabled: vi.fn(),
}));
vi.mock("../services/digitalEmployee/artifactAccessService", () => ({
accessDigitalEmployeeArtifact: mockArtifactAccess.accessDigitalEmployeeArtifact,
}));
vi.mock("../services/memory", () => ({
memoryService: {
isInitialized: () => false,
@@ -125,6 +133,7 @@ describe("digital employee managed service actions", () => {
beforeEach(() => {
vi.clearAllMocks();
mockStateService.recordManagedServiceAction.mockReturnValue({ eventId: "event-1" });
mockArtifactAccess.accessDigitalEmployeeArtifact.mockResolvedValue({ ok: true, artifact_id: "artifact-1", action: "preview" });
mockServiceManager.startFileServer.mockResolvedValue({ success: true, message: "started" });
mockServiceManager.createServiceManager.mockReturnValue({
startFileServer: mockServiceManager.startFileServer,
@@ -184,4 +193,20 @@ describe("digital employee managed service actions", () => {
result: expect.objectContaining({ error: "port busy" }),
}));
});
it("registers artifact access through the digital employee IPC boundary", async () => {
const electron = await import("electron");
const { registerDigitalEmployeeHandlers } = await import("./digitalEmployeeHandlers");
registerDigitalEmployeeHandlers(createCtx());
const calls = vi.mocked(electron.ipcMain.handle).mock.calls;
const accessCall = calls.find(([channel]) => channel === "digitalEmployee:accessArtifact");
expect(accessCall).toBeTruthy();
const handler = accessCall?.[1] as (_event: unknown, input: unknown) => Promise<unknown>;
const result = await handler({}, { artifactId: "artifact-1", action: "preview" });
expect(result).toMatchObject({ ok: true, artifact_id: "artifact-1", action: "preview" });
expect(mockArtifactAccess.accessDigitalEmployeeArtifact).toHaveBeenCalledWith({ artifactId: "artifact-1", action: "preview" });
});
});

View File

@@ -58,6 +58,10 @@ import {
listDigitalEmployeeSkillCapabilities,
setDigitalEmployeeSkillEnabled,
} from "../services/digitalEmployee/skillCatalogService";
import {
accessDigitalEmployeeArtifact,
type DigitalEmployeeArtifactAccessRequest,
} from "../services/digitalEmployee/artifactAccessService";
import { memoryService } from "../services/memory";
interface RestartManagedServiceRequest {
@@ -221,6 +225,13 @@ export function registerDigitalEmployeeHandlers(ctx: HandlerContext): void {
},
);
ipcMain.handle(
"digitalEmployee:accessArtifact",
async (_, input: DigitalEmployeeArtifactAccessRequest) => {
return accessDigitalEmployeeArtifact(input ?? {});
},
);
ipcMain.handle(
"digitalEmployee:restartManagedService",
async (_, input: RestartManagedServiceRequest) => {