diff --git a/docs/b04-12-source-review-integration.md b/docs/b04-12-source-review-integration.md
new file mode 100644
index 0000000..241f422
--- /dev/null
+++ b/docs/b04-12-source-review-integration.md
@@ -0,0 +1,34 @@
+# B04-12 旧主图独立新来源复核
+
+## 接入范围
+
+依据后端 dev 的 b04-12-primary-source-review-frontend-prompt.md、公开 shot-keyframe-source-review.md、正式 Router、SourceVisionApprovalSchema 和 service 实现。仅修改前端,未调用真实 Provider。
+
+首帧卡片中的“按当前来源人工复核”适用于已完成 Primary,即使原来源过期仍可免费预检。复用 AppDrawer 固定底栏、内容滚动、NMessage、现有项目范围 WorkflowExecution/SSE 和正式分页执行历史。
+
+- 原图、原件 SHA、原始 Provider 输入、旧 Vision、sourceChanges 与当前参考分开显示;新参考保留全部 bindings,不冒充原生成输入。
+- 每张物理参考逐项填写身份、结构、空间、动作、连续性;初始全部 unknown,不推断门轴,不将开关门当固定结构变化。
+- 人工保存绑定 expectedFingerprint、真实审核人、理由和全部观察;保存后回读原记录,原 status、原观察与当前 reviewStatus/current 分开。
+- 只有当前且 passed 的人工记录才读取免费机器计划;原图和计划的所有指纹、模型、全部步骤可审阅。
+- 费用批准独立登记。真实批准人、操作人、批准材料 SHA、CNY 范围均由用户填写;maxRequests 严格等于步骤数。更改范围撤销旧授权。
+- 执行必须再次明确确认,携带本次 authorizationId;恢复只携带正式历史提供的原 task ID 和 request fingerprint。未知费用不提供恢复。
+- 202 复用已有观察器;200 复用完整结果(含失败)。并发和断线沿用同候选提交保护,不自动重试、换模型或生图。
+- sourceReviewId 标识独立审核,按原 validationTaskId 展开完整执行历史;旧 Vision 的通过不显示为新来源通过。原 Primary 不被修改,仍需独立三镜/Production 验收。
+- 关闭、项目/镜头/候选切换取消免费查询,拒绝旧结果;人工回读先比对当前主图预检指纹,避免引用其他主图记录。
+
+## 浏览器验收
+
+自动化检查通过:105 个测试文件、782 项测试;lint、格式检查、类型检查和生产构建通过。新增 8 项来源审核测试,覆盖默认未知、明确批准、参数变更、范围切换、并发、断线保护、失败复用及真实组件的只读打开行为。
+
+复用 localhost:4312 已有 Chrome 项目标签,真实操作全部为只读:
+
+- 2.1 人工记录显示人工来源观察通过;免费机器计划显示 qwen3.8-max、general/physical 两步。批准人、批准材料和金额无默认值,没有发起授权或 Vision。
+- 2.2 保留原 insufficient_evidence,展示 needs_review,机器计划入口禁用。
+- 原图与本次参考分区、逐图初始未知、旧 Vision 不冒充新来源、桌面和 375×667 内容滚动/固定底栏已核对。
+- 未提交人工观察、未签发真实费用批准、未执行模型、未改原 Primary 或旧 Vision。
+
+## 已知契约边界
+
+- 当前没有按首帧列出人工来源记录的接口,已有人工记录需输入真实 reviewId 回读;新机器任务的 sourceReviewId 可从正式审核历史追溯。不使用本机历史缓存补齐列表。
+- 人工记录 GET 未返回 shotId/keyframeId,页面用当前主图免费预检与原 expectedFingerprint 交叉核对,不匹配的原记录仅供追溯。
+- 当前计划不提供报价,金额及批准摘要必须来自真实人工批准,不自动估价或生成批准材料。
diff --git a/src/features/production/components/KeyframeCard.vue b/src/features/production/components/KeyframeCard.vue
index 98e2b59..f0139f2 100644
--- a/src/features/production/components/KeyframeCard.vue
+++ b/src/features/production/components/KeyframeCard.vue
@@ -4,7 +4,8 @@ import ContextNotice from '../../../components/ui/ContextNotice.vue'
import IssueHint from '../../../components/ui/IssueHint.vue'
import { productionMessage } from '../production-messages'
import { useKeyframeVision } from '../keyframe-vision'
-import { computed, watch } from 'vue'
+import { computed, ref, watch } from 'vue'
+import SourceReviewDrawer from './SourceReviewDrawer.vue'
import { useQuery } from '../../../composables/useQuery'
import { qualityApi } from '../quality-api'
import { NButton, NTag } from 'naive-ui'
@@ -31,6 +32,15 @@ const props = defineProps<{
validationPassed: boolean | null
confirming: boolean
}>()
+/** 用户显式打开来源复核,不能自动调用模型。 */
+const sourceReviewOpen = ref(false)
+watch(
+ () => JSON.stringify([props.projectId, props.shotId, props.item.id]),
+ () => {
+ sourceReviewOpen.value = false
+ },
+ { flush: 'sync' }
+)
/** 用户显式触发候选审核、确认或免费恢复。 */
const emit = defineEmits<{
recover: []
@@ -181,6 +191,13 @@ const canSelect = computed(
{{
{ recorded: '已保存生成输入', 'not-recorded': '历史生成输入未记录', invalid: '生成输入证据已失效' }[
@@ -244,4 +261,11 @@ const canSelect = computed(
+
diff --git a/src/features/production/components/KeyframeValidationHistory.vue b/src/features/production/components/KeyframeValidationHistory.vue
index 8b293a5..dc5f0a9 100644
--- a/src/features/production/components/KeyframeValidationHistory.vue
+++ b/src/features/production/components/KeyframeValidationHistory.vue
@@ -445,6 +445,9 @@ const records = computed(() =>
+ 独立新来源审核 · 人工记录 {{ record.sourceReviewId }}(与旧 Vision 分开存证)
+
合并结论:{{ userFacingText(record.validation.summary) }}
diff --git a/src/features/production/components/SourceReviewDrawer.vue b/src/features/production/components/SourceReviewDrawer.vue
new file mode 100644
index 0000000..411ee01
--- /dev/null
+++ b/src/features/production/components/SourceReviewDrawer.vue
@@ -0,0 +1,378 @@
+
+
+
+
+
+
+ 免费预检当前来源
+
+ 回读人工记录
+
+
+
+
+ 原件 SHA:{{ form.preview.value.originalPixels.sha256 }}
+
+ {{
+ JSON.stringify(
+ {
+ originalProviderInput: form.preview.value.originalProviderInput,
+ historicalVision: form.preview.value.historicalVision,
+ sourceChanges: form.preview.value.sourceChanges
+ },
+ null,
+ 2
+ )
+ }}
+
+
+
+
+ 比较参考 {{ observation.imageNumber }}
+
+
+ {{ binding.subjectRef }} · {{ userFacingText(binding.role) }} {{ binding.viewDescription }}
+ {{ binding.spatialLayoutVersion }}
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ statusLabels[form.record.value.reviewStatus] || '结论待核对' }} ·
+ {{ form.record.value.current ? '来源当前' : '当前已失效' }}
+
+
+ 原记录与当前主图比较计划不一致,仅可追溯,不能批准执行。
+
+
+ 原结论:{{
+ statusLabels[form.record.value.originalResult.status] || form.record.value.originalResult.status
+ }}
+
+
+ {{ userFacingText(form.record.value.invalidation) }}
+
+
+ {{
+ JSON.stringify(form.record.value.review, null, 2)
+ }}
+
+ 免费查看独立机器审核计划
+
+
+
+
+
+ 模型:{{ form.plan.value.model }} · 步骤:{{
+ form.plan.value.steps.map(step => validationStepNames[step]).join(' → ')
+ }}
+ · 最多请求 {{ form.plan.value.steps.length }} 次
+
+
+ {{
+ JSON.stringify(form.plan.value, null, 2)
+ }}
+
+
+
+
+
+
+ 明确批准上述完整计划和费用范围
+
+ 本次授权编号:{{ form.authorizationId.value }}
+
+ 明确执行本次独立审核,可能产生上述费用
+
+
+
+ 结果或费用待核查,仅可只读刷新,不自动重发。
+
+
+
+
+ 独立新来源审核 · 人工记录 {{ record.sourceReviewId }} · 原任务 {{ record.id }} ·
+ {{ userFacingText(record.status) }}
+
+
+
+
{{ resultLabel }}
+
+ {{
+ JSON.stringify(form.result.value, null, 2)
+ }}
+
+
只读刷新审核历史
+
+
+ 关闭
+ 保存人工观察(免费)
+ 登记本次费用批准
+ 明确执行独立审核
+ 明确继续原审核
+
+
+
diff --git a/src/features/production/keyframe-vision.ts b/src/features/production/keyframe-vision.ts
index 1fc1553..6ad8c0d 100644
--- a/src/features/production/keyframe-vision.ts
+++ b/src/features/production/keyframe-vision.ts
@@ -366,3 +366,41 @@ export async function submitKeyframeVision(
throw cause
}
}
+
+/**
+ * 新来源审核复用同候选的断线保护与执行观察,绝不调用普通 validate。
+ * @param key 候选完整范围
+ * @param records 正式历史
+ * @param send 用户明确执行的请求
+ * @returns 完整复用结果或后台受理回执
+ */
+export async function submitSourceVision(
+ key: string,
+ records: KeyframeValidationHistoryItem[],
+ send: () => Promise<
+ import('./quality.types').KeyframeValidation | import('./quality.types').KeyframeValidationAccepted
+ >
+) {
+ const previous = readSubmission(key)
+ const state = visionState(records)
+ if (state.active || state.unknown || (previous && !previous.settled))
+ throw new Error('已有审核或费用待核查,请只读刷新历史。')
+ const pending: Submission = { before: records[0]?.id ?? null }
+ saveSubmission(key, pending)
+ try {
+ const result = await send()
+ const [shotId, keyframeId] = JSON.parse(key) as string[]
+ if (!result || result.shotId !== shotId || result.keyframeId !== keyframeId || !result.validationTaskId)
+ throw new Error('审核回执不完整,请只读刷新历史。')
+ if ('executionId' in result && result.status === 'pending' && result.executionId) {
+ saveSubmission(key, { ...pending, taskId: result.validationTaskId, executionId: result.executionId })
+ } else if ('passed' in result && isVisualValidation(result)) {
+ saveSubmission(key, { ...pending, taskId: result.validationTaskId, settled: true })
+ } else throw new Error('审核回执不完整,请核查原请求费用。')
+ return result
+ } catch (cause) {
+ // 明确的参数或范围拒绝无自动重试;其余断线保持未结保护。
+ if (cause instanceof ApiError && [400, 404, 409].includes(cause.status)) saveSubmission(key)
+ throw cause
+ }
+}
diff --git a/src/features/production/quality.types.ts b/src/features/production/quality.types.ts
index fa83e99..bad3d7a 100644
--- a/src/features/production/quality.types.ts
+++ b/src/features/production/quality.types.ts
@@ -274,6 +274,8 @@ export interface KeyframeValidationStep {
/** 已保存的只读首帧校验任务记录。 */
export interface KeyframeValidationHistoryItem {
+ /** 独立新来源人工记录,普通旧 Vision 保留独立。 */ sourceReviewId?: string
+ /** 审核证据类型。 */ evidenceKind?: string
/** 校验任务编号 */
id: string
/** 任务状态,保留后端原值 */
diff --git a/src/features/production/source-review.ts b/src/features/production/source-review.ts
new file mode 100644
index 0000000..76996eb
--- /dev/null
+++ b/src/features/production/source-review.ts
@@ -0,0 +1,193 @@
+import { request } from '../../lib/http'
+import type { ProviderImageInputSnapshot } from '../subject-images/generation-preview'
+import type { KeyframeValidation, KeyframeValidationAccepted } from './quality.types'
+/** 人工观察结果,未知不可默认通过。 */
+export type SourceFinding = 'passed' | 'failed' | 'unknown'
+/** 五类独立观察。 */
+export const sourceFindingLabels = {
+ identity: '身份',
+ structure: '固定结构',
+ spatial: '空间',
+ action: '动作',
+ continuity: '连续性'
+} as const
+/** 逐图人工观察。 */
+export interface SourceObservation {
+ /** 物理参考编号。 */ imageNumber: number
+ /** 全部观察项。 */ finding: Record
+ /** 可见事实。 */ note: string
+}
+/** 人工保存输入。 */
+export interface SourceReviewInput {
+ /** 预检指纹。 */ expectedFingerprint: string
+ /** 审核人。 */ reviewer: string
+ /** 理由。 */ reason: string
+ /** 全部物理参考。 */ observations: SourceObservation[]
+}
+/** 公开输入,不将当前参考冒充原始输入。 */
+export type SourcePublicInput = ProviderImageInputSnapshot & {
+ /** 服务。 */ provider: string
+ /** 模型。 */ model: string | null
+ /** 原完整描述。 */ providerPrompt: string
+}
+/**
+ * 免费比较计划。
+ * @param p 项目编号
+ * @param s 镜头编号
+ * @param k 原主图编号
+ * @param signal 取消信号
+ * @returns 正式接口回执
+ */
+export interface SourceReviewPreview {
+ /** 项目。 */ projectId: string
+ /** 镜头。 */ shotId: string
+ /** 原主图。 */ keyframeId: string
+ /** 原图。 */ imageUrl: string
+ /** 预检指纹。 */ fingerprint: string
+ /** 原件证据。 */ originalPixels: { /** 原件摘要。 */ sha256: string }
+ /** 原输入指纹。 */ originalInputFingerprint: string
+ /** 原始生成输入。 */ originalProviderInput: SourcePublicInput
+ /** 来源变化。 */ sourceChanges: Record
+ /** 旧审核。 */ historicalVision: Array<{ /** 任务。 */ id: string; /** 状态。 */ status: string }>
+ /** 当前参考原件。 */ references: Array<{
+ /** 序号。 */ imageNumber: number
+ /** 地址。 */ imageUrl: string
+ /** 编号。 */ imageId: string
+ }>
+ /** 当前全部参考职责。 */ currentReferenceInput: SourcePublicInput
+}
+/** 原人工记录及当前性。 */
+export interface SourceReviewRecord {
+ /** 记录。 */ reviewId: string
+ /** 当前有效。 */ current: boolean
+ /** 失效原因。 */ invalidation: string | null
+ /** 原观察。 */ review: SourceReviewInput
+ /** 原结论。 */ originalResult: { /** 状态。 */ status: string; /** 证据类型。 */ evidenceKind: string }
+ /** 当前结论。 */ reviewStatus: string
+}
+/** 精确机器计划,原样批准。 */
+export interface SourceVisionPlan {
+ /** 人工记录。 */ reviewId: string
+ /** 观察指纹。 */ reviewFingerprint: string
+ /** 原输入。 */ originalInputFingerprint: string
+ /** 当前参考。 */ referenceInputFingerprint: string
+ /** 来源。 */ sourceFingerprint: string
+ /** 请求。 */ requestFingerprint: string
+ /** 原件摘要。 */ imageSha256: string
+ /** 模型。 */ model: string
+ /** 路由。 */ routeFingerprint: string
+ /** 全部步骤。 */ steps: Array<'general' | 'physical' | 'gaze'>
+}
+/** 明确批准的费用材料,不推测报价。 */
+export interface SourceVisionApproval {
+ /** 原计划。 */ plan: SourceVisionPlan
+ /** 批准人。 */ approvedBy: string
+ /** 操作人。 */ operator: string
+ /** 真实批准材料摘要。 */ approvalSha256: string
+ /** 费用范围。 */ feeScope: {
+ /** 币种。 */ currency: 'CNY'
+ /** 最低估算。 */ estimatedMin: number
+ /** 最高估算。 */ estimatedMax: number
+ /** 请求数。 */ maxRequests: number
+ }
+}
+/**
+ * 人工记录路径。
+ * @param p 项目
+ * @param r 记录
+ * @returns 正式路径
+ */
+function recordPath(p: string, r: string) {
+ return '/projects/' + encodeURIComponent(p) + '/storyboard-keyframes/source-reviews/' + encodeURIComponent(r)
+}
+/**
+ * 原主图路径。
+ * @param p 项目
+ * @param s 镜头
+ * @param k 原主图
+ * @returns 正式路径
+ */
+function targetPath(p: string, s: string, k: string) {
+ return (
+ '/projects/' +
+ encodeURIComponent(p) +
+ '/storyboard-shots/' +
+ encodeURIComponent(s) +
+ '/keyframes/' +
+ encodeURIComponent(k)
+ )
+}
+/** 正式来源复核 API;所有写入只由用户操作调用。 */
+export const sourceReviewApi = {
+ /**
+ * 免费比较计划。
+ * @param p 项目编号
+ * @param s 镜头编号
+ * @param k 原主图编号
+ * @param signal 取消信号
+ * @returns 正式接口回执
+ */
+ preview: (p: string, s: string, k: string, signal?: AbortSignal) =>
+ request(targetPath(p, s, k) + '/source-review/preview', { signal, timeoutMs: 0 }),
+ /**
+ * 保存人工观察。
+ * @param p 项目编号
+ * @param s 镜头编号
+ * @param k 原主图编号
+ * @param body 本次全部人工观察
+ * @returns 正式接口回执
+ */
+ save: (p: string, s: string, k: string, body: SourceReviewInput) =>
+ request<{ reviewId: string }>(targetPath(p, s, k) + '/source-reviews', { method: 'POST', body, timeoutMs: 0 }),
+ /**
+ * 回读原记录。
+ * @param p 项目编号
+ * @param r 人工记录编号
+ * @param signal 取消信号
+ * @returns 正式接口回执
+ */
+ get: (p: string, r: string, signal?: AbortSignal) =>
+ request(recordPath(p, r), { signal, timeoutMs: 0 }),
+ /**
+ * 免费机器计划。
+ * @param p 项目编号
+ * @param r 人工记录编号
+ * @param signal 取消信号
+ * @returns 正式接口回执
+ */
+ plan: (p: string, r: string, signal?: AbortSignal) =>
+ request(recordPath(p, r) + '/vision/preview', { signal, timeoutMs: 0 }),
+ /**
+ * 登记批准,不执行模型。
+ * @param p 项目编号
+ * @param r 人工记录编号
+ * @param body 明确批准的完整计划及费用
+ * @returns 正式接口回执
+ */
+ authorize: (p: string, r: string, body: SourceVisionApproval) =>
+ request<{ authorizationId: string; plan: SourceVisionPlan }>(recordPath(p, r) + '/vision/authorizations', {
+ method: 'POST',
+ body,
+ timeoutMs: 0
+ }),
+ /**
+ * 单次执行或显式继续。
+ * @param p 项目编号
+ * @param r 人工记录编号
+ * @param body 本次授权及明确恢复证据
+ * @returns 正式接口回执
+ */
+ execute: (
+ p: string,
+ r: string,
+ body: {
+ authorizationId: string
+ resume?: { resumeValidationTaskId: string; expectedRequestFingerprint: string }
+ }
+ ) =>
+ request(recordPath(p, r) + '/vision', {
+ method: 'POST',
+ body,
+ timeoutMs: 0
+ })
+}
diff --git a/src/features/production/useSourceReview.ts b/src/features/production/useSourceReview.ts
new file mode 100644
index 0000000..a8599e1
--- /dev/null
+++ b/src/features/production/useSourceReview.ts
@@ -0,0 +1,363 @@
+import { computed, ref, shallowRef, watch, onScopeDispose, type Ref } from 'vue'
+import {
+ sourceReviewApi,
+ type SourceReviewPreview,
+ type SourceReviewRecord,
+ type SourceVisionPlan,
+ type SourceObservation,
+ type SourceVisionApproval
+} from './source-review'
+import { useKeyframeVision, submitSourceVision } from './keyframe-vision'
+import { useActionMessage, showActionFeedback } from '../../components/ui/useActionMessage'
+import { errorMessage } from '../../lib/http'
+import { runOperation, getOperation } from '../workflows/operations'
+
+/**
+ * 原 Primary 的独立来源观察及明确批准闭环。
+ * @param key 打开时的完整候选身份
+ * @returns 只读证据、人工输入和显式操作
+ */
+export function useSourceReview(key: Ref) {
+ /** 正式候选观察复用已有 SSE/GET。 */
+ const vision = useKeyframeVision(key)
+ /** 免费比较输入。 */
+ const preview = shallowRef(null)
+ /** 原人工记录。 */
+ const record = shallowRef(null)
+ /** 原记录确实属于当前主图和本次输入。 */
+ const targetMatched = ref(false)
+ /** 免费机器计划。 */
+ const plan = shallowRef(null)
+ /** 用户指定历史记录,不通过缓存推断。 */
+ const reviewId = ref('')
+ /** 真实审核人。 */
+ const reviewer = ref('')
+ /** 审核理由。 */
+ const reason = ref('')
+ /** 逐图默认未知。 */
+ const observations = ref([])
+ /** 正式授权只在本次页面内保留。 */
+ const authorizationId = ref('')
+ /** 批准人。 */
+ const approvedBy = ref('')
+ /** 操作人。 */
+ const operator = ref('')
+ /** 用户提供的真实批准材料 SHA。 */
+ const approvalSha256 = ref('')
+ /** 真实批准金额下限,打开不预填。 */
+ const estimatedMin = ref(null)
+ /** 真实批准金额上限。 */
+ const estimatedMax = ref(null)
+ /** 明确批准整份计划和费用。 */
+ const approved = ref(false)
+ /** 每次执行另行勾选,不因签发自动执行。 */
+ const executeApproved = ref(false)
+ /** 当前操作,不让并发点击创建多份任务。 */
+ const pending = ref('')
+ /** 最近完整结果,仅供展示,不改机器徽标。 */
+ const result = shallowRef(null)
+ /** 当前费用材料身份。 */
+ const approvalKey = computed(() =>
+ JSON.stringify([
+ plan.value,
+ approvedBy.value,
+ operator.value,
+ approvalSha256.value,
+ estimatedMin.value,
+ estimatedMax.value
+ ])
+ )
+ /** 反馈使用现有消息层。 */
+ const message = useActionMessage()
+ /** 请求代次与取消器。 */
+ let epoch = 0
+ let controller: AbortController | undefined
+ /** 关闭和切换忽略旧结果。 */
+ function reset() {
+ epoch++
+ controller?.abort()
+ preview.value = null
+ record.value = null
+ targetMatched.value = false
+ plan.value = null
+ reviewId.value = ''
+ reviewer.value = ''
+ reason.value = ''
+ observations.value = []
+ authorizationId.value = ''
+ approved.value = false
+ executeApproved.value = false
+ pending.value = ''
+ result.value = null
+ approvedBy.value = ''
+ operator.value = ''
+ approvalSha256.value = ''
+ estimatedMin.value = null
+ estimatedMax.value = null
+ }
+ watch(key, reset, { flush: 'sync' })
+ watch(
+ approvalKey,
+ () => {
+ authorizationId.value = ''
+ approved.value = false
+ executeApproved.value = false
+ },
+ { flush: 'sync' }
+ )
+ watch(
+ reviewId,
+ () => {
+ targetMatched.value = false
+ record.value = null
+ plan.value = null
+ authorizationId.value = ''
+ result.value = null
+ },
+ { flush: 'sync' }
+ )
+ onScopeDispose(reset)
+ /**
+ * 同一范围操作和反馈,不自动重试。
+ * @param name 操作名
+ * @param work 实际操作
+ * @returns 操作结束
+ */
+ async function run(
+ name: string,
+ work: (scope: string[], signal: AbortSignal, valid: () => boolean) => Promise
+ ) {
+ if (pending.value || !key.value) return
+ const target = key.value,
+ cycle = epoch,
+ rid = reviewId.value
+ controller?.abort()
+ controller = new AbortController()
+ pending.value = name
+ const valid = () => target === key.value && cycle === epoch && (name === 'preview' || rid === reviewId.value)
+ try {
+ await work(JSON.parse(target) as string[], controller.signal, valid)
+ } catch (cause) {
+ if (valid()) showActionFeedback(message, errorMessage(cause), 'error')
+ } finally {
+ if (target === key.value && cycle === epoch) pending.value = ''
+ }
+ }
+ /** 免费预检;只有用户操作才编译参考。 */
+ async function loadPreview() {
+ await run('preview', async ([s, k, p], signal, valid) => {
+ preview.value = null
+ plan.value = null
+ record.value = null
+ targetMatched.value = false
+ authorizationId.value = ''
+ const data = await sourceReviewApi.preview(p!, s!, k!, signal)
+ if (!valid()) return
+ if (data.projectId !== p || data.shotId !== s || data.keyframeId !== k)
+ throw new Error('比较计划不属于当前首帧。')
+ reviewId.value = ''
+ preview.value = data
+ record.value = null
+ plan.value = null
+ observations.value = data.currentReferenceInput.references.map(reference => ({
+ imageNumber: reference.imageNumber,
+ finding: {
+ identity: 'unknown',
+ structure: 'unknown',
+ spatial: 'unknown',
+ action: 'unknown',
+ continuity: 'unknown'
+ },
+ note: ''
+ }))
+ })
+ }
+ /** 免费回读原人工记录;原结论保持不变。 */
+ async function readRecord() {
+ await run('read', async ([, , p], signal, valid) => {
+ const data = await sourceReviewApi.get(p!, reviewId.value.trim(), signal)
+ if (!valid()) return
+ const [s, k] = JSON.parse(key.value) as string[]
+ record.value = data
+ preview.value = null
+ observations.value = []
+ targetMatched.value = false
+ const comparison = await sourceReviewApi.preview(p!, s!, k!, signal)
+ if (valid()) {
+ record.value = data
+ preview.value = comparison
+ observations.value = comparison.currentReferenceInput.references.map(reference => ({
+ imageNumber: reference.imageNumber,
+ finding: {
+ identity: 'unknown',
+ structure: 'unknown',
+ spatial: 'unknown',
+ action: 'unknown',
+ continuity: 'unknown'
+ },
+ note: ''
+ }))
+ targetMatched.value =
+ comparison.projectId === p &&
+ comparison.shotId === s &&
+ comparison.keyframeId === k &&
+ comparison.fingerprint === data.review.expectedFingerprint
+ plan.value = null
+ authorizationId.value = ''
+ }
+ })
+ }
+ /** 保存全部人工观察,既有生产徽标不会据此变更。 */
+ async function save() {
+ if (
+ !preview.value ||
+ !observations.value.length ||
+ !reviewer.value.trim() ||
+ !reason.value.trim() ||
+ observations.value.some(o => !o.note.trim())
+ ) {
+ showActionFeedback(message, '请填写审核人、理由及每张参考的观察说明。', 'error')
+ return
+ }
+ await run('save', async ([s, k, p], _, valid) => {
+ const savedEpoch = epoch
+ const data = await sourceReviewApi.save(p!, s!, k!, {
+ expectedFingerprint: preview.value!.fingerprint,
+ reviewer: reviewer.value.trim(),
+ reason: reason.value.trim(),
+ observations: structuredClone(observations.value.map(o => ({ ...o, finding: { ...o.finding } })))
+ })
+ if (valid()) {
+ reviewId.value = data.reviewId
+ const next = await sourceReviewApi.get(p!, data.reviewId)
+ if (
+ savedEpoch === epoch &&
+ key.value === JSON.stringify([s, k, p]) &&
+ reviewId.value === data.reviewId &&
+ !controller?.signal.aborted
+ ) {
+ record.value = next
+ targetMatched.value = true
+ }
+ }
+ })
+ }
+ /** 仅有效且全部通过的原观察才请求免费机器计划。 */
+ async function loadPlan() {
+ if (!targetMatched.value || !record.value?.current || record.value.reviewStatus !== 'passed') return
+ await run('plan', async ([, , p], signal, valid) => {
+ plan.value = null
+ authorizationId.value = ''
+ const data = await sourceReviewApi.plan(p!, reviewId.value, signal)
+ if (valid()) {
+ if (data.reviewId !== reviewId.value) throw new Error('计划归属不符。')
+ plan.value = data
+ }
+ })
+ }
+ /** 明确登记批准,不自动执行。 */
+ async function authorize() {
+ if (
+ !plan.value ||
+ !approved.value ||
+ !approvedBy.value.trim() ||
+ !operator.value.trim() ||
+ !/^[a-f0-9]{64}$/.test(approvalSha256.value) ||
+ estimatedMin.value === null ||
+ estimatedMax.value === null ||
+ estimatedMin.value < 0 ||
+ estimatedMax.value <= 0 ||
+ estimatedMin.value > estimatedMax.value
+ ) {
+ showActionFeedback(message, '请填写真实批准材料及有效费用范围,并批准本次完整计划。', 'error')
+ return
+ }
+ const input: SourceVisionApproval = {
+ plan: plan.value,
+ approvedBy: approvedBy.value.trim(),
+ operator: operator.value.trim(),
+ approvalSha256: approvalSha256.value,
+ feeScope: {
+ currency: 'CNY',
+ estimatedMin: estimatedMin.value,
+ estimatedMax: estimatedMax.value,
+ maxRequests: plan.value.steps.length
+ }
+ }
+ await run('authorize', async ([, , p], _, valid) => {
+ authorizationId.value = ''
+ executeApproved.value = false
+ const data = await sourceReviewApi.authorize(p!, reviewId.value, input)
+ if (valid()) {
+ if (JSON.stringify(data.plan) !== JSON.stringify(input.plan))
+ throw new Error('批准范围已变化,请重新预检。')
+ authorizationId.value = data.authorizationId
+ executeApproved.value = false
+ }
+ })
+ }
+ /**
+ * 用户单独执行,继续仅来自原任务证据;费用未知禁止恢复。
+ * @param resume 是否显式继续原任务
+ */
+ async function execute(resume = false) {
+ if (
+ !vision.history.data.value ||
+ !!vision.history.error.value ||
+ !authorizationId.value ||
+ !executeApproved.value ||
+ !plan.value ||
+ !record.value?.current ||
+ vision.state.value.active ||
+ vision.state.value.unknown ||
+ vision.uncertain.value
+ )
+ return
+ const original = vision.resume.value
+ const task = vision.history.data.value?.find(t => t.id === original?.resumeValidationTaskId)
+ if (resume && (!original || task?.sourceReviewId !== reviewId.value)) return
+ const rid = reviewId.value,
+ id = authorizationId.value,
+ target = key.value
+ executeApproved.value = false
+ await run('execute', async ([, , p], _, valid) => {
+ const ok = await runOperation(p!, '独立新来源机器审核', async () => {
+ const data = await submitSourceVision(target, vision.history.data.value ?? [], () =>
+ sourceReviewApi.execute(p!, rid, { authorizationId: id, ...(resume ? { resume: original! } : {}) })
+ )
+ if (valid()) result.value = data
+ })
+ if (valid()) {
+ if (!ok) showActionFeedback(message, getOperation(p!).error, 'error')
+ void vision.history.refresh()
+ }
+ })
+ }
+ return {
+ targetMatched,
+ vision,
+ preview,
+ record,
+ plan,
+ reviewId,
+ reviewer,
+ reason,
+ observations,
+ authorizationId,
+ approvedBy,
+ operator,
+ approvalSha256,
+ estimatedMin,
+ estimatedMax,
+ approved,
+ executeApproved,
+ pending,
+ result,
+ loadPreview,
+ readRecord,
+ save,
+ loadPlan,
+ authorize,
+ execute
+ }
+}
diff --git a/tests/features/production/source-review.test.ts b/tests/features/production/source-review.test.ts
new file mode 100644
index 0000000..2e4b820
--- /dev/null
+++ b/tests/features/production/source-review.test.ts
@@ -0,0 +1,276 @@
+import { effectScope, ref } from 'vue'
+import { flushPromises } from '@vue/test-utils'
+import { afterEach, expect, it, vi } from 'vitest'
+import { useSourceReview } from '@/features/production/useSourceReview'
+import { sourceReviewApi, type SourceReviewPreview, type SourceVisionPlan } from '@/features/production/source-review'
+/** 全部请求仅使用隔离数据,不连接 Provider。 */
+const hash = 'a'.repeat(64)
+/** 原输入和当前参考完整公开证据。 */
+const input = {
+ fingerprint: hash,
+ sourceFingerprint: hash,
+ provider: 'mock',
+ model: 'mock',
+ providerPrompt: '历史描述',
+ generationOptions: {},
+ references: [
+ {
+ imageNumber: 1,
+ bindings: [
+ { role: 'layout-master', subjectRef: '@SC1' },
+ { role: 'scene-form', subjectRef: '@SC2' }
+ ]
+ }
+ ]
+}
+/** 可复用隔离预检。 */
+export const sourcePreview: SourceReviewPreview = {
+ projectId: 'p',
+ shotId: 's',
+ keyframeId: 'k',
+ imageUrl: '',
+ fingerprint: hash,
+ originalPixels: { sha256: hash },
+ originalInputFingerprint: hash,
+ originalProviderInput: input,
+ sourceChanges: {},
+ historicalVision: [],
+ references: [{ imageNumber: 1, imageId: 'i', imageUrl: '' }],
+ currentReferenceInput: input
+}
+/** 精确机器计划。 */
+export const sourcePlan: SourceVisionPlan = {
+ reviewId: 'r',
+ reviewFingerprint: hash,
+ originalInputFingerprint: hash,
+ referenceInputFingerprint: hash,
+ sourceFingerprint: hash,
+ requestFingerprint: hash,
+ imageSha256: hash,
+ model: 'mock',
+ routeFingerprint: hash,
+ steps: ['general', 'physical']
+}
+/** 每次隔离作用域。 */
+let scope = effectScope()
+afterEach(() => {
+ scope.stop()
+ scope = effectScope()
+ sessionStorage.clear()
+ vi.unstubAllGlobals()
+})
+/**
+ * 创建只处理正式路径的 Mock。
+ * @param status 人工原状态
+ * @returns 请求记录
+ */
+export function sourceMock(status = 'passed') {
+ const calls: Array<{ url: string; body: Record | null }> = []
+ const record = {
+ reviewId: 'r',
+ current: true,
+ invalidation: null,
+ review: {
+ expectedFingerprint: hash,
+ reviewer: '审核人',
+ reason: '理由',
+ observations: [
+ {
+ imageNumber: 1,
+ finding: {
+ identity: 'passed',
+ structure: 'passed',
+ spatial: 'passed',
+ action: 'passed',
+ continuity: 'passed'
+ },
+ note: '可见'
+ }
+ ]
+ },
+ originalResult: { status, evidenceKind: 'manual-source-observation' },
+ reviewStatus: status === 'insufficient_evidence' ? 'needs_review' : status
+ }
+ const fetcher = vi.fn(async (url, init) => {
+ const path = String(url)
+ const body = init?.body ? JSON.parse(String(init.body)) : null
+ calls.push({ url: path, body })
+ let data: unknown
+ if (path.includes('/source-review/preview')) data = sourcePreview
+ else if (path.endsWith('/source-reviews')) data = { reviewId: 'r' }
+ else if (path.endsWith('/vision/preview')) data = sourcePlan
+ else if (path.endsWith('/vision/authorizations')) data = { authorizationId: 'auth', plan: sourcePlan }
+ else if (path.endsWith('/source-reviews/r')) data = record
+ else if (path.includes('/validations')) data = []
+ else return new Response(JSON.stringify({ error: { message: '未模拟请求' } }), { status: 404 })
+ return new Response(JSON.stringify({ data }))
+ })
+ return { calls, fetcher, record }
+}
+/** 默认未知且逐图保存,人工通过不自动批准或执行。 */
+it('默认未知,逐图包含全部职责;原人工状态不覆盖', async () => {
+ const mock = sourceMock('insufficient_evidence')
+ vi.stubGlobal('fetch', mock.fetcher)
+ const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
+ await flushPromises()
+ await form.loadPreview()
+ expect(Object.values(form.observations.value[0]!.finding)).toEqual(Array(5).fill('unknown'))
+ expect(form.preview.value?.currentReferenceInput.references[0]?.bindings).toHaveLength(2)
+ form.reviewer.value = '审核人'
+ form.reason.value = '理由'
+ form.observations.value[0]!.note = '门轴看不清'
+ await form.save()
+ expect(form.record.value?.reviewStatus).toBe('needs_review')
+ expect(form.record.value?.originalResult.status).toBe('insufficient_evidence')
+ await form.loadPlan()
+ expect(mock.calls.filter(c => c.url.endsWith('/vision/preview'))).toHaveLength(0)
+ expect(mock.calls.filter(c => c.url.endsWith('/vision') || c.url.endsWith('/authorizations'))).toHaveLength(0)
+})
+/** 批准与执行分步;变更费用撤销原授权。 */
+it('真实费用材料独立批准,变更范围撤销授权,不自动收费', async () => {
+ const mock = sourceMock()
+ vi.stubGlobal('fetch', mock.fetcher)
+ const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
+ await flushPromises()
+ form.reviewId.value = 'r'
+ await form.readRecord()
+ await form.loadPlan()
+ form.approvedBy.value = '批准人'
+ form.operator.value = '操作人'
+ form.approvalSha256.value = hash
+ form.estimatedMin.value = 1
+ form.estimatedMax.value = 2
+ form.approved.value = true
+ await form.authorize()
+ expect(form.authorizationId.value).toBe('auth')
+ const body = mock.calls.find(c => c.url.endsWith('/authorizations'))!.body!
+ expect(body.feeScope).toEqual({ currency: 'CNY', estimatedMin: 1, estimatedMax: 2, maxRequests: 2 })
+ expect(mock.calls.some(c => c.url.endsWith('/vision'))).toBe(false)
+ form.estimatedMax.value = 3
+ expect(form.authorizationId.value).toBe('')
+})
+/** 项目切换后不接收旧预检。 */
+it('旧项目迟到响应被忽略', async () => {
+ const mock = sourceMock()
+ let finish!: (value: Response) => void
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn((url, init) =>
+ String(url).includes('/source-review/preview')
+ ? new Promise(resolve => {
+ finish = resolve
+ })
+ : mock.fetcher(url, init)
+ )
+ )
+ const key = ref(JSON.stringify(['s', 'k', 'p']))
+ const form = scope.run(() => useSourceReview(key))!
+ await flushPromises()
+ const pending = form.loadPreview()
+ key.value = JSON.stringify(['s2', 'k2', 'p2'])
+ finish(new Response(JSON.stringify({ data: sourcePreview })))
+ await pending
+ expect(form.preview.value).toBeNull()
+})
+/** 执行请求仅携带本次授权和明确原任务指纹。 */
+it('执行和恢复使用正式路径,不能混入模型或文字参数', async () => {
+ const fetcher = vi.fn(async () => new Response(JSON.stringify({ data: {} })))
+ vi.stubGlobal('fetch', fetcher)
+ await sourceReviewApi.execute('p/a', 'r/b', {
+ authorizationId: 'auth',
+ resume: { resumeValidationTaskId: 'task', expectedRequestFingerprint: hash }
+ })
+ expect(String(fetcher.mock.calls[0]![0])).toBe(
+ '/api/projects/p%2Fa/storyboard-keyframes/source-reviews/r%2Fb/vision'
+ )
+ expect(JSON.parse(String(fetcher.mock.calls[0]![1]?.body))).toEqual({
+ authorizationId: 'auth',
+ resume: { resumeValidationTaskId: 'task', expectedRequestFingerprint: hash }
+ })
+})
+
+/** 并发点击仅一次送出,断线费用未知不重发。 */
+it('并发和未知费用保持同一候选提交保护', async () => {
+ const { submitSourceVision } = await import('@/features/production/keyframe-vision')
+ const key = JSON.stringify(['source-s', 'source-k', 'source-p'])
+ let fail!: (cause: Error) => void
+ const send = vi.fn<() => Promise>(
+ () =>
+ new Promise((_, reject) => {
+ fail = reject
+ })
+ )
+ const first = submitSourceVision(key, [], send)
+ await expect(submitSourceVision(key, [], send)).rejects.toThrow('费用待核查')
+ fail(new Error('断线'))
+ await expect(first).rejects.toThrow('断线')
+ await expect(submitSourceVision(key, [], send)).rejects.toThrow('费用待核查')
+ expect(send).toHaveBeenCalledTimes(1)
+})
+/** 别的主图记录只能追溯,不可签发计划。 */
+it('记录与主图指纹不同不会取得机器计划', async () => {
+ const mock = sourceMock()
+ mock.record.review.expectedFingerprint = 'b'.repeat(64)
+ vi.stubGlobal('fetch', mock.fetcher)
+ const form = scope.run(() => useSourceReview(ref(JSON.stringify(['s', 'k', 'p']))))!
+ await flushPromises()
+ form.reviewId.value = 'r'
+ await form.readRecord()
+ await form.loadPlan()
+ expect(form.record.value?.originalResult.status).toBe('passed')
+ expect(form.targetMatched.value).toBe(false)
+ expect(form.plan.value).toBeNull()
+ expect(mock.calls.some(c => c.url.endsWith('/vision/preview'))).toBe(false)
+})
+
+/** 完成的失败结论也是完整结果,返回后不自动再提交。 */
+it('200 失败结论保持原失败且结算提交观察', async () => {
+ const { submitSourceVision } = await import('@/features/production/keyframe-vision')
+ const failed = {
+ shotId: 's',
+ keyframeId: 'k',
+ validationTaskId: 'task',
+ imageUrl: '',
+ isPrimary: true,
+ passed: false,
+ summary: '结构未通过',
+ subjectCountConsistent: true,
+ subjects: [],
+ issues: [],
+ unauthorizedText: { detected: false, texts: [] },
+ qualityDecision: 'failed' as const
+ }
+ const send = vi.fn<() => Promise>(async () => failed)
+ const result = await submitSourceVision(JSON.stringify(['s', 'k', 'p']), [], send)
+ expect(result).toEqual(failed)
+ expect(result).toHaveProperty('passed', false)
+ expect(send).toHaveBeenCalledTimes(1)
+})
+
+/** 实际组件不自动预检、批准或执行,观察控件初始未知。 */
+it('抽屉使用真实表单,打开只读历史,免费预检逐项展示全部参考', async () => {
+ const { mount } = await import('@vue/test-utils')
+ const Drawer = (await import('@/features/production/components/SourceReviewDrawer.vue')).default
+ const mock = sourceMock()
+ vi.stubGlobal('fetch', mock.fetcher)
+ const wrapper = mount(Drawer, {
+ props: { open: true, projectId: 'p', shotId: 's', keyframeId: 'k' },
+ global: { stubs: { AppDrawer: { template: '
' }, AssetImage: true } }
+ })
+ try {
+ await flushPromises()
+ expect(mock.calls.every(c => c.body === null)).toBe(true)
+ await wrapper
+ .findAll('button')
+ .find(b => b.text() === '免费预检当前来源')!
+ .trigger('click')
+ await flushPromises()
+ expect(wrapper.text()).toContain('未知/无法看清')
+ expect(wrapper.text()).toContain('本次新参考与逐图观察')
+ expect(wrapper.text()).toContain('@SC1')
+ expect(wrapper.text()).toContain('@SC2')
+ expect(wrapper.text()).not.toContain('登记本次费用批准')
+ } finally {
+ wrapper.unmount()
+ }
+})