-
Notifications
You must be signed in to change notification settings - Fork 5
feat(workflow-editor): 前端接上三渲二的建资产入口与路线选择 #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnnyzhang-eng
wants to merge
2
commits into
1024XEngineer:main
Choose a base branch
from
johnnyzhang-eng:feat/render3d-frontend-entry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import type { ApiClient } from '@/shared/api' | ||
| import { createRender3DApis, Render3DContractError } from './api' | ||
|
|
||
| function clientReturning(data: unknown): { client: ApiClient; calls: string[] } { | ||
| const calls: string[] = [] | ||
| const client: ApiClient = { | ||
| request: vi.fn(async (path: string, options?: { method?: string }) => { | ||
| calls.push(`${options?.method ?? 'GET'} ${path}`) | ||
| return data | ||
| }) as ApiClient['request'], | ||
| requestList: vi.fn() as ApiClient['requestList'], | ||
| } | ||
| return { client, calls } | ||
| } | ||
|
|
||
| const ASSET = { | ||
| asset_key: 'character-7/outfit-default', | ||
| state: 'awaiting_review', | ||
| model_3d_url: null, | ||
| review_model_url: 'https://cdn.test/pending.glb', | ||
| error: null, | ||
| cost: { | ||
| model3d_credits: 20, | ||
| autorig_credits: 10, | ||
| total_credits: 30, | ||
| total_cny: 3.6, | ||
| billing: 'postpaid', | ||
| scope: 'per_outfit_once', | ||
| }, | ||
| } | ||
|
|
||
| const REPORT = { | ||
| accepted: true, | ||
| reject_code: null, | ||
| detail: '母版 400×600', | ||
| facts: { | ||
| width: 400, | ||
| height: 600, | ||
| subject_ratio: 0.19, | ||
| subject_area_ratio: 0.14, | ||
| limb_segments: [2, 2, 2, 2], | ||
| components: [33600], | ||
| }, | ||
| warnings: [{ code: 'limbs_fused', detail: '两腿之间量不到空隙' }], | ||
| } | ||
|
|
||
| describe('三渲二资产适配器', () => { | ||
| it('把后端的蛇形字段翻成实体形状', async () => { | ||
| const { client } = clientReturning(ASSET) | ||
| const asset = await createRender3DApis(client).getOutfitAsset('7', 'outfit-default') | ||
|
|
||
| expect(asset.state).toBe('awaiting_review') | ||
| expect(asset.reviewModelUrl).toBe('https://cdn.test/pending.glb') | ||
| expect(asset.cost.totalCredits).toBe(30) | ||
| expect(asset.cost.totalCny).toBe(3.6) | ||
| }) | ||
|
|
||
| it('四个动作各自打到自己的路径上', async () => { | ||
| const { client, calls } = clientReturning(ASSET) | ||
| const apis = createRender3DApis(client) | ||
| await apis.getOutfitAsset('7', 'outfit-default') | ||
| await apis.buildOutfitAsset('7', 'outfit-default') | ||
| await apis.approveOutfitAsset('7', 'outfit-default') | ||
| await apis.discardOutfitAsset('7', 'outfit-default') | ||
|
|
||
| expect(calls).toEqual([ | ||
| 'GET /render3d/characters/7/outfits/outfit-default', | ||
| 'POST /render3d/characters/7/outfits/outfit-default/build', | ||
| 'POST /render3d/characters/7/outfits/outfit-default/approve', | ||
| 'POST /render3d/characters/7/outfits/outfit-default/discard', | ||
| ]) | ||
| }) | ||
|
|
||
| it('认不出的状态直接拒收', async () => { | ||
| const { client } = clientReturning({ ...ASSET, state: 'almost_done' }) | ||
| await expect(createRender3DApis(client).getOutfitAsset('7', 'a')).rejects.toBeInstanceOf( | ||
| Render3DContractError, | ||
| ) | ||
| }) | ||
|
|
||
| it('成本字段缺一个就拒收——界面拿它让用户做付费决定', async () => { | ||
| const { total_cny: _dropped, ...partial } = ASSET.cost | ||
| const { client } = clientReturning({ ...ASSET, cost: partial }) | ||
| await expect(createRender3DApis(client).getOutfitAsset('7', 'a')).rejects.toBeInstanceOf( | ||
| Render3DContractError, | ||
| ) | ||
| }) | ||
|
|
||
| it('预检结果带回量到的形态与警告', async () => { | ||
| const { client } = clientReturning(REPORT) | ||
| const report = await createRender3DApis(client).precheckMaster('https://cdn.test/m.png') | ||
|
|
||
| expect(report.accepted).toBe(true) | ||
| expect(report.facts?.limbSegments).toEqual([2, 2, 2, 2]) | ||
| expect(report.warnings).toEqual([{ code: 'limbs_fused', detail: '两腿之间量不到空隙' }]) | ||
| }) | ||
|
|
||
| it('通过却带着拒绝码属于后端两处判定分叉,必须拒收', async () => { | ||
| // 放行的话界面会显示"这张可用"而建资产那一步拒收,用户只看到一个无从解释的失败。 | ||
| const { client } = clientReturning({ ...REPORT, reject_code: 'aspect_too_wide' }) | ||
| await expect( | ||
| createRender3DApis(client).precheckMaster('https://cdn.test/m.png'), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('被拒却没有拒绝码同样拒收', async () => { | ||
| const { client } = clientReturning({ ...REPORT, accepted: false, facts: null, warnings: [] }) | ||
| await expect( | ||
| createRender3DApis(client).precheckMaster('https://cdn.test/m.png'), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('认不出的警告码拒收——界面会按码选文案,静默丢弃等于漏报', async () => { | ||
| const { client } = clientReturning({ | ||
| ...REPORT, | ||
| warnings: [{ code: 'has_text', detail: '画面里有文字' }], | ||
| }) | ||
| await expect( | ||
| createRender3DApis(client).precheckMaster('https://cdn.test/m.png'), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
| }) | ||
|
|
||
| describe('三渲二适配器的形状守卫', () => { | ||
| // 这些分支挡的是"后端换了形状但没人发现"。放行的话,坏值会一路流到界面上: | ||
| // 用户看到的是 NaN 积分或空白状态,而错误的来源在两层之外。 | ||
| async function precheckWith(payload: unknown) { | ||
| const { client } = clientReturning(payload) | ||
| return createRender3DApis(client).precheckMaster('https://cdn.test/master.png', { | ||
| width: 64, | ||
| height: 64, | ||
| }) | ||
| } | ||
|
|
||
| it('facts 不是对象时拒收', async () => { | ||
| await expect(precheckWith({ ...REPORT, facts: 'not-an-object' })).rejects.toBeInstanceOf( | ||
| Render3DContractError, | ||
| ) | ||
| }) | ||
|
|
||
| it('量出来的尺寸不是有限数字时拒收', async () => { | ||
| await expect( | ||
| precheckWith({ ...REPORT, facts: { ...REPORT.facts, width: 'wide' } }), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('limb_segments 不是数组时拒收', async () => { | ||
| await expect( | ||
| precheckWith({ ...REPORT, facts: { ...REPORT.facts, limb_segments: 3 } }), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('limb_segments 里混进非数字时拒收', async () => { | ||
| await expect( | ||
| precheckWith({ ...REPORT, facts: { ...REPORT.facts, limb_segments: [1, '2'] } }), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('warnings 不是数组时拒收', async () => { | ||
| await expect(precheckWith({ ...REPORT, warnings: 'none' })).rejects.toBeInstanceOf( | ||
| Render3DContractError, | ||
| ) | ||
| }) | ||
|
|
||
| it('警告缺 detail 时拒收——界面要拿它告诉用户具体哪里不合格', async () => { | ||
| await expect( | ||
| precheckWith({ ...REPORT, warnings: [{ code: 'limbs_fused' }] }), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('accepted 不是布尔值时拒收', async () => { | ||
| await expect(precheckWith({ ...REPORT, accepted: 'yes' })).rejects.toBeInstanceOf( | ||
| Render3DContractError, | ||
| ) | ||
| }) | ||
|
|
||
| it('facts 缺席时是合法的——预检被拒时后端不量形态', async () => { | ||
| const report = await precheckWith({ | ||
| ...REPORT, | ||
| accepted: false, | ||
| reject_code: 'aspect_too_wide', | ||
| facts: null, | ||
| }) | ||
| expect(report.facts).toBeNull() | ||
| }) | ||
|
|
||
| it('认不出的拒绝码拒收——界面按码选文案,静默丢弃等于漏报', async () => { | ||
| await expect( | ||
| precheckWith({ ...REPORT, accepted: false, reject_code: 'no_such_reason' }), | ||
| ).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
|
|
||
| it('整个预检结果不是对象时拒收', async () => { | ||
| await expect(precheckWith(['报告'])).rejects.toBeInstanceOf(Render3DContractError) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] 仅在选择三渲二时发送 outfit_id
这里对所有完整动画请求都发送
outfit_id,但后端并不读取 WorkflowRun 中保存的method;它只要发现该造型存在model_3d_url就直接走generate_rendered。因此一个已经建好 3D 资产的造型即使用户明确点击“视频裁剪”,最终也会被静默改成三渲二,改变画风、成本和生成语义。请把所选方法传入这一层,并仅在method === '3d-to-2d'时携带outfit_id(或提供等价的显式后端路线参数),同时覆盖“有 3D 资产但选择视频裁剪”的用例。