Skip to content

Commit d051350

Browse files
author
Leo
committed
Make the thread-head E2E proof deterministic (P1 on #6887)
Address Wes/Carl's P1: the spec delayed get_thread_replies by 4s but both assertions used Playwright's 5s auto-retry window. On the buggy code the panel first shows the stale body, then the delayed relay response (which carries the root edit) lands inside the retry window and heals it, so the positive assertion can false-green. Navigation time eats into the 4s, making the false-green path more likely under load. The delay is a timer that self-heals; it does not prove the head opens with the channel-window overlay rather than healing later. Replace the timer with a manual gate. New `deferThreadReplies` mock option holds every get_thread_replies response open until the test calls `__BUZZ_E2E_RELEASE_THREAD_REPLIES__()` — mirroring the existing deferLinkPreviewMetadata / RELEASE_GET_EVENT queue pattern. The thread-aux backfill provably cannot land before the assertion, so: - head-edited assertion runs while the fetch is verifiably held (`__BUZZ_E2E_THREAD_REPLIES_PENDING__` poll guards against the fetch never having been dispatched); - release the gate and re-assert the head stays edited (dedup path). Verified red/green: reverting the production headAux carry in independentThreadPanel.ts makes the spec fail deterministically at the head assertion (received the stale "these two PRs?"); with the fix it passes. tsc clean; 8/8 independentThreadPanel unit cases pass. Signed-off-by: Leo <5faf251baee50ee6bcde338aef6acdd70bb3e60115664c2cd490d94a55dfc488@buzz.block.builderlab.xyz>
1 parent 28a00e9 commit d051350

3 files changed

Lines changed: 73 additions & 8 deletions

File tree

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ type E2eConfig = {
370370
/** Delay (ms) after snapshotting a thread-replies page so E2E tests can
371371
* deliver live reply/aux events while an older response is in flight. */
372372
threadRepliesDelayMs?: number;
373+
/** Hold every `get_thread_replies` response until
374+
* `__BUZZ_E2E_RELEASE_THREAD_REPLIES__()` is called. Unlike
375+
* `threadRepliesDelayMs` (a timer that self-heals inside Playwright's
376+
* auto-retry window), this is a manual gate: the thread-aux backfill
377+
* provably never lands until the test releases it, so a spec can assert
378+
* the panel's head state before any backfill can heal it. */
379+
deferThreadReplies?: boolean;
373380
usersBatchDelayMs?: number;
374381
/** Delay (ms) applied to continuation channel-window requests so e2e
375382
* tests can observe the in-flight prepend window. 0/undefined = instant. */
@@ -1440,6 +1447,12 @@ declare global {
14401447
__BUZZ_E2E_RELEASE_LINK_PREVIEW_METADATA__?: () => number;
14411448
/** Release link-preview uploads held before mock-native registration. */
14421449
__BUZZ_E2E_RELEASE_LINK_PREVIEW_UPLOADS__?: () => number;
1450+
/** Flush every `get_thread_replies` call held by `deferThreadReplies`.
1451+
* Returns the number of held requests released. */
1452+
__BUZZ_E2E_RELEASE_THREAD_REPLIES__?: () => number;
1453+
/** Number of `get_thread_replies` calls currently held by
1454+
* `deferThreadReplies`. */
1455+
__BUZZ_E2E_THREAD_REPLIES_PENDING__?: () => number;
14431456
/** Uploads that passed mock-native registration and began relay work. */
14441457
__BUZZ_E2E_LINK_PREVIEW_UPLOAD_STARTS__?: number;
14451458
}
@@ -1548,6 +1561,7 @@ type DeferredGetEvent = {
15481561
let deferredGetEventQueue: DeferredGetEvent[] = [];
15491562
let deferredLinkPreviewMetadataQueue: Array<() => void> = [];
15501563
let deferredLinkPreviewUploadQueue: Array<() => void> = [];
1564+
let deferredThreadRepliesQueue: Array<() => void> = [];
15511565
let cancelledMediaUploadIds = new Set<string>();
15521566
let deferNextChannelsRead = false;
15531567
let deferredChannelsReadResolve: (() => void) | null = null;
@@ -5161,6 +5175,11 @@ async function handleGetThreadReplies(
51615175
if (delayMs > 0) {
51625176
await new Promise((resolve) => window.setTimeout(resolve, delayMs));
51635177
}
5178+
if (config?.mock?.deferThreadReplies) {
5179+
await new Promise<void>((resolve) => {
5180+
deferredThreadRepliesQueue.push(resolve);
5181+
});
5182+
}
51645183

51655184
return { events: page, next_cursor: nextCursor };
51665185
}
@@ -10709,6 +10728,7 @@ export function maybeInstallE2eTauriMocks() {
1070910728
deferredSendMessageLiveEchoes.length = 0;
1071010729
deferredLinkPreviewMetadataQueue = [];
1071110730
deferredLinkPreviewUploadQueue = [];
10731+
deferredThreadRepliesQueue = [];
1071210732
cancelledMediaUploadIds = new Set<string>();
1071310733
window.__BUZZ_E2E_LINK_PREVIEW_UPLOAD_STARTS__ = 0;
1071410734
window.__BUZZ_E2E_RELEASE_LINK_PREVIEW_METADATA__ = () => {
@@ -10721,6 +10741,13 @@ export function maybeInstallE2eTauriMocks() {
1072110741
for (const release of queued) release();
1072210742
return queued.length;
1072310743
};
10744+
window.__BUZZ_E2E_RELEASE_THREAD_REPLIES__ = () => {
10745+
const queued = deferredThreadRepliesQueue.splice(0);
10746+
for (const release of queued) release();
10747+
return queued.length;
10748+
};
10749+
window.__BUZZ_E2E_THREAD_REPLIES_PENDING__ = () =>
10750+
deferredThreadRepliesQueue.length;
1072410751
mockGlobalAgentConfig = config.mock?.globalAgentConfig
1072510752
? { ...config.mock.globalAgentConfig }
1072610753
: null;

‎desktop/tests/e2e/thread-head-stale-edit.spec.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { waitForAnimations } from "../helpers/animations";
99
// edit) but its overlay was previously dropped, relying solely on the async
1010
// thread-reply aux backfill — so before that fetch lands the head renders stale.
1111
//
12-
// We reproduce the divergence deterministically by delaying the thread-replies
13-
// fetch (`threadRepliesDelayMs`): the channel window already holds the edit, but
14-
// the thread-aux response is still in flight when the panel first renders.
12+
// We reproduce the divergence deterministically by *gating* the thread-replies
13+
// fetch (`deferThreadReplies`): the channel window already holds the edit, but
14+
// the thread-aux response is held open — it provably cannot land until the test
15+
// releases it. This is stronger than a timed delay: a 4s timer self-heals
16+
// inside Playwright's auto-retry window, so on the buggy code the delayed aux
17+
// backfill could arrive mid-assertion and false-green. A held gate cannot.
1518

1619
const CHANNEL = "general";
1720
const SHOT = "test-results/thread-head-stale-edit";
@@ -52,9 +55,9 @@ async function waitForMockLiveSubscription(
5255
test("thread head reflects the channel-window edit even before thread aux loads", async ({
5356
page,
5457
}) => {
55-
// Long delay so the thread-replies (and its aux edit backfill) response is
56-
// still in flight when the thread panel first renders the head.
57-
await installMockBridge(page, { threadRepliesDelayMs: 4000 });
58+
// Hold the thread-replies (and its aux edit backfill) response open so it
59+
// provably cannot land until we release it after asserting the head.
60+
await installMockBridge(page, { deferThreadReplies: true });
5861
await page.goto("/");
5962
await page.getByTestId(`channel-${CHANNEL}`).click();
6063
await expect(page.getByTestId("chat-title")).toHaveText(CHANNEL);
@@ -124,14 +127,44 @@ test("thread head reflects the channel-window edit even before thread aux loads"
124127
await expect(threadPanel).toBeVisible();
125128

126129
// 4. The thread head must show the EDITED body immediately — while the
127-
// thread-aux backfill is still delayed in flight. Pre-fix this rendered
128-
// the stale original ("these two PRs?").
130+
// thread-aux backfill is still gated (provably not yet delivered). Pre-fix
131+
// this rendered the stale original ("these two PRs?"), and because the gate
132+
// is held (not merely delayed) no backfill can arrive to heal it.
129133
const headBody = threadPanel
130134
.locator(`[data-testid="message-row"][data-message-id="${rootId}"]`)
131135
.getByTestId("message-body");
132136
await expect(headBody).toContainText("these PRs?");
133137
await expect(headBody).not.toContainText("these two PRs?");
134138

139+
// The thread-aux fetch must actually be held: this proves the edited head
140+
// above came purely from the channel-window overlay, not from a backfill that
141+
// slipped in. (Guards against the fetch never having been dispatched.)
142+
await expect
143+
.poll(() =>
144+
page.evaluate(
145+
() =>
146+
(
147+
window as Window & {
148+
__BUZZ_E2E_THREAD_REPLIES_PENDING__?: () => number;
149+
}
150+
).__BUZZ_E2E_THREAD_REPLIES_PENDING__?.() ?? 0,
151+
),
152+
)
153+
.toBeGreaterThan(0);
154+
135155
await waitForAnimations(page);
136156
await page.screenshot({ path: `${SHOT}/thread-head-edited.png` });
157+
158+
// 5. Release the gate; the held thread-aux backfill now lands and the head
159+
// stays edited (dedup against relay-provided aux, no regression).
160+
await page.evaluate(
161+
() =>
162+
(
163+
window as Window & {
164+
__BUZZ_E2E_RELEASE_THREAD_REPLIES__?: () => number;
165+
}
166+
).__BUZZ_E2E_RELEASE_THREAD_REPLIES__?.(),
167+
);
168+
await expect(headBody).toContainText("these PRs?");
169+
await expect(headBody).not.toContainText("these two PRs?");
137170
});

‎desktop/tests/helpers/bridge.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ type MockBridgeOptions = {
301301
/** Delay (ms) after snapshotting a thread-replies page so E2E tests can
302302
* deliver live reply/aux events while an older response is in flight. */
303303
threadRepliesDelayMs?: number;
304+
/** Hold every `get_thread_replies` response until
305+
* `__BUZZ_E2E_RELEASE_THREAD_REPLIES__()` is called — a manual gate the test
306+
* releases explicitly, so the thread-aux backfill provably cannot land (and
307+
* heal a stale head) before assertions run. See e2eBridge mock config. */
308+
deferThreadReplies?: boolean;
304309
usersBatchDelayMs?: number;
305310
/** Delay (ms) for older-history fetches; see e2eBridge mock config. */
306311
channelWindowDelayMs?: number;

0 commit comments

Comments
 (0)