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]>
233 lines
8.7 KiB
TypeScript
233 lines
8.7 KiB
TypeScript
import { expect, test } from "./helpers/instrumentedTest";
|
|
|
|
test.describe("runtime utility module coverage", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto("/docs/kitchen-sink.html?__test__=1", {
|
|
waitUntil: "networkidle",
|
|
});
|
|
});
|
|
|
|
test("exercises search filter parsing and serialization", async ({ page }) => {
|
|
const result = await page.evaluate(async () => {
|
|
const { parseFilterQuery, serializeFiltersToQuery } = await import(
|
|
"/js/search/searchFilters.js"
|
|
);
|
|
|
|
// 9afbc0cb ("Decode npub authors to hex") made the author filter validate
|
|
// its value, because npub-form authors silently matched nothing. The old
|
|
// fixture used `author:abc123`, which is neither a decodable npub nor
|
|
// 64-char hex, so the filter is now (correctly) rejected and
|
|
// authorPubkeys comes back empty. Use a real pubkey to exercise the
|
|
// success path, and pin the rejection separately below.
|
|
const AUTHOR_HEX = "a".repeat(64);
|
|
|
|
const parsed = parseFilterQuery(
|
|
`author:${AUTHOR_HEX} tag:#music,nostr kind:30078 relay:wss://relay.example after:2024-01-02 before:1707000000 duration:>=1.5m has:magnet nsfw:safe "exact phrase" looseTerm`,
|
|
);
|
|
|
|
const withErrors = parseFilterQuery(
|
|
"duration:oops has:bad unknown:value before:not-a-date author:abc123",
|
|
);
|
|
|
|
const serialized = serializeFiltersToQuery(parsed.filters);
|
|
|
|
return {
|
|
parsed,
|
|
withErrors,
|
|
serialized,
|
|
};
|
|
});
|
|
|
|
expect(result.parsed.filters.authorPubkeys).toEqual(["a".repeat(64)]);
|
|
expect(result.parsed.filters.tags).toEqual(["music", "nostr"]);
|
|
expect(result.parsed.filters.kind).toBe(30078);
|
|
expect(result.parsed.filters.relay).toBe("wss://relay.example");
|
|
expect(result.parsed.filters.duration.minSeconds).toBe(90);
|
|
expect(result.parsed.filters.hasMagnet).toBe(true);
|
|
expect(result.parsed.filters.nsfw).toBe("false");
|
|
expect(result.parsed.text).toContain("exact phrase");
|
|
expect(result.parsed.text).toContain("looseTerm");
|
|
|
|
expect(result.withErrors.errors.length).toBeGreaterThanOrEqual(3);
|
|
expect(result.withErrors.errors.some((e: any) => /Duration/.test(e.message))).toBe(true);
|
|
expect(result.withErrors.errors.some((e: any) => /Has filter/.test(e.message))).toBe(true);
|
|
expect(result.withErrors.errors.some((e: any) => /Date value/.test(e.message))).toBe(true);
|
|
// An undecodable author must be reported rather than silently dropped.
|
|
expect(
|
|
result.withErrors.errors.some((e: any) => /Could not decode author/.test(e.message)),
|
|
).toBe(true);
|
|
expect(result.withErrors.filters.authorPubkeys).toEqual([]);
|
|
|
|
expect(result.serialized).toContain(`author:${"a".repeat(64)}`);
|
|
expect(result.serialized).toContain("tag:music");
|
|
expect(result.serialized).toContain("kind:30078");
|
|
expect(result.serialized).toContain("has:magnet");
|
|
});
|
|
|
|
test("exercises video note payload normalization and error mapping", async ({ page }) => {
|
|
const result = await page.evaluate(async () => {
|
|
const {
|
|
normalizeVideoNotePayload,
|
|
VIDEO_NOTE_ERROR_CODES,
|
|
getVideoNoteErrorMessage,
|
|
} = await import("/js/services/videoNotePayload.js");
|
|
|
|
const invalid = normalizeVideoNotePayload({
|
|
title: "",
|
|
url: "http://insecure.example/video.mp4",
|
|
});
|
|
|
|
const normalized = normalizeVideoNotePayload({
|
|
legacyFormData: {
|
|
title: " Coverage Video ",
|
|
url: "https://cdn.example/video.mp4 ",
|
|
magnet:
|
|
"magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567",
|
|
ws: "https://webseed.example/video.mp4",
|
|
xs: "https://cdn.example/video.torrent",
|
|
mode: "DEV",
|
|
isPrivate: true,
|
|
isNsfw: true,
|
|
isForKids: true,
|
|
storageProvider: "r2",
|
|
fileSha256:
|
|
"ABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCDEFABCD",
|
|
originalFileSha256:
|
|
"00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF",
|
|
},
|
|
nip71: {
|
|
summary: " summary text ",
|
|
publishedAt: "2024-05-01T12:00:00Z",
|
|
duration: "120",
|
|
hashtags: ["nostr", " video "],
|
|
references: [" https://example.com/ref "],
|
|
textTracks: [
|
|
{
|
|
url: " https://example.com/captions.vtt ",
|
|
type: " subtitles ",
|
|
language: " en ",
|
|
},
|
|
],
|
|
segments: [{ start: "0", end: "30", title: " Intro " }],
|
|
participants: [
|
|
{
|
|
pubkey:
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
relay: " wss://relay.example ",
|
|
},
|
|
],
|
|
imeta: [
|
|
{
|
|
m: " VIDEO/MP4 ",
|
|
url: "https://cdn.example/video.mp4",
|
|
image: [" https://cdn.example/thumb.jpg "],
|
|
duration: "98",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
return {
|
|
invalid,
|
|
normalized,
|
|
invalidUrlCode: VIDEO_NOTE_ERROR_CODES.INVALID_URL_PROTOCOL,
|
|
invalidUrlMessage: getVideoNoteErrorMessage(
|
|
VIDEO_NOTE_ERROR_CODES.INVALID_URL_PROTOCOL,
|
|
),
|
|
fallbackMessage: getVideoNoteErrorMessage("unknown"),
|
|
};
|
|
});
|
|
|
|
expect(result.invalid.errors).toContain(result.invalidUrlCode);
|
|
expect(result.invalid.errors).toContain("missing_title");
|
|
expect(result.invalidUrlMessage).toMatch(/HTTPS/i);
|
|
expect(result.fallbackMessage).toMatch(/Unable to submit video/i);
|
|
|
|
const legacy = result.normalized.payload.legacyFormData;
|
|
expect(legacy.title).toBe("Coverage Video");
|
|
expect(legacy.mode).toBe("dev");
|
|
expect(legacy.isPrivate).toBe(true);
|
|
expect(legacy.isNsfw).toBe(true);
|
|
expect(legacy.isForKids).toBe(false);
|
|
expect(legacy.storagePointer).toContain("r2:");
|
|
expect(legacy.fileSha256).toHaveLength(64);
|
|
expect(legacy.originalFileSha256).toHaveLength(64);
|
|
expect(legacy.magnet).toContain("magnet:?xt=urn:btih:");
|
|
expect(legacy.ws).toContain("https://webseed.example/video.mp4");
|
|
expect(legacy.xs).toContain("https://cdn.example/video.torrent");
|
|
|
|
const nip71 = result.normalized.payload.nip71;
|
|
expect(nip71.summary).toBe("summary text");
|
|
expect(nip71.duration).toBe(120);
|
|
expect(nip71.imeta[0].m).toBe("video/mp4");
|
|
expect(nip71.hashtags).toEqual(["nostr", "video"]);
|
|
expect(nip71.segments[0].start).toBe(0);
|
|
expect(nip71.participants[0].relay).toBe("wss://relay.example");
|
|
});
|
|
|
|
test("exercises attachment tag parsing and attachment descriptions", async ({
|
|
page,
|
|
}) => {
|
|
const result = await page.evaluate(async () => {
|
|
const {
|
|
ATTACHMENT_KIND,
|
|
parseAttachmentTags,
|
|
extractAttachmentsFromMessage,
|
|
formatAttachmentSize,
|
|
describeAttachment,
|
|
} = await import("/js/attachments/attachmentUtils.js");
|
|
|
|
const parsed = parseAttachmentTags([
|
|
["x", "A".repeat(64)],
|
|
["url", "https://cdn.example/file.bin"],
|
|
["name", "manual.pdf"],
|
|
["type", "application/pdf"],
|
|
["size", "2048"],
|
|
["k", "secret"],
|
|
]);
|
|
|
|
const noSource = parseAttachmentTags([["name", "nameless"]]);
|
|
const extracted = extractAttachmentsFromMessage({
|
|
message: {
|
|
kind: ATTACHMENT_KIND,
|
|
tags: [["x", "b".repeat(64)], ["url", "https://cdn.example/second.bin"]],
|
|
},
|
|
});
|
|
const skipped = extractAttachmentsFromMessage({
|
|
event: { kind: 1, tags: [["x", "c".repeat(64)]] },
|
|
});
|
|
|
|
return {
|
|
parsed,
|
|
noSource,
|
|
extractedLength: extracted.length,
|
|
extractedHash: extracted[0]?.x,
|
|
skippedLength: skipped.length,
|
|
sizeBytes: formatAttachmentSize(999),
|
|
sizeKilobytes: formatAttachmentSize(2048),
|
|
sizeMegabytes: formatAttachmentSize(1048576),
|
|
describedName: describeAttachment(parsed),
|
|
describedType: describeAttachment({ type: "image/png" }),
|
|
describedFallback: describeAttachment(null),
|
|
};
|
|
});
|
|
|
|
expect(result.parsed.x).toBe("a".repeat(64));
|
|
expect(result.parsed.url).toBe("https://cdn.example/file.bin");
|
|
expect(result.parsed.size).toBe(2048);
|
|
expect(result.parsed.encrypted).toBe(true);
|
|
expect(result.noSource).toBeNull();
|
|
|
|
expect(result.extractedLength).toBe(1);
|
|
expect(result.extractedHash).toBe("b".repeat(64));
|
|
expect(result.skippedLength).toBe(0);
|
|
|
|
expect(result.sizeBytes).toBe("999 B");
|
|
expect(result.sizeKilobytes).toBe("2.0 KB");
|
|
expect(result.sizeMegabytes).toBe("1.0 MB");
|
|
expect(result.describedName).toBe("Attachment: manual.pdf");
|
|
expect(result.describedType).toBe("Attachment (image/png)");
|
|
expect(result.describedFallback).toBe("Attachment");
|
|
});
|
|
});
|