import { describe, it, expect } from "vitest"; import { previewPriority } from "./preview"; /** * A preview job is created when its render finishes, so it is always newer than * the renders queued beside it. With the queue ordered by priority then age, * equal priority means every pending render goes first — a batch of ten shots * runs as ten renders and then ten previews, and nothing is reviewable until * the end. */ describe("previewPriority", () => { const URGENT = 20; it("outranks other work of the same priority so a shot finishes end to end", () => { expect(previewPriority(50, 1, URGENT)).toBe(49); }); it("keeps an urgent export's preview urgent", () => { // Urgent renders may claim outside the render window; their previews have // to be able to follow, or the shot stalls one step from being reviewable. expect(previewPriority(20, 1, URGENT)).toBe(19); expect(previewPriority(19, 1, URGENT)).toBeLessThanOrEqual(URGENT); }); it("never promotes a normal job across the urgent line", () => { // 21 - 1 would be 20, quietly granting the preview permission to run // outside the render window that its render never had. expect(previewPriority(21, 1, URGENT)).toBe(21); expect(previewPriority(25, 10, URGENT)).toBe(21); }); it("a boost of zero restores the old phase behaviour", () => { expect(previewPriority(50, 0, URGENT)).toBe(50); }); it("ignores a negative boost and never goes below zero", () => { expect(previewPriority(50, -5, URGENT)).toBe(50); expect(previewPriority(0, 5, URGENT)).toBe(0); }); });