统一 Case/Progress 阶段 label_key、修复 Job 成功未推进 OT 的可重试失败投影与写路径,并落地 OT 后行级匹配/波次履约与版面诊断开关。 Co-authored-by: Cursor <cursoragent@cursor.com>
156 lines
5.4 KiB
TypeScript
156 lines
5.4 KiB
TypeScript
/**
|
|
* features/shipping-process-gates/components/ProcessGateRecoveryCard.spec.ts
|
|
* 用途:验证待处理事项卡片不展示未知内部编号和技术诊断文本;审计缓存随 Execution 切换清空。
|
|
* 依赖:Vitest、Vue Test Utils、vue-i18n、process-gates.api mock。
|
|
* 逻辑:构造未知环节/动作/技术自由文本;断言业务文案与审计 i18n;切换 execution_no 后清空审计。
|
|
*/
|
|
import { flushPromises, mount } from '@vue/test-utils';
|
|
import { createI18n } from 'vue-i18n';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import workspaceZhCn from '@/locales/zh-CN/workspace.json';
|
|
import ProcessGateRecoveryCard from './ProcessGateRecoveryCard.vue';
|
|
import type { ShippingProcessGateUserSummary } from '../types/process-gate.types';
|
|
|
|
const listAuditMock = vi.fn();
|
|
|
|
vi.mock('../api/process-gates.api', () => ({
|
|
listWorkspaceProcessGateAuditEvents: (...args: unknown[]) => listAuditMock(...args),
|
|
postWorkspaceProcessGateAction: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('vue-router', () => ({
|
|
useRouter: () => ({ push: vi.fn() }),
|
|
}));
|
|
|
|
vi.mock('@/shared/composables/useMessage', () => ({
|
|
useMessage: () => ({
|
|
success: vi.fn(),
|
|
warning: vi.fn(),
|
|
error: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'zh-CN',
|
|
messages: { 'zh-CN': { workspace: workspaceZhCn } },
|
|
});
|
|
|
|
function baseSummary(overrides: Partial<ShippingProcessGateUserSummary> = {}): ShippingProcessGateUserSummary {
|
|
return {
|
|
execution_no: 'EXEC-1',
|
|
status: 'blocked',
|
|
current_blocking_gate: {
|
|
gate_code: 'auto_build_gate_quality_gate_passed',
|
|
label: 'quality_gate_internal',
|
|
status: 'blocked',
|
|
sequence_no: 1,
|
|
evaluation_version: 1,
|
|
blocking_reason_code: 'internal_reason_code',
|
|
next_action_code: 'internal_retry_action',
|
|
},
|
|
blocking_message: 'HTTP 500 error: node_id=abc',
|
|
diagnostic_hint: 'traceback: C:\\service\\worker.py',
|
|
responsible_party: 'owner',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('ProcessGateRecoveryCard', () => {
|
|
beforeEach(() => {
|
|
listAuditMock.mockReset();
|
|
listAuditMock.mockResolvedValue({
|
|
items: [
|
|
{
|
|
id: 1,
|
|
event_type: 'process_gate_attempt_started',
|
|
created_at: '2026-08-01T00:00:00Z',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('does not expose internal gate, action or diagnostic text', () => {
|
|
const wrapper = mount(ProcessGateRecoveryCard, {
|
|
props: { summary: baseSummary(), canHandle: true },
|
|
global: { plugins: [i18n] },
|
|
});
|
|
const text = wrapper.text();
|
|
expect(text).toContain('当前处理环节');
|
|
expect(text).toContain('当前步骤');
|
|
expect(text).toContain('继续处理');
|
|
expect(text).toContain('当前步骤需要人工处理');
|
|
expect(text).toContain('责任方');
|
|
expect(text).toContain('订单复核 / 任务负责人');
|
|
expect(text).toContain('查看审计');
|
|
for (const technicalText of [
|
|
'auto_build_gate_quality_gate_passed', 'quality_gate_internal', 'internal_reason_code',
|
|
'internal_retry_action', 'HTTP 500', 'node_id', 'traceback', 'worker.py',
|
|
]) {
|
|
expect(text).not.toContain(technicalText);
|
|
}
|
|
});
|
|
|
|
it('hides the card for system worker / technical_auto_only waits', () => {
|
|
const wrapper = mount(ProcessGateRecoveryCard, {
|
|
props: {
|
|
summary: baseSummary({
|
|
technical_auto_only: true,
|
|
owner_type: 'system',
|
|
responsible_party: 'worker',
|
|
next_action_code: 'retry_inventory_preparation',
|
|
}),
|
|
canHandle: false,
|
|
},
|
|
global: { plugins: [i18n] },
|
|
});
|
|
expect(wrapper.find('[data-testid="process-gate-recovery-card"]').exists()).toBe(false);
|
|
expect(wrapper.text()).not.toContain('待处理事项');
|
|
});
|
|
|
|
it('hides the card when responsible_party is worker without owner_type', () => {
|
|
const wrapper = mount(ProcessGateRecoveryCard, {
|
|
props: {
|
|
summary: baseSummary({
|
|
responsible_party: 'worker',
|
|
owner_type: undefined,
|
|
technical_auto_only: false,
|
|
}),
|
|
canHandle: false,
|
|
},
|
|
global: { plugins: [i18n] },
|
|
});
|
|
expect(wrapper.find('[data-testid="process-gate-recovery-card"]').exists()).toBe(false);
|
|
});
|
|
|
|
it('maps audit event codes to business labels and clears cache on execution change', async () => {
|
|
const wrapper = mount(ProcessGateRecoveryCard, {
|
|
props: { summary: baseSummary({ execution_no: 'EXEC-1' }), canHandle: true },
|
|
global: { plugins: [i18n] },
|
|
});
|
|
|
|
await wrapper.get('[data-testid="process-gate-view-audit"]').trigger('click');
|
|
await flushPromises();
|
|
expect(listAuditMock).toHaveBeenCalledWith('EXEC-1', 1, 20);
|
|
expect(wrapper.text()).toContain('开始执行处理');
|
|
expect(wrapper.text()).not.toContain('process_gate_attempt_started');
|
|
|
|
listAuditMock.mockResolvedValue({
|
|
items: [
|
|
{
|
|
id: 2,
|
|
event_type: 'process_gate_blocked',
|
|
created_at: '2026-08-01T01:00:00Z',
|
|
},
|
|
],
|
|
});
|
|
await wrapper.setProps({ summary: baseSummary({ execution_no: 'EXEC-2' }) });
|
|
await flushPromises();
|
|
expect(wrapper.text()).not.toContain('开始执行处理');
|
|
await wrapper.get('[data-testid="process-gate-view-audit"]').trigger('click');
|
|
await flushPromises();
|
|
expect(listAuditMock).toHaveBeenCalledWith('EXEC-2', 1, 20);
|
|
expect(wrapper.text()).toContain('处理环节已阻断');
|
|
});
|
|
});
|