Skip to content

Commit dac0e8c

Browse files
wesbillmanCarl
andcommitted
test(desktop): preserve readiness filter correlation and await inbox delivery
Keep raw REQ filters for exact channel/kind readiness while preserving legacy delivery projections. Gate the Inbox live reaction fixture on its actual channel consumer rather than initial history rendering. Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Signed-off-by: Wes <[email protected]>
1 parent 1b126af commit dac0e8c

4 files changed

Lines changed: 95 additions & 58 deletions

File tree

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import { switchManagedAgentModel } from "@/shared/api/agentControl";
3333
import { getAudioMediaLoadSchedulerSnapshot } from "@/features/messages/lib/audioMediaLoadScheduler";
3434
import { mockSearchHitMatches } from "./e2eBridgeSearch.ts";
3535
import { selectMockHistory } from "./e2eBridgeHistory.ts";
36-
import { hasMockSubscription } from "./e2eBridgeSubscriptions.ts";
36+
import {
37+
createMockSubscription,
38+
hasMockSubscription,
39+
} from "./e2eBridgeSubscriptions.ts";
3740
export { mockSearchHitMatches };
3841
import type { ConnectionState } from "@/shared/api/relayClientShared";
3942
import type {
@@ -1087,14 +1090,7 @@ type MockManagedAgentRuntimeRow = {
10871090
type WsHandler = (message: unknown) => void;
10881091
const GLOBAL_MOCK_SUBSCRIPTION = "*";
10891092

1090-
type MockSubscription = {
1091-
channelIds: string[];
1092-
kinds: number[] | null;
1093-
/** `#p` values from the REQ filters, if any — lets specs assert an
1094-
* owner-scoped live subscription (e.g. the observer-archive `24200`
1095-
* reconciliation gate) independently of channel-scoped ones. */
1096-
ownerPubkeys: string[];
1097-
};
1093+
type MockSubscription = ReturnType<typeof createMockSubscription>;
10981094

10991095
type MockFilter = {
11001096
"#a"?: string[];
@@ -10864,43 +10860,29 @@ function sendToMockSocket(args: {
1086410860
}
1086510861

1086610862
if (subId.startsWith("live-")) {
10867-
// Collect channel IDs from all filters in the REQ
10868-
const channelIds = new Set<string>();
10869-
const kinds = new Set<number>();
10870-
const ownerPubkeys = new Set<string>();
10871-
for (const f of filters) {
10872-
for (const channelId of f["#h"] ?? []) channelIds.add(channelId);
10873-
for (const kind of f.kinds ?? []) {
10874-
kinds.add(kind);
10875-
}
10876-
for (const p of f["#p"] ?? []) {
10877-
ownerPubkeys.add(p);
10878-
}
10879-
}
10863+
const subscription = createMockSubscription(filters);
1088010864
const onlyChannelId =
10881-
channelIds.size === 1
10882-
? (channelIds.values().next().value as string)
10865+
subscription.channelIds.length === 1 &&
10866+
subscription.channelIds[0] !== GLOBAL_MOCK_SUBSCRIPTION
10867+
? subscription.channelIds[0]
1088310868
: undefined;
1088410869
if (
1088510870
getConfig()?.mock?.closeChannelLiveSubscriptionOnce &&
1088610871
!mockClosedChannelLiveSubscription &&
1088710872
onlyChannelId &&
10888-
kinds.has(KIND_CHANNEL_THREAD_SUMMARY)
10873+
subscription.kinds?.includes(KIND_CHANNEL_THREAD_SUMMARY)
1088910874
) {
1089010875
mockClosedChannelLiveSubscription = true;
1089110876
sendWsText(socket.handler, ["CLOSED", subId, "rate-limited"]);
1089210877
return;
1089310878
}
10894-
socket.subscriptions.set(subId, {
10895-
channelIds:
10896-
channelIds.size > 0 ? [...channelIds] : [GLOBAL_MOCK_SUBSCRIPTION],
10897-
kinds: kinds.size > 0 ? [...kinds] : null,
10898-
ownerPubkeys: [...ownerPubkeys],
10899-
});
10879+
socket.subscriptions.set(subId, subscription);
1090010880
// Live requests still replay stored matches; pacing can admit them after
1090110881
// a publish. Ephemeral/global fixtures are not channel history.
1090210882
const history = new Map(
10903-
[...channelIds].map((id) => [id, getMockMessageStore(id)]),
10883+
subscription.channelIds
10884+
.filter((id) => id !== GLOBAL_MOCK_SUBSCRIPTION)
10885+
.map((id) => [id, getMockMessageStore(id)]),
1090410886
);
1090510887
for (const event of selectMockHistory(history, filters)) {
1090610888
sendWsText(socket.handler, ["EVENT", subId, event]);
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
3-
import { hasMockSubscription } from "./e2eBridgeSubscriptions.ts";
3+
import {
4+
createMockSubscription,
5+
hasMockSubscription,
6+
} from "./e2eBridgeSubscriptions.ts";
7+
8+
const ready = (filters, channel = "channel", kind = 9, exact = true) =>
9+
hasMockSubscription([createMockSubscription(filters)], channel, kind, exact);
410

511
test("channel readiness rejects global-only, wrong-channel and wrong-kind REQs", () => {
6-
const subscription = (channelIds, kinds) => ({ channelIds, kinds });
7-
for (const candidate of [
8-
subscription(["*"], [9]),
9-
subscription(["other"], [9]),
10-
subscription(["channel"], [30078]),
11-
]) {
12-
assert.equal(hasMockSubscription([candidate], "channel", 9, true), false);
13-
}
12+
for (const filter of [
13+
{ kinds: [9] },
14+
{ "#h": [], kinds: [9] },
15+
{ "#h": ["other"], kinds: [9] },
16+
{ "#h": ["channel"], kinds: [30078] },
17+
])
18+
assert.equal(ready([filter]), false);
1419
assert.equal(hasMockSubscription([], "channel", 9, true), false);
15-
for (const kinds of [[9], [7, 9], null]) {
16-
assert.equal(
17-
hasMockSubscription(
18-
[subscription(["channel"], kinds)],
19-
"channel",
20-
9,
21-
true,
22-
),
23-
true,
24-
);
20+
for (const kinds of [[9], [7, 9], [], undefined]) {
21+
assert.equal(ready([{ "#h": ["channel"], kinds }]), true);
22+
}
23+
});
24+
25+
test("REQ storage preserves channel/kind correlation across OR filters", () => {
26+
for (const unrelated of [{ kinds: [9] }, { "#h": ["other"], kinds: [9] }]) {
27+
const filters = [{ "#h": ["channel"], kinds: [30078] }, unrelated];
28+
const stored = createMockSubscription(filters);
29+
assert.deepEqual(stored.filters, filters);
30+
assert.equal(hasMockSubscription([stored], "channel", 9, true), false);
31+
assert.equal(hasMockSubscription([stored], "channel", 30078, true), true);
32+
assert.equal(ready([...filters, { "#h": ["channel"], kinds: [9] }]), true);
2533
}
2634
});
2735

2836
test("legacy readiness and explicit global queries retain their semantics", () => {
29-
const global = [{ channelIds: ["*"], kinds: [30078] }];
37+
const global = [createMockSubscription([{ kinds: [30078] }])];
3038
assert.equal(hasMockSubscription(global, "channel"), true);
3139
assert.equal(hasMockSubscription(global, "channel", 9), false);
40+
assert.equal(hasMockSubscription(global, "channel", 30078), true);
3241
assert.equal(hasMockSubscription(global, "*", 30078), true);
3342
assert.equal(hasMockSubscription(global, "*", 9), false);
43+
assert.equal(hasMockSubscription(global, "channel", 30078, true), false);
44+
assert.equal(
45+
ready(
46+
[{ "#h": ["channel"], kinds: [30078] }, { kinds: [9] }],
47+
"channel",
48+
9,
49+
false,
50+
),
51+
true,
52+
);
3453
});

‎desktop/src/testing/e2eBridgeSubscriptions.ts‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1-
type Subscription = {
2-
channelIds: readonly string[];
3-
kinds: readonly number[] | null;
1+
type SubscriptionFilter = {
2+
"#h"?: readonly string[];
3+
"#p"?: readonly string[];
4+
kinds?: readonly number[];
45
};
56

7+
/** Preserve raw REQ correlation alongside legacy mock delivery projections. */
8+
export function createMockSubscription(filters: readonly SubscriptionFilter[]) {
9+
const channelIds = [
10+
...new Set(filters.flatMap((filter) => filter["#h"] ?? [])),
11+
];
12+
const kinds = [...new Set(filters.flatMap((filter) => filter.kinds ?? []))];
13+
return {
14+
filters,
15+
channelIds: channelIds.length ? channelIds : ["*"],
16+
kinds: kinds.length ? kinds : null,
17+
ownerPubkeys: [...new Set(filters.flatMap((filter) => filter["#p"] ?? []))],
18+
};
19+
}
20+
621
/** Test readiness must distinguish a channel consumer from unrelated global REQs. */
722
export function hasMockSubscription(
8-
subscriptions: Iterable<Subscription>,
23+
subscriptions: Iterable<ReturnType<typeof createMockSubscription>>,
924
channelId: string,
1025
kind?: number,
1126
exactChannel = false,
1227
): boolean {
1328
for (const subscription of subscriptions) {
14-
if (
29+
if (exactChannel) {
30+
if (
31+
subscription.filters.some(
32+
(filter) =>
33+
filter["#h"]?.includes(channelId) &&
34+
(kind === undefined ||
35+
!filter.kinds?.length ||
36+
filter.kinds.includes(kind)),
37+
)
38+
)
39+
return true;
40+
} else if (
1541
(subscription.channelIds.includes(channelId) ||
16-
(!exactChannel && subscription.channelIds.includes("*"))) &&
42+
subscription.channelIds.includes("*")) &&
1743
(kind === undefined ||
1844
!subscription.kinds ||
1945
subscription.kinds.includes(kind))

‎desktop/tests/e2e/inbox-reactions.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ test("inbox reaction on a thread-reply mention persists after refetch", async ({
122122

123123
const selectedMessage = page.getByTestId("home-inbox-selected-message");
124124

125+
// Detail renders from history before the paced background consumer is ready.
126+
// Exercise live delivery only once this channel actually requests kind 7.
127+
await page.waitForFunction(() =>
128+
window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
129+
channelName: "general",
130+
kind: 7,
131+
exactChannel: true,
132+
}),
133+
);
134+
125135
// Deliver a live reaction with the real add_reaction wire shape: `e` target,
126136
// no `h` channel tag. The Inbox must render it without waiting for another
127137
// message or a context refetch.

0 commit comments

Comments
 (0)