Skip to content

Commit a8061c5

Browse files
wpfleger96npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhw
andauthored
feat(catalog): resolve publisher display name in catalog detail pane (block#3640)
The catalog detail pane hardcoded "Community member" for every non-own catalog entry. The publisher pubkey (`catalogSource.ownerPubkey`) was already on every entry — it just was not being resolved to a name. ## What changed **`desktop/src/features/agents/ui/PersonaCatalogDialog.tsx`** `PersonaCatalogDetail` now calls `useUsersBatchQuery([ownerPubkey])` when the selected entry is a community (non-own) catalog agent. The label derivation is extracted into the exported pure function `resolveCatalogOwnerLabel` and uses truthy fallbacks to handle empty or whitespace-only kind:0 fields: - Own entry → `"You"` (unchanged) - `displayName` present and non-blank → the display name - `displayName` absent/blank but `name` present and non-blank → the name - Loading, unresolvable, or both candidates blank → `"Community member"` (fallback preserved) The batch query is disabled (`enabled: false`) when the entry is not a community entry, so there is no extra network call for own entries or built-in agents. **`desktop/src/features/agents/ui/personaCatalogOwnerLabel.test.mjs`** Unit tests for `resolveCatalogOwnerLabel` covering: populated `displayName` wins; whitespace-only `displayName` falls through to `name`; both candidates empty/whitespace/null/undefined all fall through to `"Community member"`. **`desktop/tests/e2e/agents.spec.ts`** - Updated the existing assertion — it previously checked for the hardcoded fallback; now asserts the resolved mock display name `"alice"`. - Added "catalog detail shows Community member when the publisher profile cannot be resolved" — installs a catalog event from an unknown pubkey and asserts the fallback still renders. --------- Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhw <41ea58f1e64c243627e8acde7c89be667052ee6e17d8f021c1195be4324ebf04@buzz.block.builderlab.xyz>
1 parent c002ed4 commit a8061c5

3 files changed

Lines changed: 149 additions & 9 deletions

File tree

‎desktop/src/features/agents/ui/PersonaCatalogDialog.tsx‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22

33
import { isCatalogPersonaSelected } from "@/features/agents/lib/catalog";
44
import { isCatalogPersona } from "@/features/agents/lib/personaCatalogRelay";
5+
import { useUsersBatchQuery } from "@/features/profile/hooks";
56
import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar";
67
import type { AgentPersona } from "@/shared/api/types";
78
import { useFeedbackToasts } from "@/shared/hooks/useToastEffect";
@@ -276,7 +277,42 @@ function PersonaCatalogChooser({
276277
);
277278
}
278279

280+
/**
281+
* Derives the "Added by" label for a catalog entry from a resolved profile
282+
* summary. Prefers `displayName`, falls back to `name`, then to the default
283+
* "Community member" string when both are absent, null, or whitespace-only.
284+
*/
285+
export function resolveCatalogOwnerLabel(
286+
summary:
287+
| { displayName?: string | null; name?: string | null }
288+
| null
289+
| undefined,
290+
): string {
291+
return (
292+
summary?.displayName?.trim() || summary?.name?.trim() || "Community member"
293+
);
294+
}
295+
279296
function PersonaCatalogDetail({ persona }: { persona: AgentPersona }) {
297+
const isCommunityEntry =
298+
isCatalogPersona(persona) && !persona.catalogSource.isOwn;
299+
const ownerPubkey = isCommunityEntry
300+
? persona.catalogSource.ownerPubkey
301+
: undefined;
302+
const ownerBatchQuery = useUsersBatchQuery(ownerPubkey ? [ownerPubkey] : [], {
303+
enabled: !!ownerPubkey,
304+
});
305+
306+
let addedByLabel: string;
307+
if (!isCommunityEntry) {
308+
addedByLabel = "You";
309+
} else {
310+
const summary = ownerPubkey
311+
? ownerBatchQuery.data?.profiles[ownerPubkey.toLowerCase()]
312+
: undefined;
313+
addedByLabel = resolveCatalogOwnerLabel(summary);
314+
}
315+
280316
return (
281317
<div className="w-full min-w-0 max-w-full space-y-6 overflow-x-hidden">
282318
<div className="flex items-center gap-3">
@@ -290,14 +326,7 @@ function PersonaCatalogDetail({ persona }: { persona: AgentPersona }) {
290326
{persona.displayName}
291327
</h3>
292328
{persona.isBuiltIn ? null : (
293-
<PersonaAddedBy
294-
className="mt-0.5"
295-
label={
296-
isCatalogPersona(persona) && !persona.catalogSource.isOwn
297-
? "Community member"
298-
: "You"
299-
}
300-
/>
329+
<PersonaAddedBy className="mt-0.5" label={addedByLabel} />
301330
)}
302331
</div>
303332
</div>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { resolveCatalogOwnerLabel } from "./PersonaCatalogDialog.tsx";
5+
6+
// ── null / undefined summary ──────────────────────────────────────────────────
7+
8+
test("test_null_summary_returns_community_member", () => {
9+
assert.equal(resolveCatalogOwnerLabel(null), "Community member");
10+
});
11+
12+
test("test_undefined_summary_returns_community_member", () => {
13+
assert.equal(resolveCatalogOwnerLabel(undefined), "Community member");
14+
});
15+
16+
// ── populated displayName ─────────────────────────────────────────────────────
17+
18+
test("test_display_name_present_returns_display_name", () => {
19+
assert.equal(
20+
resolveCatalogOwnerLabel({ displayName: "Alice", name: "alice" }),
21+
"Alice",
22+
);
23+
});
24+
25+
test("test_display_name_present_without_name_returns_display_name", () => {
26+
assert.equal(resolveCatalogOwnerLabel({ displayName: "Alice" }), "Alice");
27+
});
28+
29+
// ── empty / whitespace displayName with valid name ────────────────────────────
30+
31+
test("test_empty_display_name_falls_through_to_name", () => {
32+
assert.equal(
33+
resolveCatalogOwnerLabel({ displayName: "", name: "alice" }),
34+
"alice",
35+
);
36+
});
37+
38+
test("test_whitespace_only_display_name_falls_through_to_name", () => {
39+
assert.equal(
40+
resolveCatalogOwnerLabel({ displayName: " ", name: "alice" }),
41+
"alice",
42+
);
43+
});
44+
45+
// ── both candidates absent / empty ────────────────────────────────────────────
46+
47+
test("test_both_null_returns_community_member", () => {
48+
assert.equal(
49+
resolveCatalogOwnerLabel({ displayName: null, name: null }),
50+
"Community member",
51+
);
52+
});
53+
54+
test("test_both_empty_returns_community_member", () => {
55+
assert.equal(
56+
resolveCatalogOwnerLabel({ displayName: "", name: "" }),
57+
"Community member",
58+
);
59+
});
60+
61+
test("test_both_whitespace_returns_community_member", () => {
62+
assert.equal(
63+
resolveCatalogOwnerLabel({ displayName: " ", name: "\t" }),
64+
"Community member",
65+
);
66+
});
67+
68+
test("test_display_name_absent_name_present_returns_name", () => {
69+
assert.equal(resolveCatalogOwnerLabel({ name: "alice" }), "alice");
70+
});
71+
72+
test("test_display_name_null_name_present_returns_name", () => {
73+
assert.equal(
74+
resolveCatalogOwnerLabel({ displayName: null, name: "alice" }),
75+
"alice",
76+
);
77+
});

‎desktop/tests/e2e/agents.spec.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,10 @@ test("a community member can discover and add another member's catalog agent", a
17361736
);
17371737
await expect(remoteEntry).toContainText("Alice’s Reviewer");
17381738
await remoteEntry.click();
1739+
// The detail pane resolves the publisher's display name; 'Community member'
1740+
// is only the fallback for an unresolvable pubkey.
17391741
await expect(page.getByTestId("persona-catalog-detail-pane")).toContainText(
1740-
"Added by Community member",
1742+
"Added by alice",
17411743
);
17421744

17431745
await page
@@ -1790,6 +1792,38 @@ test("a community member can discover and add another member's catalog agent", a
17901792
expect(await countCommandInvocations(page, "create_persona")).toBe(1);
17911793
});
17921794

1795+
test("catalog detail shows Community member when the publisher profile cannot be resolved", async ({
1796+
page,
1797+
}) => {
1798+
// A pubkey that is not in the mock profile registry — profile resolution
1799+
// will fail and the detail pane must fall back gracefully.
1800+
const unknownPubkey =
1801+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1802+
const personaId = "unresolvable-reviewer";
1803+
await installMockBridge(page, {
1804+
personaCatalogEvents: [
1805+
createCatalogEvent({
1806+
ownerPubkey: unknownPubkey,
1807+
sourcePersonaId: personaId,
1808+
displayName: "Mystery Agent",
1809+
systemPrompt: "Published by someone whose profile cannot be fetched.",
1810+
}),
1811+
],
1812+
});
1813+
await gotoApp(page);
1814+
await page.getByTestId("open-agents-view").click();
1815+
await openPersonaCatalog(page);
1816+
1817+
await page
1818+
.getByTestId(
1819+
`persona-catalog-list-item-catalog:${unknownPubkey}:${personaId}`,
1820+
)
1821+
.click();
1822+
await expect(page.getByTestId("persona-catalog-detail-pane")).toContainText(
1823+
"Added by Community member",
1824+
);
1825+
});
1826+
17931827
test("one share level selector drives both the link and send paths", async ({
17941828
page,
17951829
}) => {

0 commit comments

Comments
 (0)