fix(webui): connection-diff-loop compares ONLY level — strip detail timestamps
Adversarial review caught: HttpPostAdapter.describeStatus() embeds
HH:MM:SS in 'detail' (e.g. "上次推送 14:53:01"). Every webhook delivery
rotates that string every second under any active push — and the diff
loop's raw JSON.stringify compared everything, so it published on every
500ms tick under any non-idle webhook. Net effect: SSE pushed a full
connections frame at 2 Hz, exactly the polling the loop was meant to
replace, just on the push channel.
Add an optional pickComparable projector. server.ts caller passes one
that returns { uin, nickname, adapters[{ name, kind, status }] } — the
LEVEL only, not the live-rendered detail string. The SSE handler still
ships the FULL snapshot (including detail) to the WebUI; only the diff
key is pruned.
2 new tests pin the invariant: 10 detail-only ticks → ZERO publishes; a
real status-level transition publishes exactly once. Plus a throwing-
projector isolation test. 7/7 diff-loop tests green.
This commit is contained in:
4 files changed
+96
-3
No files matched your search
@@ -164,7 +164,7 @@ describe('bindStateStream', () => {
|
||||
// observed frame as the older snapshot.
|
||||
let call = 0;
|
||||
const versions = ['snap-T0', 'snap-T60'];
|
||||
const snapshot = vi.fn(async (resource: StateResource): Promise<unknown> => {
|
||||
const snapshot = vi.fn(async (_resource: StateResource): Promise<unknown> => {
|
||||
const i = call++;
|
||||
const sleep = i === 0 ? 200 : 10;
|
||||
await new Promise<void>((r) => setTimeout(r, sleep));
|
||||
@@ -196,7 +196,7 @@ describe('bindStateStream', () => {
|
||||
const bus = new StateBus();
|
||||
const sent: CapturedFrame[] = [];
|
||||
let call = 0;
|
||||
const snapshot = vi.fn(async (resource: StateResource): Promise<unknown> => {
|
||||
const snapshot = vi.fn(async (_resource: StateResource): Promise<unknown> => {
|
||||
call++;
|
||||
await new Promise<void>((r) => setTimeout(r, 100));
|
||||
return `snap-#${call}`;
|
||||
|
||||
Reference in new issue
Block a user