fix(short-drama-agent-front): 修复代码格式检查问题
This commit is contained in:
1 parent
81d6a85260
commit
48fce3975f
87 files changed
+5714
-1436
No files matched your search
@@ -8,16 +8,28 @@ import { qualityPolicySignature } from '@/features/projects/quality-policy-confi
|
||||
import { policyReceipt } from '../../fixtures/quality-policy'
|
||||
|
||||
/** 真实规则回执,旧项目初始修订也必须明确确认。 */
|
||||
const initial = () => policyReceipt('policy-project', {
|
||||
version: 1, physicsMode: 'realistic', allowExaggeratedMotion: false,
|
||||
allowNonPhysicalActions: false, allowSupernaturalAbilities: false, customRules: []
|
||||
}, { revision: 0 })
|
||||
const initial = () =>
|
||||
policyReceipt(
|
||||
'policy-project',
|
||||
{
|
||||
version: 1,
|
||||
physicsMode: 'realistic',
|
||||
allowExaggeratedMotion: false,
|
||||
allowNonPhysicalActions: false,
|
||||
allowSupernaturalAbilities: false,
|
||||
customRules: []
|
||||
},
|
||||
{ revision: 0 }
|
||||
)
|
||||
/** 测试结束释放全部流程观察器。 */
|
||||
const scopes: EffectScope[] = []
|
||||
/** 创建独立流程,不访问真实模型。 */
|
||||
function setup() {
|
||||
const id = ref('policy-project'), input = ref('preview-1'), allowed = ref(true)
|
||||
const scope = effectScope(); scopes.push(scope)
|
||||
const id = ref('policy-project'),
|
||||
input = ref('preview-1'),
|
||||
allowed = ref(true)
|
||||
const scope = effectScope()
|
||||
scopes.push(scope)
|
||||
return { id, input, allowed, flow: scope.run(() => useBreakdownStartPolicy(id, input, allowed))! }
|
||||
}
|
||||
/** 模拟服务端 CAS 保存及独立明确确认,复制回执避免测试污染。 */
|
||||
@@ -26,7 +38,10 @@ function server() {
|
||||
const read = vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () => structuredClone(saved))
|
||||
const save = vi.spyOn(projectsApi, 'saveQualityPolicy').mockImplementation(async (_id, policy, expected) => {
|
||||
if (expected !== saved.revision) throw new Error('版本冲突')
|
||||
saved = policyReceipt(saved.projectId, policyDraft(policy), { revision: saved.revision + 1, fingerprint: 'b'.repeat(64) })
|
||||
saved = policyReceipt(saved.projectId, policyDraft(policy), {
|
||||
revision: saved.revision + 1,
|
||||
fingerprint: 'b'.repeat(64)
|
||||
})
|
||||
return structuredClone(saved)
|
||||
})
|
||||
const confirm = vi.spyOn(projectsApi, 'confirmQualityPolicy').mockImplementation(async (_id, expected) => {
|
||||
@@ -34,101 +49,219 @@ function server() {
|
||||
saved = { ...saved, confirmed: true, confirmedRevision: expected, confirmedAt: '2026-10-17T15:00:00Z' }
|
||||
return structuredClone(saved)
|
||||
})
|
||||
return { read, save, confirm, get: () => saved, change: (value: Partial<ProjectQualityPolicyResult>) => { saved = { ...saved, ...value } } }
|
||||
return {
|
||||
read,
|
||||
save,
|
||||
confirm,
|
||||
get: () => saved,
|
||||
change: (value: Partial<ProjectQualityPolicyResult>) => {
|
||||
saved = { ...saved, ...value }
|
||||
}
|
||||
}
|
||||
}
|
||||
afterEach(() => { scopes.splice(0).forEach(scope => scope.stop()); vi.restoreAllMocks(); vi.unstubAllGlobals(); localStorage.clear() })
|
||||
afterEach(() => {
|
||||
scopes.splice(0).forEach(scope => scope.stop())
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
describe('规则内容比较与服务端确认', () => {
|
||||
it('格式版本不代替修订,比较内容时保留许可、规则和例外变化', () => {
|
||||
const base = initial().policy
|
||||
expect(qualityPolicySignature({ ...base, actionExceptions: [] })).toBe(qualityPolicySignature(base))
|
||||
expect(qualityPolicySignature({ ...base, customRules: [' 规则 '] })).toBe(qualityPolicySignature({ ...base, customRules: ['规则'] }))
|
||||
for (const change of [{ physicsMode: 'fantasy' as const }, { allowExaggeratedMotion: true }, { allowNonPhysicalActions: true }, { allowSupernaturalAbilities: true }, { customRules: ['新规则'] }, { actionExceptions: [{ code: 'action_resource_conflict' as const, ownerRef: '@CH1', resource: 'left_hand' as const, reason: '许可' }] }])
|
||||
expect(qualityPolicySignature({ ...base, customRules: [' 规则 '] })).toBe(
|
||||
qualityPolicySignature({ ...base, customRules: ['规则'] })
|
||||
)
|
||||
for (const change of [
|
||||
{ physicsMode: 'fantasy' as const },
|
||||
{ allowExaggeratedMotion: true },
|
||||
{ allowNonPhysicalActions: true },
|
||||
{ allowSupernaturalAbilities: true },
|
||||
{ customRules: ['新规则'] },
|
||||
{
|
||||
actionExceptions: [
|
||||
{
|
||||
code: 'action_resource_conflict' as const,
|
||||
ownerRef: '@CH1',
|
||||
resource: 'left_hand' as const,
|
||||
reason: '许可'
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
expect(qualityPolicySignature({ ...base, ...change })).not.toBe(qualityPolicySignature(base))
|
||||
})
|
||||
it('旧浏览器确认记录不能跳过服务未确认规则;取消不写入确认', async () => {
|
||||
const api = server()
|
||||
localStorage.setItem('short-drama:breakdown-quality-confirmation:v1:policy-project', JSON.stringify({ formatVersion: 1, signature: qualityPolicySignature(initial().policy) }))
|
||||
const { flow } = setup(); await flow.prepare()
|
||||
expect(flow.reviewOpen.value).toBe(true); expect(flow.startOpen.value).toBe(false)
|
||||
flow.cancel(); expect(api.confirm).not.toHaveBeenCalled(); expect(flow.consumePermit()).toBeNull()
|
||||
localStorage.setItem(
|
||||
'short-drama:breakdown-quality-confirmation:v1:policy-project',
|
||||
JSON.stringify({ formatVersion: 1, signature: qualityPolicySignature(initial().policy) })
|
||||
)
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
expect(flow.reviewOpen.value).toBe(true)
|
||||
expect(flow.startOpen.value).toBe(false)
|
||||
flow.cancel()
|
||||
expect(api.confirm).not.toHaveBeenCalled()
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
})
|
||||
it('未改规则也独立明确确认,修订零可启动,其他页面重进不重复提醒', async () => {
|
||||
const api = server(); const { flow } = setup()
|
||||
await flow.prepare(); expect(await flow.confirmRules(initial().policy)).toBe(true)
|
||||
expect(api.save).not.toHaveBeenCalled(); expect(api.confirm).toHaveBeenCalledExactlyOnceWith('policy-project', 0)
|
||||
flow.cancel(); const next = setup().flow; await next.prepare()
|
||||
expect(next.reviewOpen.value).toBe(false); expect(next.startOpen.value).toBe(true)
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
expect(await flow.confirmRules(initial().policy)).toBe(true)
|
||||
expect(api.save).not.toHaveBeenCalled()
|
||||
expect(api.confirm).toHaveBeenCalledExactlyOnceWith('policy-project', 0)
|
||||
flow.cancel()
|
||||
const next = setup().flow
|
||||
await next.prepare()
|
||||
expect(next.reviewOpen.value).toBe(false)
|
||||
expect(next.startOpen.value).toBe(true)
|
||||
expect(await next.verifyStart()).toBe(true)
|
||||
expect(next.consumePermit()).toEqual({ expectedRevision: 0 }); expect(next.consumePermit()).toBeNull()
|
||||
expect(next.consumePermit()).toEqual({ expectedRevision: 0 })
|
||||
expect(next.consumePermit()).toBeNull()
|
||||
})
|
||||
it('修改规则先携带旧修订保存,再确认新修订,最后重读确认', async () => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare()
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
const draft = { ...initial().policy, allowExaggeratedMotion: true }
|
||||
expect(await flow.confirmRules(draft)).toBe(true)
|
||||
expect(api.save).toHaveBeenCalledExactlyOnceWith('policy-project', draft, 0)
|
||||
expect(api.confirm).toHaveBeenCalledExactlyOnceWith('policy-project', 1)
|
||||
expect(api.read).toHaveBeenCalledTimes(3)
|
||||
expect(await flow.verifyStart()).toBe(true); expect(flow.consumePermit()).toEqual({ expectedRevision: 1 })
|
||||
expect(await flow.verifyStart()).toBe(true)
|
||||
expect(flow.consumePermit()).toEqual({ expectedRevision: 1 })
|
||||
})
|
||||
it('同内容被修改后又恢复但修订增加时仍重新确认,不能覆盖更新', async () => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare()
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
api.change({ revision: 4 })
|
||||
expect(await flow.confirmRules(initial().policy)).toBe(false)
|
||||
expect(flow.policy.value?.revision).toBe(4); expect(api.save).not.toHaveBeenCalled(); expect(api.confirm).not.toHaveBeenCalled()
|
||||
})
|
||||
it.each(['读取失败', '项目不符', '元数据缺失', '保存失败', '确认失败', '回执不符', '确认后变化'])('拦截%s且不取得启动许可', async kind => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare()
|
||||
const draft = { ...initial().policy, allowNonPhysicalActions: true }
|
||||
if (kind === '读取失败') api.read.mockRejectedValueOnce(new Error('读取失败'))
|
||||
if (kind === '项目不符') api.read.mockResolvedValueOnce({ ...initial(), projectId: 'other' })
|
||||
if (kind === '元数据缺失') api.read.mockResolvedValueOnce({ ...initial(), revision: undefined } as unknown as ProjectQualityPolicyResult)
|
||||
if (kind === '保存失败') api.save.mockRejectedValueOnce(new Error('保存失败'))
|
||||
if (kind === '确认失败') api.confirm.mockRejectedValueOnce(new Error('确认失败'))
|
||||
if (kind === '回执不符') api.confirm.mockResolvedValueOnce(initial())
|
||||
if (kind === '确认后变化') api.confirm.mockImplementationOnce(async () => {
|
||||
const confirmed = { ...api.get(), confirmed: true, confirmedRevision: api.get().revision, confirmedAt: '2026-10-17T15:00:00Z' }
|
||||
api.change({ revision: api.get().revision + 1 }); return confirmed
|
||||
})
|
||||
expect(await flow.confirmRules(draft)).toBe(false); expect(flow.startOpen.value).toBe(false); expect(flow.consumePermit()).toBeNull()
|
||||
expect(flow.policy.value?.revision).toBe(4)
|
||||
expect(api.save).not.toHaveBeenCalled()
|
||||
expect(api.confirm).not.toHaveBeenCalled()
|
||||
})
|
||||
it.each(['读取失败', '项目不符', '元数据缺失', '保存失败', '确认失败', '回执不符', '确认后变化'])(
|
||||
'拦截%s且不取得启动许可',
|
||||
async kind => {
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
const draft = { ...initial().policy, allowNonPhysicalActions: true }
|
||||
if (kind === '读取失败') api.read.mockRejectedValueOnce(new Error('读取失败'))
|
||||
if (kind === '项目不符') api.read.mockResolvedValueOnce({ ...initial(), projectId: 'other' })
|
||||
if (kind === '元数据缺失')
|
||||
api.read.mockResolvedValueOnce({
|
||||
...initial(),
|
||||
revision: undefined
|
||||
} as unknown as ProjectQualityPolicyResult)
|
||||
if (kind === '保存失败') api.save.mockRejectedValueOnce(new Error('保存失败'))
|
||||
if (kind === '确认失败') api.confirm.mockRejectedValueOnce(new Error('确认失败'))
|
||||
if (kind === '回执不符') api.confirm.mockResolvedValueOnce(initial())
|
||||
if (kind === '确认后变化')
|
||||
api.confirm.mockImplementationOnce(async () => {
|
||||
const confirmed = {
|
||||
...api.get(),
|
||||
confirmed: true,
|
||||
confirmedRevision: api.get().revision,
|
||||
confirmedAt: '2026-10-17T15:00:00Z'
|
||||
}
|
||||
api.change({ revision: api.get().revision + 1 })
|
||||
return confirmed
|
||||
})
|
||||
expect(await flow.confirmRules(draft)).toBe(false)
|
||||
expect(flow.startOpen.value).toBe(false)
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
}
|
||||
)
|
||||
it.each(['cancel', 'project', 'scope', 'locked'])('%s 后丢弃迟到读取,重复点击不重复读取', async cause => {
|
||||
let finish!: (value: ProjectQualityPolicyResult) => void
|
||||
const read = vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(() => new Promise(resolve => { finish = resolve }))
|
||||
const { flow, id, input, allowed } = setup(); const pending = flow.prepare(); await flow.prepare()
|
||||
const read = vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
const { flow, id, input, allowed } = setup()
|
||||
const pending = flow.prepare()
|
||||
await flow.prepare()
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
if (cause === 'cancel') flow.cancel()
|
||||
if (cause === 'project') id.value = 'other'
|
||||
if (cause === 'scope') input.value = 'new'
|
||||
if (cause === 'locked') allowed.value = false
|
||||
finish(initial()); await pending
|
||||
expect(flow.reviewOpen.value).toBe(false); expect(flow.startOpen.value).toBe(false); expect(flow.consumePermit()).toBeNull()
|
||||
finish(initial())
|
||||
await pending
|
||||
expect(flow.reviewOpen.value).toBe(false)
|
||||
expect(flow.startOpen.value).toBe(false)
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
})
|
||||
it('确认写入时锁定取消,写入后的只读回查仍可关闭且迟到响应不启动', async () => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare()
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
let finish!: (value: ProjectQualityPolicyResult) => void
|
||||
api.confirm.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
|
||||
api.confirm.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
const pending = flow.confirmRules(initial().policy)
|
||||
await Promise.resolve(); await Promise.resolve(); expect(flow.saving.value).toBe(true)
|
||||
flow.cancel(); expect(flow.reviewOpen.value).toBe(true)
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
expect(flow.saving.value).toBe(true)
|
||||
flow.cancel()
|
||||
expect(flow.reviewOpen.value).toBe(true)
|
||||
let finishRead!: (value: ProjectQualityPolicyResult) => void
|
||||
api.read.mockImplementationOnce(() => new Promise(resolve => { finishRead = resolve }))
|
||||
api.read.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
finishRead = resolve
|
||||
})
|
||||
)
|
||||
const confirmed = { ...initial(), confirmed: true, confirmedRevision: 0, confirmedAt: '2026-10-17T15:00:00Z' }
|
||||
finish(confirmed); await Promise.resolve(); await Promise.resolve()
|
||||
expect(flow.reading.value).toBe(true); expect(flow.saving.value).toBe(false)
|
||||
flow.cancel(); finishRead(confirmed); expect(await pending).toBe(false); expect(flow.consumePermit()).toBeNull()
|
||||
finish(confirmed)
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
expect(flow.reading.value).toBe(true)
|
||||
expect(flow.saving.value).toBe(false)
|
||||
flow.cancel()
|
||||
finishRead(confirmed)
|
||||
expect(await pending).toBe(false)
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
})
|
||||
it('最终费用确认期间规则更新或确认撤销均返回规则核对', async () => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare(); await flow.confirmRules(initial().policy)
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
await flow.confirmRules(initial().policy)
|
||||
api.change({ confirmed: false, confirmedRevision: null, confirmedAt: null })
|
||||
expect(await flow.verifyStart()).toBe(false); expect(flow.reviewOpen.value).toBe(true); expect(flow.consumePermit()).toBeNull()
|
||||
expect(await flow.verifyStart()).toBe(false)
|
||||
expect(flow.reviewOpen.value).toBe(true)
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
})
|
||||
it('最终重读失败不能启动,取消后迟到成功也不能启动', async () => {
|
||||
const api = server(); const { flow } = setup(); await flow.prepare(); await flow.confirmRules(initial().policy)
|
||||
api.read.mockRejectedValueOnce(new Error('重读失败')); expect(await flow.verifyStart()).toBe(false)
|
||||
const api = server()
|
||||
const { flow } = setup()
|
||||
await flow.prepare()
|
||||
await flow.confirmRules(initial().policy)
|
||||
api.read.mockRejectedValueOnce(new Error('重读失败'))
|
||||
expect(await flow.verifyStart()).toBe(false)
|
||||
let finish!: (value: ProjectQualityPolicyResult) => void
|
||||
api.read.mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
|
||||
const pending = flow.verifyStart(); flow.cancel(); finish(api.get())
|
||||
expect(await pending).toBe(false); expect(flow.consumePermit()).toBeNull()
|
||||
api.read.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
)
|
||||
const pending = flow.verifyStart()
|
||||
flow.cancel()
|
||||
finish(api.get())
|
||||
expect(await pending).toBe(false)
|
||||
expect(flow.consumePermit()).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user