吸收数字员工管理端低风险动作闭环
This commit is contained in:
@@ -650,6 +650,73 @@ describe("digital employee sync service", () => {
|
||||
]));
|
||||
});
|
||||
|
||||
it("pulls low-risk admin actions, applies them locally, and reports results", async () => {
|
||||
mockState.fetch
|
||||
.mockResolvedValueOnce(jsonResponse({
|
||||
success: true,
|
||||
data: {
|
||||
records: [
|
||||
{
|
||||
id: 10,
|
||||
entity_type: "artifact",
|
||||
entity_id: "artifact-1",
|
||||
action: "mark_expire",
|
||||
request_payload: { reason: "管理端标记到期" },
|
||||
},
|
||||
],
|
||||
},
|
||||
}))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true, data: { ok: true } }));
|
||||
|
||||
const { pullAndApplyDigitalEmployeeAdminActions } = await import("./syncService");
|
||||
const result = await pullAndApplyDigitalEmployeeAdminActions({ force: true });
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
endpoint: "https://manage.example.com/api/digital-employee/admin/actions/pending?device_id=device-001",
|
||||
applied: 1,
|
||||
rejected: 0,
|
||||
failed: 0,
|
||||
ignored: 0,
|
||||
});
|
||||
expect(mockState.fetch).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"https://manage.example.com/api/digital-employee/admin/actions/pending?device_id=device-001",
|
||||
expect.objectContaining({ method: "GET" }),
|
||||
);
|
||||
expect(mockState.fetch).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"https://manage.example.com/api/digital-employee/admin/actions/10/result",
|
||||
expect.objectContaining({ method: "POST", body: expect.stringContaining("admin_action_applied") }),
|
||||
);
|
||||
expect(Array.from(mockState.db?.events.values() ?? [])).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ kind: "artifact_retention_marked" }),
|
||||
expect.objectContaining({ kind: "admin_action_applied" }),
|
||||
]));
|
||||
});
|
||||
|
||||
it("rejects high-risk admin actions without changing local facts", async () => {
|
||||
mockState.fetch
|
||||
.mockResolvedValueOnce(jsonResponse({
|
||||
success: true,
|
||||
data: { records: [{ id: 11, entity_type: "artifact", entity_id: "artifact-1", action: "cleanup_file_batch" }] },
|
||||
}))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true, data: { ok: true } }));
|
||||
|
||||
const { pullAndApplyDigitalEmployeeAdminActions } = await import("./syncService");
|
||||
const result = await pullAndApplyDigitalEmployeeAdminActions({ force: true });
|
||||
|
||||
expect(result).toMatchObject({ ok: true, applied: 0, rejected: 1, failed: 0 });
|
||||
expect(mockState.fetch).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"https://manage.example.com/api/digital-employee/admin/actions/11/result",
|
||||
expect.objectContaining({ method: "POST", body: expect.stringContaining("admin_action_rejected") }),
|
||||
);
|
||||
expect(Array.from(mockState.db?.events.values() ?? [])).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ kind: "admin_action_rejected" }),
|
||||
]));
|
||||
});
|
||||
|
||||
it.each([
|
||||
["skillPolicies"],
|
||||
["policies"],
|
||||
|
||||
Reference in New Issue
Block a user