mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 00:18:27 +00:00
* fix(cli): read BOM-prefixed JSON files for timeline plans, grades and motion specs * fix(cli): read BOM-prefixed files for render --batch, lambda policy and transcripts * test(cli): drop the batch BOM test #6605 already covers * fix(cli): decodeJsonText is only used inside jsonFlag.ts * fix(cli): drop a fallow suppression the export no longer needs
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { consumeCommandResult } from "../utils/commandResult.js";
|
|
import { readEditPlan, runIds } from "./a2Commands.js";
|
|
|
|
const hooks = vi.hoisted(() => ({ minting: undefined as (() => void) | undefined }));
|
|
vi.mock("@hyperframes/parsers/hf-ids", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("@hyperframes/parsers/hf-ids")>();
|
|
return {
|
|
...actual,
|
|
ensureHfIds: (html: string) => {
|
|
hooks.minting?.();
|
|
return actual.ensureHfIds(html);
|
|
},
|
|
};
|
|
});
|
|
|
|
const dirs: string[] = [];
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("timeline ids", () => {
|
|
it("keeps a save that lands while ids are minted instead of writing over it", async () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "hf-timeline-ids-"));
|
|
dirs.push(dir);
|
|
const indexPath = join(dir, "index.html");
|
|
writeFileSync(
|
|
indexPath,
|
|
`<div data-composition-id="main" data-duration="4"><div id="clip" data-start="0" data-duration="2" data-track-index="0"></div></div>`,
|
|
);
|
|
const save = `<div data-composition-id="main" data-duration="4"><div id="clip" data-start="1" data-duration="2" data-track-index="0"></div></div>`;
|
|
hooks.minting = () => {
|
|
hooks.minting = undefined;
|
|
writeFileSync(indexPath, save);
|
|
};
|
|
const stdout = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
|
|
await runIds({ dir, json: true });
|
|
|
|
expect(readFileSync(indexPath, "utf-8")).toBe(save);
|
|
expect(consumeCommandResult().exitCode).toBe(2);
|
|
expect(JSON.parse(String(stdout.mock.calls.at(-1)?.[0]))).toMatchObject({
|
|
ok: false,
|
|
error: { code: "refused", message: "file changed since the timeline was read" },
|
|
reason: "file changed since the timeline was read",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("timeline apply plan file", () => {
|
|
it("reads an edit plan saved with a UTF-8 BOM", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "hf-timeline-plan-"));
|
|
dirs.push(dir);
|
|
const file = join(dir, "plan.json");
|
|
writeFileSync(file, '\uFEFF[{"op":"trim"}]');
|
|
expect(readEditPlan(file)).toEqual({ ok: true, edits: [{ op: "trim" }] });
|
|
});
|
|
});
|