app-api-runtime 对 /api/me、/api/workflow/tasks*、/api/workflow/approvers*、 /api/notifications* 使用 NetworkFirst + networkTimeoutSeconds: 3。网络响应 超过 3 秒时 Service Worker 返回审批前缓存的旧响应,真实响应被丢弃,页面 仍显示「待派发」。审批写入本身正确。自 2026-03(9112383d)起存在。 去掉网络超时,只在网络失败(离线)时回退缓存;退出登录清理缓存不变。 新增回归测试锁定该规则。负载复现修复前 3 轮命中 2 轮,修复后 3 轮 0 命中。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
25 行
1.1 KiB
JavaScript
25 行
1.1 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
const viteConfig = readFileSync(path.resolve(__dirname, "../../../../client/vite.config.ts"), "utf8");
|
|
|
|
function runtimeCacheRule(cacheName) {
|
|
const marker = `cacheName: "${cacheName}"`;
|
|
const at = viteConfig.indexOf(marker);
|
|
expect(at, `${cacheName} rule must exist`).toBeGreaterThan(-1);
|
|
const start = viteConfig.lastIndexOf("urlPattern:", at);
|
|
const end = viteConfig.indexOf("urlPattern:", at);
|
|
return viteConfig.slice(start, end === -1 ? undefined : end);
|
|
}
|
|
|
|
describe("client PWA API runtime cache", () => {
|
|
it("falls back to cached API data only when the network fails, never on a slow response", () => {
|
|
const rule = runtimeCacheRule("app-api-runtime");
|
|
expect(rule).toContain('handler: "NetworkFirst"');
|
|
// A timeout made the service worker answer a post-approval refetch with the
|
|
// cached pre-approval task after 3s, so the page kept showing "待派发".
|
|
expect(rule).not.toMatch(/networkTimeoutSeconds/);
|
|
});
|
|
});
|