Ensure comment events keep root e tags alongside addresses

This commit is contained in:
thePR0M3TH3AN committed 2025-11-03 09:56:33 -05:00
1 parent a107f59221
commit d9b45ed867
6 files changed
+71 -10

No files matched your search

+3
View File
@@ -25,6 +25,7 @@ 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"],
@@ -48,6 +49,7 @@ 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)],
@@ -76,6 +78,7 @@ 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)],
+36
View File
@@ -62,6 +62,24 @@ test(
}),
};
assert.ok(
topLevelEvent.tags.some(
(tag) =>
Array.isArray(tag) &&
tag[0] === "e" &&
tag[1] === videoEventId &&
tag[2] === relayUrl,
),
"builder should retain legacy #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,
),
"builder should include #a pointer for the scoped video definition",
);
const replyEvent = {
id: replyCommentId,
...buildCommentEvent({
@@ -81,6 +99,24 @@ test(
}),
};
assert.ok(
replyEvent.tags.some(
(tag) =>
Array.isArray(tag) &&
tag[0] === "e" &&
tag[1] === videoEventId &&
tag[2] === relayUrl,
),
"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,
),
"reply builder should preserve #a pointer",
);
const listCalls = [];
const client = {
relays: [relayUrl],
+2
View File
@@ -115,6 +115,7 @@ 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)],
@@ -239,6 +240,7 @@ 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)],
+19 -6
View File
@@ -26,6 +26,17 @@ function createCommentEvent({ id, pubkey, content, createdAt, parentId = null })
if (parentId) {
tags.push(["e", parentId]);
}
assert.ok(
tags.some((tag) => Array.isArray(tag) && tag[0] === "e" && tag[1] === "video123"),
"comment fixture should include root #e tag",
);
assert.ok(
tags.some(
(tag) =>
Array.isArray(tag) && tag[0] === "a" && tag[1] === "30078:authorpk:video-root",
),
"comment fixture should include root #a tag",
);
return {
id,
pubkey,
@@ -213,12 +224,13 @@ test(
},
});
const video = {
id: "video123",
pubkey: "AUTHORPK",
enableComments: true,
kind: 30078,
};
const video = {
id: "video123",
pubkey: "AUTHORPK",
enableComments: true,
kind: 30078,
tags: [["d", "video-root"]],
};
controller.load(video);
controller.submit({ text: "Nice" });
@@ -229,6 +241,7 @@ test(
const payload = publishCalls[0];
assert.equal(payload.videoEventId, "video123");
assert.equal(payload.videoAuthorPubkey, "AUTHORPK");
assert.equal(payload.videoDefinitionAddress, "30078:AUTHORPK:video-root");
},
);