吸收数字员工管理端审计诊断预览

This commit is contained in:
baiyanyun
2026-06-13 13:54:18 +08:00
parent b0f0b95c2a
commit d86f82a4c5
3 changed files with 166 additions and 1 deletions

View File

@@ -604,6 +604,101 @@ class DigitalEmployeeSyncApplicationServiceImplTest {
assertThat(result.getRecords().get(2).getBusinessView()).containsEntry("deleted_at", "2026-06-13T00:00:00+08:00");
}
@Test
void queryAdminWorkbenchAuditsReturnsAuditRowsOnly() {
when(repository.queryBusinessRecords(eq(101L), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(1L), eq(20L)))
.thenReturn(page(List.of(
record("outbox-sandbox-audit", "event", "event-audit-1", 101L, new Date(10_000),
Map.of(
"entity_type", "event",
"category", "sandbox_audit",
"kind", "sandbox_command_observed",
"status", "warn",
"level", "warn",
"title", "Sandbox 命令观察",
"operation", "shell_exec",
"summary", "命令参数已脱敏"
),
Map.of("id", "event-audit-1", "kind", "sandbox_command_observed")),
record("outbox-token-cost", "event", "event-audit-2", 101L, new Date(11_000),
Map.of(
"entity_type", "event",
"category", "token_cost",
"kind", "token_cost_recorded",
"status", "recorded",
"title", "Token 成本估算",
"model", "gpt-4.1",
"input_tokens", 120,
"output_tokens", 60,
"total_tokens", 180,
"estimated_cost_usd", 0.012
),
Map.of("id", "event-audit-2", "kind", "token_cost_recorded")),
record("outbox-tool-audit", "event", "event-audit-3", 101L, new Date(12_000),
Map.of(
"entity_type", "event",
"category", "tool_call_audit",
"kind", "tool_call_audit",
"status", "rejected",
"level", "error",
"title", "工具调用被拒绝",
"tool_name", "shell",
"server_id", "local"
),
Map.of("id", "event-audit-3", "kind", "tool_call_audit")),
record("outbox-sync-failure", "event", "event-audit-4", 101L, new Date(13_000),
Map.of(
"entity_type", "event",
"category", "sync_failure",
"kind", "digital_sync_failed",
"status", "failed",
"title", "同步失败",
"reason", "remote_timeout"
),
Map.of("id", "event-audit-4", "kind", "digital_sync_failed")),
record("outbox-governance", "event", "event-audit-5", 101L, new Date(14_000),
Map.of(
"entity_type", "event",
"category", "governance",
"kind", "governance_skip_task",
"status", "recorded",
"title", "治理命令审计",
"command_id", "command-1"
),
Map.of("id", "event-audit-5", "kind", "governance_skip_task")),
record("outbox-task", "task", "task-1", 101L, new Date(15_000),
Map.of("entity_type", "task", "title", "普通任务", "status", "running"),
Map.of("id", "task-1", "status", "running")),
record("outbox-approval", "approval", "approval-1", 101L, new Date(16_000),
Map.of("entity_type", "approval", "title", "普通审批", "status", "pending"),
Map.of("id", "approval-1", "status", "pending")),
record("outbox-notification", "notification", "notification-1", 101L, new Date(17_000),
Map.of("entity_type", "notification", "title", "普通通知", "status", "unread"),
Map.of("id", "notification-1", "status", "unread")),
record("outbox-artifact", "artifact", "artifact-1", 101L, new Date(18_000),
Map.of("entity_type", "artifact", "title", "普通产物", "status", "available"),
Map.of("id", "artifact-1", "status", "available"))
)));
DigitalEmployeeAdminWorkbenchPageDto result = service.queryAdminWorkbench(
"audits", null, null, null, null, null, null, null, null, null, null, null, 1L, 20L
);
assertThat(result.getTotal()).isEqualTo(5);
assertThat(result.getRecords()).extracting(DigitalEmployeeAdminWorkbenchRowDto::getEntityId)
.containsExactly("event-audit-1", "event-audit-2", "event-audit-3", "event-audit-4", "event-audit-5");
assertThat(result.getRecords().get(0).getView()).isEqualTo("audits");
assertThat(result.getRecords()).extracting(DigitalEmployeeAdminWorkbenchRowDto::getCategory)
.containsExactly("sandbox_audit", "token_cost", "tool_call_audit", "sync_failure", "governance");
assertThat(result.getRecords().get(0).getLevel()).isEqualTo("warn");
assertThat(result.getRecords().get(0).getSummary()).isEqualTo("命令参数已脱敏");
assertThat(result.getRecords().get(1).getBusinessView()).containsEntry("total_tokens", 180);
assertThat(result.getRecords().get(1).getBusinessView()).containsEntry("estimated_cost_usd", 0.012);
assertThat(result.getRecords().get(2).getBusinessView()).containsEntry("tool_name", "shell");
assertThat(result.getRecords().get(3).getSummary()).isEqualTo("remote_timeout");
assertThat(result.getRecords().get(4).getBusinessView()).containsEntry("command_id", "command-1");
}
@Test
void queryAdminWorkbenchAuditsRedactsSensitivePayloadFields() {
when(repository.queryBusinessRecords(eq(101L), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(1L), eq(20L)))