feat(short-drama-agent-front): 接入关系修复并优化配置与弹窗

This commit is contained in:
GJ committed 2026-10-31 22:37:22 +08:00
1 parent 2db8549818
commit 41d1cfe3ed
15 files changed
+1134 -323

No files matched your search

+229 -63
View File
@@ -7,8 +7,9 @@ import { breakdownQuality, selectBreakdownSource } from '@/features/breakdown/qu
import { getOperation } from '@/features/workflows/operations'
import { candidateCheckpoint, candidateReview, candidateState, commitPreview } from '../../fixtures/breakdown-candidate'
import type { CandidateCommitPreview } from '@/features/breakdown/candidate.types'
import { NButton } from 'naive-ui'
/** 真实确认弹窗挂载于 body,验证完成后清理。 */
/** 真实全屏抽屉挂载于 body,测试仅模拟网络,不接触项目数据。 */
let wrapper: VueWrapper | undefined
beforeEach(() => {
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([candidateCheckpoint()])
@@ -20,11 +21,13 @@ afterEach(() => {
vi.restoreAllMocks()
})
/** 创建质量已通过但尚未经过安全预检查的面板。 */
/** 创建尚未打开的安全预检抽屉,不自动执行请求。 */
function openPanel() {
wrapper = mount(BreakdownCandidatePanel, {
attachTo: document.body,
props: {
open: false,
'onUpdate:open': (value: boolean) => wrapper?.setProps({ open: value }),
projectId: 'candidate-project',
checkpointId: 'candidate-current',
state: candidateState(),
@@ -35,28 +38,68 @@ function openPanel() {
return wrapper
}
/** 点击只读预检查入口,不直接提交。 */
/** 打开只读预检查抽屉,不直接提交。 */
async function checkCandidate() {
await wrapper!
.findAll('button')
.find(button => button.text() === '提交候选为正式结果')!
.trigger('click')
await wrapper!.setProps({ open: true })
await flushPromises()
}
/** 用户勾选并点击最终确认按钮。 */
async function confirmCandidate() {
const dialog = new DOMWrapper(document.querySelector<HTMLElement>('.app-dialog'))
await dialog.get('[role="checkbox"]').trigger('click')
await dialog
/** 取得当前打开的预检抽屉正文及固定底栏。 */
function drawer() {
return new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!)
}
/**
* 点击抽屉内的真实操作按钮。
* @param label 按钮可见名称
*/
async function clickAction(label: string) {
const button = drawer()
.findAll('button')
.find(button => button.text() === '确认提交候选为正式结果')!
.trigger('click')
.find(item => item.text() === label)
expect(button, `缺少操作:${label}`).toBeDefined()
await button!.trigger('click')
await flushPromises()
}
/** 用户勾选固定底栏的确认,再点击最终提交。 */
async function confirmCandidate() {
await drawer().get('.app-drawer-footer [role="checkbox"]').trigger('click')
await clickAction('确认提交候选为正式结果')
}
/** 两条关系仅为隔离测试样例,保留原始证据空格以检验请求不被改写。 */
function relationPreview() {
const result = commitPreview({ ready: false })
result.checks.relationEvidenceValid = false
result.relationIssues = ['@SC0002 位于→测试空地', '@PR0001 悬挂于→测试横木']
result.relationRepairTargets = [
{
subjectRef: '@SC0002',
subjectName: '测试场景',
relation: '位于',
target: '测试空地',
evidence: ' 原始证据 '
},
{
subjectRef: '@PR0001',
subjectName: '测试铜铃',
relation: '悬挂于',
target: '测试横木',
evidence: '另一条证据'
}
]
return result
}
/** 选择第一条真实返回的关系;选择不代表确认。 */
async function selectRelation() {
await drawer().get('input[type="radio"]').setValue(true)
await flushPromises()
}
describe('候选预检查与最终提交门禁', () => {
it('审核通过不会直接提交;预检查及最终确认均通过后只提交一次并刷新', async () => {
it('打开仅预检,固定底栏明确确认后重新核对版本和门禁,只提交一次并刷新', async () => {
const preview = vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(commitPreview())
const commit = vi.spyOn(breakdownApi, 'commitCandidate').mockResolvedValue({
projectId: 'candidate-project',
@@ -69,56 +112,46 @@ describe('候选预检查与最终提交门禁', () => {
})
openPanel()
expect(preview).not.toHaveBeenCalled()
expect(commit).not.toHaveBeenCalled()
expect(wrapper!.findAll('button').some(button => button.text() === '重新检查')).toBe(true)
await wrapper!
.findAll('button')
.find(button => button.text() === '重新检查')!
.trigger('click')
expect(wrapper!.emitted('refresh')).toHaveLength(1)
await checkCandidate()
expect(commit).not.toHaveBeenCalled()
expect(document.querySelector('.app-dialog')?.textContent).toContain('确认提交候选为正式结果')
expect(drawer().get('.app-drawer-footer [role="checkbox"]').attributes('aria-checked')).toBe('false')
await confirmCandidate()
expect(preview).toHaveBeenCalledTimes(2)
expect(commit).toHaveBeenCalledExactlyOnceWith('candidate-project')
expect(wrapper!.emitted('refresh')).toHaveLength(2)
expect(wrapper!.text()).toContain('拆解结果已保存并采用')
expect(wrapper!.findAll('button').some(button => button.text() === '重新检查')).toBe(false)
await wrapper!.setProps({
state: candidateState({ storyboardPersisted: true, candidateCommitted: true }),
quality: breakdownQuality(
selectBreakdownSource([
candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true }))
]),
null
)
})
expect(wrapper!.findAll('button').some(button => button.text() === '提交候选为正式结果')).toBe(false)
expect(wrapper!.findAll('button').some(button => button.text() === '重新检查')).toBe(false)
expect(wrapper!.emitted('refresh')).toHaveLength(1)
expect(wrapper!.emitted('update:open')?.at(-1)).toEqual([false])
})
it('ready=false 显示未通过项且不打开最终确认', async () => {
const result = commitPreview()
result.ready = false
it('ready=false 展示未通过项,禁止最终确认', async () => {
const result = commitPreview({ ready: false })
result.checks.noProtectedShots = false
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(result)
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
openPanel()
await checkCandidate()
expect(wrapper!.text()).toContain('没有需要保护的镜头资产')
expect(document.querySelector('.app-dialog')).toBeNull()
expect(drawer().text()).toContain('镜头资产')
expect(drawer().text()).not.toContain('确认提交候选为正式结果')
expect(commit).not.toHaveBeenCalled()
})
it('即使 ready=true,缺少一项安全门禁也禁止确认', async () => {
const result = commitPreview()
result.checks.noSubjectImages = false
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(result)
it('已提交分支不伪造缺失检查失败,刷新页面且隐藏所有写入口', async () => {
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue({
projectId: 'candidate-project',
checkpointId: 'new-committed',
readOnly: true,
ready: false,
status: 'already_committed',
reason: '最新候选已正式提交'
})
openPanel()
await checkCandidate()
expect(document.querySelector('.app-dialog')).toBeNull()
expect(wrapper!.text()).toContain('主体图片')
expect(drawer().text()).toContain('已提交正式结果')
expect(drawer().find('[aria-label="未通过的提交安全检查"]').exists()).toBe(false)
expect(drawer().text()).not.toContain('确认提交候选为正式结果')
expect(wrapper!.emitted('refresh')).toHaveLength(1)
})
it('最终确认重新发现版本变化时禁止替换并要求刷新', async () => {
it('最终提交时发现来源版本变化,拒绝替换并刷新', async () => {
vi.mocked(projectsApi.checkpoints).mockResolvedValue([candidateCheckpoint(candidateState(), 'new')])
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(commitPreview())
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
@@ -129,10 +162,11 @@ describe('候选预检查与最终提交门禁', () => {
expect(getOperation('candidate-project').error).toContain('版本已变化')
expect(wrapper!.emitted('refresh')).toHaveLength(1)
})
it('最终确认时安全条件改变,原先通过的预检查不能继续使用', async () => {
it('最终确认发现安全条件变化,不沿用原许可', async () => {
vi.spyOn(breakdownApi, 'candidateCommitPreview')
.mockResolvedValueOnce(commitPreview())
.mockResolvedValueOnce(commitPreview({ ready: false }))
.mockResolvedValueOnce(relationPreview())
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
openPanel()
await checkCandidate()
@@ -140,9 +174,10 @@ describe('候选预检查与最终提交门禁', () => {
expect(commit).not.toHaveBeenCalled()
expect(getOperation('candidate-project').error).toContain('安全条件已变化')
})
it('版本变化后晚到的预检查响应不会重新打开确认窗口', async () => {
it.each(['close', 'project'] as const)('读取期间 %s,晚到的响应不回填原抽屉', async action => {
let resolve!: (value: CandidateCommitPreview) => void
const preview = vi.spyOn(breakdownApi, 'candidateCommitPreview').mockImplementation(
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockImplementation(
() =>
new Promise(done => {
resolve = done
@@ -150,19 +185,150 @@ describe('候选预检查与最终提交门禁', () => {
)
openPanel()
await checkCandidate()
await wrapper!
.findAll('button')
.find(button => button.text() === '提交候选为正式结果')!
.trigger('click')
expect(preview).toHaveBeenCalledTimes(1)
await wrapper!.setProps({ checkpointId: 'new' })
if (action === 'close') await wrapper!.setProps({ open: false })
else await wrapper!.setProps({ projectId: 'other-project', disabled: true })
resolve(commitPreview())
await flushPromises()
expect(document.querySelector('.app-dialog')).toBeNull()
expect(document.body.textContent).not.toContain('确认提交候选为正式结果')
})
it('新快照没有候选标记时不会复用旧候选入口', async () => {
})
describe('候选关系人工修复', () => {
it('真实写入期间按钮保留 loading,锁定关闭,连点不会重复移除', async () => {
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(relationPreview())
let finish!: (value: { checkpointId: string; subjectRef: string; removed: 1 }) => void
const repair = vi.spyOn(breakdownApi, 'repairCandidateRelation').mockImplementation(
() =>
new Promise(resolve => {
finish = resolve
})
)
openPanel()
await wrapper!.setProps({ checkpointId: 'new', state: {} })
expect(wrapper!.text()).not.toContain('提交候选为正式结果')
await checkCandidate()
await selectRelation()
await drawer().get('.app-drawer-footer [role="checkbox"]').trigger('click')
await clickAction('确认移除这条关系')
await wrapper!.setProps({ disabled: true })
const submit = wrapper!.findAllComponents(NButton).find(button => button.text() === '确认移除这条关系')!
expect(submit.props('loading')).toBe(true)
expect(
drawer()
.findAll('button')
.find(button => button.text() === '关闭')!
.attributes('disabled')
).toBeDefined()
await submit.trigger('click')
expect(repair).toHaveBeenCalledOnce()
finish({ checkpointId: 'new-version', subjectRef: '@SC0002', removed: 1 })
await flushPromises()
})
it('完整展示原始关系,不自动选择、删除或提交', async () => {
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(relationPreview())
const repair = vi.spyOn(breakdownApi, 'repairCandidateRelation')
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
openPanel()
await checkCandidate()
expect(drawer().text()).toContain('测试场景')
expect(drawer().text()).toContain('测试空地')
expect(drawer().text()).toContain('原始证据')
expect(
drawer()
.findAll<HTMLInputElement>('input[type="radio"]')
.every(item => !item.element.checked)
).toBe(true)
expect(repair).not.toHaveBeenCalled()
expect(commit).not.toHaveBeenCalled()
})
it('每次仅移除用户明确确认的一条原始关系,新版本到达后重新预检,不自动提交', async () => {
const preview = vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(relationPreview())
const repair = vi.spyOn(breakdownApi, 'repairCandidateRelation').mockResolvedValue({
checkpointId: 'repaired-version',
subjectRef: '@SC0002',
removed: 1
})
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
openPanel()
await checkCandidate()
await selectRelation()
expect(repair).not.toHaveBeenCalled()
const button = drawer()
.findAll('button')
.find(item => item.text() === '确认移除这条关系')!
expect(button.attributes('disabled')).toBeDefined()
await drawer().get('.app-drawer-footer [role="checkbox"]').trigger('click')
await button.trigger('click')
await button.trigger('click')
await flushPromises()
expect(repair).toHaveBeenCalledExactlyOnceWith('candidate-project', {
expectedCheckpointId: 'candidate-current',
confirmed: true,
subjectRef: '@SC0002',
relation: '位于',
target: '测试空地',
evidence: ' 原始证据 '
})
expect(wrapper!.emitted('refresh')).toHaveLength(1)
expect(commit).not.toHaveBeenCalled()
expect(drawer().text()).not.toContain('确认移除这条关系')
preview.mockResolvedValue(commitPreview({ checkpointId: 'repaired-version' }))
await wrapper!.setProps({
checkpointId: 'repaired-version',
quality: breakdownQuality(
selectBreakdownSource([candidateCheckpoint(candidateState(), 'repaired-version')]),
candidateReview({ checkpointId: 'repaired-version' })
)
})
await flushPromises()
expect(preview).toHaveBeenCalledTimes(3)
expect(drawer().text()).toContain('确认提交候选为正式结果')
expect(drawer().get('.app-drawer-footer [role="checkbox"]').attributes('aria-checked')).toBe('false')
expect(commit).not.toHaveBeenCalled()
})
it.each(['version', 'target', 'active'] as const)('提交前 %s 变化,拒绝移除并撤销旧确认', async change => {
const next = relationPreview()
if (change === 'version') next.checkpointId = 'other-version'
if (change === 'target') next.relationRepairTargets = []
if (change === 'active') next.checks.noActiveExecutions = false
vi.spyOn(breakdownApi, 'candidateCommitPreview')
.mockResolvedValueOnce(relationPreview())
.mockResolvedValue(next)
const repair = vi.spyOn(breakdownApi, 'repairCandidateRelation')
openPanel()
await checkCandidate()
await selectRelation()
await drawer().get('.app-drawer-footer [role="checkbox"]').trigger('click')
await clickAction('确认移除这条关系')
expect(repair).not.toHaveBeenCalled()
expect(drawer().text()).not.toContain('确认移除这条关系')
expect(wrapper!.emitted('refresh')).toHaveLength(1)
})
it('普通提交失败保留所选关系,清除勾选后允许用户修正重试', async () => {
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(relationPreview())
vi.spyOn(breakdownApi, 'repairCandidateRelation').mockRejectedValue(new Error('网络中断,请重新读取状态'))
openPanel()
await checkCandidate()
await selectRelation()
await drawer().get('.app-drawer-footer [role="checkbox"]').trigger('click')
await clickAction('确认移除这条关系')
expect(drawer().get<HTMLInputElement>('input[type="radio"]').element.checked).toBe(true)
expect(drawer().text()).toContain('网络中断')
expect(drawer().get('.app-drawer-footer [role="checkbox"]').attributes('aria-checked')).toBe('false')
})
it('完全相同的重复定位关系不能提交删除', async () => {
const result = relationPreview()
result.relationRepairTargets.push({ ...result.relationRepairTargets[0]! })
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(result)
const repair = vi.spyOn(breakdownApi, 'repairCandidateRelation')
openPanel()
await checkCandidate()
await selectRelation()
expect(drawer().text()).toContain('定位不唯一')
expect(drawer().text()).not.toContain('确认移除这条关系')
expect(repair).not.toHaveBeenCalled()
})
})