火山 Seedance 2.0 于 2026-04-16 上线 1080P 支持。本次实现前端 UI、
后端校验/计费、数据库迁移,并严格遵守三原则:
1. 禁止兜底/静默降级 — Fast+1080P 组合在 UI/store/serializer/view/计价
五层防御,任一层穿透都 fail loud,不悄悄按 720P 扣费
2. 钱的计算绝对准确 — 前端预估公式与后端 estimate_tokens 完全一致
`(输入时长+输出时长) × 宽 × 高 × fps / 1024`;实际扣费按火山返回
total_tokens × 官方单价;预估端不维护最低 token 修正表
3. 不隐藏 bug — 无 `or '720p'` / `|| '720p'` 兜底;类型严格;异常暴露
## 后端(7 处 + 1 次迁移)
- models.py: QuotaConfig 加 base_token_price_1080p(51)/base_token_price_1080p_video(31);
GenerationRecord.resolution 加 RESOLUTION_CHOICES 约束 + default='720p'
- migrations/0020: 含 RunPython data migration 回填历史 resolution='' → '720p'
- utils/billing.py:
* RESOLUTION_MAP 加 1080P 六种宽高比(21:9 是 2206×946,不是 seedance 1.0 值)
* get_resolution 去掉 tier 默认值,非法组合 raise KeyError 不静默降级
* estimate_tokens 纯官方公式,加 input_video_duration 参数(公式完整)
- utils/airdrama_client.py: create_task 加 resolution 必填参数(无默认值)
- apps/generation/serializers.py:
* VideoGenerateSerializer 加 resolution ChoiceField
* aspect_ratio 改 ChoiceField 显式拒绝 adaptive
* SystemSettingsSerializer 加 2 个 1080P 单价
- apps/generation/views.py:
* _get_token_price 加 resolution 必填参数,Fast+1080P raise ValueError
* _sum_video_duration 累加视频参考时长
* video_generate_view 读 resolution、400 拒绝 Fast+1080P 组合、
传给 get_resolution/estimate_tokens/_get_token_price/create_task/
GenerationRecord.resolution(移除 L450 硬编码 '720p')
* _settle_payment 按 record.resolution 取单价(1080P 结算按 1080P 价)
* _serialize_task + 5 处手工序列化加 resolution 字段(无 `or '720p'`)
- apps/accounts/views.py: team 接口返回 token_price_1080p/_video
## 前端(10 处)
- types/index.ts: Resolution 类型;GenerationTask/BackendTask/Team/
QuotaConfig/AssetVideo 加字段(全部必填,无 optional)
- store/inputBar.ts: resolution state;setModel/setResolution 双向拦截
Fast+1080P 组合,toast 提示引导,不静默降级
- store/generation.ts: addTask/backendToFrontend/reEdit/regenerate 全链路
携带 resolution;mapErrorMessage 改 '今日生成次数或团队余额不足'
- components/Toolbar.tsx:
* 加分辨率选择器 Dropdown(位置:比例和时长之间)
* modelItems/resolutionItems 双向 disabled(Fast 下 1080P 灰 / 1080P 下 Fast 灰)
* estimatedTokens 对齐后端公式(含输入视频时长 + assetMentions 视频时长)
* estimatedCost 按 resolution 选单价(Fast→fast_*、1080p→1080p_*、其他→基础)
* tooltip 明示"实际费用以火山 API 返回的 token 数为准"
- components/Dropdown.tsx: 加 disabled 属性支持
- components/VideoDetailModal.tsx: 重新编辑恢复 resolution
- components/GenerationCard.tsx: 动态显示 task.resolution.toUpperCase()
- pages/SettingsPage.tsx: 加 2 个 1080P 单价输入框(独立分组)
- pages/AdminAssetsPage.tsx / TeamAssetsPage.tsx: 去 || '720p' 兜底
- lib/api.ts: videoApi.generate 参数 resolution 必填
## 测试(47 个用例)
### 后端(28 个)
- tests/test_1080p_billing.py(23): RESOLUTION_MAP 像素、estimate_tokens
公式(含/不含输入视频、不做最低 token 修正)、_get_token_price 六种
组合、Fast+1080P 抛异常、calculate_cost 对齐官方示例 4.97 / 12.39 元
- tests/test_1080p_api.py(5): video_generate_view 拒绝 Fast+1080P (400)
+ 拒绝 adaptive + 拒绝非法 resolution + 默认值兼容 + 合法组合通过
### 前端(19 个)
- test/unit/resolution1080p.test.ts(14): store 状态、双向拦截
(1080P 下切 Fast 被阻止 model 不变、反向同样)、官方像素契约测试、
价格示例对齐(720P 4.97 / 1080P 12.39)
- test/e2e/resolution-1080p.spec.ts(5): 真实浏览器验证默认 720P、
Dropdown 双向置灰、tooltip 明示以火山为准
## 与官方文档对齐
- 参数:resolution (480p/720p/1080p 小写)、ratio、duration、generate_audio
- 像素:来自 docs/API文档/创建视频生成任务API.md Seedance 2.0 & 2.0 fast 列
- 单价:来自 docs/API文档/seedance模型价格.md (46/28/51/31/37/22)
- Fast 不支持 1080P:来自 docs/API文档/Seedance 2.0 1080P.md
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
137 lines
5.1 KiB
TypeScript
137 lines
5.1 KiB
TypeScript
/**
|
||
* 1080P 分辨率支持 E2E — 真实浏览器验证 UI 双向约束和预估费用。
|
||
* 针对本地开发环境(localhost:5173 + 127.0.0.1:8000)。
|
||
*/
|
||
import { test, expect, Page } from '@playwright/test';
|
||
|
||
const BASE_URL = 'http://localhost:5173';
|
||
const API_URL = 'http://127.0.0.1:8000';
|
||
const USERNAME = 'admin';
|
||
const PASSWORD = 'admin123';
|
||
|
||
async function login(page: Page) {
|
||
const resp = await page.request.post(`${API_URL}/api/v1/auth/login`, {
|
||
data: { username: USERNAME, password: PASSWORD },
|
||
});
|
||
if (!resp.ok()) {
|
||
const err = await resp.text();
|
||
throw new Error(`Login failed: ${resp.status()} ${err}`);
|
||
}
|
||
const body = await resp.json();
|
||
|
||
await page.goto(BASE_URL);
|
||
await page.evaluate(({ access, refresh }) => {
|
||
localStorage.setItem('access_token', access);
|
||
localStorage.setItem('refresh_token', refresh);
|
||
}, { access: body.tokens.access, refresh: body.tokens.refresh });
|
||
await page.goto(`${BASE_URL}/app`);
|
||
await page.waitForTimeout(1500);
|
||
|
||
// 关闭公告弹窗
|
||
const knowBtn = page.getByRole('button', { name: /我知道了|知道了|关闭/ }).first();
|
||
if (await knowBtn.isVisible().catch(() => false)) {
|
||
await knowBtn.click();
|
||
await page.waitForTimeout(300);
|
||
}
|
||
}
|
||
|
||
test.describe.serial('1080P 分辨率支持', () => {
|
||
test('默认分辨率显示 720P', async ({ page }) => {
|
||
await login(page);
|
||
// 找到 Toolbar 里的分辨率按钮(label 应显示 720P)
|
||
const resolutionBtn = page.getByRole('button', { name: '720P', exact: true }).first();
|
||
await expect(resolutionBtn).toBeVisible();
|
||
});
|
||
|
||
test('AirDrama 模式下可切换到 1080P', async ({ page }) => {
|
||
await login(page);
|
||
// 点分辨率按钮展开 dropdown
|
||
await page.getByRole('button', { name: '720P', exact: true }).first().click();
|
||
await page.waitForTimeout(200);
|
||
|
||
// 选 1080P
|
||
await page.getByText('1080P', { exact: true }).click();
|
||
await page.waitForTimeout(300);
|
||
|
||
// 分辨率按钮应显示 1080P
|
||
await expect(page.getByRole('button', { name: '1080P', exact: true }).first()).toBeVisible();
|
||
});
|
||
|
||
test('1080P 下 Fast 模型置灰(UI 不可达 Fast+1080P)', async ({ page }) => {
|
||
await login(page);
|
||
// 先切到 1080P
|
||
await page.getByRole('button', { name: '720P', exact: true }).first().click();
|
||
await page.waitForTimeout(200);
|
||
await page.getByText('1080P', { exact: true }).click();
|
||
await page.waitForTimeout(300);
|
||
|
||
// 打开模型 dropdown
|
||
await page.getByRole('button', { name: /AirDrama$/, exact: false }).first().click();
|
||
await page.waitForTimeout(200);
|
||
|
||
// Fast 项应包含 "不支持 1080P" 且有 disabled 视觉
|
||
const fastItem = page.getByText(/AirDrama Fast.*不支持 1080P/);
|
||
await expect(fastItem).toBeVisible();
|
||
|
||
// 点击 Fast 不应切换(Dropdown 的 disabled 阻止了 onSelect)
|
||
await fastItem.click({ force: true });
|
||
await page.waitForTimeout(300);
|
||
|
||
// 模型应仍是 AirDrama
|
||
await expect(page.getByRole('button', { name: /AirDrama$/, exact: false }).first()).toBeVisible();
|
||
});
|
||
|
||
test('Fast 模式下 1080P 置灰(UI 不可达 Fast+1080P,反向)', async ({ page }) => {
|
||
await login(page);
|
||
// 先确保 resolution 是 720P(reset)
|
||
await page.reload();
|
||
await page.waitForTimeout(1500);
|
||
|
||
// 切到 Fast 模型
|
||
await page.getByRole('button', { name: /AirDrama$/, exact: false }).first().click();
|
||
await page.waitForTimeout(200);
|
||
await page.getByText('AirDrama Fast', { exact: true }).click();
|
||
await page.waitForTimeout(300);
|
||
|
||
// 打开分辨率 dropdown
|
||
await page.getByRole('button', { name: '720P', exact: true }).first().click();
|
||
await page.waitForTimeout(200);
|
||
|
||
// 1080P 项应带 "Fast 不支持" 标注
|
||
const disabled1080p = page.getByText(/1080P.*Fast 不支持/);
|
||
await expect(disabled1080p).toBeVisible();
|
||
|
||
// 点击不生效
|
||
await disabled1080p.click({ force: true });
|
||
await page.waitForTimeout(300);
|
||
|
||
// 分辨率仍为 720P(可能 Dropdown 保持打开或关闭,但按钮不该变)
|
||
const bodyText = await page.textContent('body');
|
||
expect(bodyText).toContain('720P');
|
||
});
|
||
|
||
test('预估费用 tooltip 明示「以火山为准」', async ({ page }) => {
|
||
await login(page);
|
||
// 需要让按钮栏里的"预估"显示出来(需要有 prompt 或素材)
|
||
// 输入一个简单 prompt
|
||
const promptArea = page.locator('[contenteditable]').first();
|
||
if (await promptArea.isVisible().catch(() => false)) {
|
||
await promptArea.click();
|
||
await promptArea.type('测试提示词');
|
||
await page.waitForTimeout(300);
|
||
}
|
||
|
||
// 找到"预估消耗"文案
|
||
const estSpan = page.getByText(/预估消耗/).first();
|
||
if (await estSpan.isVisible().catch(() => false)) {
|
||
const title = await estSpan.getAttribute('title');
|
||
expect(title).toBeTruthy();
|
||
expect(title!).toContain('实际');
|
||
expect(title!).toContain('火山');
|
||
} else {
|
||
// 如果没有预估显示(比如 team 没配单价),跳过
|
||
console.log('跳过:预估未显示(team 可能未配单价)');
|
||
}
|
||
});
|
||
});
|