Skip to content

Commit 50b7da2

Browse files
wesbillmanCarl
andcommitted
test(desktop): verify readiness through socket REQs
Explicit empty kinds match nothing; omitted kinds remain wildcard. Exercise serialized REQs through the mock socket, including cross-filter counterexamples, same-filter positives, EOSE acceptance and CLOSE cleanup. Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Signed-off-by: Wes <[email protected]>
1 parent dac0e8c commit 50b7da2

4 files changed

Lines changed: 113 additions & 4 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
name: "smoke",
2121
testMatch: [
2222
"**/smoke.spec.ts",
23+
"**/mock-subscription-readiness.spec.ts",
2324
"**/owned-agent-discovery.spec.ts",
2425
"**/thread-head-stale-edit.spec.ts",
2526
"**/sidebar-offcanvas-rail.spec.ts",

‎desktop/src/testing/e2eBridgeSubscriptions.test.mjs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,24 @@ test("channel readiness rejects global-only, wrong-channel and wrong-kind REQs",
1717
])
1818
assert.equal(ready([filter]), false);
1919
assert.equal(hasMockSubscription([], "channel", 9, true), false);
20-
for (const kinds of [[9], [7, 9], [], undefined]) {
20+
for (const kinds of [[9], [7, 9], undefined]) {
2121
assert.equal(ready([{ "#h": ["channel"], kinds }]), true);
2222
}
23+
const emptyKinds = [
24+
createMockSubscription([{ "#h": ["channel"], kinds: [] }]),
25+
];
26+
assert.equal(hasMockSubscription(emptyKinds, "channel", 9, true), false);
27+
assert.equal(
28+
hasMockSubscription(emptyKinds, "channel", undefined, true),
29+
false,
30+
);
31+
assert.equal(
32+
ready([
33+
{ "#h": ["channel"], kinds: [] },
34+
{ "#h": ["channel"], kinds: [9] },
35+
]),
36+
true,
37+
);
2338
});
2439

2540
test("REQ storage preserves channel/kind correlation across OR filters", () => {

‎desktop/src/testing/e2eBridgeSubscriptions.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function hasMockSubscription(
3131
subscription.filters.some(
3232
(filter) =>
3333
filter["#h"]?.includes(channelId) &&
34-
(kind === undefined ||
35-
!filter.kinds?.length ||
36-
filter.kinds.includes(kind)),
34+
(filter.kinds === undefined ||
35+
(filter.kinds.length > 0 &&
36+
(kind === undefined || filter.kinds.includes(kind)))),
3737
)
3838
)
3939
return true;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
import { installMockBridge } from "../helpers/bridge";
4+
5+
test("mock socket REQs preserve exact readiness semantics", async ({
6+
page,
7+
}) => {
8+
// Keep app-owned channel subscriptions out of the readiness result. The
9+
// bridge is installed, but locked boot never mounts the channel consumers.
10+
await installMockBridge(page, { identityLocked: true });
11+
await page.goto("/");
12+
await expect(page.getByTestId("keyring-locked")).toBeVisible();
13+
14+
const observed = await page.evaluate(async () => {
15+
const invoke = window.__BUZZ_E2E_INVOKE_MOCK_COMMAND__;
16+
const ready = window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__;
17+
if (!invoke || !ready) throw new Error("Mock socket bridge is unavailable");
18+
const channel = "9a1657ac-f7aa-5db0-b632-d8bbeb6dfb50";
19+
const owner = "deadbeef".repeat(8);
20+
const frames: unknown[][] = [];
21+
const id = await invoke("plugin:websocket|connect", {
22+
onMessage: (batch: Array<{ type: string; data?: string }>) => {
23+
for (const frame of batch) {
24+
if (frame.type === "Text" && frame.data) {
25+
frames.push(JSON.parse(frame.data));
26+
}
27+
}
28+
},
29+
});
30+
const subId = "live-readiness-regression";
31+
const check = (kind: number | undefined = 9, exactChannel = true) =>
32+
ready({ channelName: "general", kind, exactChannel });
33+
const send = (message: unknown[]) =>
34+
invoke("plugin:websocket|send", {
35+
id,
36+
message: { type: "Text", data: JSON.stringify(message) },
37+
});
38+
const req = async (filters: Array<Record<string, unknown>>) => {
39+
frames.length = 0;
40+
await send(["REQ", subId, ...filters]);
41+
if (!frames.some((frame) => frame[0] === "EOSE" && frame[1] === subId)) {
42+
throw new Error(`REQ was not accepted: ${JSON.stringify(frames)}`);
43+
}
44+
return check();
45+
};
46+
47+
try {
48+
const before = check();
49+
const splitGlobal = await req([
50+
{ "#h": [channel], kinds: [30078] },
51+
{ kinds: [9] },
52+
]);
53+
const splitOtherChannel = await req([
54+
{ "#h": [channel], kinds: [30078] },
55+
{ "#h": ["other"], kinds: [9] },
56+
]);
57+
const sameFilter = await req([{ "#h": [channel], kinds: [9] }]);
58+
const emptyKinds = await req([
59+
{ "#h": [channel], "#p": [owner], kinds: [] },
60+
]);
61+
const omittedKinds = await req([{ "#h": [channel], "#p": [owner] }]);
62+
const globalOnly = await req([{ kinds: [9] }]);
63+
const legacyGlobal = check(9, false);
64+
await send(["CLOSE", subId]);
65+
const afterClose = check();
66+
return {
67+
before,
68+
splitGlobal,
69+
splitOtherChannel,
70+
sameFilter,
71+
emptyKinds,
72+
omittedKinds,
73+
globalOnly,
74+
legacyGlobal,
75+
afterClose,
76+
};
77+
} finally {
78+
await invoke("plugin:websocket|disconnect", { id });
79+
}
80+
});
81+
82+
expect(observed).toEqual({
83+
before: false,
84+
splitGlobal: false,
85+
splitOtherChannel: false,
86+
sameFilter: true,
87+
emptyKinds: false,
88+
omittedKinds: true,
89+
globalOnly: false,
90+
legacyGlobal: true,
91+
afterClose: false,
92+
});
93+
});

0 commit comments

Comments
 (0)