Use uppercase tags for comment events

This commit is contained in:
thePR0M3TH3AN committed 2026-01-06 16:22:49 -05:00
1 parent 90e5c745d3
commit 5979d4e25f
8 files changed
+139 -219

No files matched your search

+20 -21
View File
@@ -48,10 +48,9 @@ test("buildCommentEvent emits NIP-22 root metadata while keeping legacy fallback
["A", "30078:deadbeefcafebabe:clip-1"],
["K", "30078"],
["P", "deadbeefcafebabe"],
["e", "video-event-id"],
["a", "30078:deadbeefcafebabe:clip-1"],
["k", "30078"],
["p", "deadbeefcafebabe"],
["E", "video-event-id"],
["A", "30078:deadbeefcafebabe:clip-1"],
["K", "30078"],
]);
assert.equal(event.content, "Great video!");
});
@@ -72,11 +71,11 @@ test("buildCommentEvent includes parent pointers, kinds, and authors for replies
["A", "30078:deadbeefcafebabe:clip-1"],
["K", "30078"],
["P", "deadbeefcafebabe"],
["e", "video-event-id"],
["a", "30078:deadbeefcafebabe:clip-1"],
["e", "parent-comment-id", "parent-author"],
["k", String(VIDEO_COMMENT_KIND)],
["p", "parent-author"],
["E", "video-event-id"],
["A", "30078:deadbeefcafebabe:clip-1"],
["E", "parent-comment-id", "parent-author"],
["K", String(VIDEO_COMMENT_KIND)],
["P", "parent-author"],
]);
});
@@ -101,11 +100,11 @@ test("buildCommentEvent normalizes relays and preserves explicit overrides", ()
["A", "30078:deadbeefcafebabe:clip-2", "wss://video.def"],
["K", "30078"],
["P", "deadbeefcafebabe", "wss://video.def"],
["e", "event123", "wss://comments.main"],
["a", "30078:deadbeefcafebabe:clip-2", "wss://video.def"],
["e", "root-comment", "wss://parent", "cafecafe"],
["k", String(VIDEO_COMMENT_KIND)],
["p", "cafecafe", "wss://profile"],
["E", "event123", "wss://comments.main"],
["A", "30078:deadbeefcafebabe:clip-2", "wss://video.def"],
["E", "root-comment", "wss://parent", "cafecafe"],
["K", String(VIDEO_COMMENT_KIND)],
["P", "cafecafe", "wss://profile"],
["client", "bitvid"],
]);
assert.equal(event.content, " Appreciated! ");
@@ -128,9 +127,9 @@ test("buildCommentEvent falls back to event pointers when no address is supplied
["E", "legacy-event", "wss://legacy.example", "legacy-author"],
["K", "1063"],
["P", "legacy-author"],
["e", "legacy-event", "wss://legacy.example"],
["k", "1063"],
["p", "legacy-pubkey"],
["E", "legacy-event", "wss://legacy.example"],
["K", "1063"],
["P", "legacy-pubkey"],
]);
});
@@ -152,10 +151,10 @@ test("buildCommentEvent accepts partial metadata for parent overrides", () => {
assert.deepStrictEqual(event.tags, [
["E", "file-event"],
["K", "1063"],
["e", "file-event"],
["e", "parent-comment", "wss://parent", "parent-only"],
["k", "1111"],
["p", "parent-only", "wss://parent-author"],
["E", "file-event"],
["E", "parent-comment", "wss://parent", "parent-only"],
["K", "1111"],
["P", "parent-only", "wss://parent-author"],
]);
});
+8 -8
View File
@@ -608,18 +608,18 @@ test(
topLevelEvent.tags.some(
(tag) =>
Array.isArray(tag) &&
tag[0] === "e" &&
tag[0] === "E" &&
tag[1] === videoEventId &&
tag[2] === relayUrl,
),
"builder should retain legacy #e tag for the root event when address pointer is present",
"builder should retain uppercase #E tag for the root event when address pointer is present",
);
assert.ok(
topLevelEvent.tags.some(
(tag) =>
Array.isArray(tag) && tag[0] === "a" && tag[1] === videoDefinitionAddress,
Array.isArray(tag) && tag[0] === "A" && tag[1] === videoDefinitionAddress,
),
"builder should include #a pointer for the scoped video definition",
"builder should include #A pointer for the scoped video definition",
);
const replyEvent = {
@@ -645,18 +645,18 @@ test(
replyEvent.tags.some(
(tag) =>
Array.isArray(tag) &&
tag[0] === "e" &&
tag[0] === "E" &&
tag[1] === videoEventId &&
tag[2] === relayUrl,
),
"reply builder should include root #e tag alongside #a pointer",
"reply builder should include root #E tag alongside #A pointer",
);
assert.ok(
replyEvent.tags.some(
(tag) =>
Array.isArray(tag) && tag[0] === "a" && tag[1] === videoDefinitionAddress,
Array.isArray(tag) && tag[0] === "A" && tag[1] === videoDefinitionAddress,
),
"reply builder should preserve #a pointer",
"reply builder should preserve #A pointer",
);
const listCalls = [];
+4 -4
View File
@@ -40,7 +40,7 @@ async function testRefreshCountsCachesResults() {
const [eventFilter, uppercaseFilter, addressFilter] = filters;
assert.deepEqual(eventFilter, {
kinds: [COMMENT_EVENT_KIND],
"#e": ["count-video-1"],
"#E": ["count-video-1"],
});
assert.deepEqual(uppercaseFilter, {
kinds: [COMMENT_EVENT_KIND],
@@ -50,7 +50,7 @@ async function testRefreshCountsCachesResults() {
});
assert.deepEqual(addressFilter, {
kinds: [COMMENT_EVENT_KIND],
"#a": ["30078:pubkey-1:identifier-1"],
"#A": ["30078:pubkey-1:identifier-1"],
});
return {
total: 5,
@@ -123,7 +123,7 @@ async function testUnsupportedRelaysUpdateDomState() {
const [eventFilter, uppercaseFilter, addressFilter] = filters;
assert.deepEqual(eventFilter, {
kinds: [COMMENT_EVENT_KIND],
"#e": ["unsupported-video"],
"#E": ["unsupported-video"],
});
assert.deepEqual(uppercaseFilter, {
kinds: [COMMENT_EVENT_KIND],
@@ -133,7 +133,7 @@ async function testUnsupportedRelaysUpdateDomState() {
});
assert.deepEqual(addressFilter, {
kinds: [COMMENT_EVENT_KIND],
"#a": ["30078:pubkey-2:identifier-2"],
"#A": ["30078:pubkey-2:identifier-2"],
});
return {
total: 7,
+61 -85
View File
@@ -118,13 +118,13 @@ test("publishComment prefers active signer when available", async () => {
["A", "30078:deadbeef:clip", "wss://definition-relay"],
["K", "30078"],
["P", "deadbeef", "wss://definition-relay"],
["e", "video-event-id", "wss://video-relay"],
["a", "30078:deadbeef:clip", "wss://definition-relay"],
["e", "parent-comment-id", "thread-participant"],
["k", String(COMMENT_EVENT_KIND)],
["p", "thread-participant"],
["E", "video-event-id", "wss://video-relay"],
["A", "30078:deadbeef:clip", "wss://definition-relay"],
["E", "parent-comment-id", "thread-participant"],
["K", String(COMMENT_EVENT_KIND)],
["P", "thread-participant"],
],
"comment event should include NIP-22 root tags while preserving fallback markers",
"comment event should include uppercase pointers and participant metadata",
);
});
@@ -193,9 +193,9 @@ test("publishComment accepts legacy targets with only an event id", async () =>
[
["E", "legacy-event-id"],
["K", String(COMMENT_EVENT_KIND)],
["e", "legacy-event-id"],
["e", "parent-legacy"],
["k", String(COMMENT_EVENT_KIND)],
["E", "legacy-event-id"],
["E", "parent-legacy"],
["K", String(COMMENT_EVENT_KIND)],
],
"legacy publish should emit uppercase root metadata with lowercase fallbacks",
);
@@ -213,10 +213,10 @@ test("publishComment derives root and parent metadata from parent comment tags",
["K", "30078"],
["P", "videopk", "wss://author"],
["A", "30078:videopk:root", "wss://definition"],
["e", "video-event", "wss://root"],
["e", "parent-comment", "wss://parent", "parentpk"],
["k", String(COMMENT_EVENT_KIND)],
["p", "parentpk", "wss://parent"],
["E", "video-event", "wss://root"],
["E", "parent-comment", "wss://parent", "parentpk"],
["K", String(COMMENT_EVENT_KIND)],
["P", "parentpk", "wss://parent"],
],
};
@@ -240,11 +240,11 @@ test("publishComment derives root and parent metadata from parent comment tags",
["A", "30078:videopk:root", "wss://definition"],
["K", "30078"],
["P", "videopk", "wss://author"],
["e", "video-event", "wss://root"],
["a", "30078:videopk:root", "wss://definition"],
["e", "parent-comment", "wss://parent", "parentpk"],
["k", String(COMMENT_EVENT_KIND)],
["p", "parentpk", "wss://parent"],
["E", "video-event", "wss://root"],
["A", "30078:videopk:root", "wss://definition"],
["E", "parent-comment", "wss://parent", "parentpk"],
["K", String(COMMENT_EVENT_KIND)],
["P", "parentpk", "wss://parent"],
]);
});
@@ -255,11 +255,11 @@ test("listVideoComments matches comments even when tag casing and whitespace dif
created_at: 1700000300,
tags: [
[" A ", " 30078:AUTHOR:CLIP ", " WSS://Definition "],
["e", " VIDEO-1 "],
["E", " VIDEO-1 "],
[" E ", " VIDEO-1 "],
["e", " PARENT-1 "],
["k", String(COMMENT_EVENT_KIND)],
["p", " THREAD-PARTICIPANT "],
["E", " PARENT-1 "],
["K", String(COMMENT_EVENT_KIND)],
["P", " THREAD-PARTICIPANT "],
],
};
@@ -293,7 +293,7 @@ test("listVideoComments matches uppercase definition addresses without lowering"
created_at: 1700000400,
tags: [
["A", uppercasePointer],
["e", "video-1"],
["E", "video-1"],
],
};
@@ -324,11 +324,11 @@ test("listVideoComments matches comments even when tag casing and whitespace dif
created_at: 1700000300,
tags: [
[" A ", " 30078:AUTHOR:CLIP ", " WSS://Definition "],
["e", " VIDEO-1 "],
["E", " VIDEO-1 "],
[" E ", " VIDEO-1 "],
["e", " PARENT-1 "],
["k", String(COMMENT_EVENT_KIND)],
["p", " THREAD-PARTICIPANT "],
["E", " PARENT-1 "],
["K", String(COMMENT_EVENT_KIND)],
["P", " THREAD-PARTICIPANT "],
],
};
@@ -354,11 +354,11 @@ test("listVideoComments matches comments even when tag casing and whitespace dif
);
});
["p", "parentpk", "wss://parent"],
["P", "parentpk", "wss://parent"],
]);
});
test("publishComment emits only video event #e tag when address and parent are absent", async () => {
test("publishComment emits only uppercase video event pointer when address and parent are absent", async () => {
const { client, publishCalls } = createMockClient();
const signer = {
@@ -389,9 +389,8 @@ test("publishComment emits only video event #e tag when address and parent are a
tags,
[
["E", "video-only"],
["e", "video-only"],
],
"event should include an uppercase root pointer along with the legacy #e tag",
"event should include a single uppercase pointer",
);
});
@@ -404,9 +403,9 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
["A", "30078:author:clip"],
["K", "30078"],
["P", "author"],
["e", "parent-1"],
["k", String(COMMENT_EVENT_KIND)],
["p", "thread-participant"],
["E", "parent-1"],
["K", String(COMMENT_EVENT_KIND)],
["P", "thread-participant"],
],
};
@@ -415,8 +414,8 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
kind: COMMENT_EVENT_KIND,
created_at: 1690000000,
tags: [
["a", "30078:author:clip"],
["e", "parent-1"],
["A", "30078:author:clip"],
["E", "parent-1"],
],
};
@@ -424,7 +423,7 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
id: "comment-3",
kind: COMMENT_EVENT_KIND,
created_at: 1700000100,
tags: [["a", "30078:author:clip"]],
tags: [["A", "30078:author:clip"]],
};
const {
@@ -473,9 +472,9 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
"event filter should target comment kind",
);
assert.deepEqual(
eventFilter["#e"],
eventFilter["#E"],
["video-1"],
"event filter should target the video via #e",
"event filter should target the video via #E",
);
assert.equal(
uppercaseFilter.kinds[0],
@@ -511,11 +510,11 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
parentFilter,
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["parent-1"],
"#E": ["parent-1"],
since: 1700000000,
limit: 10,
},
"parent filter should scope the thread via #e",
"parent filter should scope the thread via #E",
);
assert.equal(
eventFilter.since,
@@ -534,12 +533,12 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
"definition filter should target comment kind",
);
assert.deepEqual(
definitionFilter["#a"],
definitionFilter["#A"],
["30078:author:clip"],
"definition filter should bind the video definition via #a",
"definition filter should bind the video definition via #A",
);
assert.deepEqual(
definitionFilter["#e"],
definitionFilter["#E"],
["parent-1"],
"definition filter should continue scoping to the parent comment",
);
@@ -555,14 +554,14 @@ test("listVideoComments builds filters with uppercase roots plus legacy fallback
);
});
test("listVideoComments adds lowercase root filters when only the identifier is known", async () => {
test("listVideoComments emits uppercase root filters when only the identifier is known", async () => {
const matchingEvent = {
id: "comment-root",
kind: COMMENT_EVENT_KIND,
tags: [
["I", "root-only"],
["P", "root-author"],
["e", "video-rooted"],
["E", "video-rooted"],
],
};
@@ -589,44 +588,21 @@ test("listVideoComments adds lowercase root filters when only the identifier is
assert.ok(receivedFilters, "pool.list should receive filters");
assert.equal(
receivedFilters.filters.length,
4,
"root identifier requests should include lowercase fallbacks",
2,
"root identifier requests should emit uppercase filters only",
);
const [eventFilter, uppercaseEventFilter, lowercaseRootFilter, uppercaseRootFilter] =
receivedFilters.filters;
const [eventFilter, uppercaseRootFilter] = receivedFilters.filters;
assert.deepEqual(
eventFilter,
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["video-rooted"],
since: 1700000000,
limit: 5,
},
"event filter should continue targeting the video event id",
);
assert.deepEqual(
uppercaseEventFilter,
{
kinds: [COMMENT_EVENT_KIND],
"#E": ["video-rooted"],
since: 1700000000,
limit: 5,
},
"uppercase event filter should continue targeting legacy #E pointers",
);
assert.deepEqual(
lowercaseRootFilter,
{
kinds: [COMMENT_EVENT_KIND],
"#i": ["root-only"],
since: 1700000000,
limit: 5,
},
"root identifier filter should include lowercase #i tag queries",
"event filter should target the video event id via #E",
);
assert.equal(
@@ -660,7 +636,7 @@ test("listVideoComments supports legacy targets without a definition address", a
const legacyEvent = {
id: "legacy-comment",
kind: COMMENT_EVENT_KIND,
tags: [["e", "legacy-video"]],
tags: [["E", "legacy-video"]],
};
const { client, pool } = createMockClient();
@@ -688,14 +664,14 @@ test("listVideoComments supports legacy targets without a definition address", a
[
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["legacy-video"],
"#E": ["legacy-video"],
},
{
kinds: [COMMENT_EVENT_KIND],
"#E": ["legacy-video"],
},
],
"legacy listing should target the video event id via #e/#E",
"legacy listing should target the video event id via #E",
);
});
@@ -756,7 +732,7 @@ test("subscribeVideoComments forwards matching events and cleans up unsubscribe"
[
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["video-1"],
"#E": ["video-1"],
},
{
kinds: [COMMENT_EVENT_KIND],
@@ -766,12 +742,12 @@ test("subscribeVideoComments forwards matching events and cleans up unsubscribe"
},
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["parent-1"],
"#E": ["parent-1"],
},
{
kinds: [COMMENT_EVENT_KIND],
"#a": ["30078:author:clip"],
"#e": ["parent-1"],
"#E": ["parent-1"],
},
],
"subscription should emit event, parent, and address filters",
@@ -784,16 +760,16 @@ test("subscribeVideoComments forwards matching events and cleans up unsubscribe"
["A", "30078:author:clip"],
["K", "30078"],
["P", "author"],
["e", "parent-1"],
["k", String(COMMENT_EVENT_KIND)],
["p", "thread-participant"],
["E", "parent-1"],
["K", String(COMMENT_EVENT_KIND)],
["P", "thread-participant"],
],
});
handler({
id: "comment-rejected",
kind: COMMENT_EVENT_KIND,
tags: [["e", "video-1"]],
tags: [["E", "video-1"]],
});
assert.equal(receivedEvents.length, 1, "only matching events should reach the callback");
@@ -839,7 +815,7 @@ test("subscribeVideoComments supports video targets without a definition address
[
{
kinds: [COMMENT_EVENT_KIND],
"#e": ["legacy-video"],
"#E": ["legacy-video"],
},
{
kinds: [COMMENT_EVENT_KIND],
@@ -854,7 +830,7 @@ test("subscribeVideoComments supports video targets without a definition address
handler({
id: "legacy-comment",
kind: COMMENT_EVENT_KIND,
tags: [["e", "legacy-video"]],
tags: [["E", "legacy-video"]],
});
assert.equal(receivedEvents.length, 1, "legacy comment should be forwarded");