feat(cli): share rendered videos through unified reviews (#7135)

This commit is contained in:
Terence Cho
2026-11-09 16:10:31 -08:00
parent 48a2b4e019
commit b72970cb4a
23 changed files with 1363 additions and 20 deletions
+6 -4
View File
@@ -49,10 +49,11 @@ import { versionSentence } from "./reviewVersionSentences.mjs";
/** `projectId` overrides the recorded review project; `open`: a held video is watched only while the project is open.
* `filesForExport`: the synced snapshot a new version carries, null for
* none.
* none. `allowPending` lets a host treat accepted processing or screening as a successful return.
* @typedef {VersionHooks & { projectPath: string, title: string, client: ReviewClient, put?: typeof putFile,
* sleep?: (ms: number) => Promise<void>, probe?: (file: string) => Promise<VideoFacts | null>, now?: () => number,
* projectId?: string | null, filesForExport?: FilesForRender, fromReview?: FromReview | null }} VersionRequest */
* projectId?: string | null, filesForExport?: FilesForRender, fromReview?: FromReview | null,
* allowPending?: boolean }} VersionRequest */
/** The snapshot of `rendered`, the project as the export was rendered; null when the folder is not that render.
* @typedef {(projectPath: string, rendered: string | null) => Promise<import("./types/reviewWire.js").SnapshotRef | null>}
@@ -640,7 +641,7 @@ async function sendVersion(r, report, source, id, state) {
/** @param {Required<VersionRequest>} r @param {VersionRecord} state
* @param {NonNullable<VersionRecord["pending"]>} pending @param {string} id @param {ExportDTO} done @param {boolean} first */
async function finishRun(r, state, pending, id, done, first) {
if (going(done)) return stillGoing(done);
if (going(done)) return r.allowPending ? null : stillGoing(done);
const failed = await finish(r.projectPath, state, pending, id, done, r.fromReview);
if (!failed) {
const fromReview = pending.reviewSent?.value;
@@ -663,6 +664,7 @@ export async function addVersion(request) {
now: () => Date.now(),
onProgress: () => {},
open: () => true,
allowPending: false,
filesForExport: async () => null,
fromReview: null,
onAdded: () => {},
@@ -755,7 +757,7 @@ async function settleSavedExport(dir, client, fromReview) {
const id = await reviewProjectId(dir);
if (!pending?.videoId || !id || pending.projectId !== id) return;
const done = await client.readExport(id, pending.videoId);
if (going(done)) return;
if (done.status === "upload_pending" || going(done)) return;
const failure = await finish(dir, state, pending, id, done, fromReview);
const key = normalize(dir);
if (failure) failures.set(key, { ...failure, exportKey: exportKeyOf(dir) });
+48 -2
View File
@@ -12,6 +12,7 @@ import {
shareForReview,
reviewRecord,
addVersion,
pendingReviewExport,
reviewVersion,
refreshReviewExport,
putFile,
@@ -146,6 +147,45 @@ test("HTML stamps and generated render metadata do not dirty the shared source",
await writeFile(join(dir, "index.html"), '<div data-hf-id="123">Changed</div>');
assert.notEqual(await projectFingerprint(dir), before);
});
test("a host can accept a version that is still screening when it stops waiting", async (t) => {
const dir = await folder(t);
const api = client();
await shareForReview({ projectPath: dir, title: "Video", client: api, audience: "public" });
await writeFile(join(dir, ".hyperframes/video.mp4"), "video bytes");
bindShareHost({ projectFingerprint: async () => "rendered" });
t.after(() => bindShareHost({ projectFingerprint }));
let video = {
status: "screening",
screening_state: "held",
video_id: "vid",
version_id: "v1",
exported_at: "2026-11-04T00:00:00Z",
};
api.createExport = t.mock.fn(async () => video);
api.readExport = async () => video;
const onAdded = t.mock.fn();
const request = {
projectPath: dir,
title: "Video",
client: api,
probe: async () => ({ width: 1920, height: 1080, duration: 1 }),
open: () => false,
onAdded,
};
assert.ok(await addVersion(request));
assert.equal((await reviewVersion(dir)).held, true);
assert.equal(await addVersion({ ...request, allowPending: true }), null);
assert.equal((await pendingReviewExport(dir)).videoId, "vid");
assert.equal((await reviewVersion(dir)).failure, null);
assert.equal(onAdded.mock.callCount(), 0);
assert.equal(api.createExport.mock.callCount(), 1);
video = { ...video, status: "ready" };
await refreshReviewExport(dir, api);
assert.equal(await pendingReviewExport(dir), null);
assert.equal((await reviewVersion(dir)).last.current, true);
});
const moduleUrl = new URL("../src/index.mjs", import.meta.url).href;
function child(script, args) {
return spawn(process.execPath, ["--input-type=module", "-e", script, ...args], {
@@ -232,13 +272,15 @@ test("status recovery settles distinct video/version IDs without a new upload",
},
}),
);
const saved = await readFile(file, "utf8");
let status = "upload_pending";
let reads = 0;
api.readExport = async (project, video) => {
reads++;
assert.equal(project, "p1");
assert.equal(video, "video-id");
return {
status: "ready",
status,
video_id: video,
version_id: "version-id",
exported_at: "2026-11-04T00:00:00Z",
@@ -248,13 +290,17 @@ test("status recovery settles distinct video/version IDs without a new upload",
assert.equal(reads, 0);
await refreshReviewExport(dir, api);
assert.equal(reads, 1);
assert.equal(await readFile(file, "utf8"), saved);
status = "ready";
await refreshReviewExport(dir, api);
assert.equal(reads, 2);
assert.equal(JSON.parse(await readFile(file, "utf8")).pending, null);
assert.equal(
(await reviewVersion(dir, { latestReadyVersionId: "version-id" })).last.current,
true,
);
await refreshReviewExport(dir, api);
assert.equal(reads, 1);
assert.equal(reads, 2);
});
test("refuses an unconfigured review upload destination before sending the file", async (t) => {
const dir = await folder(t);