feat(shipping-process-gates): 落地全门禁中断恢复并消除双真相

纳入 Execution/Gate/Attempt 模型与迁移、Worker/API/前端恢复卡片与 Admin 诊断,
Gate 阻断时清零旧 action_buttons,异常摘要统一脱敏,并为运维筛选与 Attempt Diff 补齐入口。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-01 13:08:32 +08:00
1 parent b352c281d5
commit 323928626b
92 files changed
+11930 -458

No files matched your search

@@ -28,7 +28,7 @@ const emit = defineEmits<{
refreshed: [];
}>();
const { t } = useI18n();
const { t, te } = useI18n();
const msg = useMessage();
const workflowSteps = computed(() => resolveShippingWorkflowSteps(props.detail));
@@ -42,11 +42,32 @@ const workflowItem = computed(() => props.detail.workflow_item || null);
const workflowEvents = computed(() => workflowItem.value?.events || []);
const stpFacts = computed(() => props.detail.ui_state?.summary?.stp_facts || null);
const lastActivityAt = computed(() => workflowItem.value?.last_activity_at || props.detail.updated_at || null);
const terminateReason = computed(() => workflowItem.value?.closed_reason || null);
const terminateReason = computed(() => {
const code = String(workflowItem.value?.closed_reason || '').trim();
if (!code) return null;
const key = `workspace.shippingNotice.workflowReasons.${code}`;
return te(key) ? t(key) : t('workspace.shippingNotice.timeline.updated');
});
const hasExcelArtifact = computed(() =>
Array.isArray(props.detail.export_artifacts) && props.detail.export_artifacts.length > 0,
);
/** 将内部状态映射为业务文案,未知值不回显原始状态码。 */
function workflowStatusLabel(value: unknown): string {
const code = String(value || '').trim();
if (!code) return t('workspace.shippingNotice.status.unknown');
const key = `workspace.shippingNotice.workflowStatus.${code}`;
return te(key) ? t(key) : t('workspace.shippingNotice.status.unknown');
}
const taskStatusLabel = computed(() => workflowStatusLabel(props.detail.process_status));
const taskMatchStatusLabel = computed(() => {
const code = String(props.detail.match_status || '').trim();
if (!code) return t('workspace.shippingNotice.matchStatus.unknown');
const key = `workspace.shippingNotice.matchStatus.${code}`;
return te(key) ? t(key) : t('workspace.shippingNotice.matchStatus.unknown');
});
/**
* 下载已生成的发货 Excel。
*/
@@ -84,8 +105,8 @@ async function downloadExcel() {
</div>
<div v-if="workflowItem" class="sm:col-span-2">
<dt class="text-muted">{{ $t('workspace.shippingNotice.todo.workflowItem') }}</dt>
<dd class="font-mono text-secondary">
{{ workflowItem.item_no }} · {{ workflowItem.lifecycle_status }} · {{ workflowItem.current_stage }}
<dd class="text-secondary">
{{ workflowStatusLabel(workflowItem.lifecycle_status) }} · {{ workflowStatusLabel(workflowItem.current_stage) }}
</dd>
</div>
</dl>
@@ -109,11 +130,11 @@ async function downloadExcel() {
<dl class="grid gap-3 text-sm sm:grid-cols-2">
<div>
<dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt>
<dd>{{ detail.process_status || '—' }}</dd>
<dd>{{ taskStatusLabel }}</dd>
</div>
<div>
<dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt>
<dd>{{ detail.match_status || '—' }}</dd>
<dd>{{ taskMatchStatusLabel }}</dd>
</div>
<div>
<dt class="text-muted">{{ $t('workspace.shippingNotice.fields.shipTo') }}</dt>
@@ -2,7 +2,7 @@
* features/workspace/shipping-task-center/TaskProgressTimeline.spec.ts
* 用途:锁定任务中心时间线同时消费 Task Event 与 Workflow Event。
* 依赖:Vitest、@vue/test-utils、TaskProgressTimeline。
* 逻辑:合并排序后两类事件均可见;Workflow 操作人展示 type/id。
* 逻辑:合并排序后两类事件均可见;未知内部码、操作人 ID 与 JSON 详情不展示。
*/
import { describe, expect, it } from 'vitest';
import { mount } from '@vue/test-utils';
@@ -21,8 +21,10 @@ const messages = {
empty: '暂无事件记录',
detail: '查看详情',
sourceTask: '任务事件',
sourceWorkflow: 'Workflow 事件',
workflowEvent: 'Workflow 事件',
sourceWorkflow: '文件处理记录',
workflowEvent: '文件处理记录',
updated: '处理状态已更新',
actors: { user: '业务人员', system: '系统' },
},
},
},
@@ -51,10 +53,40 @@ describe('TaskProgressTimeline', () => {
});
// 关键断言:时间线同时展示 Task 与 Workflow 事件来源标签,且 Workflow 显示操作人。
expect(wrapper.text()).toContain('任务事件');
expect(wrapper.text()).toContain('Workflow 事件');
expect(wrapper.text()).toContain('文件处理记录');
expect(wrapper.text()).toContain('任务已创建');
expect(wrapper.text()).toContain('人工上传已登记');
expect(wrapper.text()).toContain('操作者 1');
expect(wrapper.text()).toContain('操作者 user/42');
expect(wrapper.text()).toContain('操作者 业务人员');
expect(wrapper.text()).not.toContain('user/42');
expect(wrapper.text()).not.toContain('操作者 1');
});
it('does not expose unknown event codes or raw detail JSON', () => {
const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages });
const wrapper = mount(TaskProgressTimeline, {
props: {
events: [{
event_type: 'internal_task_event',
actor_id: 99,
detail_json: { node_id: 'node-1', error: 'HTTP 500' },
}],
workflowEvents: [{
seq_no: 2,
event_code: 'internal_workflow_event',
actor_type: 'worker',
actor_id: 'worker-7',
payload: { gate_code: 'quality_gate_internal' },
}],
},
global: { plugins: [i18n] },
});
const text = wrapper.text();
expect(text).toContain('处理状态已更新');
for (const technicalText of [
'internal_task_event', 'internal_workflow_event', 'node_id', 'HTTP 500',
'gate_code', 'quality_gate_internal', 'worker-7',
]) {
expect(text).not.toContain(technicalText);
}
});
});
@@ -3,7 +3,7 @@
* 用途:展示任务事件 + Workflow Event 统一时间线(只读),不发明进度百分比。
* 依赖:ShippingTaskEvent、ShippingWorkflowEvent、dateTime、vue-i18n。
* 逻辑:由 ShippingTaskWorkbench 传入 task events 与 workflow events;按时间合并排序;
* Workflow 事件操作人展示为 actor_type/actor_id。
* 未知事件与操作者内部标识统一使用通用业务文案。
*/
<script setup lang="ts">
import { computed } from 'vue';
@@ -23,18 +23,17 @@ type TimelineRow = {
label: string;
createdAt?: string | null;
actor?: string | null;
detail?: Record<string, unknown> | null;
source: 'task' | 'workflow';
};
/**
* 将任务事件类型映射为可读文案;契约外码原样展示。
* 将任务事件类型映射为可读文案;契约外码使用通用说明。
*/
function taskEventLabel(eventType: string | null | undefined): string {
const code = String(eventType || '').trim();
if (!code) return t('workspace.shippingNotice.eventTypes.system');
const key = `workspace.shippingNotice.eventTypes.${code}`;
return te(key) ? t(key) : code;
return te(key) ? t(key) : t('workspace.shippingNotice.timeline.updated');
}
/**
@@ -44,20 +43,20 @@ function workflowEventLabel(event: ShippingWorkflowEvent): string {
const code = String(event.event_code || event.message_code || event.stage_code || '').trim();
if (!code) return t('workspace.shippingNotice.timeline.workflowEvent');
const key = `workspace.shippingNotice.workflowEvents.${code}`;
return te(key) ? t(key) : code;
return te(key) ? t(key) : t('workspace.shippingNotice.timeline.updated');
}
/**
* 格式化操作人展示:优先 type/id,便于审计追溯。
* 格式化操作人展示:普通工作台只显示业务角色,不展示内部 ID。
* @param actorType - 角色(user/system/admin…)
* @param actorId - 操作者 ID 或系统标识
*/
function formatActorLabel(actorType?: string | null, actorId?: string | number | null): string | null {
const type = String(actorType || '').trim();
const id = actorId == null ? '' : String(actorId).trim();
if (type && id) return `${type}/${id}`;
if (id) return id;
if (type) return type;
const roleKey = `workspace.shippingNotice.timeline.actors.${type}`;
if (type && te(roleKey)) return t(roleKey);
if (type || id) return t('workspace.shippingNotice.timeline.actors.user');
return null;
}
@@ -67,7 +66,6 @@ const rows = computed<TimelineRow[]>(() => {
label: taskEventLabel(event.event_type),
createdAt: event.created_at,
actor: formatActorLabel(null, event.actor_id),
detail: event.detail_json || null,
source: 'task',
}));
const workflowRows: TimelineRow[] = (props.workflowEvents || []).map((event, index) => ({
@@ -75,11 +73,6 @@ const rows = computed<TimelineRow[]>(() => {
label: workflowEventLabel(event),
createdAt: event.occurred_at,
actor: formatActorLabel(event.actor_type, event.actor_id),
detail: {
...(event.payload || {}),
...(event.reason ? { reason: event.reason } : {}),
...(event.stage_code ? { stage_code: event.stage_code } : {}),
},
source: 'workflow',
}));
return [...taskRows, ...workflowRows].sort((a, b) => {
@@ -116,13 +109,6 @@ const rows = computed<TimelineRow[]>(() => {
<span class="text-muted">{{ formatLocalDateTime(row.createdAt) }}</span>
<span v-if="row.actor" class="text-muted">{{ $t('workspace.shippingNotice.operator', { id: row.actor }) }}</span>
</div>
<details
v-if="row.detail && Object.keys(row.detail).length"
class="mt-1 text-xs text-muted"
>
<summary class="cursor-pointer select-none">{{ $t('workspace.shippingNotice.timeline.detail') }}</summary>
<pre class="mt-1 whitespace-pre-wrap break-words">{{ JSON.stringify(row.detail, null, 2) }}</pre>
</details>
</div>
</section>
</template>
@@ -1,10 +1,10 @@
/**
* features/workspace/shipping-task-center/TaskTodoPanel.vue
* 用途:仅渲染后端 ui_state.action_buttons / summary.allowed_actions 对应的当前待办动作。
* 依赖:shipping.api 履约写接口、shipping-tasks.api 下载/人工上传、ManualUploadEvidenceDialog、各确认对话框。
* 逻辑:禁止按 process_status 二次推导按钮;管理员 can_handle=false 时只读;
* wait_manual_upload 允许下载 Excel + 登记人工上传凭据(禁 RPA);
* 多源阻断时对话框候选强制取 stp_facts.recovery_source_codes,禁止展示冻结全集。
* 用途:渲染统一 Gate 恢复卡片与 STP 履约待办动作(ui_state.action_buttons)。
* 依赖:ProcessGateRecoveryCard、shipping.api、shipping-tasks.api、ManualUploadEvidenceDialog。
* 逻辑:优先展示 ui_state.process_gate 阻断信息与 next_action_code;禁止按 process_status
* 二次推导门禁动作;存在 current_blocking_gate 时不渲染旧 action_buttons(Gate 唯一真相);
* 管理员 can_handle=false 时只读;无 Gate 阻断时 wait_manual_upload 允许下载 Excel + 人工上传凭据。
*/
<script setup lang="ts">
import { computed, ref } from 'vue';
@@ -32,6 +32,8 @@ import { downloadWorkspaceShippingExcelFile } from '@/features/workspace/api/shi
import { refreshShippingTodoBadge } from '@/features/workspace/composables/useShippingTodoBadge';
import InventorySourceSelectDialog from './InventorySourceSelectDialog.vue';
import ManualUploadEvidenceDialog from './ManualUploadEvidenceDialog.vue';
import ProcessGateRecoveryCard from '@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue';
import type { ShippingProcessGateUserSummary } from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
detail: ShippingTaskDetail;
@@ -56,9 +58,34 @@ const inventorySourceCandidates = ref<ShippingInventorySourceCandidate[]>([]);
const inventorySourceInitialCode = ref('');
const summary = computed(() => props.detail.ui_state?.summary || {});
const processGateSummary = computed((): ShippingProcessGateUserSummary | null =>
props.detail.ui_state?.process_gate
|| (summary.value.process_gate as ShippingProcessGateUserSummary | null | undefined)
|| null,
);
const actionButtons = computed(() => props.detail.ui_state?.action_buttons || []);
const checkpointKind = computed(() => String(props.detail.ui_state?.checkpoint_kind || ''));
const checkpoint = computed(() => String(props.detail.ui_state?.checkpoint || ''));
/** 统一 Gate 投影中的主要恢复动作;用于去重旧 action_buttons。 */
const processGateNextAction = computed(() =>
String(
processGateSummary.value?.next_action_code
|| processGateSummary.value?.current_blocking_gate?.next_action_code
|| '',
).trim(),
);
/** 有 Gate 阻断时优先展示统一投影文案。 */
const displayTodoTitle = computed(() =>
processGateSummary.value?.current_blocking_gate?.label
|| summary.value.current_todo
|| summary.value.title
|| t('workspace.shippingNotice.todo.noActionTitle'),
);
const displayTodoMessage = computed(() =>
processGateSummary.value?.blocking_message
|| summary.value.message
|| t('workspace.shippingNotice.todo.noActionMessage'),
);
/**
* 是否展示「待人工上传登记」提示。
@@ -117,12 +144,22 @@ const allowedIds = computed(() => {
if (Array.isArray(fromSummary) && fromSummary.length) return new Set(fromSummary.map(String));
return new Set(actionButtons.value.map((item) => item.id));
});
const visibleActions = computed(() =>
actionButtons.value.filter((action) => {
const hasBlockingGate = computed(() => Boolean(processGateSummary.value?.current_blocking_gate));
const visibleActions = computed(() => {
// [STEP] Gate 阻断时后端已清零 action_buttons;前端再兜底隐藏,避免双真相。
if (hasBlockingGate.value) return [];
return actionButtons.value.filter((action) => {
const id = String(action.id || '');
return allowedIds.value.has(id) && isActionAllowedForCheckpoint(id, checkpointKind.value);
}),
);
if (!allowedIds.value.has(id) || !isActionAllowedForCheckpoint(id, checkpointKind.value)) {
return false;
}
if (processGateNextAction.value && id === processGateNextAction.value) {
return false;
}
return true;
});
});
/**
* 动作成功后刷新详情并更新导航徽标。
*/
@@ -327,15 +364,29 @@ async function runAction(action: ShippingChatAction) {
}
</script>
<template>
<section class="rounded-2xl border border-brand-200/80 bg-brand-50/40 px-4 py-3">
<div class="space-y-3">
<ProcessGateRecoveryCard
:summary="processGateSummary"
:can-handle="canHandle"
:navigation-context="{
agentId: detail.owner_agent_id != null ? String(detail.owner_agent_id) : undefined,
conversationId: detail.conversation_id || undefined,
}"
@refreshed="afterSuccess"
@refresh-needed="afterSuccess"
/>
<section
v-if="!hasBlockingGate"
class="rounded-2xl border border-brand-200/80 bg-brand-50/40 px-4 py-3"
>
<div class="mb-1 text-xs font-semibold uppercase tracking-wide text-brand-700">
{{ $t('workspace.shippingNotice.todo.currentTodo') }}
</div>
<h3 class="text-sm font-semibold text-primary">
{{ summary.current_todo || summary.title || $t('workspace.shippingNotice.todo.noActionTitle') }}
{{ displayTodoTitle }}
</h3>
<p class="mt-1 text-sm text-secondary">
{{ summary.message || $t('workspace.shippingNotice.todo.noActionMessage') }}
{{ displayTodoMessage }}
</p>
<p v-if="summary.pause_reason" class="mt-1 text-xs text-amber-700">
{{ summary.pause_reason }}
@@ -398,5 +449,6 @@ async function runAction(action: ShippingChatAction) {
@confirm="onFreezeConfirm"
/>
</section>
</div>
</template>