mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-09-21 13:31:42 +00:00
feat(worker): cross-channel CRC-fingerprint repost check for the forward path
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
const candidate = {
|
||||
id: "pkg-1", archiveType: "ZIP", fileName: "a.zip", fileCount: 3, fileSize: 100n,
|
||||
destMessageId: 1n, destMessageIds: [1n], destChannel: { telegramId: 999n },
|
||||
};
|
||||
|
||||
vi.mock("../db/queries.js", () => ({
|
||||
findFingerprintDedupCandidates: vi.fn(async () => [candidate]),
|
||||
}));
|
||||
const resolveMock = vi.fn(async (..._args: unknown[]) => [{ path: "x", fileName: "x", extension: null, compressedSize: 1n, uncompressedSize: 1n, crc32: "AAAA" }]);
|
||||
const compareMock = vi.fn();
|
||||
vi.mock("../provenance-backfill.js", () => ({
|
||||
resolveCandidateFingerprintEntries: (...args: unknown[]) => resolveMock(...args),
|
||||
compareFingerprints: (...args: unknown[]) => compareMock(...args),
|
||||
}));
|
||||
|
||||
import { checkFingerprintRepost } from "./forward-repost-check.js";
|
||||
import type { FileEntry } from "./zip-reader.js";
|
||||
|
||||
const newEntries: FileEntry[] = [{ path: "x", fileName: "x", extension: null, compressedSize: 1n, uncompressedSize: 1n, crc32: "AAAA" }];
|
||||
|
||||
describe("checkFingerprintRepost", () => {
|
||||
it("reports a duplicate when a candidate's fingerprint matches", async () => {
|
||||
compareMock.mockReturnValueOnce("match");
|
||||
const result = await checkFingerprintRepost({} as never, newEntries, "a.zip", 100n);
|
||||
expect(result).toEqual({ isDuplicate: true, matchedPackageId: "pkg-1" });
|
||||
});
|
||||
|
||||
it("reports no duplicate when no candidate matches", async () => {
|
||||
compareMock.mockReturnValueOnce("mismatch");
|
||||
const result = await checkFingerprintRepost({} as never, newEntries, "a.zip", 100n);
|
||||
expect(result).toEqual({ isDuplicate: false, matchedPackageId: null });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user