合入主线登录和营业时段策略,对齐旧界面与 React 访问流程

This commit is contained in:
黄健铭 committed 2026-12-05 21:46:55 -08:00
commit 42395de23a
113 files changed
+1915 -558

No files matched your search

+39
View File
@@ -72,6 +72,8 @@ function harness(
});
const run = code => vm.runInContext(code, context),
json = code => JSON.parse(JSON.stringify(run(code)));
for (const file of ['login-diagnostics.js', 'login-ui.js'])
run(fs.readFileSync(path.join(__dirname, '../public', file), 'utf8'));
run(source);
run(
`session={user:__user};state={user:__user,today:'${D}'};applyAfterSaleRestrictions=function(){};updateOrderDetailNavigation=function(){};toast=function(){};showSavedPeopleCount=async function(date){globalThis.__finished=date;};`,
@@ -516,3 +518,40 @@ test('二进制Excel读取沿用账号校验与有限GET重试,HTML成功页
);
assert.equal(denied.calls.length, 1);
});
test('登录诊断区分传输中断、超时、服务端拒绝和读取响应失败,隐藏提交内容', async () => {
const cases = [
{
fetcher: () => {
throw new TypeError('Load failed');
},
text: ['提交登录失败', 'HTTP 状态:未收到', '浏览器提示:Load failed'],
},
{
fetcher: (_url, { signal }) =>
new Promise((_, reject) => signal.addEventListener('abort', () => reject(new Error('fetch is aborted')))),
timeout: true,
text: ['等待超过 25 秒', 'HTTP 状态:未收到'],
},
{ fetcher: () => httpError(401, '账号或密码不正确'), text: ['账号或密码不正确', 'HTTP 状态:401'] },
{ fetcher: () => new Response('private-response-content'), text: ['未能读取完整', 'HTTP 状态:200'] },
];
for (const c of cases) {
const h = harness(c.fetcher, { timeout: c.timeout });
const html = await h.run("api('/api/login',{password:'secret-input'}).catch(err=>loginErrorHTML(err,'提交登录'))");
for (const text of [...c.text, '北京时间', 'POST /api/login', '复制诊断信息']) assert.ok(html.includes(text), text);
assert.doesNotMatch(html, /secret-input|private-response-content/);
assert.equal(h.calls.length, 1);
}
for (const [route, stage] of [
['/api/session', '检查登录状态'],
['/api/state', '读取账本'],
]) {
const h = harness(() => {
throw new TypeError('Load failed');
});
const html = await h.run(`api('${route}').catch(err=>loginErrorHTML(err,'打开账本页面'))`);
assert.ok(html.includes(stage + '失败'));
assert.ok(html.includes('GET ' + route));
}
});