Ensure delete tombstones carry explicit flag

This commit is contained in:
thePR0M3TH3AN committed 2025-10-20 09:54:07 -04:00
1 parent 8000d2e73b
commit cc3ef2fb1f
2 files changed
+107 -1

No files matched your search

+1 -1
View File
@@ -7126,7 +7126,7 @@ export class NostrClient {
const contentPayload = {
version: Number.isFinite(vid.version) ? vid.version : 3,
deleted: vid.deleted === true,
deleted: true,
isPrivate: vid.isPrivate === true,
isNsfw: vid.isNsfw === true,
isForKids: vid.isForKids === true && vid.isNsfw !== true,
+106
View File
@@ -0,0 +1,106 @@
import "./test-helpers/setup-localstorage.mjs";
import assert from "node:assert/strict";
import { NostrClient } from "../js/nostr.js";
await (async function testDeleteFlowPublishesDeletionFlag() {
const client = new NostrClient();
client.hydrateVideoHistory = async () => {};
const pubkey = "PUBKEY123";
const videoRootId = "root-abc";
const baseVideo = {
id: "evt-original",
pubkey,
created_at: 1_700_000_000,
version: 3,
videoRootId,
title: "Sample",
url: "https://example.com/video.mp4",
magnet: "",
thumbnail: "https://example.com/thumb.jpg",
description: "example",
mode: "live",
tags: [
["t", "video"],
["d", videoRootId],
],
};
client.allEvents.set(baseVideo.id, { ...baseVideo });
const revertCalls = [];
client.revertVideo = async (event) => {
revertCalls.push(event);
return { id: `revert-${revertCalls.length}` };
};
const result = await client.deleteAllVersions(videoRootId, pubkey, {
confirm: false,
video: baseVideo,
});
assert.equal(result, true, "deleteAllVersions should resolve true on success");
assert.equal(revertCalls.length, 1, "deleteAllVersions should call revertVideo once");
const parsedPayload = JSON.parse(revertCalls[0].content);
assert.equal(parsedPayload.deleted, true, "revert payload should mark deleted true");
assert.equal(parsedPayload.videoRootId, videoRootId);
const cached = client.allEvents.get(baseVideo.id);
assert.equal(cached.deleted, true, "cached original video should be marked deleted");
const activeKey = `ROOT:${videoRootId}`;
client.activeMap.set(activeKey, {
...baseVideo,
videoRootId,
created_at: baseVideo.created_at,
});
const seenUpdates = [];
const handlers = {};
const fakeSub = {
on(type, handler) {
handlers[type] = handler;
},
unsub() {},
};
client.pool = {
sub() {
return fakeSub;
},
};
client.subscribeVideos((videoUpdate) => {
seenUpdates.push(videoUpdate);
});
const deleteEvent = {
id: "delete-event-1",
pubkey,
created_at: baseVideo.created_at + 100,
content: revertCalls[0].content,
tags: baseVideo.tags,
};
handlers.event(deleteEvent);
if (typeof handlers.eose === "function") {
handlers.eose();
}
assert.equal(
seenUpdates.length,
0,
"deleted events should not trigger subscription callbacks",
);
assert.equal(
client.activeMap.has(activeKey),
false,
"deleted events should remove the active map entry",
);
const storedDelete = client.allEvents.get(deleteEvent.id);
assert.equal(storedDelete.deleted, true, "stored delete event should be marked deleted");
})();
console.log("nostr delete flow tests passed");