mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
## Summary Test-side fixes for ten desktop E2E flake clusters and six long-tail rows from the 21–28 Oct 2026 CI audit. Each spec now waits for the state it assumes (a rendered row, a mounted listener, a finished animation, a held boot read), not a fixed delay or a one-shot probe. Two mock-bridge seams support this. The PR changes test code and mock-bridge seams only, apart from one product constant extracted with its value unchanged. It is one of seven PRs split out of the `flakey-tests` branch (siblings below). ### Related issue None found. - #8622, #8244 and #8386 touch some of these spec files, but not the tests fixed here. - §7 mode A (`navigation:472`) is left to open PR #6852, which already sets the width and measures in one polled evaluate. - Draft #8279 queues cold-launch nostr-bind links in the product. Its mock returns null, so the §12 listener seam is still needed. ### Mock-bridge seams - `__BUZZ_E2E_EVENT_LISTENER_COUNT__(event)` counts live **app** listeners per Tauri event. It wraps the mocked `plugin:event|listen`/`unlisten`. The spec-facing `__TAURI_INTERNALS__.listen` passes a marker target that the wrapper skips, so a spec's own subscription can't satisfy the wait. Tauri 2.11.1's mock ignores targets, so delivery is unchanged. - `deferFirstChannelsRead` arms the existing channels-read hold at boot. `__BUZZ_E2E_RELEASE_CHANNELS_READ__` releases it. - `CREATE_PROJECT_REFOCUS_DELAY_MS` moves to `createProjectFormFocus.ts` with its value unchanged (50 ms). Both `CreateProjectFormContent` and `project-commit-detail.spec` import it. ### Flaky tests fixed | Test | Failing runs | Cause | Change | |---|---|---|---| | §2 `overscroll-boundary.spec.ts:34` (and its sibling) | 39601763602, 40367495044, 40583830861, 40597484657, 40373404267 | The `message-timeline` test id first lands on the loading skeleton, which doesn't overflow, so the scroll lock rightly cancels the wheel. | Wait for a rendered row, and content taller than the viewport, before dispatching wheels. | | §4 `project-conversation-load-failure.spec.ts:73` | 40367495044 (all 3 attempts), 40608383847, 40583830861; PRs 39541263507, 40509460168 | The seeded root and reply were dated `now`. The panel's live REQ (`since = floor(now)`) still replayed the reply, so the error card never appeared. | Date both events a minute in the past, and correct the comment. | | §6 `workflows.spec.ts` `createWorkflow` cluster (:222, :365, :297, :525, :471, :406, :614, :997) | 14 of 50 main jobs; :222 ×4, e.g. 40353619362 | `AnimatePresence mode="wait"` keeps the trigger body mounted through its exit, so "Message text" could fill the trigger's field (:222 and the callers). For :297, `isVisible()` read "closed" one frame before the dialog opened its own channel list. | Wait for the step body's "Step details" control before filling. Create dialogs wait for the list; only the duplicate dialog clicks it. | | §12 `nostr-bind.spec.ts` (:156, :198, :228, :247, :260, :335, :417, :447) | 8 main jobs, each test once | The spec emitted `deep-link-nostr-bind` before the app subscribed, and the mock drops events that have no listener. | Wait for `__BUZZ_E2E_EVENT_LISTENER_COUNT__` to report the app listener before emitting. | | §15 `profile.spec.ts:1128` (integration) | 7 of 50 main jobs | The 320 ms motion-sampling window started before the click. | Start the window when `activeTab` reads "runtime". | | §17 `agent-availability.spec.ts:602`, both shutdown-failure variants (integration) | 6 jobs (4 disconnected-online, 2 failed-online) | The "shutdown refused" toast sits over the Delete row and pauses while the pointer is on it, so the retry click is intercepted. | Assert the toast, then retry with focus + Enter. The toaster has no close button. | | §19 `virtualization.spec.ts:247` "08 — cascading older pages…" | 4 of 50 main jobs; PR 40605736093 (all 3 attempts) | The 120 ms and 400 ms windows were timed from before the wheel bursts, and CDP can deliver wheels late. | Count the wheels the page receives. Each window opens at the first wheel and closes only after all have landed, then waits for still frames. **A second, product-side mode remains** (see below). | | §20 `message-copy-link.spec.ts:160` | 4 of 50 main jobs (5 failed attempts), e.g. 40595483966 | The huddle row reused `"d".repeat(64)`, which is a seeded ordinary `#general` message. | Use ids that no seed uses, and emit only after `waitForMockChannelHeadReady`. | | §21 `navigation.spec.ts:687` | 4 of 50 main jobs | The pending chip's `boundingBox()` was read once, and can be null while the row mounts. | Poll until the chip has a width. | | §23 `sidebar-snapshot.spec.ts:358`, `:388`, `:438` | PR 40427822003 (all 3 attempts); never on main | The 500 ms loading-state budget counted app boot, so a slow runner finished the channels read first. | Hold the first channels read with `deferFirstChannelsRead`, assert the loading state, then release it. | | `project-commit-detail.spec.ts:259` | 1–2 CI failures (audit long tail) | A 50 ms refocus timer can land mid-fill and type the description into the name field. | Once the name field is focused, wait out a page timer of `CREATE_PROJECT_REFOCUS_DELAY_MS`; equal-delay timers fire in order. | | `project-pr-review.spec.ts:3520` | 1–2 CI failures | The same timer pattern in `CreateProjectWorkItemDialog`. | Wait for `toBeFocused()` on the title, which only that timer can satisfy. | | `thread-load-failure.spec.ts:79` | 1–2 CI failures | `openWelcomeThread` branched on a one-shot `count()` and fell back to a hover-only Reply click. | Wait for the summary row, then click it. | | `virtualization.spec.ts:201` | 1–2 CI failures | The drop point sat 2 px above the target's bottom edge, after two fixed frames. | Drop at the centre, after dnd-kit's live region names the target. | | `channel-composer-overflow.spec.ts:217` | 1–2 CI failures | Same-second emits sort by id, and the clearance was checked once. | `createdAt: base + i` and `expect.poll`. | | `scroll-history.spec.ts:1289` | 1–2 CI failures | A fixed 250 ms wait before idle sampling. | Poll for coverage first. | Local before/after counts are from the original `flakey-tests` commits (e286a6ae0, 816c7c35e, 67185df6a). Each used a forcing that made `main`'s copy fail with CI's signature: | Test | Before | After | |---|---|---| | §2 | 3/15 | 15/15 | | §4 | 0/10 | 10/10 | | §6 :222 | 0/3 | 3/3 | | §6 :297 | 0/3 | 3/3 | | §12 | 0/3 | 3/3 | | §15 | 0/3 | 3/3 | | §17 | 1/4 | 4/4 | | §19 late-wheel modes | 0/3 | 3/3 and 2/3 | | §23 | 2/6 | 6/6 | | project-commit-detail | 0/3 | 3/3 | | project-pr-review | 0/3 | 3/3 | §20, §21, `thread-load-failure:79`, `virtualization:201`, `channel-composer-overflow:217` and `scroll-history:1289` were not reproduced; they get the fix that matches their CI signature. Not fixed (follow-up): `virtualization:247` also has a product-side mode. In one frame after a prepend, `scrollHeight` can drop 458–639 px while `scrollTop` moves only 50–114 px, so the anchor row jumps 382–457 px. That is lost anchor compensation, and this test can still fail on it. ### Verification This branch was pushed without local re-verification, by the user's choice: local test runs were overloading the machine and failing for that reason. **Hosted CI is the check.** It was pushed with `git push --no-verify`, because the pre-push hook runs typecheck and the unit suites. #8613's flake-check lane will also repeat the changed specs. - Every file except `virtualization.spec.ts` is byte-identical to its final version on `flakey-tests` (67185df6a). That file carries only this PR's hunks; see "Merge order". - Checked for this PR: `git diff --check`, biome on the partial spec (no changes, the same as on `main`), and a conflict-free merge with all six siblings onto `main`. ### Readiness Test and mock-bridge change; the one product edit is a constant extraction with its value unchanged. AGENTS.md's readiness steps (agent review, then human confirmation) are still outstanding, so `buzz-review-completed` is not set. ### Merge order No required order. `desktop/tests/e2e/virtualization.spec.ts` is also edited by **flakey-tests-desktop-races**, which adds one test after line 929; this PR's hunks are all above line 551. They don't touch, so the two merge cleanly in either order, as checked with `git merge-tree`. ### Sibling PRs Split from `flakey-tests` (one PR per area): #8676 (PostgreSQL lease + lane), #8677 (relay E2E helper + Windows shell), #8678 (mobile), #8679 (Tauri apt cache + Windows Rust cap), #8680 (desktop product races), #8682 (desktop E2E composer + row actions). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jitter <2b2e6415e748c35180847a37aadae06a11e30dddc76b784e7fd9354c4eb42e7a@buzz.block.builderlab.xyz>
642 lines
20 KiB
TypeScript
642 lines
20 KiB
TypeScript
import { expect, test, type Page } from "@playwright/test";
|
|
|
|
import { installMockBridge } from "../helpers/bridge";
|
|
|
|
const RELAY_URL = "ws://localhost:3000";
|
|
const OTHER_RELAY_URL = "ws://localhost:3001";
|
|
const OWNER_PUBKEY = "deadbeef".repeat(8);
|
|
const STALE_COMMUNITY_PUBKEY = "cafebabe".repeat(8);
|
|
const MATCHING_HASH = "mock-hash";
|
|
const READ_DELAY_MS = 600;
|
|
const SNAPSHOT_FRAME_DELAY_MS = 3_000;
|
|
|
|
function snapshotKey(relayUrl: string, ownerPubkey = OWNER_PUBKEY) {
|
|
return `buzz-channels.v1:${relayUrl}:${ownerPubkey.toLowerCase()}`;
|
|
}
|
|
|
|
function makeSnapshotChannel(index: number, prefix = "snapshot") {
|
|
return {
|
|
id: `${prefix}-${index}`,
|
|
name: `${prefix}-${String(index).padStart(2, "0")}`,
|
|
channelType: "stream",
|
|
visibility: "open",
|
|
description: "",
|
|
topic: null,
|
|
purpose: null,
|
|
memberCount: 1,
|
|
memberPubkeys: [OWNER_PUBKEY],
|
|
lastMessageAt: null,
|
|
archivedAt: null,
|
|
participants: [],
|
|
participantPubkeys: [],
|
|
isMember: true,
|
|
ttlSeconds: null,
|
|
ttlDeadline: null,
|
|
};
|
|
}
|
|
|
|
// Cold-boot tests hold the first channels read (deferFirstChannelsRead) so the
|
|
// loading state is on screen however long boot takes, then release it here.
|
|
async function releaseFirstChannelsRead(page: Page) {
|
|
await expect
|
|
.poll(() => page.evaluate(() => window.__BUZZ_E2E_CHANNELS_READ_PENDING__))
|
|
.toBe(1);
|
|
expect(
|
|
await page.evaluate(() => window.__BUZZ_E2E_RELEASE_CHANNELS_READ__?.()),
|
|
).toBe(1);
|
|
}
|
|
|
|
const FULL_SNAPSHOT = Array.from({ length: 14 }, (_, index) =>
|
|
makeSnapshotChannel(index),
|
|
);
|
|
const SNAPSHOT_DIAGNOSTIC_MARK = "buzz:sidebar:snapshot-diagnostic";
|
|
const FULL_SIDEBAR_PAINT_MARK = "buzz:sidebar:full-list-painted";
|
|
const BOOT_TO_FULL_SIDEBAR_MEASURE = "buzz:sidebar:boot-to-full-list-painted";
|
|
|
|
function snapshotIntegrity(
|
|
ownerPubkey: string,
|
|
hash: string,
|
|
channels: ReturnType<typeof makeSnapshotChannel>[],
|
|
) {
|
|
const value = JSON.stringify([ownerPubkey.toLowerCase(), hash, channels]);
|
|
let result = 0x811c9dc5;
|
|
for (let index = 0; index < value.length; index += 1) {
|
|
result ^= value.charCodeAt(index);
|
|
result = Math.imul(result, 0x01000193);
|
|
}
|
|
return (result >>> 0).toString(16).padStart(8, "0");
|
|
}
|
|
|
|
type SnapshotDiagnostics = {
|
|
ageMs: number;
|
|
channelCount: number;
|
|
presence: "absent" | "invalid" | "present";
|
|
serializedBytes: number;
|
|
};
|
|
|
|
async function getSnapshotDiagnostic(page: Page) {
|
|
return page.evaluate((name) => {
|
|
const entry = performance.getEntriesByName(name).at(-1) as
|
|
| PerformanceMark
|
|
| undefined;
|
|
return entry?.detail as SnapshotDiagnostics | undefined;
|
|
}, SNAPSHOT_DIAGNOSTIC_MARK);
|
|
}
|
|
|
|
async function getFullSidebarMeasure(page: Page) {
|
|
return page.evaluate(
|
|
({ markName, measureName }) => ({
|
|
markCount: performance.getEntriesByName(markName).length,
|
|
measure: performance.getEntriesByName(measureName).at(-1)?.duration,
|
|
}),
|
|
{
|
|
markName: FULL_SIDEBAR_PAINT_MARK,
|
|
measureName: BOOT_TO_FULL_SIDEBAR_MEASURE,
|
|
},
|
|
);
|
|
}
|
|
|
|
async function seedSnapshot(
|
|
page: Page,
|
|
options: {
|
|
channels?: ReturnType<typeof makeSnapshotChannel>[];
|
|
hash: string;
|
|
keyOwnerPubkey?: string;
|
|
ownerPubkey?: string;
|
|
relayUrl?: string;
|
|
},
|
|
) {
|
|
const channels = options.channels ?? FULL_SNAPSHOT;
|
|
const ownerPubkey = options.ownerPubkey ?? OWNER_PUBKEY;
|
|
await page.addInitScript(
|
|
({ channels, hash, integrity, key, ownerPubkey }) => {
|
|
window.localStorage.setItem(
|
|
key,
|
|
JSON.stringify({
|
|
version: 2,
|
|
updatedAt: Date.now(),
|
|
ownerPubkey,
|
|
hash,
|
|
channels,
|
|
integrity,
|
|
}),
|
|
);
|
|
},
|
|
{
|
|
channels,
|
|
hash: options.hash,
|
|
integrity: snapshotIntegrity(ownerPubkey, options.hash, channels),
|
|
key: snapshotKey(
|
|
options.relayUrl ?? RELAY_URL,
|
|
options.keyOwnerPubkey ?? ownerPubkey,
|
|
),
|
|
ownerPubkey,
|
|
},
|
|
);
|
|
}
|
|
|
|
async function seedCommunities(page: Page, communityPubkey = OWNER_PUBKEY) {
|
|
await page.addInitScript(
|
|
({ communityPubkey, relayA, relayB }) => {
|
|
const communities = [
|
|
{
|
|
id: "community-a",
|
|
name: "Alpha",
|
|
relayUrl: relayA,
|
|
pubkey: communityPubkey,
|
|
addedAt: "2026-01-01T00:00:00.000Z",
|
|
},
|
|
{
|
|
id: "community-b",
|
|
name: "Bravo",
|
|
relayUrl: relayB,
|
|
pubkey: communityPubkey,
|
|
addedAt: "2026-01-02T00:00:00.000Z",
|
|
},
|
|
];
|
|
window.localStorage.setItem(
|
|
"buzz-communities",
|
|
JSON.stringify(communities),
|
|
);
|
|
window.localStorage.setItem(
|
|
"buzz-active-community-id",
|
|
communities[0].id,
|
|
);
|
|
},
|
|
{ communityPubkey, relayA: RELAY_URL, relayB: OTHER_RELAY_URL },
|
|
);
|
|
}
|
|
|
|
async function getChannelsPayloads(page: Page) {
|
|
return page.evaluate(() =>
|
|
(window.__BUZZ_E2E_COMMAND_LOG__ ?? [])
|
|
.filter((entry) => entry.command === "get_channels")
|
|
.map((entry) => entry.payload as { knownHash?: unknown }),
|
|
);
|
|
}
|
|
|
|
async function mutateDisplayedChannels(page: Page, channelName: string) {
|
|
await page.evaluate((name) => {
|
|
const queryClient = window.__BUZZ_E2E_QUERY_CLIENT__ as
|
|
| {
|
|
setQueryData: (
|
|
queryKey: readonly string[],
|
|
updater: (
|
|
channels: ReturnType<typeof makeSnapshotChannel>[] | undefined,
|
|
) => ReturnType<typeof makeSnapshotChannel>[],
|
|
) => unknown;
|
|
}
|
|
| undefined;
|
|
if (!queryClient) {
|
|
throw new Error("E2E query client seam is not installed.");
|
|
}
|
|
queryClient.setQueryData(["channels"], (channels) => {
|
|
const template = channels?.[0];
|
|
if (!template) {
|
|
throw new Error("Displayed channel cache is empty.");
|
|
}
|
|
return [...channels, { ...template, id: "optimistic-channel", name }];
|
|
});
|
|
}, channelName);
|
|
}
|
|
|
|
async function readPersistedSnapshot(page: Page) {
|
|
return page.evaluate((key) => {
|
|
const raw = window.localStorage.getItem(key);
|
|
if (!raw) return null;
|
|
const snapshot = JSON.parse(raw) as {
|
|
channels: Array<{ name: string }>;
|
|
hash: string;
|
|
};
|
|
return {
|
|
channelNames: snapshot.channels.map((channel) => channel.name),
|
|
hash: snapshot.hash,
|
|
};
|
|
}, snapshotKey(RELAY_URL));
|
|
}
|
|
|
|
async function trackSnapshotRows(page: Page) {
|
|
await page.addInitScript(() => {
|
|
const testWindow = window as Window & {
|
|
__BUZZ_E2E_SNAPSHOT_ROWS_SEEN__?: string[];
|
|
};
|
|
const seen: string[] = [];
|
|
testWindow.__BUZZ_E2E_SNAPSHOT_ROWS_SEEN__ = seen;
|
|
const record = (node: Node) => {
|
|
if (!(node instanceof Element)) return;
|
|
const rows = node.matches('[data-channel-id^="snapshot-"]')
|
|
? [node]
|
|
: Array.from(node.querySelectorAll('[data-channel-id^="snapshot-"]'));
|
|
for (const row of rows) {
|
|
const id = row.getAttribute("data-channel-id");
|
|
if (id && !seen.includes(id)) seen.push(id);
|
|
}
|
|
};
|
|
new MutationObserver((records) => {
|
|
for (const mutation of records) {
|
|
for (const node of mutation.addedNodes) record(node);
|
|
}
|
|
}).observe(document, { childList: true, subtree: true });
|
|
});
|
|
}
|
|
|
|
async function getTrackedSnapshotRows(page: Page) {
|
|
return page.evaluate(
|
|
() =>
|
|
(
|
|
window as Window & {
|
|
__BUZZ_E2E_SNAPSHOT_ROWS_SEEN__?: string[];
|
|
}
|
|
).__BUZZ_E2E_SNAPSHOT_ROWS_SEEN__ ?? [],
|
|
);
|
|
}
|
|
|
|
test("cold boot paints the complete snapshot, sends its hash, and revalidates", async ({
|
|
page,
|
|
}) => {
|
|
await seedSnapshot(page, { hash: MATCHING_HASH });
|
|
await installMockBridge(page, {
|
|
channelsReadDelayMs: SNAPSHOT_FRAME_DELAY_MS,
|
|
honorChannelsKnownHash: true,
|
|
});
|
|
|
|
const navigationStartedAt = performance.now();
|
|
await page.goto("/");
|
|
const rows = page.locator('[data-channel-id^="snapshot-"]');
|
|
await expect(rows).toHaveCount(FULL_SNAPSHOT.length, { timeout: 2_000 });
|
|
const snapshotPaintedAt = performance.now();
|
|
expect(snapshotPaintedAt - navigationStartedAt).toBeLessThan(
|
|
SNAPSHOT_FRAME_DELAY_MS,
|
|
);
|
|
await expect(page.getByTestId("sidebar-loading")).toHaveCount(0);
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: MATCHING_HASH }]);
|
|
await expect
|
|
.poll(() => getSnapshotDiagnostic(page))
|
|
.toMatchObject({
|
|
channelCount: FULL_SNAPSHOT.length,
|
|
presence: "present",
|
|
});
|
|
const diagnostics = await getSnapshotDiagnostic(page);
|
|
expect(diagnostics?.serializedBytes).toBeGreaterThan(0);
|
|
expect(diagnostics?.ageMs).toBeGreaterThanOrEqual(0);
|
|
|
|
// The persisted data is deliberately stale: it paints immediately but still
|
|
// validates. The delayed matching response leaves a deterministic snapshot
|
|
// frame, then not-modified must not shrink the list.
|
|
await expect(rows).toHaveCount(FULL_SNAPSHOT.length);
|
|
await expect
|
|
.poll(() => getFullSidebarMeasure(page))
|
|
.toEqual({
|
|
markCount: expect.any(Number),
|
|
measure: expect.any(Number),
|
|
});
|
|
expect((await getFullSidebarMeasure(page)).markCount).toBeGreaterThan(0);
|
|
|
|
const liveSettledAt = performance.now();
|
|
console.info(
|
|
`[sidebar-snapshot] firstPaint=${Math.round(snapshotPaintedAt - navigationStartedAt)}ms snapshotToLive=${Math.round(liveSettledAt - snapshotPaintedAt)}ms rows=${FULL_SNAPSHOT.length}`,
|
|
);
|
|
});
|
|
|
|
test("matching not-modified preserves display mutations without persisting them", async ({
|
|
page,
|
|
}) => {
|
|
const optimisticName = "optimistic-local-channel";
|
|
await seedSnapshot(page, { hash: MATCHING_HASH });
|
|
await installMockBridge(page, { honorChannelsKnownHash: true });
|
|
await page.goto("/");
|
|
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(
|
|
FULL_SNAPSHOT.length,
|
|
);
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate(() =>
|
|
window.__BUZZ_E2E_QUERY_CLIENT__?.getQueryState(["channels"]),
|
|
),
|
|
)
|
|
.toMatchObject({ fetchStatus: "idle", status: "success" });
|
|
|
|
// Exercise the mutation during a real revalidation, not a race between boot
|
|
// rendering and a fixed response delay. The cold-boot test covers first paint.
|
|
await page.evaluate(() => {
|
|
window.__BUZZ_E2E_DEFER_NEXT_CHANNELS_READ__?.();
|
|
void window.__BUZZ_E2E_QUERY_CLIENT__?.invalidateQueries({
|
|
queryKey: ["channels"],
|
|
exact: true,
|
|
});
|
|
});
|
|
await expect
|
|
.poll(() => page.evaluate(() => window.__BUZZ_E2E_CHANNELS_READ_PENDING__))
|
|
.toBe(1);
|
|
await mutateDisplayedChannels(page, optimisticName);
|
|
await expect(
|
|
page.locator('[data-channel-id="optimistic-channel"]'),
|
|
).toBeVisible();
|
|
|
|
expect(
|
|
await page.evaluate(() => window.__BUZZ_E2E_RELEASE_CHANNELS_READ__?.()),
|
|
).toBe(1);
|
|
// Invocation logging only proves the request started. Wait for the query to
|
|
// consume its response before checking either display state or persistence.
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate(() =>
|
|
window.__BUZZ_E2E_QUERY_CLIENT__?.getQueryState(["channels"]),
|
|
),
|
|
)
|
|
.toMatchObject({ fetchStatus: "idle", status: "success" });
|
|
expect(await getChannelsPayloads(page)).toEqual([
|
|
{ knownHash: MATCHING_HASH },
|
|
{ knownHash: MATCHING_HASH },
|
|
]);
|
|
await expect
|
|
.poll(() => readPersistedSnapshot(page))
|
|
.toEqual({
|
|
channelNames: FULL_SNAPSHOT.map((channel) => channel.name),
|
|
hash: MATCHING_HASH,
|
|
});
|
|
await expect(
|
|
page.locator('[data-channel-id="optimistic-channel"]'),
|
|
).toBeVisible();
|
|
expect((await readPersistedSnapshot(page))?.channelNames).not.toContain(
|
|
optimisticName,
|
|
);
|
|
});
|
|
|
|
test("first-ever boot without a snapshot sends null and shows loading", async ({
|
|
page,
|
|
}) => {
|
|
await installMockBridge(page, { deferFirstChannelsRead: true });
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("sidebar-loading")).toBeVisible();
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(0);
|
|
await releaseFirstChannelsRead(page);
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: null }]);
|
|
await expect
|
|
.poll(() => getSnapshotDiagnostic(page))
|
|
.toMatchObject({
|
|
channelCount: 0,
|
|
presence: "absent",
|
|
serializedBytes: 0,
|
|
});
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect
|
|
.poll(() => getFullSidebarMeasure(page))
|
|
.toEqual({
|
|
markCount: expect.any(Number),
|
|
measure: expect.any(Number),
|
|
});
|
|
expect((await getFullSidebarMeasure(page)).markCount).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("a different identity's snapshot is ignored", async ({ page }) => {
|
|
await seedSnapshot(page, {
|
|
hash: "foreign-hash",
|
|
keyOwnerPubkey: OWNER_PUBKEY,
|
|
ownerPubkey: STALE_COMMUNITY_PUBKEY,
|
|
});
|
|
await installMockBridge(page, { deferFirstChannelsRead: true });
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("sidebar-loading")).toBeVisible();
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(0);
|
|
await releaseFirstChannelsRead(page);
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: null }]);
|
|
await expect
|
|
.poll(() => getSnapshotDiagnostic(page))
|
|
.toMatchObject({
|
|
channelCount: 0,
|
|
presence: "invalid",
|
|
});
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
});
|
|
|
|
test("display-only community pubkey cannot expose another identity's snapshot", async ({
|
|
page,
|
|
}) => {
|
|
await seedSnapshot(page, {
|
|
hash: "stale-community-identity-hash",
|
|
ownerPubkey: STALE_COMMUNITY_PUBKEY,
|
|
});
|
|
await trackSnapshotRows(page);
|
|
await installMockBridge(
|
|
page,
|
|
{ channelsReadDelayMs: READ_DELAY_MS },
|
|
{ skipCommunitySeed: true },
|
|
);
|
|
await seedCommunities(page, STALE_COMMUNITY_PUBKEY);
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
expect(await getTrackedSnapshotRows(page)).toEqual([]);
|
|
const payloads = await getChannelsPayloads(page);
|
|
expect(payloads).toEqual([{ knownHash: null }]);
|
|
expect(payloads).not.toContainEqual({
|
|
knownHash: "stale-community-identity-hash",
|
|
});
|
|
});
|
|
|
|
test("partial hash/list write fails toward a full fetch", async ({ page }) => {
|
|
await seedSnapshot(page, { hash: MATCHING_HASH });
|
|
await page.addInitScript((key) => {
|
|
const raw = window.localStorage.getItem(key);
|
|
if (!raw) return;
|
|
const snapshot = JSON.parse(raw) as { hash: string };
|
|
window.localStorage.setItem(
|
|
key,
|
|
JSON.stringify({ ...snapshot, hash: "newer-partial-hash" }),
|
|
);
|
|
}, snapshotKey(RELAY_URL));
|
|
await installMockBridge(page, {
|
|
deferFirstChannelsRead: true,
|
|
honorChannelsKnownHash: true,
|
|
});
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("sidebar-loading")).toBeVisible();
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(0);
|
|
await releaseFirstChannelsRead(page);
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: null }]);
|
|
await expect
|
|
.poll(() => getSnapshotDiagnostic(page))
|
|
.toMatchObject({
|
|
channelCount: 0,
|
|
presence: "invalid",
|
|
});
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(0);
|
|
});
|
|
|
|
test("unexpected not-modified response retries without a hash", async ({
|
|
page,
|
|
}) => {
|
|
await installMockBridge(page, {
|
|
channelsNotModifiedResponses: 1,
|
|
});
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: null }, { knownHash: null }]);
|
|
});
|
|
|
|
test("mismatched not-modified hash falls back to a full list", async ({
|
|
page,
|
|
}) => {
|
|
await seedSnapshot(page, { hash: "persisted-stale-hash" });
|
|
await trackSnapshotRows(page);
|
|
await installMockBridge(page, {
|
|
channelsReadDelayMs: READ_DELAY_MS,
|
|
channelsNotModifiedResponses: 1,
|
|
});
|
|
await page.goto("/");
|
|
|
|
const snapshotRows = page.locator('[data-channel-id^="snapshot-"]');
|
|
// Record the transient boot frame independently of test-runner scheduling;
|
|
// cold-boot coverage separately enforces the snapshot paint deadline.
|
|
await expect
|
|
.poll(() => getTrackedSnapshotRows(page))
|
|
.toEqual(FULL_SNAPSHOT.map((channel) => channel.id));
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: "persisted-stale-hash" }, { knownHash: null }]);
|
|
|
|
// The stale snapshot may provide the immediate boot frame, but an impossible
|
|
// not-modified hash/list pairing must never survive as the settled result.
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect(snapshotRows).toHaveCount(0);
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate((key) => {
|
|
const raw = window.localStorage.getItem(key);
|
|
if (!raw) return null;
|
|
const snapshot = JSON.parse(raw) as {
|
|
channels: Array<{ name: string }>;
|
|
hash: string;
|
|
};
|
|
return {
|
|
hash: snapshot.hash,
|
|
hasGeneral: snapshot.channels.some(
|
|
(channel) => channel.name === "general",
|
|
),
|
|
hasSnapshotRow: snapshot.channels.some((channel) =>
|
|
channel.name.startsWith("snapshot-"),
|
|
),
|
|
};
|
|
}, snapshotKey(RELAY_URL)),
|
|
)
|
|
.toEqual({ hash: MATCHING_HASH, hasGeneral: true, hasSnapshotRow: false });
|
|
});
|
|
|
|
test("hash mismatch replaces the snapshot with the full live list", async ({
|
|
page,
|
|
}) => {
|
|
await seedSnapshot(page, { hash: "stale-hash" });
|
|
await trackSnapshotRows(page);
|
|
await installMockBridge(page, {
|
|
channelsReadDelayMs: READ_DELAY_MS,
|
|
honorChannelsKnownHash: true,
|
|
});
|
|
await page.goto("/");
|
|
|
|
// Observe the boot frame even if live revalidation finishes before the
|
|
// test runner gets its next turn; cold-boot coverage separately times paint.
|
|
await expect
|
|
.poll(() => getTrackedSnapshotRows(page))
|
|
.toEqual(FULL_SNAPSHOT.map((channel) => channel.id));
|
|
await expect
|
|
.poll(() => getChannelsPayloads(page))
|
|
.toEqual([{ knownHash: "stale-hash" }]);
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect(page.locator('[data-channel-id^="snapshot-"]')).toHaveCount(0);
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate((key) => {
|
|
const raw = window.localStorage.getItem(key);
|
|
if (!raw) return null;
|
|
const snapshot = JSON.parse(raw) as {
|
|
channels: Array<{ name: string }>;
|
|
hash: string;
|
|
};
|
|
return {
|
|
hash: snapshot.hash,
|
|
hasGeneral: snapshot.channels.some(
|
|
(channel) => channel.name === "general",
|
|
),
|
|
hasSnapshotRow: snapshot.channels.some((channel) =>
|
|
channel.name.startsWith("snapshot-"),
|
|
),
|
|
};
|
|
}, snapshotKey(RELAY_URL)),
|
|
)
|
|
.toEqual({ hash: MATCHING_HASH, hasGeneral: true, hasSnapshotRow: false });
|
|
});
|
|
|
|
test("community switch validates a stale relay snapshot and replaces it", async ({
|
|
page,
|
|
}) => {
|
|
const switchedSnapshot = Array.from({ length: 6 }, (_, index) =>
|
|
makeSnapshotChannel(index, "switched"),
|
|
);
|
|
await seedSnapshot(page, {
|
|
channels: switchedSnapshot,
|
|
hash: "stale-community-hash",
|
|
relayUrl: OTHER_RELAY_URL,
|
|
});
|
|
await installMockBridge(
|
|
page,
|
|
{
|
|
channelsReadDelayMs: READ_DELAY_MS,
|
|
honorChannelsKnownHash: true,
|
|
},
|
|
{ skipCommunitySeed: true },
|
|
);
|
|
await seedCommunities(page);
|
|
await page.goto("/");
|
|
await expect(page.getByTestId("app-sidebar")).toBeVisible();
|
|
|
|
const payloadCountBeforeSwitch = (await getChannelsPayloads(page)).length;
|
|
await page.getByTestId("community-rail-button-community-b").click();
|
|
const switchedRows = page.locator('[data-channel-id^="switched-"]');
|
|
await expect(switchedRows).toHaveCount(switchedSnapshot.length, {
|
|
timeout: 500,
|
|
});
|
|
await expect
|
|
.poll(async () =>
|
|
(await getChannelsPayloads(page)).slice(payloadCountBeforeSwitch).at(0),
|
|
)
|
|
.toEqual({ knownHash: "stale-community-hash" });
|
|
|
|
await expect(page.getByTestId("channel-general")).toBeVisible();
|
|
await expect(switchedRows).toHaveCount(0);
|
|
await expect
|
|
.poll(() =>
|
|
page.evaluate((key) => {
|
|
const raw = window.localStorage.getItem(key);
|
|
if (!raw) return null;
|
|
const snapshot = JSON.parse(raw) as {
|
|
channels: Array<{ name: string }>;
|
|
hash: string;
|
|
};
|
|
return {
|
|
hash: snapshot.hash,
|
|
hasGeneral: snapshot.channels.some(
|
|
(channel) => channel.name === "general",
|
|
),
|
|
};
|
|
}, snapshotKey(OTHER_RELAY_URL)),
|
|
)
|
|
.toEqual({ hash: MATCHING_HASH, hasGeneral: true });
|
|
});
|