droboticflow/tests/frontend/video-preview.test.mjs

127 lines
4.8 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import {
buildBrowserPlayableVideoURL,
isObjectStorageContentURL,
isHumanEvidenceContentURL,
isPackageContentURL,
isRunArtifactContentURL,
isSourceDataContentURL,
} from "../../src/lib/video-preview.js";
test("recognizes source data content urls", () => {
assert.equal(
isSourceDataContentURL("/api/source-data/collections/run-1/BJ_001/content?relativePath=DJI_001%2FDJI_0001_D.mp4"),
true,
);
assert.equal(isSourceDataContentURL("https://example.com/video.mp4"), false);
});
test("recognizes package content urls", () => {
assert.equal(
isPackageContentURL("/api/packages/run-1/DJI_0001_D_clip001_package/content?relativePath=DJI_0001_D_clip001.mp4"),
true,
);
assert.equal(isPackageContentURL("https://example.com/video.mp4"), false);
});
test("recognizes object storage content urls", () => {
assert.equal(
isObjectStorageContentURL(
"/api/object-storage/content?connectionId=storage-1&bucket=datastorage&key=demo%2Fvideo.mp4",
),
true,
);
assert.equal(isObjectStorageContentURL("https://example.com/video.mp4"), false);
});
test("recognizes run artifact content urls", () => {
assert.equal(isRunArtifactContentURL("/api/runs/run-1/artifacts/artifact-video/content"), true);
assert.equal(isRunArtifactContentURL("/api/runs/run-1/lineage"), false);
assert.equal(isRunArtifactContentURL("https://example.com/video.mp4"), false);
});
test("recognizes role-scoped human evidence content urls", () => {
assert.equal(
isHumanEvidenceContentURL("/api/plugins/human-loop/items/item-1/evidence/headpose-render/content"),
true,
);
assert.equal(isHumanEvidenceContentURL("/api/human-items/item-1/subject-content"), false);
assert.equal(isHumanEvidenceContentURL("/api/human-items/item-1/evidence/headpose-render/content"), true);
assert.equal(
isHumanEvidenceContentURL("/api/human-items/item-1/evidence/slice-directory/members/left-video/content"),
true,
);
assert.equal(isHumanEvidenceContentURL("/api/plugins/human-loop/items/item-1"), false);
assert.equal(isHumanEvidenceContentURL("/api/human-items/item-1"), false);
});
test("keeps source data video preview urls direct", () => {
assert.equal(
buildBrowserPlayableVideoURL(
"/api/source-data/collections/run-1/BJ_001/content?relativePath=DJI_001%2FDJI_0001_D.mp4",
),
"/api/source-data/collections/run-1/BJ_001/content?relativePath=DJI_001%2FDJI_0001_D.mp4",
);
});
test("keeps package video preview urls direct", () => {
assert.equal(
buildBrowserPlayableVideoURL(
"/api/packages/run-1/DJI_0001_D_clip001_package/content?relativePath=DJI_0001_D_clip001.mp4",
),
"/api/packages/run-1/DJI_0001_D_clip001_package/content?relativePath=DJI_0001_D_clip001.mp4",
);
});
test("keeps object storage video preview urls direct", () => {
assert.equal(
buildBrowserPlayableVideoURL(
"/api/object-storage/content?connectionId=storage-1&bucket=datastorage&key=demo%2Fvideo.mp4",
),
"/api/object-storage/content?connectionId=storage-1&bucket=datastorage&key=demo%2Fvideo.mp4",
);
});
test("keeps run artifact video preview urls direct", () => {
assert.equal(
buildBrowserPlayableVideoURL("/api/runs/run-1/artifacts/artifact-video/content"),
"/api/runs/run-1/artifacts/artifact-video/content",
);
});
test("keeps reviewed prelabel evidence urls direct", () => {
const url = "/api/plugins/human-loop/items/item-1/evidence/headpose-render/content";
assert.equal(buildBrowserPlayableVideoURL(url), url);
});
test("keeps current human item video endpoints direct", () => {
const subjectURL = "/api/human-items/item-1/subject-content";
const evidenceURL = "/api/human-items/item-1/evidence/headpose-render/content";
const memberURL = "/api/human-items/item-1/evidence/slice-directory/members/left-video/content";
assert.equal(buildBrowserPlayableVideoURL(subjectURL), subjectURL);
assert.equal(buildBrowserPlayableVideoURL(evidenceURL), evidenceURL);
assert.equal(buildBrowserPlayableVideoURL(memberURL), memberURL);
});
test("routes bos urls through the object storage proxy without transcode", () => {
assert.equal(
buildBrowserPlayableVideoURL("bos://datastorage/demo/video.mp4"),
"/api/object-storage/content?bucket=datastorage&key=demo%2Fvideo.mp4",
);
});
test("strips legacy browser transcode flag", () => {
assert.equal(
buildBrowserPlayableVideoURL(
"/api/source-data/collections/run-1/BJ_001/content?relativePath=DJI_001%2FDJI_0001_D.mp4&transcode=browser",
),
"/api/source-data/collections/run-1/BJ_001/content?relativePath=DJI_001%2FDJI_0001_D.mp4",
);
});
test("leaves non source data urls untouched", () => {
assert.equal(buildBrowserPlayableVideoURL("https://example.com/preview.mp4"), "https://example.com/preview.mp4");
});