Skip to content

Commit 17351a5

Browse files
loganjLarryclaude
committed
test(channels): keep missing and failed DM name retry coverage
Review feedback on #2187. The sidebar label cases now include an empty and a failed initial name read: the roster change retries the name exactly once, and later renders send no more reads. The hook comment and relay-queries.md no longer say that access loss clears profiles. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Logan Johnson <[email protected]>
1 parent 11ee514 commit 17351a5

3 files changed

Lines changed: 48 additions & 15 deletions

File tree

‎docs/relay-queries.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,10 @@ its management snapshot still exposes those operations, while read overlays hide
575575
them until access returns. Confirmed evidence is not pending intent and is dropped
576576
when inaccessible. If revocation races initial outbox hydration, that load's entire
577577
confirmed cache is discarded conservatively; pending signed records are preserved.
578-
Shared signed profile projections and already-opened disk-head caches are also
579-
cleared conservatively because they can include cross-channel evidence. Disk-cache
578+
Already-opened disk-head caches are also cleared conservatively because they can
579+
include cross-channel evidence. Signed profiles (kind 0 and NIP-FI kind 30382) are
580+
kept: they are global relay events, not channel evidence, so a profile read in
581+
flight finishes too. Only a full cache clear empties the profile directory. Disk-cache
580582
failure does not reauthorize in-memory views. This does not erase copies already
581583
made by trusted plugins, cancel/re-sign durable writes, or replace relay-side checks.
582584

‎src/bundled/channels/useChannelLabels.test.tsx‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ it.each([
5252
{ loaded: false },
5353
{ loaded: false, hidden: true },
5454
{ loaded: false, archived: true },
55-
])(
55+
{ loaded: true, outcome: "missing" },
56+
{ loaded: true, outcome: "failed" },
57+
] as const)(
5658
"keeps surviving DM names after authoritative channel deletion (%s)",
57-
async ({ loaded, hidden, archived }) => {
59+
async (options: {
60+
loaded: boolean;
61+
hidden?: boolean;
62+
archived?: boolean;
63+
outcome?: "missing" | "failed";
64+
}) => {
65+
const { loaded, hidden, archived, outcome } = options;
5866
const relay = keypair(),
5967
viewer = keypair(),
6068
alice = keypair();
@@ -120,12 +128,20 @@ it.each([
120128
display_name: "Alice",
121129
picture: "https://example.com/alice.png",
122130
});
131+
const fallback = alice.pubkey.slice(0, 10);
132+
// An empty or failed read leaves the name missing until membership changes.
133+
const answer = (read: ReturnType<typeof wire.next>) => {
134+
if (outcome === "failed") read.fail(new Error("offline"));
135+
else read.respond(outcome === "missing" ? [] : [alicePicture]);
136+
};
123137
if (loaded) {
124138
await act(async () => {
125-
initial.respond([alicePicture]);
139+
answer(initial);
126140
await flush();
127141
});
128-
expect(labels.find((row) => row.id === "dm")?.name).toBe("Alice");
142+
expect(labels.find((row) => row.id === "dm")?.name).toBe(
143+
outcome ? fallback : "Alice",
144+
);
129145
}
130146
expect(wire.pending).toHaveLength(0);
131147
// Exercise the actual complete-roster omission -> session purge. Do not
@@ -144,13 +160,27 @@ it.each([
144160
});
145161
}
146162
expect(labels.map((row) => row.id)).toEqual(["dm"]);
147-
expect(owner.session.profiles.snapshot().has(alice.pubkey)).toBe(true);
148-
expect(labels[0]?.name).toBe("Alice");
149-
expect(selectedProfiles.get(alice.pubkey)?.picture).toBe(
150-
"https://example.com/alice.png",
151-
);
163+
if (outcome) {
164+
// The membership change retries the missing name exactly once.
165+
expect(wire.pending).toHaveLength(1);
166+
expect(wire.pending[0]?.filters).toEqual([
167+
{ kinds: [0], authors: [alice.pubkey], limit: 500 },
168+
]);
169+
await act(async () => {
170+
answer(wire.next());
171+
await flush();
172+
});
173+
expect(owner.session.profiles.snapshot().has(alice.pubkey)).toBe(false);
174+
expect(labels[0]?.name).toBe(fallback);
175+
} else {
176+
expect(owner.session.profiles.snapshot().has(alice.pubkey)).toBe(true);
177+
expect(labels[0]?.name).toBe("Alice");
178+
expect(selectedProfiles.get(alice.pubkey)?.picture).toBe(
179+
"https://example.com/alice.png",
180+
);
181+
}
152182
expect(wire.pending).toHaveLength(0);
153-
// Unrelated renders must not cause a request loop.
183+
// Unrelated renders and empty/failed results must not cause a request loop.
154184
await act(async () => {
155185
incoming([message(viewer, "dm", "ordinary traffic", 1_700_000_002)]);
156186
await flush();

‎src/bundled/channels/useChannelLabels.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export function useChannelLabels(
3737
selection.snapshot,
3838
selection.snapshot,
3939
);
40-
// Access loss can purge loaded names or abort a cold fetch without changing
41-
// DM participants. Retry for missing names or changed channel membership,
42-
// not for message previews/renders; keep enrichment in the background.
40+
// A name read can come back empty or fail (offline), and a full cache clear
41+
// empties the directory, without changing DM participants. Retry missing
42+
// names when channel membership changes, not for message previews/renders;
43+
// keep enrichment in the background.
4344
const membership = useMemo(
4445
() =>
4546
roster

0 commit comments

Comments
 (0)