Skip to content
Open
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
Binary file added review-assets/pr1751/pr1751-run-detail-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added review-img/oc-zhipu-1711.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 26 additions & 15 deletions web/evolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ function evoAssetsHTML(){

// ---------- 回归样本 ----------
function evoSamplesHTML(){
const rows=(evo.samples||[]).map(s=>kbRow(kbText(evoRunLink(s.runId,s.runId),escapeHTML(s.note||'无备注')+(s.workflowId?` · ${escapeHTML(s.workflowId)}`:'')),`${kbValue(relativeTime(s.createdAt))}<button type="button" class="kb-btn small" data-evo-unpin="${escapeHTML(s.runId)}">移除</button>`));
const note=kbCaption('钉选样本每次提案都会回放,用来守住已知的好结果。在运行详情页点「钉为回归样本」添加。');
return kbPanel(kbPanelTitle('回归样本',`${rows.length} 个`),note+(rows.join('')||'<div class="kb-empty">还没有钉选样本</div>'),{label:'回归样本'});
const rows=(evo.samples||[]).map(s=>kbRow(kbText(evoRunLink(s.runId,s.runId),escapeHTML(s.note||lfT('无备注','No note'))+(s.workflowId?` · ${escapeHTML(s.workflowId)}`:'')),`${kbValue(relativeTime(s.createdAt))}<button type="button" class="kb-btn small" data-evo-unpin="${escapeHTML(s.runId)}">${lfT('移除','Remove')}</button>`));
const note=kbCaption(lfT('钉选样本每次提案都会回放,用来守住已知的好结果。在运行详情页点「钉为回归样本」添加。','Pinned samples replay on every proposal to guard known good results. Add one from a run detail page with "Pin as regression sample".'));
return kbPanel(kbPanelTitle(lfT('回归样本','Regression samples'),lfT(`${rows.length} 个`,`${rows.length}`)),note+(rows.join('')||`<div class="kb-empty">${lfT('还没有钉选样本','No pinned samples yet')}</div>`),{label:lfT('回归样本','Regression samples')});
}

// ---------- 抽屉 ----------
Expand Down Expand Up @@ -1434,24 +1434,35 @@ async function evoSetLevel(kind,id,level){

async function evoUnpin(runId,btn){
if(btn)btn.disabled=true;
try{await api(`/api/runs/${encodeURIComponent(runId)}/pin-sample`,{method:'DELETE'});toast('已移除样本','ok');await evoAfterChange()}
catch(err){toast(err.message,'err');if(btn)btn.disabled=false}
try{await api(`/api/runs/${encodeURIComponent(runId)}/pin-sample`,{method:'DELETE'});toast(lfT('已移除样本','Sample removed'),'ok');await evoAfterChange()}
catch(err){toast(evoPinError(err),'err');if(btn)btn.disabled=false}
}

// The pin-sample API answers in Chinese; show the two known reasons in English.
const EVO_PIN_ERRORS={
'该运行没有所属项目':'This run does not belong to a project',
'只能把成功的业务运行设为回归样本':'Only successful business runs (not evolution replays) can be pinned as regression samples',
};
function evoPinError(err){
const message=String(err?.message||'');
const en=EVO_PIN_ERRORS[message];
return en?lfT(message,en):message;
}

// ---------- 运行详情:反馈、钉为样本、回放标记 ----------
function evoDecorateRunDetail(host,r){
if(!host||!r)return;
if(r.executionContext?.purpose==='evolution_replay'){
host.querySelector('.run-header-meta')?.insertAdjacentHTML('afterbegin','<span class="run-meta-chip evo-replay-chip" title="修改稿正文的回放运行:不交付需求、不发通知、不计入统计">进化回放</span>');
host.querySelector('.run-header-meta')?.insertAdjacentHTML('afterbegin',`<span class="run-meta-chip evo-replay-chip" title="${lfT('修改稿正文的回放运行:不交付需求、不发通知、不计入统计','A replay run of the revised prompt: it delivers no requirement, sends no notifications and is not counted in metrics.')}">${lfT('进化回放','Evolution replay')}</span>`);
return;
}
if((r.executionContext?.evolutionCanaryIds||[]).length)host.querySelector('.run-header-meta')?.insertAdjacentHTML('afterbegin','<span class="run-meta-chip evo-replay-chip" title="本次运行参与进化试用:受试资产使用修改稿正文,结果计入试用对比">进化试用</span>');
if((r.executionContext?.evolutionCanaryIds||[]).length)host.querySelector('.run-header-meta')?.insertAdjacentHTML('afterbegin',`<span class="run-meta-chip evo-replay-chip" title="${lfT('本次运行参与进化试用:受试资产使用修改稿正文,结果计入试用对比','This run joined an evolution trial: candidate assets ran the revised prompt and its result counts toward the trial comparison.')}">${lfT('进化试用','Evolution trial')}</span>`);
if(!['succeeded','failed','cancelled'].includes(r.status)||!r.executionContext?.projectId)return;
const actions=host.querySelector('.run-header-actions');if(!actions)return;
actions.insertAdjacentHTML('afterbegin',`<button class="button ghost small" data-evo-feedback="${escapeHTML(r.id)}" title="把问题反馈给RSI工作台,参与角色与规则的诊断">反馈问题</button><button class="button ghost small" data-evo-pin="${escapeHTML(r.id)}" title="每次进化提案都会回放这次运行">钉为回归样本</button>`);
actions.insertAdjacentHTML('afterbegin',`<button class="button ghost small" data-evo-feedback="${escapeHTML(r.id)}" title="${lfT('把问题反馈给RSI工作台,参与角色与规则的诊断','Report the problem to the RSI workbench to help diagnose roles and rules.')}">${lfT('反馈问题','Report an issue')}</button><button class="button ghost small" data-evo-pin="${escapeHTML(r.id)}" title="${lfT('每次进化提案都会回放这次运行','Every evolution proposal replays this run.')}">${lfT('钉为回归样本','Pin as regression sample')}</button>`);
actions.querySelector('[data-evo-feedback]')?.addEventListener('click',async ev=>{
const btn=ev.currentTarget,nodeId=state.selectedRunNode||'';
const detail=await afPrompt({title:'反馈问题',message:'请写清预期结果、实际结果和需要改进的地方。提交后会整理为关联角色的问题。',defaultValue:'',multiline:true});
const detail=await afPrompt({title:lfT('反馈问题','Report an issue'),message:lfT('请写清预期结果、实际结果和需要改进的地方。提交后会整理为关联角色的问题。','Describe the expected result, the actual result and what should improve. It is filed as an issue on the related role.'),defaultValue:'',multiline:true});
if(!detail||!String(detail).trim())return;
btn.disabled=true;
try{
Expand All @@ -1460,20 +1471,20 @@ function evoDecorateRunDetail(host,r){
if(btn.isConnected){
host.querySelector('.evo-feedback-result')?.remove();
const notice=document.createElement('div');notice.className='evo-feedback-result';notice.setAttribute('role','status');
notice.innerHTML=`<span>${escapeHTML(result.message||'反馈已保存,请在RSI工作台检查最近运行后查看。')}</span>${result.findingId?'<button type="button">查看问题 ↗</button>':''}`;
notice.innerHTML=`<span>${escapeHTML(result.message||lfT('反馈已保存,请在RSI工作台检查最近运行后查看。','Feedback saved; check the RSI workbench after the recent runs.'))}</span>${result.findingId?`<button type="button">${lfT('查看问题 ↗','View issue ↗')}</button>`:''}`;
notice.querySelector('button')?.addEventListener('click',()=>evoOpenFeedbackFinding(result));host.prepend(notice);
}
toast(result.findingId?'反馈已加入RSI工作台':'反馈已保存,详见提示','ok');
toast(result.findingId?lfT('反馈已加入RSI工作台','Feedback filed in the RSI workbench'):lfT('反馈已保存,详见提示','Feedback saved; see the notice above'),'ok');
}catch(err){toast(err.message,'err')}
finally{btn.disabled=false}
});
actions.querySelector('[data-evo-pin]')?.addEventListener('click',async ev=>{
const btn=ev.currentTarget;
const note=await afPrompt({title:'钉为回归样本',message:'备注(可选),说明这次运行为什么值得守住:',defaultValue:''});
const note=await afPrompt({title:lfT('钉为回归样本','Pin as regression sample'),message:lfT('备注(可选),说明这次运行为什么值得守住:','Note (optional): why this run is worth keeping:'),defaultValue:''});
if(note===null||note===undefined)return;
btn.disabled=true;
try{await api(`/api/runs/${encodeURIComponent(r.id)}/pin-sample`,{method:'POST',body:JSON.stringify({note})});toast('已钉为回归样本','ok')}
catch(err){toast(err.message,'err')}
try{await api(`/api/runs/${encodeURIComponent(r.id)}/pin-sample`,{method:'POST',body:JSON.stringify({note})});toast(lfT('已钉为回归样本','Pinned as a regression sample'),'ok')}
catch(err){toast(evoPinError(err),'err')}
finally{btn.disabled=false}
});
}
Expand All @@ -1482,7 +1493,7 @@ async function evoOpenFeedbackFinding(result){
const pid=result.projectId;
if(state.projectFilter!==pid){
const picker=$('#projectSwitcher');
if(!picker?.onchange||![...picker.options].some(o=>o.value===pid))return toast('请先选择该运行所属项目,再打开RSI工作台','warn');
if(!picker?.onchange||![...picker.options].some(o=>o.value===pid))return toast(lfT('请先选择该运行所属项目,再打开RSI工作台','Switch to the run\'s project first, then open the RSI workbench'),'warn');
await picker.onchange({target:{value:pid}});
if(state.projectFilter!==pid)return;
}
Expand Down
70 changes: 70 additions & 0 deletions webtest/tests/evolution-feedback.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,73 @@ test('queued findings explain why dismiss is disabled until the queue entry is r
assert.match(result[1],/取消排队/);
assert.equal(result[2],false);
});

test('English mode renders the run detail feedback and pin controls in English', async (t) => {
const app = await loadApp({ lang: 'en' }); t.after(app.close);
const isEn = app.evaluate(`document.documentElement.dataset.lang==='en' && window.lfT('中文','English')==='English'`);
assert.equal(isEn, true, 'the app must boot in English mode for this test');
const labels = app.evaluate(`(() => {
const host=document.createElement('div');
host.innerHTML='<div class="run-header-actions"></div><div class="run-header-meta"></div>';
evoDecorateRunDetail(host,{id:'i18n-run',status:'succeeded',executionContext:{projectId:'project-1'}});
const buttons=[...host.querySelectorAll('[data-evo-feedback],[data-evo-pin]')].map(b=>({label:b.textContent.trim(),title:b.title}));
evoDecorateRunDetail(host,{id:'i18n-replay',status:'succeeded',executionContext:{purpose:'evolution_replay',projectId:'project-1'}});
const chip=host.querySelector('.evo-replay-chip');
return {buttons,chip:{label:chip?.textContent.trim(),title:chip?.title}};
})()`);
const HAN = /[㐀-鿿]/;
for (const b of labels.buttons) {
assert.doesNotMatch(b.label, HAN);
assert.doesNotMatch(b.title, HAN);
}
assert.match(labels.buttons[0].label, /Report an issue/);
assert.match(labels.buttons[1].label, /Pin as regression sample/);
assert.doesNotMatch(labels.chip.label, HAN);
assert.doesNotMatch(labels.chip.title, HAN);
});

test('English mode unpins a regression sample with an English toast', async (t) => {
const app = await loadApp({ lang: 'en' }); t.after(app.close);
app.evaluate(`
window.__unpinToasts=[];
window.__origToast=window.toast;
window.toast=(msg,kind)=>{window.__unpinToasts.push(String(msg));return window.__origToast(msg,kind);};
window.evoAfterChange=async()=>{};
const view=document.createElement('div');
view.id='evolutionView';
const btn=document.createElement('button');
btn.dataset.evoUnpin='en-unpin-run';
view.appendChild(btn);
document.body.appendChild(view);
btn.click();
`);
await settle(6);
const toasts = app.evaluate(`(()=>{window.toast=window.__origToast;return window.__unpinToasts})()`);
assert.equal(toasts.length, 1);
assert.equal(toasts[0], 'Sample removed');
});

test('English mode localizes the server reasons when pinning a regression sample fails', async (t) => {
const app = await loadApp({ lang: 'en', routes: [
{ method: 'POST', path: '/api/runs/pin-fail-run/pin-sample', status: 409, body: { error: '只能把成功的业务运行设为回归样本' } },
] }); t.after(app.close);
app.evaluate(`
window.__pinToasts=[];
window.__origToast=window.toast;
window.toast=(msg,kind)=>{window.__pinToasts.push(String(msg));return window.__origToast(msg,kind);};
window.afPrompt=async()=>'';
const view=document.createElement('div');
view.id='evolutionView';
document.body.appendChild(view);
const host=document.createElement('div');
host.innerHTML='<div class="run-header-actions"></div><div class="run-header-meta"></div>';
document.body.appendChild(host);
evoDecorateRunDetail(host,{id:'pin-fail-run',status:'succeeded',executionContext:{projectId:'project-1'}});
host.querySelector('[data-evo-pin]').click();
`);
await settle(8);
const toasts = app.evaluate('window.__pinToasts');
assert.equal(toasts.length, 1);
assert.match(toasts[0], /Only successful business runs .* can be pinned as regression samples/);
assert.doesNotMatch(toasts[0], /[\u3400-\u9fff]/);
});
Loading