fix: recover dashboard after cellular cache failures

Clear stale errors after successful signal reads and prevent staged slow data from crossing SIM boundaries. Cover cache recovery, partial reads, persistent failures and SIM changes with the real dashboard in Chromium; retain the validation record.
This commit is contained in:
kanoqwq committed 2026-10-24 15:57:42 +08:00
1 parent b474853411
commit 3c35010518
4 files changed
+116 -6

No files matched your search

@@ -0,0 +1,11 @@
# 看板缓存失败恢复(2026-10-24)
已确认当前 `clean-tf-7.2` 的 MU300 看板存在与 E5 相同的快慢档错误继承:慢档 `cell.error` 报错后,较新成功的 `sig` 仅覆盖部分字段,旧 `error` 留在合并对象,顶部继续显示「无应答」。已使用真实页面、共享模块和 Chromium 复现,原版在「成功信号应清除旧失败」断言失败。
修复位于共享 `view/mu300/home.js` 和 `mu300/common.js`。成功快档清除旧错误;从失败状态恢复的部分首包使用其有效 CESQ 数据;正常部分首包继续保留有效工程信号。不同卡的快慢档不合并,慢档分阶段合并也拒绝继承另一卡或错误快照的身份/QoS/邻区。重绘标识加入卡槽及错误状态,保证同时间戳的切卡和恢复正确刷新。持续失败及比失败更旧的成功数据不会被当作恢复。
新增 `tests/dashboard_cache_browser.py`,加载真实共享模块、页面 HTML 与完整 update 方法,验证失败后完整/部分成功恢复、旧成功拒绝、同卡有效详情保留、不同卡隔离、持续失败显示、输入对象不可变及快档无变化时不重绘慢档;通过。原版失败/修复版通过的日志与源码快照保存在 `work/dashboard-cache-20261024/`。
现有快捷控制、刷新调度/暂停/离页/失败检查通过;共享模块国际化测试中,与本次相关的分阶段合并和 JS 检查通过。该组共 15 项,13 项通过、1 项因缺少 po2lmo 跳过、1 项为既有菜单目录缺少 TTL 翻译;对应测试、菜单与 po 文件均无本次差异,未在缓存修复中改动此无关问题。`git diff --check` 通过。
本次仅更新当前工作分支源码及测试,未同步其他分支、未打包发布、未部署设备。此前 U30 Air 已部署的省电优化保留;该设备的网页缓存修复尚未部署。当前代码验证不能替代原故障设备上的实测。
@@ -1295,7 +1295,8 @@ function carrierName(op) {
* Explicit null in a completed stage means unavailable, not stale data. */
function mergeCell(previous, next) {
if (!next) return previous || null;
if (!next.partial || !previous || next.error) return Object.assign({}, next);
if (!next.partial || !previous || next.error || previous.error || previous.card !== next.card)
return Object.assign({}, next);
var merged = Object.assign({}, next);
['ident', 'qos'].forEach(function(k) { merged[k] = previous[k]; });
if (next.neigh_pending) merged.neigh = previous.neigh;
@@ -433,19 +433,23 @@ return view.extend({
var c = this._slowCell;
var s = st.sig || null;
if (s && !s.error && (!c || !c.ts || (s.ts || 0) >= c.ts)) {
if (c && s.partial) {
if (c && c.card != null && s.card != null && c.card !== s.card) c = null;
if (c && !c.error && s.partial) {
/* 核心首包先更新驻网状态,但不让临时 CESQ 空值擦掉上一份工程信号。 */
c = Object.assign({}, c, {
ts: s.ts, cfun: s.cfun, reg: s.reg, reg5g: s.reg5g
ts: s.ts, card: s.card, cfun: s.cfun, reg: s.reg, reg5g: s.reg5g
});
} else c = c ? Object.assign({}, c, {
ts: s.ts, cfun: s.cfun, reg: s.reg, reg5g: s.reg5g,
ts: s.ts, card: s.card, cfun: s.cfun, reg: s.reg, reg5g: s.reg5g,
sig_src: s.sig_src, sig: s.sig, lte: s.lte, nr: s.nr
}) : s;
}) : Object.assign({}, s);
/* A newer successful read supersedes the slow tier's old failure. */
delete c.error;
}
this.lastCell = c;
/* 慢档数据(邻区/运营商/身份)只在整份缓存的时间戳变化时重绘 */
var fullTs = st.cell ? [st.cell.ts, st.cell.partial || 0, st.cell.neigh_pending || 0].join(':') : '';
var fullTs = [c && c.card, st.cell && st.cell.ts, st.cell && st.cell.partial || 0,
st.cell && st.cell.neigh_pending || 0, c && c.error || ''].join(':');
var slowChanged = fullTs !== this.lastFullTs;
this.lastFullTs = fullTs;
+94
View File
@@ -0,0 +1,94 @@
"""Render the shipped dashboard with failed/recovered cache snapshots, no modem."""
import argparse
from pathlib import Path
from playwright.sync_api import sync_playwright
TOP=Path(__file__).resolve().parents[1]
ap=argparse.ArgumentParser(description=__doc__)
ap.add_argument('--source',type=Path,default=TOP/'openwrt/luci-app-mu300/htdocs/luci-static/resources/view/mu300/home.js')
ap.add_argument('--common',type=Path,default=TOP/'openwrt/luci-app-mu300/htdocs/luci-static/resources/mu300/common.js')
args=ap.parse_args();SOURCE=args.source
with sync_playwright() as pw:
browser=pw.chromium.launch(executable_path='C:/Program Files/Google/Chrome/Application/chrome.exe')
page=browser.new_page(viewport={'width':390,'height':844})
errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
page.set_content('<main></main>')
page.evaluate('''([source,sharedSource])=>{
window.neighborPaints=0;
const shared=new Function('rpc','baseclass','L',sharedSource)(
{declare:()=>()=>Promise.resolve({})},{extend:o=>o},{env:{lang:'zh'}});
const M={...shared,
v:id=>document.getElementById('mud-'+id),
set:(id,text)=>{M.v(id).textContent=text ?? '--';},
translate:s=>s,localize(){},
esc:s=>String(s ?? '').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c])),
qLabel:rsrp=>rsrp==null?'未知':'良好',qCol:()=> '#123456',
qScore:s=>s.rsrp==null?null:8,
carrierName:op=>op?.name || '--',PLMN_CN:{},
neighborRows:c=>{neighborPaints++;return '<tr><td>'+M.esc(c.neigh?.[0]?.pci ?? '--')+'</td></tr>';}
};
window.app=new Function('view','uci','M','SimRadio',source)({extend:o=>o},{},M,{});
const root=document.querySelector('main');root.innerHTML=app.html();app._root=root;
app.identShown=true;
window.show=st=>app.update({info:{modem:{alive:1,atd:1}},...st});
window.text=id=>M.v(id).textContent;
window.freeze=value=>{
if(value && typeof value==='object'){Object.values(value).forEach(freeze);Object.freeze(value);}
return value;
};
}''',[SOURCE.read_text(encoding='utf-8'),args.common.read_text(encoding='utf-8')])
result=page.evaluate('''()=>{
const check=(ok,message)=>{if(!ok)throw Error(message);};
const slow=freeze({ts:100,error:'AT backend did not answer'});
const signal=freeze({ts:101,card:0,cfun:1,reg:{stat:1,act:7},reg5g:null,
sig_src:'lte',sig:{rsrp:-88,rsrq:-10},lte:{band:41,pci:123,earfcn:40000},nr:null});
show({cell:slow,sig:{ts:100,error:'AT backend did not answer'}});
check(document.querySelector('#mud-rat').firstChild.nodeValue==='无应答','real failures must be visible');
show({cell:slow,sig:signal});
check(document.querySelector('#mud-rat').firstChild.nodeValue==='4G','successful signal must clear old failure');
check(text('rsrp').includes('-88.0'),'signal must repaint immediately');
check(text('reg')==='已注册','registration must recover');
check(!app.lastCell.error && slow.error,'must not mutate RPC snapshots');
const paints=neighborPaints;
show({cell:slow,sig:{...signal,ts:102}});
check(neighborPaints===paints,'fast-only polls must not repaint unchanged slow sections');
// Partial recovery has useful CESQ data even though engineering reads are pending.
show({cell:slow,sig:{...signal,ts:103,partial:1,sig_src:'cesq',sig:{rsrp:-95},lte:null,nr:null}});
check(!app.lastCell.error && text('rsrp').includes('-95.0'),'partial recovery must use its fresh fallback signal');
check(document.querySelector('#mud-rat').firstChild.nodeValue!=='无应答','partial recovery must clear error');
show({cell:{ts:110,error:'new failure'},sig:signal});
check(app.lastCell.error==='new failure','older good signal must not erase newer failure');
check(document.querySelector('#mud-rat').firstChild.nodeValue==='无应答','newer failure must remain visible');
const full=freeze({...signal,ts:200,ident:{imei:'fixture-zero',model:'fixture'},
operator:{name:'fixture carrier',act:7},qos:{qci:9},neigh:[{pci:456}],
sig_src:'nr',sig:{rsrp:-80},lte:null,nr:{band:41,pci:321,arfcn:500000}});
show({cell:full,sig:null});
const staged=freeze({...full,ts:201,partial:1,neigh_pending:1,ident:null,qos:null,neigh:null});
const partial=freeze({ts:202,card:0,partial:1,cfun:1,reg:{stat:1},reg5g:null,
sig_src:'cesq',sig:null,lte:null,nr:null});
show({cell:staged,sig:partial});
check(document.querySelector('#mud-rat').firstChild.nodeValue==='5G SA','healthy partial read must preserve engineering signal');
check(text('rsrp').includes('-80.0'),'partial read must not blank healthy engineering metrics');
check(text('imei')==='fixture-zero' && text('qci')==='9' && text('neigh').includes('456'),'same SIM must keep completed slow tiers');
// A different card at the same slow timestamp must repaint and never inherit identity.
const switched=freeze({...staged,card:1});
show({cell:switched,sig:{...partial,card:1}});
check(text('imei')==='--' && text('qci')==='--' && !text('neigh').includes('456'),'SIM change must clear previous card details');
check(app.lastCell.card===1,'selected card must follow fresh snapshot');
show({cell:full,sig:{...signal,card:1,ts:203}});
check(app.lastCell.card===1 && !app.lastCell.ident && text('imei')==='--','mismatched slow/fast cards must not merge');
show({cell:freeze({ts:204,error:'both failed'}),sig:freeze({ts:205,error:'both failed'})});
check(document.querySelector('#mud-rat').firstChild.nodeValue==='无应答','continued failure must not reuse last successful signal');
return {recovery:true,partial_recovery:true,older_signal_rejected:true,
same_sim_details_preserved:true,sim_isolation:true,real_failures_visible:true,input_immutable:true};
}''')
assert not errors,errors
browser.close()
print('PASS:',result)