Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/scripts/issue825-video-pricing-fixture.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Synthetic data only; both source trees use this identical component harness.
import { createApp, h } from 'vue'
import { createI18n } from 'vue-i18n'
import Table from './src/components/modelPlaza/PlazaModelPricingTable.vue'
import zh from './src/i18n/locales/zh/dashboard.ts'
import en from './src/i18n/locales/en/dashboard.ts'
import './src/style.css'

const locale = new URLSearchParams(location.search).get('lang') || 'zh'
document.documentElement.lang = locale
const price = (billing_mode, per_request_price) => ({
billing_mode, per_request_price, input_price: null, output_price: null,
cache_write_price: null, cache_read_price: null, image_input_price: null,
image_output_price: null, intervals: []
})
const model = (name, pricing) => ({ name, platform: 'openai', pricing, official_pricing: null })
const models = [
model('demo-video-base', price('video', 0.54)),
model('demo-video-resolution', {
...price('video', 0.54),
intervals: [0.54, 1.08].map((value, index) => ({
...price('video', value), min_tokens: 0, max_tokens: null,
tier_label: index === 0 ? '480p' : '720p'
}))
}),
model('demo-image', price('image', 0.2)),
model('demo-request', price('per_request', 0.04)),
model('demo-token', {
...price('token', null), input_price: 2e-6, output_price: 8e-6,
cache_write_price: 4e-6, cache_read_price: 1e-6
})
]
const groups = [
{ id: 'group', title: 'Synthetic group rate 0.5', props: {} },
{ id: 'user', title: 'Synthetic user rate 0.25', props: { userRateMultiplier: 0.25 } },
{ id: 'independent', title: 'Synthetic video rate 2 / image rate 3', props: {
userRateMultiplier: 0.25, videoRateIndependent: true, videoRateMultiplier: 2,
imageRateIndependent: true, imageRateMultiplier: 3
} }
]
const app = createApp({
render: () => h('main', { class: 'min-h-screen bg-white p-6 text-gray-900 dark:bg-dark-900 dark:text-white' }, [
h('h1', { class: 'mb-2 text-xl font-bold' }, `Model Plaza · ${locale} · synthetic component preview`),
h('p', { class: 'mb-4 text-sm text-gray-500' }, 'Actual Vue component, locale and application CSS. No API calls.'),
...groups.map(group => h('section', { 'data-scenario': group.id, class: 'mb-5' }, [
h('h2', { class: 'mb-2 font-semibold' }, group.title),
h(Table, { models, platform: 'openai', rateMultiplier: 0.5, ...group.props })
]))
])
})
app.use(createI18n({ legacy: false, locale, messages: { zh, en } }))
app.mount('#app')
window.__issue825Ready = true
100 changes: 100 additions & 0 deletions .github/scripts/issue825-video-pricing-screenshot.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Remote-only: same full-tree / actual CSS rendering pattern as upstream-v0221-screenshot.mjs.
import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { join, resolve } from 'node:path'
import { pathToFileURL } from 'node:url'

const output = process.env.SCREENSHOT_DIR
assert.ok(output && process.env.SOURCE_BASE && process.env.BASELINE_ROOT && process.env.PLAYWRIGHT_ROOT)
const head = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim()
assert.equal(head, process.env.EXPECTED_HEAD_SHA)
mkdirSync(output, { recursive: true })
const digest = path => createHash('sha256').update(readFileSync(path)).digest('hex')
const manifest = {
baseline: process.env.SOURCE_BASE, candidate: head,
boundary: 'Full baseline archive and exact candidate; actual Vue component, locales, style.css and original Tailwind. Identical synthetic props, no API calls or production data. Component preview only.',
screenshots: [], observations: [], sources: [], errors: []
}
const { chromium } = await import(pathToFileURL(join(process.env.PLAYWRIGHT_ROOT, 'index.mjs')).href)
const browser = await chromium.launch({ headless: true })
try {
for (const mode of ['before', 'after']) {
const root = resolve(mode === 'before' ? process.env.BASELINE_ROOT : 'frontend')
const require = createRequire(join(root, 'package.json'))
const { build, preview } = await import(pathToFileURL(join(root, 'node_modules/vite/dist/node/index.js')).href)
const vue = (await import(pathToFileURL(require.resolve('@vitejs/plugin-vue')).href)).default
const tailwind = (await import(pathToFileURL(join(root, 'tailwind.config.js')).href)).default
const tag = '.ci-issue825-' + process.pid
const paths = [join(root, tag + '.html'), join(root, tag + '.mjs')]
writeFileSync(paths[0], `<html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script type="module" src="./${tag}.mjs"></script></html>`)
writeFileSync(paths[1], readFileSync('.github/scripts/issue825-video-pricing-fixture.mjs'))
const sourcePaths = ['src/components/modelPlaza/PlazaModelPricingTable.vue', 'src/style.css', 'tailwind.config.js', 'src/i18n/locales/zh/dashboard.ts', 'src/i18n/locales/en/dashboard.ts']
manifest.sources.push({ mode, sha: mode === 'before' ? process.env.SOURCE_BASE : head, files: sourcePaths.map(path => ({ path, sha256: digest(join(root, path)) })) })
const buildDir = join(output, mode + '-build')
let server
try {
await build({
root, configFile: false, cacheDir: join(output, mode + '-cache'), plugins: [vue()],
resolve: { alias: { '@': join(root, 'src'), 'vue-i18n': require.resolve('vue-i18n/dist/vue-i18n.runtime.esm-bundler.js') } },
define: { __INTLIFY_JIT_COMPILATION__: true },
css: { postcss: { plugins: [require('tailwindcss')({ ...tailwind, content: [...paths, join(root, 'src/**/*.{vue,js,ts}')] }), require('autoprefixer')()] } },
build: { outDir: buildDir, emptyOutDir: true, minify: false, target: 'esnext', rollupOptions: { input: paths[0] } }
})
server = await preview({ root, configFile: false, build: { outDir: buildDir }, preview: { host: '127.0.0.1', port: 4199, strictPort: true } })
for (const lang of ['zh', 'en']) {
const page = await browser.newPage({ viewport: { width: 1440, height: 1100 }, locale: lang === 'zh' ? 'zh-CN' : 'en-US', timezoneId: 'UTC' })
page.on('pageerror', error => manifest.errors.push(`${mode}/${lang}: ${error.message}`))
await page.route('**/*', route => new URL(route.request().url()).origin === 'http://127.0.0.1:4199' ? route.continue() : route.abort())
try {
await page.goto(`http://127.0.0.1:4199/${tag}.html?lang=${lang}`)
await page.waitForFunction(() => window.__issue825Ready)
await page.evaluate(async () => { await document.fonts.ready; await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))) })
const observed = await page.locator('section').evaluateAll(sections => sections.map(section => ({
scenario: section.dataset.scenario,
rows: [...section.querySelectorAll('tbody tr')].map(row => [...row.querySelectorAll('td')].map(cell => cell.innerText.trim()))
})))
const label = lang === 'zh' ? (mode === 'before' ? '按次计费' : '按秒计费') : (mode === 'before' ? 'Per request' : 'Per second')
const suffix = lang === 'zh' ? (mode === 'before' ? '/ 次' : '/ 秒') : (mode === 'before' ? '/ request' : '/ second')
const prices = { group: ['$0.27', '$0.54'], user: ['$0.135', '$0.27'], independent: ['$1.08', '$2.16'] }
for (const section of observed) {
const videos = section.rows.filter(row => row[0].startsWith('demo-video'))
assert.equal(videos.length, 2)
for (const row of videos) {
assert.ok(row[0].includes(label), JSON.stringify(row))
assert.ok(row[1].includes(suffix), JSON.stringify(row))
assert.ok(row[1].includes(prices[section.scenario][0]), JSON.stringify(row))
if (row[0].startsWith('demo-video-resolution')) {
assert.ok(row[1].includes('480p') && row[1].includes('720p'))
assert.ok(row[1].includes(prices[section.scenario][1]))
}
}
}
const css = await page.locator('table').first().evaluate(table => ({ fontSize: getComputedStyle(table).fontSize, minWidth: getComputedStyle(table).minWidth, borderCollapse: getComputedStyle(table).borderCollapse }))
assert.equal(css.minWidth, '1000px')
assert.equal(css.fontSize, '14px')
manifest.observations.push({ mode, lang, css, sections: observed })
for (const theme of ['light', 'dark']) {
await page.evaluate(value => document.documentElement.classList.toggle('dark', value === 'dark'), theme)
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))))
const name = `${mode}-${lang}-${theme}.png`
await page.screenshot({ path: join(output, name), fullPage: true, animations: 'disabled' })
manifest.screenshots.push({ name, sha: mode === 'before' ? process.env.SOURCE_BASE : head, sha256: digest(join(output, name)) })
}
console.log(JSON.stringify({ mode, lang, label, suffix, css, scenarios: observed.length }))
} finally { await page.close() }
}
} finally {
if (server) await new Promise(resolve => server.httpServer.close(resolve))
paths.forEach(path => rmSync(path, { force: true }))
rmSync(buildDir, { recursive: true, force: true })
rmSync(join(output, mode + '-cache'), { recursive: true, force: true })
}
}
assert.deepEqual(manifest.errors, [])
} finally {
writeFileSync(join(output, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n')
await browser.close()
}
120 changes: 120 additions & 0 deletions .github/workflows/issue825-video-pricing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Issue825 video pricing units
on:
push:
branches: [fix/issue825-video-pricing-unit]
pull_request:
branches: [production]
permissions:
contents: read
env:
EXPECTED_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
SOURCE_BASE: c424f8217da12cd4fb8d10aeaf1c4f2592c3f286
jobs:
regression:
if: github.head_ref == 'fix/issue825-video-pricing-unit' || github.ref_name == 'fix/issue825-video-pricing-unit'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Assert exact candidate
run: test "$(git rev-parse HEAD)" = "$EXPECTED_HEAD_SHA"
- uses: pnpm/action-setup@v6
with:
version: 9
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- run: pnpm --dir frontend install --frozen-lockfile
- name: Real pricing components and locale completeness (GREEN)
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/issue825-tests"
pnpm --dir frontend exec vitest run src/components/modelPlaza/__tests__/PlazaModelPricingTable.spec.ts src/components/modelPlaza/__tests__/PlazaModelPricingTable.video.spec.ts src/i18n/__tests__/localeKeyCompleteness.spec.ts --reporter=verbose 2>&1 | tee "$RUNNER_TEMP/issue825-tests/green.log"
- name: Same localized component regression against fixed defective source (RED)
env:
EVIDENCE_DIR: ${{ runner.temp }}/issue825-tests
run: |
set -euo pipefail
for file in frontend/src/components/modelPlaza/PlazaModelPricingTable.vue frontend/src/i18n/locales/zh/dashboard.ts frontend/src/i18n/locales/en/dashboard.ts; do
git show "$SOURCE_BASE:$file" > "$file"
done
set +e
pnpm --dir frontend exec vitest run src/components/modelPlaza/__tests__/PlazaModelPricingTable.video.spec.ts --reporter=verbose --reporter=json --outputFile="$EVIDENCE_DIR/red.json" > "$EVIDENCE_DIR/red.log" 2>&1
result=$?
set -e
cat "$EVIDENCE_DIR/red.log"
test "$result" -ne 0
node --input-type=module <<'JS'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
const report = JSON.parse(readFileSync(`${process.env.EVIDENCE_DIR}/red.json`, 'utf8'))
assert.equal(report.numFailedTests, 10)
assert.equal(report.numPassedTests, 6)
const failures = report.testResults.flatMap(file => file.assertionResults).filter(test => test.status === 'failed')
assert.equal(failures.length, 10)
for (const test of failures) {
assert.ok(test.fullName.includes('shows seconds and preserves'))
assert.ok(test.failureMessages.join('\n').includes('to contain'))
}
console.log('RED confirmed: 10 video label assertions fail; 6 image/request/token controls pass')
JS
- uses: actions/upload-artifact@v7
if: always()
with:
name: issue825-tests-${{ github.event_name }}-${{ github.event.pull_request.head.sha || github.sha }}
path: ${{ runner.temp }}/issue825-tests
if-no-files-found: error
rendered:
if: github.head_ref == 'fix/issue825-video-pricing-unit' || github.ref_name == 'fix/issue825-video-pricing-unit'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Assert exact candidate
run: test "$(git rev-parse HEAD)" = "$EXPECTED_HEAD_SHA"
- uses: pnpm/action-setup@v6
with:
version: 9
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- run: pnpm --dir frontend install --frozen-lockfile
- name: Preserve complete baseline archive
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/issue825-baseline"
git archive "$SOURCE_BASE" | tar -x -C "$RUNNER_TEMP/issue825-baseline"
cmp frontend/package.json "$RUNNER_TEMP/issue825-baseline/frontend/package.json"
cmp frontend/pnpm-lock.yaml "$RUNNER_TEMP/issue825-baseline/frontend/pnpm-lock.yaml"
ln -s "$GITHUB_WORKSPACE/frontend/node_modules" "$RUNNER_TEMP/issue825-baseline/frontend/node_modules"
- name: Install isolated browser remotely
run: |
npm install --prefix "$RUNNER_TEMP/issue825-browser" --no-save --ignore-scripts playwright@1.56.1
"$RUNNER_TEMP/issue825-browser/node_modules/.bin/playwright" install --with-deps chromium
- name: Render actual baseline and candidate components with real CSS
env:
BASELINE_ROOT: ${{ runner.temp }}/issue825-baseline/frontend
PLAYWRIGHT_ROOT: ${{ runner.temp }}/issue825-browser/node_modules/playwright
SCREENSHOT_DIR: ${{ runner.temp }}/issue825-ui
run: |
set -euo pipefail
mkdir -p "$SCREENSHOT_DIR"
node .github/scripts/issue825-video-pricing-screenshot.mjs 2>&1 | tee "$SCREENSHOT_DIR/render.log"
- uses: actions/upload-artifact@v7
if: always()
with:
name: issue825-ui-${{ github.event_name }}-${{ github.event.pull_request.head.sha || github.sha }}
path: ${{ runner.temp }}/issue825-ui
if-no-files-found: error
16 changes: 9 additions & 7 deletions frontend/src/components/modelPlaza/PlazaModelPricingTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ function billingMode(m: PlazaModel): BillingMode {
}

function billingModeLabel(m: PlazaModel): string {
return billingMode(m) === BILLING_MODE_IMAGE
? t('modelPlaza.table.perImage')
: t('modelPlaza.table.perRequest')
const mode = billingMode(m)
if (mode === BILLING_MODE_IMAGE) return t('modelPlaza.table.perImage')
if (mode === BILLING_MODE_VIDEO) return t('modelPlaza.table.perSecond')
return t('modelPlaza.table.perRequest')
}

/** 价格统一保底 2 位小数,更长的有效小数原样保留。 */
Expand Down Expand Up @@ -469,11 +470,12 @@ function official(value: number | null | undefined): string {
return formatScaled(value, PER_MILLION, MIN_DECIMALS)
}

/** 非 token 计费的单位后缀:按图片 → “/ 张”,按次 → “/ 次”。 */
/** 非 token 计费的单位后缀:按图片 → “/ 张”,按视频 → “/ 秒”,按次 → “/ 次”。 */
function perUnitSuffix(m: PlazaModel): string {
return billingMode(m) === BILLING_MODE_IMAGE
? t('modelPlaza.table.perUnitImage')
: t('modelPlaza.table.perUnitRequest')
const mode = billingMode(m)
if (mode === BILLING_MODE_IMAGE) return t('modelPlaza.table.perUnitImage')
if (mode === BILLING_MODE_VIDEO) return t('modelPlaza.table.perUnitSecond')
return t('modelPlaza.table.perUnitRequest')
}

function hasCachePricing(m: PlazaModel): boolean {
Expand Down
Loading
Loading