Add bilingual storyboard prompts and English MiniMax H3 submission

This commit is contained in:
Codex
2026-11-12 12:25:21 +08:00
parent 0af38fa742
commit 45cf52351c
21 changed files with 513 additions and 23 deletions
@@ -0,0 +1,20 @@
// Read only: verify the installed bilingual panel without submitting generations.
const {chromium}=require('playwright-core'),fs=require('node:fs'),assert=require('node:assert/strict');
(async()=>{
const root='D:/web/dj',base=JSON.parse(fs.readFileSync(root+'/huobao-data/last-launch.json')).api.replace('/api/v1','');
const browser=await chromium.launch({channel:'chrome',headless:true});
try {
const page=await browser.newPage({viewport:{width:1600,height:1100}}),errors=[];
page.on('pageerror',e=>errors.push(e.message));
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/**',r=>['GET','HEAD'].includes(r.request().method())?r.continue():r.abort());
await page.goto(base+'/drama/6/episode/1',{waitUntil:'networkidle'});
await page.getByText('视频制作',{exact:true}).first().click();
const panel=page.locator('.english-video-prompt');await panel.waitFor();await panel.scrollIntoViewIfNeeded();
assert.match(await panel.innerText(),/已同步/);
assert.match(await panel.getByRole('textbox',{name:'英文视频提示词'}).inputValue(),/rain/i);
assert.equal(await page.getByRole('button',{name:'补齐英文',exact:true}).count(),1);
assert.deepEqual(errors,[]);await page.screenshot({path:root+'/integration-work/english-installed.png'});
console.log('PASS: installed bilingual prompt and batch-fill controls; GET-only inspection');
}finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});
@@ -0,0 +1,40 @@
const {chromium}=require('playwright-core'),assert=require('node:assert/strict');
(async()=>{
const browser=await chromium.launch({channel:'chrome',headless:true});
try {
const page=await browser.newPage({viewport:{width:1600,height:1100}}),errors=[],writes=[];
let selected=null,english='',status='missing';
page.on('pageerror',e=>errors.push(e.message));
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/**',async route=>{
const req=route.request(),url=req.url(),method=req.method();
if(method==='GET'&&/\/episodes\/\d+\/storyboards$/.test(url)){
const response=await route.fetch(),body=await response.json();selected=body.data[0];
Object.assign(selected,{video_prompt_en:english,video_prompt_en_status:status});
return route.fulfill({response,json:body});
}
if(method==='POST'&&url.endsWith('/english-prompt')){
writes.push('translate');english='0-3s: Heavy rain falls on an old dormitory.\n3-9s: Slowly push in toward the dim window. No dialogue or subtitles.';status='ready';
return route.fulfill({status:200,json:{code:200,data:{...selected,video_prompt_en:english,video_prompt_en_status:status}}});
}
if(method==='PUT'&&/\/storyboards\/\d+$/.test(url)){
const body=req.postDataJSON();assert.ok(body.video_prompt_en);assert.equal(body.source_prompt,selected.video_prompt);
english=body.video_prompt_en;writes.push('save-english');return route.fulfill({status:200,json:{code:200,data:{}}});
}
if(!['GET','HEAD'].includes(method))throw Error('Unexpected mutation: '+method+' '+url);
return route.continue();
});
await page.goto('http://127.0.0.1:18938/drama/6/episode/1',{waitUntil:'networkidle'});
await page.getByText('视频制作',{exact:true}).first().click();
const panel=page.locator('.english-video-prompt');await panel.waitFor();await panel.scrollIntoViewIfNeeded();
assert.match(await panel.innerText(),/待生成/);
await panel.getByRole('button',{name:'生成 / 更新英文'}).click();
await panel.locator('.english-state.ready').waitFor();
const input=panel.getByRole('textbox',{name:'英文视频提示词'});assert.match(await input.inputValue(),/Heavy rain/);
await input.fill(english+' Keep the same framing.');await panel.locator('strong').click();
await page.waitForFunction(()=>document.querySelector('.english-actions [role="status"]')?.textContent==='英文修改已保存');
assert.deepEqual(writes,['translate','save-english']);assert.deepEqual(errors,[]);
await panel.scrollIntoViewIfNeeded();await page.screenshot({path:'D:/web/dj/integration-work/english-ui-fixture.png'});
console.log('PASS: English panel, generate/save, Chinese source guard, no real API mutations');
}finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});
@@ -0,0 +1,17 @@
"""Validate English visual directions with Chinese speech in memory; no generation."""
import subprocess
code='''import app,json
from workflow import load_registry,compile_workflow
prompt='Cast: @图片1乔雨灵. 0-3s: In heavy rain, @图片1乔雨灵 looks up and says in Mandarin Chinese: 「别开门!」 3-9s: The camera slowly moves toward the dark window. No subtitles.'
for key in ['minimax_h3_r2v','minimax_h3_r2v_4step','minimax_h3_hybrid_v0331_i2v','minimax_h3_vdn_hd']:
try:
spec=load_registry()[key];req=app.JobRequest(workflow_key=key,prompt=prompt,duration=9,width=1344,height=768)
plan=app.request_audio_plan(spec,req)
print(json.dumps({'workflow':key,**{k:plan.get(k) for k in ['supported','status','audio_mode','speech_requested','expected_transcript','normalized_prompt']}},ensure_ascii=False))
except KeyError:pass
for speech in ['@乔雨灵 says: "别开门!"','@乔雨灵 说:「别开门!」','Dialogue: "别开门!"','Dialogue: 「剧目《偷宿》。演员:高天明,乔雨灵。」','台词:别开门!','旁白:「别开门!」']:
plan=app.plan_h3_audio('0-3s: A woman stands in the rain. '+speech+' 3-9s: A dark window. No subtitles.',9)
if speech.startswith('Dialogue:'):assert plan.get('speech_requested'),plan
print(json.dumps({'speech':speech,**{k:plan.get(k) for k in ['speech_requested','audio_mode','expected_transcript','normalized_prompt']}},ensure_ascii=False))
'''
r=subprocess.run(['docker','exec','canvas-h3-prompt-normalizer-healthy-20261026','python','-c',code],capture_output=True,text=True);print(r.stdout);print(r.stderr);raise SystemExit(r.returncode)
+5 -1
View File
@@ -21,6 +21,10 @@ class Mock(BaseHTTPRequestHandler):
def do_POST(self):
body=json.loads(self.rfile.read(int(self.headers['Content-Length'])))
if self.path.endswith('/chat/completions'):
if 'tools' not in body:
translated='Maintain continuity. Do not read these visual instructions aloud. '+ ' '.join(re.findall(r'__HB_KEEP_\d+__',body['messages'][-1]['content']))
raw=json.dumps({'choices':[{'message':{'content':json.dumps({'translation':translated})}}]}).encode()
self.send_response(200);self.send_header('Content-Type','application/json');self.end_headers();self.wfile.write(raw);return
chat_posts.append(body)
if len(chat_posts)==1:
tool=next(t['function']['name'] for t in body['tools'] if 'storyboard' in t['function']['name'].lower() and ('context' in t['function']['name'].lower()))
@@ -99,7 +103,7 @@ try:
result=wait_task(task,status='completed');assert len(posts)==2
sent=posts[-1];images=[x for x in sent['content'] if x['type']=='image_url']
assert len(images)==1 and images[0]['role']=='first_frame' and images[0]['image_url']['url'].startswith('data:image/')
assert sent['gpu']=='gpu3' and '@图片1' not in sent['content'][0]['text'] and '禁止朗读' in sent['content'][0]['text']
assert sent['gpu']=='gpu3' and '@图片1' not in sent['content'][0]['text'] and 'Do not read' in sent['content'][0]['text']
params=json.loads(result['params']);assert params['continuity']['sourceId']==2 and params['continuity']['frameUrl']
assert api('GET','/storyboards/3/continuity')['stale'] is False
# Changing previous video flags the existing downstream output without replacing it.
@@ -0,0 +1,138 @@
"""Isolated bilingual prompt, stale-write, and actual-provider-body checks. No real models/GPU jobs."""
import base64,concurrent.futures,json,os,pathlib,re,sqlite3,subprocess,threading,time,urllib.request,urllib.error
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
root=pathlib.Path(__file__).resolve().parent.parent
data=root/'integration-work'/('english-test-'+time.strftime('%Y%m%d-%H%M%S'));data.mkdir()
stage=root/'integration-work/stage-4.0.11/app';dbfile=data/'huobao.sqlite3'
source=(root/'huobao-source/desktop/build/backend.mjs').read_text('utf-8')
source=source.replace('const require = __hbCreateRequire(import.meta.url)','const require = __hbCreateRequire('+json.dumps(str(stage/'resources/app.asar/build/backend.mjs'))+')',1)
source=re.sub(r'^import (\w+) from "(better-sqlite3|sharp)";',r'const \1 = require("\2");',source,flags=re.M)
source=source.replace('target.hostname === "192.168.110.111" && ["18792", "18794"].includes(target.port)','target.hostname === "127.0.0.1" && target.port === "18941"')
source=re.sub(r'(url\d*)\.hostname === "192\.168\.110\.111" && \["18792", "18794"\]\.includes\(\1.port\)',r'\1.hostname === "127.0.0.1" && \1.port === "18941"',source)
source=re.sub(r'&& !!taskRouting\(\{ provider: config\d*\.provider, taskId \}\)','&& !!taskId',source)
(data/'backend.mjs').write_text(source,'utf-8')
events=[];translations=[];mode='ok';entered=threading.Event();release=threading.Event();process=None
class Mock(BaseHTTPRequestHandler):
def log_message(self,*args):pass
def reply(self,status,body):
raw=json.dumps(body).encode();self.send_response(status);self.send_header('Content-Type','application/json');self.end_headers();self.wfile.write(raw)
def do_POST(self):
body=json.loads(self.rfile.read(int(self.headers['Content-Length'])))
if self.path.endswith('/chat/completions'):
if body.get('tools'):
if any(m.get('role')=='tool' for m in body['messages']):message={'role':'assistant','content':'Bilingual storyboard saved.'};finish='stop'
else:
name=next(t['function']['name'] for t in body['tools'] if 'save' in t['function']['name'].lower() and 'storyboard' in t['function']['name'].lower())
en=shot(1)['video_prompt_en']
args={'storyboards':[{'shot_number':4,'description':'【镜头1】暴雨中,乔雨灵说:「别开门!」【镜头2】镜头靠近四楼宿舍。','video_prompt':shot(1)['video_prompt'],'video_prompt_en':en,'duration':9,'character_ids':[1],'scene_id':1,'continuity_mode':'none'}]}
message={'role':'assistant','content':None,'tool_calls':[{'id':'save_bilingual_fixture','type':'function','function':{'name':name,'arguments':json.dumps(args)}}]};finish='tool_calls'
self.reply(200,{'id':'fixture','object':'chat.completion','created':1,'model':'fixture-translator','choices':[{'index':0,'message':message,'finish_reason':finish}],'usage':{'prompt_tokens':1,'completion_tokens':1,'total_tokens':2}});return
translations.append(body)
if mode=='unavailable':self.reply(503,{'error':'fixture'});return
if mode=='delay':entered.set();release.wait(6)
text='Cinematic rain and camera movement. '+ ' '.join(('Dialogue: '+x if x=='__HB_KEEP_0__' else x) for x in re.findall(r'__HB_KEEP_\d+__',body['messages'][-1]['content']))
if mode=='invalid':text='Wrong translation without protected tokens'
self.reply(200,{'choices':[{'message':{'content':json.dumps({'translation':text})}}]});return
events.append((self.path,body))
if self.path.endswith('/validate'):self.reply(200,{'valid':True})
elif self.path.endswith('/cancel'):self.reply(200,{'task':{'id':self.path.split('/')[-2],'status':'cancelled'}})
else:self.reply(200,{'task_id':'new-'+str(len(events))})
def do_GET(self):self.reply(200,{'task':{'id':self.path.split('/')[-1],'status':'running','worker_state':'running'}})
server=ThreadingHTTPServer(('127.0.0.1',18941),Mock);threading.Thread(target=server.serve_forever,daemon=True).start()
env={**os.environ,'ELECTRON_RUN_AS_NODE':'1','PORT':'18940','HUOBAO_DATA_DIR':str(data),'SQLITE_PATH':str(dbfile),'FRONTEND_DIST':str(root/'huobao-source/frontend/.output/public'),'WORKSPACE_PATH':str(stage/'resources/workspace-template')}
log=(data/'backend.log').open('w',encoding='utf-8')
def api(method,path,body=None,expected=200):
req=urllib.request.Request('http://127.0.0.1:18940/api/v1'+path,method=method,data=None if body is None else json.dumps(body).encode(),headers={'Content-Type':'application/json'})
try:
with urllib.request.urlopen(req,timeout=30) as r:status=r.status;result=json.load(r)
except urllib.error.HTTPError as e:status=e.code;result=json.load(e)
assert status==expected,(path,status,result)
return result.get('data',result)
def sql(query,args=()):
with sqlite3.connect(dbfile) as db:db.row_factory=sqlite3.Row;return [dict(r) for r in db.execute(query,args)]
def shot(i):return sql('select * from storyboards where id=?',(i,))[0]
def start():
global process
process=subprocess.Popen([str(stage/'HuobaoDrama.exe'),str(data/'backend.mjs')],cwd=data,env=env,stdout=log,stderr=log,creationflags=subprocess.CREATE_NO_WINDOW)
for _ in range(150):
assert process.poll() is None
try:api('GET','/health');return
except OSError:time.sleep(.1)
raise AssertionError('Backend failed to start')
cn='出场人物:@乔雨灵;场景:@四楼宿舍。\n0-3秒:暴雨中,@乔雨灵 抬头,说:「别开门!」\n3-9秒:镜头缓慢靠近 @四楼宿舍,无字幕。'
png='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aN1kAAAAASUVORK5CYII='
try:
start();ts='2026-11-12T00:00:00Z'
sql('insert into dramas(id,title,created_at,updated_at) values(1,?,?,?)',('fixture',ts,ts))
sql('insert into episodes(id,drama_id,episode_number,title,created_at,updated_at) values(1,1,1,?,?,?)',('fixture',ts,ts))
for id,service,provider,model in [(1,'video','minimax','MiniMax-H3'),(2,'text','openai','fixture-translator')]:
sql('insert into ai_service_configs(id,service_type,provider,name,base_url,api_key,model,is_active,created_at,updated_at) values(?,?,?,?,?,?,?,1,?,?)',(id,service,provider,'fixture','http://127.0.0.1:18941','test-key',json.dumps([model]),ts,ts))
sql('insert into characters(id,drama_id,name,created_at,updated_at) values(1,1,?,?,?)',('乔雨灵',ts,ts))
sql("insert into scenes(id,drama_id,location,time,prompt,created_at,updated_at) values(1,1,?,'night','rain',?,?)",('四楼宿舍',ts,ts))
for i in [1,2,3]:sql('insert into storyboards(id,episode_id,storyboard_number,video_prompt,created_at,updated_at) values(?,1,?,?,?,?)',(i,i,cn,ts,ts))
row=api('POST','/storyboards/1/english-prompt',{})
assert row['video_prompt_en_status']=='ready' and '「别开门!」' in row['video_prompt_en'] and '@乔雨灵' in row['video_prompt_en'] and '0-3s:' in row['video_prompt_en']
n=len(translations);api('POST','/storyboards/1/english-prompt',{});assert len(translations)==n
assert shot(1)['video_prompt']==cn
# Manual EN validation rejects modified dialogue and stale-source edits.
api('PUT','/storyboards/1',{'video_prompt_en':row['video_prompt_en'].replace('别开门','快开门'),'source_prompt':cn},400)
api('PUT','/storyboards/1',{'video_prompt_en':row['video_prompt_en']+' No new dialogue.','source_prompt':cn})
api('PUT','/storyboards/1',{'video_prompt':cn+' 暗蓝色光线。'})
assert api('GET','/episodes/1/storyboards')[0]['video_prompt_en_status']=='stale'
api('PUT','/storyboards/1',{'video_prompt_en':row['video_prompt_en'],'source_prompt':cn},400)
old=shot(1)['video_prompt_en'];mode='invalid'
api('POST','/storyboards/1/english-prompt',{},400);assert shot(1)['video_prompt_en']==old
# Translation failure must not cancel an existing shot or create a provider job.
sql('insert into sys_task(id,type,storyboard_id,provider,model,status,stage,task_id,config_id,config_base_url,created_at,updated_at) values(10,?,?,?,?,?,?,?,?,?,?,?)',('video',2,'minimax','MiniMax-H3','processing','running','old-2',1,'http://127.0.0.1:18941',ts,ts))
mode='unavailable';before=len(events)
api('POST','/tasks',{'type':'video','storyboard_id':2,'model':'MiniMax-H3','config_id':1,'prompt':cn,'replace_task_id':10,'reference_image_urls':[png]},400)
assert len(events)==before and sql('select status from sys_task where id=10')[0]['status']=='processing'
# Reuse EN, map asset reference indexes, translate continuity, and submit exactly the preflight prompt.
mode='ok';sql("update storyboards set continuity_start='暴雨夜窗前无人' where id=2")
result=api('POST','/tasks',{'type':'video','storyboard_id':2,'drama_id':1,'model':'MiniMax-H3','config_id':1,'prompt':cn.replace('@乔雨灵','@图片2乔雨灵').replace('@四楼宿舍','@图片1四楼宿舍'),'replace_task_id':10,'reference_image_urls':[png,png]},201)
for _ in range(80):
if len(events)>=before+3:break
time.sleep(.1)
assert [x[0] for x in events[before:]]==['/v2/video_generation/validate','/v2/video_generation/old-2/cancel','/v2/video_generation']
sent=events[-1][1]['content'][0]['text'];assert sent==events[before][1]['content'][0]['text']
assert '「别开门!」' in sent and '@图片2乔雨灵' in sent and '@图片1四楼宿舍' in sent
assert '暴雨夜窗前无人' not in sent and '画面衔接约束' not in sent
saved=sql('select prompt,params from sys_task where id=?',(result['id'],))[0]
assert saved['prompt']==sent and json.loads(saved['params'])['promptLanguage']=='en'
# An in-flight translation may never overwrite a new Chinese edit.
mode='delay'
with concurrent.futures.ThreadPoolExecutor() as pool:
f=pool.submit(api,'POST','/storyboards/3/english-prompt',{},400);assert entered.wait(3)
api('PUT','/storyboards/3',{'video_prompt':cn+' 新内容。'});release.set();f.result()
assert shot(3)['video_prompt_en'] is None and '新内容' in shot(3)['video_prompt']
# Batch fill EN only preserves all original CN and media/task records.
mode='ok';before=len(events);originals=[shot(i)['video_prompt'] for i in [1,2,3]]
batch=api('POST','/episodes/1/generate-video-prompts',{'english_only':True});assert batch['total']==2
for _ in range(100):
state=api('GET','/episodes/1/video-prompts-status')
if state['status']!='running':break
time.sleep(.1)
assert state['failed']==0 and state['completed']==2,state
assert len(events)==before and [shot(i)['video_prompt'] for i in [1,2,3]]==originals
assert all(r['video_prompt_en_status']=='ready' for r in api('GET','/episodes/1/storyboards'))
# New storyboard Agent tool persists CN and EN together, without changing prior shots.
api('POST','/agent/storyboard_breaker/chat',{'drama_id':1,'episode_id':1,'message':'Save the next bilingual storyboard.','config_id':2})
created=sql('select * from storyboards where storyboard_number=4')[0]
assert created['video_prompt_en'] and created['video_prompt_en_source_hash'] and '「别开门!」' in created['video_prompt_en']
# Broadcast labels are canonicalized; numbers inside speech remain literal.
broadcast='0-3秒:老式广播音响起:「0-3秒:别开门!」\n3-9秒:雨水落下。'
sql('insert into storyboards(id,episode_id,storyboard_number,video_prompt,created_at,updated_at) values(30,1,30,?,?,?)',(broadcast,ts,ts))
translated=api('POST','/storyboards/30/english-prompt',{})['video_prompt_en']
assert 'Dialogue: 「0-3秒:别开门!」' in translated and '0-3s:' in translated
# English possessives around Chinese asset identifiers are not literal speech.
original="0-3秒:@乔雨灵 的手搭在 @乔雨灵 的肩上;系统音:「停了。NG,两次。」"
sql('insert into storyboards(id,episode_id,storyboard_number,video_prompt,created_at,updated_at) values(31,1,31,?,?,?)',(original,ts,ts))
candidate="0-3s: @乔雨灵's hand rests on @乔雨灵's shoulder; a system voice announces: 「停了。NG,两次。」"
api('PUT','/storyboards/31',{'video_prompt_en':candidate,'source_prompt':original})
assert "@乔雨灵's" in shot(31)['video_prompt_en'] and 'Dialogue: 「停了。NG,两次。」' in shot(31)['video_prompt_en']
process.terminate();process.wait(10);process=None;start()
assert all(r['video_prompt_en_status']=='ready' for r in api('GET','/episodes/1/storyboards'))
print(json.dumps({'passed':True,'literal_dialogue_preserved':True,'reference_mapping_preserved':True,'actual_submission_english':True,'continuity_english':True,'failure_before_cancel':True,'stale_write_protection':True,'batch_preserves_originals':True,'restart_persistence':True,'fixture':str(data)}))
finally:
if process:process.terminate();process.wait(10)
server.shutdown();log.close()
+1 -1
View File
@@ -19,6 +19,6 @@ class ReadOnly(http.server.SimpleHTTPRequestHandler):
server=http.server.ThreadingHTTPServer(('127.0.0.1',18938),ReadOnly)
threading.Thread(target=server.serve_forever,daemon=True).start()
script = sys.argv[1] if len(sys.argv)>1 else 'verify_progress_ui.cjs'
if script not in {'verify_progress_ui.cjs','verify_cancel_ui.cjs'}:raise ValueError('Unknown UI test')
if script not in {'verify_progress_ui.cjs','verify_cancel_ui.cjs','verify_english_ui.cjs'}:raise ValueError('Unknown UI test')
try:subprocess.run(['node',str(root/'integration-work/browser-test'/script)],cwd=root,check=True)
finally:server.shutdown()