mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 19:36:04 +00:00
* perf(studio): settle the edit accuracy bench on frames and network, not a fixed window settled() waited for the box and the preview frames to hold still for 500 ms, 7 to 15 times a case. It now resolves once they read the same on 3 animation frames in a row while the Studio page has no request in flight (the event stream and server-rendered timeline thumbnails excepted) and the server has announced every project file written since its last file-change event, so a save, a preview reload or a reload the event starts still holds it open. EDIT_ACCURACY_STILL_MS restores the fixed window with no network signal. Also polls studio_seek every 50 ms instead of 250 ms while Studio opens. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * perf(studio): keep one producer Chrome open across edit accuracy renders Every render launched and closed its own producer Chrome. The run now holds a lease on the engine's pooled browser (a capture session with the renders' launch settings and its page closed), so each render opens a page in that browser instead. Each render still gets its own page and file server, and clears the browser cache first. A held browser that failed to launch or whose Chrome died is dropped and held again, never reused. Studio's server stays per case: it serves one project folder, stamps it on start and keeps that folder's undo history open, so switching folders under it would leak history between cases. Its start is polled every 50 ms instead of 200 ms. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(studio): import render.mjs at the top of the edit accuracy render test Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(studio): restart the settle window when a busy request's frame goes away Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * style(studio): format the edit accuracy settle test Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(studio): seek the edit bench only after Studio binds the timeline openStudio now polls every 50 ms, so after a reload its first studio_seek often lands before the runtime binds the timeline (Studio still reports duration 0, but the playhead moves). The bind then replays the playhead from near 0 (core init.ts progress(0.0001) then totalTime). A tween that starts on the playhead was already initialised by the early seek, so GSAP skips its first keyframe. The preview then holds a box no fresh seek or render shows. In resize-fromto-px-r0-nested-z100-on that box is 90 px off, and it persists until the next seek. Wait for studio_look to report a duration before seeking. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
168 lines
6.6 KiB
JavaScript
168 lines
6.6 KiB
JavaScript
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
STILL_FRAMES,
|
|
heldStill,
|
|
networkBusy,
|
|
seekBound,
|
|
swapPending,
|
|
unsettledBy,
|
|
} from "./case.mjs";
|
|
import { heldSize } from "./sequences.mjs";
|
|
|
|
describe("settling on the shown preview", () => {
|
|
const read = (pending, x = 0, frames = "a") => ({
|
|
pending,
|
|
frames,
|
|
m: {
|
|
visible: [
|
|
[x, 0],
|
|
[x + 1, 0],
|
|
[x + 1, 1],
|
|
[x, 1],
|
|
],
|
|
},
|
|
});
|
|
|
|
it("keeps waiting while a shadow preview is loading, and restarts once it is promoted", () => {
|
|
expect(unsettledBy(read(false), read(false))).toBe(false);
|
|
expect(unsettledBy(read(false), read(true))).toBe(true);
|
|
expect(unsettledBy(read(true), read(false))).toBe(true);
|
|
expect(unsettledBy(read(false), read(false, 0.02))).toBe(true);
|
|
});
|
|
|
|
const frame = (url, shown, holds) => ({
|
|
url: () => url,
|
|
frameElement: async () => ({ evaluate: async () => shown }),
|
|
$: async () => (holds ? {} : null),
|
|
});
|
|
const keys = { times: [0, 3] };
|
|
const page = (...frames) => ({ frames: () => frames });
|
|
const swapping = page(frame("/preview/a", true, true), frame("/preview/a?_t=1", false, true));
|
|
|
|
it("calls a swap pending only for a hidden preview that holds the target", async () => {
|
|
expect(await swapPending({ page: page(frame("/preview/a", true, true)), keys })).toBe(false);
|
|
expect(await swapPending({ page: swapping, keys })).toBe(true);
|
|
expect(await swapPending({ page: page(frame("/preview/a?_t=1", false, false)), keys })).toBe(
|
|
false,
|
|
);
|
|
expect(await swapPending({ page: page(frame("/studio", false, true)), keys })).toBe(false);
|
|
});
|
|
|
|
it("never waits on a swap in a case without keyframes, so its undo keeps main's timing", async () => {
|
|
expect(await swapPending({ page: swapping })).toBe(false);
|
|
expect(await swapPending({ page: swapping, keys: undefined, selector: "#other" })).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("settling on the page's network", () => {
|
|
const read = (busy, activity) => ({
|
|
pending: false,
|
|
frames: "a",
|
|
m: { visible: [[0, 0]] },
|
|
net: { busy, activity },
|
|
});
|
|
|
|
it("restarts on a request in flight or any network activity since the window began", () => {
|
|
expect(unsettledBy(read(false, 3), read(false, 3))).toBe(false);
|
|
expect(unsettledBy(read(false, 3), read(true, 3))).toBe(true);
|
|
expect(unsettledBy(read(false, 3), read(false, 4))).toBe(true);
|
|
});
|
|
|
|
it("holds after STILL_FRAMES quiet reads, or after the fixed window when one is set", () => {
|
|
const since = Date.now();
|
|
expect(heldStill(read(false, 0), STILL_FRAMES - 1, since, null)).toBe(false);
|
|
expect(heldStill(read(false, 0), STILL_FRAMES, since, null)).toBe(true);
|
|
expect(heldStill(read(true, 0), STILL_FRAMES, since, null)).toBe(false);
|
|
expect(heldStill({ ...read(false, 0), pending: true }, STILL_FRAMES, since, null)).toBe(false);
|
|
expect(heldStill(read(false, 0), 100, since, 500)).toBe(false);
|
|
expect(heldStill(read(false, 0), 0, since - 500, 500)).toBe(true);
|
|
});
|
|
|
|
it("restarts a window that began busy once its request's frame is gone", () => {
|
|
const request = { frame: () => ({ detached: false }) };
|
|
const net = {
|
|
inflight: new Set([request]),
|
|
activity: 0,
|
|
announced: new Map(),
|
|
since: Date.now(),
|
|
};
|
|
const ctx = { dir: tmpdir(), files: [], net };
|
|
const start = { ...read(false, 0), net: networkBusy(ctx) };
|
|
expect(start.net.busy).toBe(true);
|
|
request.frame = () => null;
|
|
const now = { ...read(false, 0), net: networkBusy(ctx) };
|
|
expect(now.net.busy).toBe(false);
|
|
expect(unsettledBy(start, now)).toBe(true);
|
|
});
|
|
|
|
it("waits for requests in live frames and for the server to announce each written file", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "edit-bench-net-"));
|
|
try {
|
|
writeFileSync(join(dir, "index.html"), "");
|
|
const since = Date.now() / 1000;
|
|
utimesSync(join(dir, "index.html"), since - 10, since - 10);
|
|
const request = (detached) => ({ frame: () => (detached === null ? null : { detached }) });
|
|
const live = request(false);
|
|
const net = {
|
|
inflight: new Set([live, request(true), request(null)]),
|
|
activity: 7,
|
|
announced: new Map(),
|
|
since: since * 1000,
|
|
};
|
|
const ctx = { dir, files: ["index.html"], net };
|
|
expect(networkBusy(ctx)).toEqual({ busy: true, activity: 9 });
|
|
expect([...net.inflight]).toEqual([live]);
|
|
net.inflight.clear();
|
|
expect(networkBusy(ctx).busy).toBe(false);
|
|
utimesSync(join(dir, "index.html"), since + 5, since + 5);
|
|
expect(networkBusy(ctx).busy).toBe(true);
|
|
net.announced.set("index.html", since * 1000 + 6000);
|
|
expect(networkBusy(ctx).busy).toBe(false);
|
|
} finally {
|
|
rmSync(dir, { recursive: true });
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("seeking to the playhead after a reload", () => {
|
|
it("seeks only once Studio reports the composition's duration, so the timeline bind cannot replay it", async () => {
|
|
// Studio before its timeline bind: a seek still moves the playhead, but the duration reads 0.
|
|
const calls = [];
|
|
let looks = 0;
|
|
const studio = {
|
|
studio_look: () => ({ ok: true, duration: ++looks > 2 ? 4 : 0 }),
|
|
studio_seek: ({ time }) => ({ ok: true, playhead: time, duration: looks > 2 ? 4 : 0 }),
|
|
};
|
|
globalThis.window = {
|
|
__editBench: { call: (name, args) => (calls.push(name), studio[name](args)) },
|
|
};
|
|
const host = { evaluate: async () => true, boundingBox: async () => ({ width: 1, height: 1 }) };
|
|
const preview = { url: () => "/preview", $: async () => ({}), frameElement: async () => host };
|
|
const page = { evaluate: async (fn, ...args) => fn(...args), frames: () => [preview] };
|
|
try {
|
|
expect(await seekBound({ page, playhead: 2 })).toMatchObject({ playhead: 2, duration: 4 });
|
|
expect(calls).toEqual(["studio_look", "studio_look", "studio_look", "studio_seek"]);
|
|
} finally {
|
|
delete globalThis.window;
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("the size auto-record keys hold", () => {
|
|
const keys = new Map([
|
|
[3, { width: 440, height: 294 }],
|
|
[2, { width: 380, height: 250 }],
|
|
]);
|
|
|
|
it("holds the first key before it and the last after it, and leaves eased spans unscored", () => {
|
|
expect(heldSize(keys, 1)).toEqual({ width: 380, height: 250 });
|
|
expect(heldSize(keys, 3)).toEqual({ width: 440, height: 294 });
|
|
expect(heldSize(keys, 5)).toEqual({ width: 440, height: 294 });
|
|
expect(heldSize(keys, 2.5)).toBeUndefined();
|
|
expect(heldSize(new Map(), 1)).toBeUndefined();
|
|
});
|
|
});
|