feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -1,15 +1,17 @@
|
||||
/**
|
||||
* features/admin/e2e/shipping-audit.spec.ts
|
||||
* 用途:阶段 4 管理员审计中心契约冒烟——Diff/导出权限、会话工作项筛选与脱敏边界。
|
||||
* 用途:阶段 4 管理员审计中心契约冒烟——权限脱敏、Diff、关联链与哈希校验 DTO。
|
||||
* 依赖:Vitest、shipping-audit.api 类型约定。
|
||||
* 逻辑:断言列表不含快照字段;详情 Diff 仅白名单键;筛选 DTO 含 session 工作项字段。
|
||||
* 逻辑:断言列表不含快照;筛选含 Workflow/Item/Run/PDF/Case/Task;敏感脱敏字段存在。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type {
|
||||
ShippingAuditAssociationChain,
|
||||
ShippingAuditDiffRow,
|
||||
ShippingAuditEventDetail,
|
||||
ShippingAuditEventSummary,
|
||||
ShippingAuditFilters,
|
||||
ShippingAuditHashVerifyResult,
|
||||
} from '@/features/admin/api/shipping-audit.api';
|
||||
|
||||
describe('shipping audit center e2e contract', () => {
|
||||
@@ -23,6 +25,8 @@ describe('shipping audit center e2e contract', () => {
|
||||
has_snapshots: true,
|
||||
run_no: 'SNER-1',
|
||||
task_no: 'ST-1',
|
||||
workflow_id: 'WF-1',
|
||||
workflow_item_id: 'WFI-1',
|
||||
operation_id: 'op-1',
|
||||
};
|
||||
// 关键断言:列表 DTO 无 before/after 快照字段,避免误渲染正文。
|
||||
@@ -39,6 +43,7 @@ describe('shipping audit center e2e contract', () => {
|
||||
aggregate_id: 'SNER-2',
|
||||
actor_type: 'system',
|
||||
has_snapshots: true,
|
||||
sensitive_redacted: false,
|
||||
before_snapshot: { status: 'queued' },
|
||||
after_snapshot: { status: 'processing' },
|
||||
diff: [
|
||||
@@ -50,43 +55,72 @@ describe('shipping audit center e2e contract', () => {
|
||||
expect(JSON.stringify(detail)).not.toContain('https://');
|
||||
});
|
||||
|
||||
it('sensitive detail can be redacted by permission', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 4,
|
||||
event_type: 'order_review_confirmed',
|
||||
aggregate_type: 'shipping_order_review_case',
|
||||
aggregate_id: 'SRC-4',
|
||||
actor_type: 'user',
|
||||
has_snapshots: true,
|
||||
sensitivity_level: 'sensitive',
|
||||
sensitive_redacted: true,
|
||||
before_snapshot: null,
|
||||
after_snapshot: null,
|
||||
diff: [],
|
||||
};
|
||||
// 关键断言:无 audit_sensitive_read 时敏感正文脱敏。
|
||||
expect(detail.sensitive_redacted).toBe(true);
|
||||
expect(detail.before_snapshot).toBeNull();
|
||||
expect(detail.diff).toEqual([]);
|
||||
});
|
||||
|
||||
it('export disabled error code is stable for i18n', () => {
|
||||
const code = 'SHIPPING_NOTICE.AUDIT_EXPORT_FEATURE_DISABLED';
|
||||
expect(code.startsWith('SHIPPING_NOTICE.')).toBe(true);
|
||||
});
|
||||
|
||||
it('audit filters carry session work item query keys', () => {
|
||||
it('audit filters carry workflow association query keys', () => {
|
||||
const filters: ShippingAuditFilters = {
|
||||
conversation_id: 'conv-1',
|
||||
session_item_id: 'SPWI-1',
|
||||
workflow_id: 'WF-1',
|
||||
workflow_item_id: 'WFI-1',
|
||||
run_no: 'SNER-1',
|
||||
document_id: '42',
|
||||
review_case_no: 'SRC-1',
|
||||
owner_user_id: '42',
|
||||
task_no: 'ST-1',
|
||||
actor_id: '9',
|
||||
result: 'success',
|
||||
};
|
||||
// 关键断言:前端筛选 DTO 与 admin API _audit_filters_from_request 键对齐。
|
||||
expect(Object.keys(filters).sort()).toEqual([
|
||||
'conversation_id',
|
||||
'owner_user_id',
|
||||
'actor_id',
|
||||
'document_id',
|
||||
'result',
|
||||
'review_case_no',
|
||||
'session_item_id',
|
||||
'run_no',
|
||||
'task_no',
|
||||
'workflow_id',
|
||||
'workflow_item_id',
|
||||
]);
|
||||
});
|
||||
|
||||
it('detail exposes session work item context without snapshots in summary', () => {
|
||||
const detail: ShippingAuditEventDetail = {
|
||||
id: 3,
|
||||
event_type: 'session_work_item_confirmed',
|
||||
aggregate_type: 'shipping_session_pdf_work_item',
|
||||
aggregate_id: 'SPWI-3',
|
||||
actor_type: 'user',
|
||||
has_snapshots: true,
|
||||
conversation_id: 'conv-3',
|
||||
session_item_id: 'SPWI-3',
|
||||
review_case_no: 'SRC-3',
|
||||
owner_user_id: '99',
|
||||
diff: [],
|
||||
it('association chain and hash verify DTOs expose integrity fields', () => {
|
||||
const chain: ShippingAuditAssociationChain = {
|
||||
items: [],
|
||||
total: 0,
|
||||
association_keys: { workflow_id: ['WF-1'], task_no: ['ST-1'] },
|
||||
truncated: false,
|
||||
limit: 500,
|
||||
};
|
||||
expect(detail.session_item_id).toBe('SPWI-3');
|
||||
expect(detail.owner_user_id).toBe('99');
|
||||
expect('before_snapshot' in (detail as ShippingAuditEventSummary)).toBe(false);
|
||||
const verify: ShippingAuditHashVerifyResult = {
|
||||
ok: true,
|
||||
checked_chains: 3,
|
||||
failed_chains: 0,
|
||||
failures_sample: [],
|
||||
mode: 'sample',
|
||||
};
|
||||
expect(chain.association_keys.workflow_id).toEqual(['WF-1']);
|
||||
expect(verify.failed_chains).toBe(0);
|
||||
expect(verify.ok).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user