Skip to content

Commit 927f431

Browse files
author
Meli
committed
test(app): adapt merged journeys to v1 read and thread contracts
Use real read menus and canonical channel identities. Preserve explicit permission failure coverage with exact request/error accounting. Exercise focused embedded thread reading leases instead of removed channel visits. Separate bounded newest-window opening from user-demanded thread scrollback and label changed profile metrics. Remove retired branch unread-count rendering, stale subscription mocks and obsolete unread bounds documentation. Local checkpoint, not acceptance: bounded file receipts are in workspace research. Latest full Vitest summary: 5674 pass, one baseline HEIC failure, one opt-in skip. Typing and held-pagination browser failures, six correctness findings, full browser validation, paired measurement and live acceptance remain open. No push intended. Co-authored-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz> Signed-off-by: Meli <5aaa86bce934fc3445fc254aab560a40923f10252f92107e665073dede0e04d3@buzz.block.builderlab.xyz>
1 parent de08d5b commit 927f431

25 files changed

Lines changed: 409 additions & 242 deletions

‎docs/browser-testing.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ The separate `channel-opening.test.ts` exercises catch-up ownership and terminal
262262
retry states through the production session. A held-response reproducer establishes
263263
a failure mechanism; it does not on its own identify a live incident's cause.
264264

265+
The same file's 300-author thread journey measures `firstVisibleMs` and
266+
`newestWindowPaintMs` separately for cold and reopened views. Both open with ten
267+
newest replies and one strict-window request; reopening is sampled before older
268+
history is loaded into the shared verified cache. Afterwards, six user scrollback
269+
gestures demand the remaining history in 50-row requests and prove all 300 replies
270+
are retained. `demandedFullHistoryMs` includes automation round trips between those
271+
gestures; it is not a pure render benchmark or comparable to the former eager
272+
`fullTraversalPaintMs`. The dataset, both engines and opening watchdog remain;
273+
these thread timings are observations, not a new latency budget.
274+
265275
## DM label recovery
266276

267277
`dm-labels.spec.mjs` builds the actual page and uses the production broker with

‎docs/unread.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ list stays marked incomplete. Merely revealing the popover does not acknowledge
9898
reply.
9999
A local manual-unread mark strengthens the label without fabricating priority; the
100100
underlying relay count remains available.
101-
Channel Settings → Diagnostics exposes explicit actions and Unread status/retry. Unknown and
101+
The sidebar row menu offers **Mark as Unread** on read channels and **Mark as Read**
102+
on unread channels. The message menu offers **Mark unread** and **Mark read through here**
103+
for individual message contexts. Diagnostics has no read-state controls. Unknown and
102104
zero both omit unread styling; the API preserves the distinction. There is no
103105
notification or feed service here.
104106

@@ -176,14 +178,13 @@ development broker.
176178

177179
## Bounds and failure semantics
178180

179-
Mounted thread panels group descendant evidence by canonical context. Each partial
180-
lease admits at most 500 new message selectors within the session's 1,000-selector
181-
budget. Unselected messages stay unknown, so nested branch labels say “At least”
182-
or “Unread status unknown” rather than claiming completeness. The 500 limit is
183-
per grant, not a class-wide reservation: multiple large panels can consume the
184-
whole budget. Notification leases require their full selection; exhaustion reaches
185-
the notification service's reported-error path, rather than silently expiring an
186-
unknown candidate. This is not a guarantee of native OS banner delivery.
181+
Collapsed reply branches show total replies, not aggregated unread counts.
182+
Message subscriptions retain their resolved context selectors until disposal.
183+
The session admits at most 1,000 context leases and 1,000 distinct message selectors
184+
across their contexts; a request exceeding either bound throws rather than
185+
partially admitting selectors. Disposing a lease releases its demand. Context
186+
reads batch at most 20 targets and 100 message IDs per request; these wire bounds
187+
are separate from the retained-demand limits.
187188

188189
The journal coalesces dominated pending prefixes before sending. If a newer anchor
189190
covers an older pending prefix but the relay subsequently blocks the newer anchor

‎src/features/conversation/EmbeddedThread.test.tsx‎

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ vi.mock("../relay/react", () => {
2828
});
2929
vi.mock("../messages/MessageRow", () => ({
3030
MessageRow: ({ row, onOpenLink, onOpenMediaReview }: MessageRowProps) => (
31-
<article>
31+
<article data-message-id={row.id}>
3232
<button type="button" onClick={() => onOpenLink?.("fixture:one")}>
3333
Open linked panel
3434
</button>
@@ -67,6 +67,7 @@ vi.mock("../../shared/design-system/ui/Dialog", () => ({
6767
}));
6868
afterEach(() => {
6969
cleanup();
70+
vi.restoreAllMocks();
7071
vi.unstubAllGlobals();
7172
});
7273

@@ -128,8 +129,11 @@ function fixture(
128129
snapshot: () => undefined,
129130
subscribe: () => () => {},
130131
attention: () => ({ unread: false }),
131-
enterChannel: vi.fn(async () => {}),
132-
leaveChannel: vi.fn(),
132+
reading: vi.fn((_channelId: string) => ({
133+
view: vi.fn(),
134+
observe: vi.fn(async () => {}),
135+
dispose: vi.fn(),
136+
})),
133137
};
134138
const outbox = {
135139
subscribe: () => () => {},
@@ -239,17 +243,53 @@ it.each([
239243
},
240244
);
241245

242-
it("keeps one channel visit while the thread is retargeted within a channel", () => {
246+
it("owns focused reading per thread and retires it on thread/channel retarget and unmount", () => {
243247
const h = fixture();
248+
vi.spyOn(document, "hasFocus").mockReturnValue(true);
249+
vi.spyOn(document, "visibilityState", "get").mockReturnValue("visible");
250+
vi.spyOn(HTMLElement.prototype, "getClientRects").mockReturnValue([
251+
new DOMRect(0, 0, 500, 500),
252+
] as unknown as DOMRectList);
253+
vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockReturnValue(
254+
new DOMRect(0, 0, 500, 500),
255+
);
244256
const view = render(<EmbeddedThread {...h.props} />);
245-
expect(h.unread.enterChannel).toHaveBeenCalledExactlyOnceWith("c");
257+
const focusReading = () =>
258+
act(() => {
259+
screen.getByRole("region", { name: "Thread messages" }).focus();
260+
});
261+
expect(h.unread.reading).not.toHaveBeenCalled(); // Mount is not reading.
262+
focusReading();
263+
expect(h.unread.reading).toHaveBeenCalledExactlyOnceWith("c");
264+
const first = h.unread.reading.mock.results[0]?.value;
265+
if (!first) throw new Error("Missing first reading lease");
266+
expect(first.view).toHaveBeenCalledWith(
267+
[h.props.messageId],
268+
expect.any(Function),
269+
);
270+
expect(first.view.mock.calls[0][1]()).toBe(true);
271+
246272
view.rerender(<EmbeddedThread {...h.props} messageId={"c".repeat(64)} />);
247-
expect(h.unread.enterChannel).toHaveBeenCalledOnce();
248-
expect(h.unread.leaveChannel).not.toHaveBeenCalled();
249-
// Leaving the channel is the barrier: the visit does follow the channel.
273+
expect(first.dispose).toHaveBeenCalledOnce();
274+
expect(first.view.mock.calls[0][1]()).toBe(false);
275+
expect(h.unread.reading).toHaveBeenCalledOnce();
276+
focusReading();
277+
expect(h.unread.reading).toHaveBeenCalledTimes(2);
278+
expect(h.unread.reading).toHaveBeenLastCalledWith("c");
279+
const second = h.unread.reading.mock.results[1]?.value;
280+
if (!second) throw new Error("Missing second reading lease");
281+
250282
view.rerender(<EmbeddedThread {...h.props} channelId="d" />);
251-
expect(h.unread.leaveChannel).toHaveBeenCalledExactlyOnceWith("c");
252-
expect(h.unread.enterChannel).toHaveBeenLastCalledWith("d");
283+
expect(second.dispose).toHaveBeenCalledOnce();
284+
expect(second.view.mock.calls[0][1]()).toBe(false);
285+
focusReading();
286+
expect(h.unread.reading).toHaveBeenCalledTimes(3);
287+
expect(h.unread.reading).toHaveBeenLastCalledWith("d");
288+
const third = h.unread.reading.mock.results[2]?.value;
289+
if (!third) throw new Error("Missing third reading lease");
290+
view.unmount();
291+
expect(third.dispose).toHaveBeenCalledOnce();
292+
expect(third.view.mock.calls[0][1]()).toBe(false);
253293
});
254294

255295
it("offers recovery for a failed edit left in the outbox", () => {

‎src/features/conversation/EmbeddedThread.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type Overlay =
3939
};
4040

4141
/**
42-
* As in Channels, the channel visit and message recovery span threads of one
43-
* channel; retargeting remounts only the thread and its overlay.
42+
* As in Channels, message recovery spans threads of one channel; retargeting
43+
* remounts the thread, its reading observation and its overlay.
4444
*/
4545
export function EmbeddedThread(props: Props) {
4646
const { session, scope, channelId, messageId } = props;

‎src/features/messages/ReplySummary.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export function ReplySummary({
1111
resolveName,
1212
media,
1313
unreadLabel,
14-
unreadCount,
1514
}: {
1615
count: number;
1716
participants: readonly string[];
@@ -20,7 +19,6 @@ export function ReplySummary({
2019
resolveName(id: string, fallback: string): string;
2120
media(url: string, size?: "small"): string | undefined;
2221
unreadLabel?: string | undefined;
23-
unreadCount?: number;
2422
}) {
2523
return (
2624
<>
@@ -61,9 +59,7 @@ export function ReplySummary({
6159
<span>
6260
{count} {count === 1 ? "reply" : "replies"}
6361
</span>
64-
{unreadCount ? (
65-
<span>({unreadCount} new)</span>
66-
) : unreadLabel ? (
62+
{unreadLabel ? (
6763
<span
6864
className={styles.threadUnread}
6965
aria-hidden="true"

‎src/features/messages/ThreadPanel.nesting.test.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ function setup(messageId = "root", unread?: RelaySession["unread"]) {
106106
messages: { retry: () => {} },
107107
media: () => undefined,
108108
unread: unread ?? {
109-
subscribeMessages: () => () => {},
110109
snapshot: () => undefined,
111110
attention: () => ({ unread: false }),
112111
},
@@ -345,20 +344,16 @@ for (const startsWithChild of [false, true])
345344
).toBeVisible();
346345
});
347346

348-
it("keeps branch totals without deriving unread counts or retaining descendant selectors", () => {
349-
const subscribeMessages = vi.fn(() => () => {});
347+
it("keeps branch totals without deriving unread counts", () => {
350348
const attention = vi.fn(() => ({ status: "unread", unread: true }));
351349
const unread = {
352-
subscribeMessages,
353350
attention,
354351
} as unknown as RelaySession["unread"];
355352
const h = setup("root", unread);
356353
expect(screen.getByRole("button", { name: "View 2 replies" })).toBeVisible();
357-
expect(subscribeMessages).not.toHaveBeenCalled();
358354
expect(attention).not.toHaveBeenCalled();
359355
h.update([row("parent", "root"), row("replacement", "parent")]);
360356
expect(screen.getByRole("button", { name: "View 1 reply" })).toBeVisible();
361-
expect(subscribeMessages).not.toHaveBeenCalled();
362357
});
363358

364359
it("starts a nested branch with an author header even when the author matches its parent", () => {

‎src/features/messages/ThreadPanel.test.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ function messagesHarness(
182182
messages: { retry: vi.fn() },
183183
media: () => undefined,
184184
unread: {
185-
subscribeMessages: () => () => {},
186185
sync: () => ({ capability: "unsupported" }),
187186
snapshot: () => undefined,
188187
subscribe: () => () => {},

‎tests/browser/channel-activity-corners.spec.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from "./fixture.mjs";
1+
import { test, expect, ids } from "./fixture.mjs";
22
import { open } from "./timeline.mjs";
33

44
// Browser geometry is the contract: jsdom cannot show a rounded overflow clip.
@@ -27,7 +27,7 @@ for (const multiple of [false, true]) {
2727
name: "Show navigation",
2828
exact: true,
2929
});
30-
const alpha = sidebar.locator('button[data-channel-id="alpha"]');
30+
const alpha = sidebar.locator(`button[data-channel-id="${ids.alpha}"]`);
3131
await expect(
3232
alpha.getByRole("img", { name: /unread threads?/ }),
3333
).toBeVisible();

‎tests/browser/channel-opening.spec.mjs‎

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ test.describe("large thread opening", () => {
237237
threadUnread: true,
238238
presenceThreadAuthors: 300,
239239
});
240-
test("300-author thread opening retains bounded traversal and measures cold/reopened rendering", async ({
240+
test("300-author thread measures bounded opening separately from demanded full history", async ({
241241
page,
242242
app,
243243
}) => {
@@ -251,13 +251,14 @@ test.describe("large thread opening", () => {
251251
exact: true,
252252
});
253253
for (const phase of ["cold", "reopened"]) {
254+
const beforeQueries = app.report.queries.length;
254255
const timing = await trigger.evaluate(async (button) => {
255256
const start = performance.now();
256257
button.click();
257258
let firstPaint;
258259
await new Promise((resolve, reject) => {
259260
const deadline = setTimeout(
260-
() => reject(new Error("thread did not finish traversal")),
261+
() => reject(new Error("thread did not paint its newest window")),
261262
10000,
262263
);
263264
const check = () => {
@@ -280,7 +281,7 @@ test.describe("large thread opening", () => {
280281
firstPaint = performance.now() - start;
281282
if (
282283
!visible ||
283-
rows.length !== 301 ||
284+
rows.length !== 11 ||
284285
panel.textContent.includes("Loading thread…")
285286
)
286287
return requestAnimationFrame(check);
@@ -293,18 +294,63 @@ test.describe("large thread opening", () => {
293294
});
294295
return {
295296
firstVisibleMs: firstPaint,
296-
fullTraversalPaintMs: performance.now() - start,
297+
newestWindowPaintMs: performance.now() - start,
297298
};
298299
});
300+
await expect(history.locator("[data-message-id]")).toHaveCount(11);
301+
await expect(
302+
history.getByText("Distinct author reply 299", { exact: true }),
303+
).toBeInViewport();
304+
const windows = () =>
305+
app.report.queries
306+
.slice(beforeQueries)
307+
.filter(({ filter }) => filter.thread_window);
308+
expect(windows()).toHaveLength(1);
309+
expect(windows()[0].filter.limit).toBe(10);
310+
expect(windows()[0].filter.until).toBeUndefined();
299311
app.report.measurements.push({
300312
scenario: "300-author-thread",
301313
phase,
302314
...timing,
303315
});
304-
await expect(history.locator("[data-message-id]")).toHaveCount(301);
305-
await expect(
306-
history.getByText("Distinct author reply 299", { exact: true }),
307-
).toBeInViewport();
316+
// Sample reopening before expanding shared verified history, so both
317+
// opening phases measure the same bounded tail.
318+
if (phase === "reopened") {
319+
// Separate user-demand traversal from opening: this includes automation
320+
// round trips between gestures, so it is not a pure render benchmark.
321+
const scrollbackStart = await page.evaluate(() => performance.now());
322+
for (const count of [61, 111, 161, 211, 261, 301]) {
323+
await history.evaluate((element) => {
324+
element.scrollTop = 0;
325+
element.dispatchEvent(new Event("scroll"));
326+
});
327+
await history.hover();
328+
await page.mouse.wheel(0, -300);
329+
await expect(history.locator("[data-message-id]")).toHaveCount(count);
330+
}
331+
const fullHistoryPaint = await page.evaluate(
332+
() =>
333+
new Promise((resolve) => {
334+
requestAnimationFrame(() =>
335+
requestAnimationFrame(() => resolve(performance.now())),
336+
);
337+
}),
338+
);
339+
expect(windows()).toHaveLength(7);
340+
for (const { filter } of windows().slice(1)) {
341+
expect(filter.limit).toBe(50);
342+
expect(filter.until).toEqual(expect.any(Number));
343+
expect(filter.before_id).toEqual(expect.any(String));
344+
expect(filter.thread_cursor).toBeUndefined();
345+
}
346+
await expect(
347+
history.getByText("Distinct author reply 0", { exact: true }),
348+
).toBeAttached();
349+
app.report.measurements.push({
350+
scenario: "300-author-thread-scrollback",
351+
demandedFullHistoryMs: fullHistoryPaint - scrollbackStart,
352+
});
353+
}
308354
await page
309355
.getByRole("button", { name: "Close thread", exact: true })
310356
.click();

‎tests/browser/composer-resources.spec.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { finalizeEvent, getPublicKey } from "nostr-tools";
2-
import { test, expect } from "./fixture.mjs";
2+
import { test, expect, ids } from "./fixture.mjs";
33
import { open } from "./timeline.mjs";
44

55
// Browser-only: Chromium moves focus to <body> when the focused button is
@@ -16,7 +16,7 @@ const repo = finalizeEvent(
1616
tags: [
1717
["d", "game"],
1818
["name", "Game repo"],
19-
["buzz-channel", "alpha"],
19+
["buzz-channel", ids.alpha],
2020
],
2121
},
2222
key,
@@ -29,7 +29,7 @@ const project = finalizeEvent(
2929
tags: [
3030
["d", "proj"],
3131
["name", "Proj"],
32-
["buzz-channel", "alpha"],
32+
["buzz-channel", ids.alpha],
3333
["a", `30617:${owner}:game`],
3434
],
3535
},

0 commit comments

Comments
 (0)