mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
CI has been failing on unstable for weeks, across four unit files and a set of e2e specs. None of it was a product regression: every failure is a test that encodes behavior a later commit deliberately changed. Each is corrected against the spec that superseded it, not adjusted until it passed. Unit: - video-modal-moderation: the fixture set flat `blurThumbnail`/`trustedMuteCount`, but normalizeVideoModerationContext derives shouldShow from `original.blurThumbnail`/`trustedCount`, so the assertion ran against a context whose early return had just deleted the blur it was checking.4525c1c6also made a lone trusted mute a non-blocking ranking signal (its sibling test was renamed to say exactly that; this one was missed). Fixture now mirrors what moderationDecorator emits. - trustBootstrap: asserted a subscription to onWhitelistChange that18e08bf2deliberately removed -- buildTrustedSeeds derives seeds from the super admin, editors and fallback seeds, so a whitelist change cannot alter them. The removal is now pinned so it is not reinstated by reflex. - moderation-service:18e08bf2removed `status.whitelisted ||` from isTrustedReporter (being allowed to publish is not a statement that your reports carry weight). A whitelisted reporter now counts toward the report total but not toward trusted. - playbackService_forcedSource: forced P2P now falls back to a hosted URL when the torrent definitively fails -- playbackService documents the change and its rollback. The old assertion did not merely fail, it HUNG: forced sources skip the start timeout, so the now-reachable hosted attempt waited forever on a <video> that never emits. E2E: - ui-modals: asserted exactly one `.bv-modal` per component page, but profile-modal.html also bundles #storageCorsModal (d7ad1516). Requires at least one and drives the primary, which is what the test's own injected querySelector already used. - coverage-utility-modules: used `author:abc123`, which9afbc0cbcorrectly began rejecting as undecodable. Uses a real pubkey for the success path and pins the rejection separately. - webseed-playback: asserted the FINAL src equals the CDN URL while also tolerating "No playable source found" in its status check -- contradictory, since a failed attempt calls resetVideoElement() and clears src. Headless CI cannot decode the archive.org H.264 sample. Now records src attachments and asserts the URL was attached, which is the behavior under test. - nostr-runtime-coverage: asserted a legacy plaintext session-actor entry reads back as null. Since8692dac6added per-account storage, readV1Entry PURGES the plaintext entry and the reader falls back to the sole remaining encrypted account -- so null no longer describes the security property. Asserts the property directly: no plaintext key survives, in the entry or in raw storage. Also drops the syncAuthUiState share-gate wiring added ind141c316. It was redundant: Application.updateShareNostrAuthState() already fires on init, login, logout, pubkey-change and signer-change and forwards to videoModal.setShareNostrAuthState(). That call short-circuited on its own `if (!this.videoModal?.setShareNostrAuthState) return;` guard purely because the method did not exist -- adding it (d141c316) was the whole fix. The tests now pin that contract instead of a second, competing code path. All 416 unit files, all three CI shards, both DM suites and lint are green. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
178 lines
6.2 KiB
JavaScript
178 lines
6.2 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import "./test-setup.mjs";
|
|
|
|
import { setupModal } from "./video-modal-accessibility.test.mjs";
|
|
|
|
const RESTORE_BUTTON_LABEL = "Restore default moderation";
|
|
|
|
test("VideoModal blurs and restores playback when moderation overlay toggles", async (t) => {
|
|
const { modal, cleanup } = await setupModal();
|
|
const document = modal.document;
|
|
const window = document.defaultView;
|
|
|
|
try {
|
|
await t.test("trusted reports blur the active video", async () => {
|
|
const videoElement = modal.getVideoElement();
|
|
assert.ok(videoElement, "modal video element should exist");
|
|
|
|
let pauseCalls = 0;
|
|
const originalPause = videoElement.pause;
|
|
videoElement.pause = function patchedPause() {
|
|
pauseCalls += 1;
|
|
if (typeof originalPause === "function") {
|
|
return originalPause.call(this);
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
const video = {
|
|
id: "event-trusted-blur",
|
|
title: "Blurred video",
|
|
moderation: {
|
|
blurThumbnail: true,
|
|
trustedCount: 3,
|
|
reporterDisplayNames: ["Alice", "Bob"],
|
|
summary: {
|
|
types: {
|
|
nudity: { trusted: 3 },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
modal.open(video);
|
|
|
|
const stage = document.querySelector(".video-modal__video");
|
|
assert.ok(stage, "video stage should exist");
|
|
assert.equal(stage.dataset.visualState, "blurred");
|
|
|
|
const overlay = document.querySelector("[data-moderation-bar]");
|
|
assert.ok(overlay, "moderation overlay should be rendered");
|
|
assert.equal(overlay.hasAttribute("hidden"), false);
|
|
|
|
assert.ok(pauseCalls > 0, "video pause should be invoked when blur is applied");
|
|
|
|
const textEl = overlay.querySelector("[data-moderation-text]");
|
|
assert.ok(textEl, "moderation text element should exist");
|
|
assert.match(
|
|
textEl.textContent,
|
|
/blurred/i,
|
|
"overlay text should describe the blur state",
|
|
);
|
|
|
|
let overrideEvent = null;
|
|
let hideEvent = null;
|
|
modal.addEventListener("video:moderation-override", (event) => {
|
|
overrideEvent = event;
|
|
});
|
|
modal.addEventListener("video:moderation-hide", (event) => {
|
|
hideEvent = event;
|
|
});
|
|
|
|
const showButton = overlay.querySelector(
|
|
"[data-moderation-action='override']",
|
|
);
|
|
assert.ok(showButton, "Show anyway button should be present");
|
|
showButton.click();
|
|
|
|
assert.ok(overrideEvent, "clicking the CTA should emit override event");
|
|
assert.equal(overrideEvent.detail.video, video);
|
|
|
|
video.moderation.blurThumbnail = false;
|
|
video.moderation.viewerOverride = { showAnyway: true };
|
|
|
|
const overrideSignal = new window.CustomEvent("video:moderation-override", {
|
|
detail: { video },
|
|
});
|
|
document.dispatchEvent(overrideSignal);
|
|
|
|
assert.equal(stage.dataset.visualState, undefined);
|
|
assert.equal(overlay.hasAttribute("hidden"), false);
|
|
assert.equal(overlay.dataset.overlayState, "override");
|
|
|
|
const restoreButton = document.querySelector(
|
|
"[data-moderation-action='hide']",
|
|
);
|
|
assert.ok(
|
|
restoreButton,
|
|
"Restore default moderation button should be present after override",
|
|
);
|
|
assert.equal(
|
|
restoreButton.textContent.trim(),
|
|
RESTORE_BUTTON_LABEL,
|
|
"Restore button should expose the new label",
|
|
);
|
|
|
|
restoreButton.click();
|
|
|
|
assert.ok(hideEvent, "clicking restore should emit moderation hide event");
|
|
assert.equal(hideEvent.detail.video, video);
|
|
|
|
delete video.moderation.viewerOverride;
|
|
video.moderation.blurThumbnail = true;
|
|
|
|
const hideSignal = new window.CustomEvent("video:moderation-block", {
|
|
detail: { video },
|
|
});
|
|
document.dispatchEvent(hideSignal);
|
|
|
|
assert.equal(stage.dataset.visualState, "blurred");
|
|
assert.equal(overlay.hasAttribute("hidden"), false);
|
|
|
|
videoElement.pause = originalPause;
|
|
modal.close();
|
|
});
|
|
|
|
await t.test("trusted mute blur state matches moderation context", async () => {
|
|
// Fixture mirrors what moderationDecorator actually emits. Two things
|
|
// made the old hand-rolled shape stop exercising this path:
|
|
//
|
|
// 1. normalizeVideoModerationContext derives `shouldShow` from
|
|
// `original.blurThumbnail` and `trustedCount`, NOT from a flat
|
|
// `blurThumbnail`/`trustedMuteCount`. The old fixture set fields the
|
|
// helper never reads, so shouldShow was false and applyModerationOverlay
|
|
// took its early return and deleted the blur it was asserting on.
|
|
// 2. 4525c1c6 made a lone trusted mute a non-blocking ranking signal (see
|
|
// "VideoCard keeps a single trusted mute as a non-blocking ranking
|
|
// signal"), so trusted-mute alone no longer forces the overlay.
|
|
//
|
|
// The scenario under test is still "a trusted mute that DID trigger a
|
|
// blur renders blurred with a trusted-mute badge", so the fixture now
|
|
// carries the decorator's `original` block that represents exactly that.
|
|
const video = {
|
|
id: "event-trusted-mute",
|
|
title: "Trusted mute video",
|
|
moderation: {
|
|
blurThumbnail: true,
|
|
blurReason: "trusted-mute",
|
|
trustedMuted: true,
|
|
trustedCount: 2,
|
|
trustedMuteCount: 2,
|
|
trustedMuterDisplayNames: ["Carol", "Dave"],
|
|
trustedMuteDisplayNames: ["Carol", "Dave"],
|
|
original: { blurThumbnail: true, blurReason: "trusted-mute" },
|
|
},
|
|
};
|
|
|
|
modal.open(video);
|
|
|
|
const stage = document.querySelector(".video-modal__video");
|
|
assert.ok(stage, "video stage should exist");
|
|
assert.equal(stage.dataset.visualState, "blurred");
|
|
|
|
const overlay = document.querySelector("[data-moderation-bar]");
|
|
assert.ok(overlay, "moderation overlay should be rendered");
|
|
assert.equal(overlay.hasAttribute("hidden"), false);
|
|
|
|
const badge = overlay.querySelector("[data-moderation-badge='true']");
|
|
assert.ok(badge, "moderation badge should exist");
|
|
assert.equal(badge.dataset.moderationState, "trusted-mute");
|
|
|
|
modal.close();
|
|
});
|
|
} finally {
|
|
await cleanup();
|
|
}
|
|
});
|