fix(sdk): §4.5 红线补全(act/重放包裹)+ beacon-false 丢批计数 + 空闲负向测试 + es2020

- events.ts:act 回调与 visibilitychange 监听体包 try/catch(字面红线)
- transport.ts:sendBeacon 返回 false(64KB 超限等)按批事件数计 dropped
  ——与 stringify 丢包计数对称的缺口
- index.ts:顶层队列重放双层包裹,单个坏条目只跳过自身不吞后续 init/track
- 测试:30s 空闲负向(active_ms=29000 后停止)、beacon-false 丢批;44→46
- build.mjs target es2018→es2020(代码依赖 globalThis,目标诚实化)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-15 16:40:35 +08:00
parent dc13ae6e0e
commit 21c3cb2423
6 changed files with 54 additions and 6 deletions
+10
View File
@@ -177,6 +177,16 @@ describe("transport", () => {
expect(t.dropped).toBe(1); // maxRetry=0 耗尽 → 按事件数丢弃
});
it("sendBeacon 返回 false(队列满/载荷超限)按本批事件数计 dropped", () => {
vi.stubGlobal("navigator", { sendBeacon: vi.fn().mockReturnValue(false) });
const t = new Transport(mkCfg({ batchSize: 10 }));
t.push({ event_id: "e1" });
t.push({ event_id: "e2" });
t.flush(true);
expect(t.dropped).toBe(2); // 信标被浏览器拒收(64KB 上限等)→ 整批丢
expect(fetchMock).not.toHaveBeenCalled();
});
it("stringify 抛错(track 引入宿主可控对象):已换出批次按事件数计 dropped", () => {
const t = new Transport(mkCfg({ batchSize: 10, flushMs: 60000 }));
const bad: { event_id: string; self?: unknown } = { event_id: "bad" };