feat(short-drama-agent-front): 完善质量规则确认与中文交互
This commit is contained in:
1 parent
190333d4f9
commit
c4b43b9725
85 files changed
+2059
-480
No files matched your search
@@ -4,6 +4,7 @@ import { policyDraft, policyIssue } from '@/features/projects/quality-policy'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
import type { ProjectQualityPolicy } from '@/features/projects/types'
|
||||
import QualityPolicySettings from '@/features/generation-config/components/QualityPolicySettings.vue'
|
||||
import { qualityPolicySignature, readQualityPolicyConfirmation, rememberQualityPolicyConfirmation } from '@/features/projects/quality-policy-confirmation'
|
||||
|
||||
/** 保留已有精确例外的服务端完整策略。 */
|
||||
const saved: ProjectQualityPolicy = {
|
||||
@@ -23,66 +24,61 @@ afterEach(() => {
|
||||
settings?.unmount()
|
||||
settings = undefined
|
||||
vi.unstubAllGlobals()
|
||||
vi.restoreAllMocks()
|
||||
localStorage.clear()
|
||||
})
|
||||
describe('项目质量策略', () => {
|
||||
it('进入和新增例外不立即报错,保存时拦截缺失字段,修正后才写入', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async (_url, init) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
projectId: 'p',
|
||||
policy:
|
||||
init?.method === 'PUT'
|
||||
? JSON.parse(String(init.body))
|
||||
: { ...saved, actionExceptions: [] }
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(QualityPolicySettings, { props: { projectId: 'p', disabled: false } })
|
||||
it('基础规则不再添加空白例外,已有例外只读展示且完整保留在提交草稿中', async () => {
|
||||
const wrapper = mount(QualityPolicySettings, { props: { projectId: 'p', disabled: false, initialPolicy: { projectId: 'p', policy: saved } } })
|
||||
settings = wrapper
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('button').some(button => button.text() === '添加例外')).toBe(false)
|
||||
expect(wrapper.find('[aria-label="例外 1 主体引用"]').exists()).toBe(false)
|
||||
expect(wrapper.text()).toContain('已有动作例外 · 1 项')
|
||||
expect(wrapper.vm.validatedDraft()?.actionExceptions).toEqual(saved.actionExceptions)
|
||||
})
|
||||
it('启动入口复用真实回执,不重复读取,无变化保存保留确认,修改后撤销确认', async () => {
|
||||
let currentPolicy = policyDraft(saved)
|
||||
const read = vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () => ({ projectId: 'p', policy: policyDraft(currentPolicy) }))
|
||||
vi.spyOn(projectsApi, 'saveQualityPolicy').mockImplementation(async (id, policy) => { currentPolicy = policyDraft(policy); return { projectId: id, policy: policyDraft(policy) } })
|
||||
const signature = qualityPolicySignature(saved)
|
||||
rememberQualityPolicyConfirmation('p', signature)
|
||||
const wrapper = mount(QualityPolicySettings, { props: { projectId: 'p', disabled: false, initialPolicy: { projectId: 'p', policy: saved } } })
|
||||
settings = wrapper
|
||||
await flushPromises()
|
||||
expect(read).not.toHaveBeenCalled()
|
||||
expect(wrapper.vm.validatedDraft()).toEqual(saved)
|
||||
await wrapper.vm.save()
|
||||
expect(readQualityPolicyConfirmation('p')).toBe(signature)
|
||||
await wrapper.get('#quality-custom-rules').setValue('新规则')
|
||||
await wrapper.vm.save()
|
||||
expect(readQualityPolicyConfirmation('p')).toBeNull()
|
||||
})
|
||||
it('保存基础规则时合并后来新增的例外,不覆盖隐藏的服务端最新例外', async () => {
|
||||
const latest = { ...saved, actionExceptions: [...saved.actionExceptions!, { code: 'action_resource_conflict' as const, ownerRef: '@CH0002', resource: 'right_hand' as const, reason: '另一处刚添加的例外' }] }
|
||||
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue({ projectId: 'p', policy: latest })
|
||||
const write = vi.spyOn(projectsApi, 'saveQualityPolicy').mockImplementation(async (id, policy) => ({ projectId: id, policy: policyDraft(policy) }))
|
||||
const wrapper = mount(QualityPolicySettings, { props: { projectId: 'p', disabled: false, initialPolicy: { projectId: 'p', policy: saved } } })
|
||||
settings = wrapper
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.text-danger').exists()).toBe(false)
|
||||
await wrapper
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '添加例外')!
|
||||
.trigger('click')
|
||||
expect(wrapper.text()).not.toContain('精确例外需填写')
|
||||
expect(wrapper.vm.canSave).toBe(true)
|
||||
|
||||
await wrapper.vm.save()
|
||||
expect(wrapper.text()).toContain('精确例外需填写')
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')).toHaveLength(0)
|
||||
await wrapper.get('[aria-label="例外 1 主体引用"] input').setValue('@CH0001')
|
||||
expect(wrapper.text()).not.toContain('精确例外需填写')
|
||||
await wrapper.vm.save()
|
||||
expect(wrapper.text()).toContain('精确例外需填写')
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')).toHaveLength(0)
|
||||
|
||||
await wrapper.get('[aria-label="例外 1 确认依据"] input').setValue('剧本明确的动作许可')
|
||||
await wrapper.get('#quality-custom-rules').setValue('新的整体规则')
|
||||
await wrapper.vm.save()
|
||||
expect(write).toHaveBeenCalledExactlyOnceWith('p', { ...saved, customRules: ['新的整体规则'], actionExceptions: latest.actionExceptions })
|
||||
expect(wrapper.vm.validatedDraft()?.actionExceptions).toEqual(latest.actionExceptions)
|
||||
expect(wrapper.text()).toContain('已有动作例外 · 2 项')
|
||||
})
|
||||
it('基础规则已被其他位置修改时拒绝覆盖,保留用户草稿', async () => {
|
||||
vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue({ projectId: 'p', policy: { ...saved, physicsMode: 'fantasy' } })
|
||||
const write = vi.spyOn(projectsApi, 'saveQualityPolicy')
|
||||
const wrapper = mount(QualityPolicySettings, { props: { projectId: 'p', disabled: false, initialPolicy: { projectId: 'p', policy: saved } } })
|
||||
settings = wrapper
|
||||
await flushPromises()
|
||||
const writes = fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')
|
||||
expect(writes).toHaveLength(1)
|
||||
expect(JSON.parse(String(writes[0]?.[1]?.body))).toEqual({
|
||||
version: 1,
|
||||
physicsMode: 'realistic',
|
||||
allowExaggeratedMotion: false,
|
||||
allowNonPhysicalActions: false,
|
||||
allowSupernaturalAbilities: false,
|
||||
customRules: ['规则'],
|
||||
actionExceptions: [
|
||||
{
|
||||
code: 'action_resource_conflict',
|
||||
ownerRef: '@CH0001',
|
||||
resource: 'left_hand',
|
||||
reason: '剧本明确的动作许可'
|
||||
}
|
||||
]
|
||||
})
|
||||
expect(wrapper.text()).toContain('质量策略已保存')
|
||||
await wrapper.get('#quality-custom-rules').setValue('不能丢失的用户草稿')
|
||||
await wrapper.vm.save()
|
||||
expect(write).not.toHaveBeenCalled()
|
||||
expect(wrapper.text()).toContain('质量规则已在其他位置更新')
|
||||
expect(wrapper.vm.validatedDraft()?.customRules).toEqual(['不能丢失的用户草稿'])
|
||||
})
|
||||
it('草稿编辑不污染已保存策略,完整保留精确例外', () => {
|
||||
const draft = policyDraft(saved)
|
||||
|
||||
Reference in new issue
Block a user