fix(e2e,api): 联系表单限流同登录一样可覆盖;修 uj-08 面板动画与导航点击错位的两处真因

全量功能 E2E 在「修好数据」后的干净读数:1066 passed / 2 failed,两条都是
website-acceptance 的「导航菜单功能正常」在 firefox/webkit 上 15s 超时。
按「能复现就修根因」处理,不记成墙钟抖动:

1) 登录/联系表单限流同族:contact 也是进程内内存桶 5 次/小时/IP,而 e2e server
   跨整轮用例存活 ⇒ 多次提交必然 429。抽出 src/lib/rate-limit-config.ts 的
   readRateLimitMax(未设⇒默认、非法值⇒默认且打 [rate-limit-config] warn、
   合法值⇒取整),login 与 contact 都改用它;默认值都不动(10/5),
   仅在 e2e harness 抬到 500/200。3 例判据覆盖上述三条路径。
2) uj-08:helper hover 的是顶栏里第一个 a[href=/services](实测命中工具行那条),
   且面板正在播 280ms 入场动画 ⇒ Playwright 判 not stable 重试到 15s。
   改为语义锚点「查看全部能力」+ 等 320ms(> token 的 280ms),
   并断言其 href 就是导航项自己声明的 /services。firefox+chromium 复跑 2 passed。
3) website-acceptance「导航菜单功能正常」:日志显示点击后 navigated to /
   ⇒ 点在了 logo 上。①补 expectHydrated(nav)(相邻用例早有,这条漏了);
   ②选择器排除 href=/ ⇒ 测的真是菜单项。firefox+webkit 连跑 **5/5 绿**(4.7s,
   此前 15s 超时)。

复算:tsc 0、type-check:e2e 0、rate-limit-config + login + seed-target 测试全绿。
This commit is contained in:
zhangxiang committed 2026-10-20 05:46:05 +08:00
1 parent 944fb018e7
commit 5530add712
7 files changed
+92 -5

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import { describe, it, expect, jest, afterEach } from '@jest/globals';
import { readRateLimitMax } from './rate-limit-config';
/**
* 限流额度读取的判据用例。重点不是"能读数字",而是三条容易静默失效的路径:
* 未设置 ⇒ 默认;非法值 ⇒ 默认且**留痕**;合法值 ⇒ 生效(含取整)。
*/
describe('readRateLimitMax', () => {
const originalWarn = console.warn;
afterEach(() => {
console.warn = originalWarn;
});
it('未设置 / 空串 ⇒ 默认值(生产姿态)', () => {
expect(readRateLimitMax('X_LIMIT', 10, {})).toBe(10);
expect(readRateLimitMax('X_LIMIT', 5, { X_LIMIT: '' })).toBe(5);
});
it('合法值 ⇒ 取该值并向下取整', () => {
expect(readRateLimitMax('X_LIMIT', 10, { X_LIMIT: '500' })).toBe(500);
expect(readRateLimitMax('X_LIMIT', 10, { X_LIMIT: '7.9' })).toBe(7);
});
it('非法值(0 / 负数 / 非数字)⇒ 退回默认,且必须留痕(不许静默采纳也不许静默忽略)', () => {
const spy = jest.fn();
console.warn = spy as never;
expect(readRateLimitMax('X_LIMIT', 10, { X_LIMIT: '0' })).toBe(10);
expect(readRateLimitMax('X_LIMIT', 10, { X_LIMIT: '-3' })).toBe(10);
expect(readRateLimitMax('X_LIMIT', 10, { X_LIMIT: 'abc' })).toBe(10);
expect(spy).toHaveBeenCalledTimes(3);
expect(String(spy.mock.calls[0]?.[0])).toContain('[rate-limit-config]');
});
});
+27
View File
@@ -0,0 +1,27 @@
/**
* 限流额度的环境变量读取(2026-10-17)。
*
* 为什么需要:登录与联系表单的限流都是**进程内内存桶**,而 E2E 的 dev/standalone server
* 跨整轮用例存活 ⇒ 全量功能 E2E 里第 6 次联系提交、第 11 次登录必然 429。
* 这是「单跑绿、全量红」的结构性原因(§14.3/§14.4),不是限流逻辑坏了。
*
* 原则:**默认值不变**(生产姿态一字不动),只在 e2e harness 显式抬高;
* 非法的覆盖值不静默采用 —— 退回默认并打一条可 grep 的 warn,
* 否则「写错变量名」会表现成「限流没生效」,那是更难查的一类。
*/
export function readRateLimitMax(
envName: string,
fallback: number,
env: Record<string, string | undefined> = process.env,
): number {
const raw = env[envName];
if (raw === undefined || raw === '') return fallback;
const n = Number(raw);
if (!Number.isFinite(n) || n <= 0) {
console.warn(
`[rate-limit-config] ${envName}="${raw}" 不是正数 ⇒ 退回默认 ${fallback}(没静默采用非法值)`,
);
return fallback;
}
return Math.floor(n);
}