mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
* fix(cli): batch render outputs stay inside the --output folder A row value may still name a subfolder of the folder written before the template's first placeholder, but a value that resolves outside it stops the batch before any folder is made or file is written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): project text shows control characters as visible escapes compositions, lint, snapshot and info --media print composition ids, sources, element ids, lint messages and media paths through one helper that writes C0, DEL and C1 control characters out as \xNN, so they reach the terminal as text. The CLI's own colors are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(studio-server): waveform and peaks key one cache entry per file and refuse other sites Both caches are keyed on the resolved project-relative path, so another spelling of the same file (a doubled or trailing slash) reads the cached peaks instead of decoding again. Waveform and peaks requests that another site makes are refused the way thumbnail requests already are; the Studio page asks for both as itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(studio-server): preview stills run at most four at a time A video's stand-in still is made through a small job queue: four at once, 32 more waiting, and a 503 with Retry-After beyond that. A waiting request whose client goes away leaves the queue without starting ffmpeg. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): batch output folder check keeps backslash names and row-named paths A trailing backslash counts as a separator only where it is one, and the check compares path segments. A template that starts with a placeholder names no folder, so each row's value is the whole output path as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(cli): lint header shows control characters in file names as escapes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(studio-server): a finished or in-progress still never waits for a still slot Only a still that is neither on disk nor already being made takes one of the four slots, through a hook resolveStill gives the route. Waiters queue without a cap and nothing answers 503, since a poster is never asked for again. A waiter whose client leaves still never starts ffmpeg; a request that shared that waiter's still tries again on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: raise the studio-server packed budget to 172000 main already packs about 170 KB against a 168500 budget; the request guards, still slots and cache-key change here add about 550 bytes. * fix(core,studio-server): a preview served to another site offers no editing port When the Studio server answers a preview document to another site's request, it now marks the document, and the runtime's editing agent ignores every connect in a marked document. The Studio's own frames, which load the preview from the same origin, keep the editing port. The marked copy carries no ETag, so it is never revalidated in place of the unmarked one. * fix(studio-server): a media still stops when no request waits on it Each still job now counts the requests waiting on it. A request whose connection closes leaves the job, and when the last one leaves, the job's ffmpeg is killed and the job is forgotten, so the next request starts afresh. A caller that passes no signal keeps the job running, and a request that has already closed starts nothing. * test(studio-server): group the still cancellation tests after the real-ffmpeg still test * fix(studio-server): a preview framed by another site is never revalidated A frame load of a preview from another site now drops If-None-Match and If-Modified-Since before the route answers, so it always gets a fresh, marked document instead of a 304 that could reuse the unmarked copy a browser cached for the Studio's own page on the same site. Subresource loads keep their validators. * fix(cli): check findings and keyframes headers show control characters as escapes check prints each finding's message, source file, selector and fix hint, and keyframes prints each composition's name and source, through terminalText. * test(studio-server): a request sharing an abandoned still waiter gets its still * chore(studio-server): raise the unpacked size budget for the still job slots and cross-site guards * fix(cli): layout and contrast lines in check show control characters as escapes --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
304 lines
10 KiB
TypeScript
304 lines
10 KiB
TypeScript
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||
import { tmpdir } from "node:os";
|
||
import { join } from "node:path";
|
||
import { describe, expect, it, onTestFinished } from "vitest";
|
||
import type { HyperframeLintFinding } from "@hyperframes/core/lint";
|
||
import { formatLintFindings, formatLintStartupMessage } from "./lintFormat.js";
|
||
import { lintProject, type ProjectLintResult } from "./lintProject.js";
|
||
|
||
function finding(
|
||
severity: HyperframeLintFinding["severity"],
|
||
overrides: Partial<HyperframeLintFinding> = {},
|
||
): HyperframeLintFinding {
|
||
return { code: `${severity}-code`, severity, message: `${severity} message`, ...overrides };
|
||
}
|
||
|
||
function project(
|
||
files: Array<{ file: string; findings: HyperframeLintFinding[] }>,
|
||
): ProjectLintResult {
|
||
const all = files.flatMap((f) => f.findings);
|
||
const count = (severity: HyperframeLintFinding["severity"]) =>
|
||
all.filter((f) => f.severity === severity).length;
|
||
return {
|
||
results: files.map(({ file, findings }) => ({
|
||
file,
|
||
contentHash: "test",
|
||
result: {
|
||
ok: findings.every((f) => f.severity !== "error"),
|
||
errorCount: findings.filter((f) => f.severity === "error").length,
|
||
warningCount: findings.filter((f) => f.severity === "warning").length,
|
||
infoCount: findings.filter((f) => f.severity === "info").length,
|
||
findings,
|
||
},
|
||
})),
|
||
totalErrors: count("error"),
|
||
totalWarnings: count("warning"),
|
||
totalInfos: count("info"),
|
||
};
|
||
}
|
||
|
||
describe("formatLintFindings", () => {
|
||
it("shows control characters in project-derived text as visible escapes", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "a\u001b]0;title\u0007.html",
|
||
findings: [
|
||
finding("error", {
|
||
elementId: "x\u001b[2K",
|
||
message: "bad \u009b2J\rclean",
|
||
fixHint: "fix \u001b]52;c;Y2xpcA==\u0007",
|
||
line: 3,
|
||
}),
|
||
],
|
||
},
|
||
]),
|
||
);
|
||
const out = lines.join("\n");
|
||
for (const control of ["\u0007", "\r", "\u001b", "\u009b"]) expect(out).not.toContain(control);
|
||
expect(out).toContain("[x\\x1b[2K]");
|
||
expect(out).toContain("bad \\x9b2J\\x0dclean");
|
||
expect(out).toContain("Fix: fix \\x1b]52;c;Y2xpcA==\\x07");
|
||
expect(out).toContain("[a\\x1b]0;title\\x07.html:3]");
|
||
});
|
||
|
||
it("returns no lines when no file has findings", () => {
|
||
expect(formatLintFindings(project([{ file: "index.html", findings: [] }]))).toEqual([]);
|
||
});
|
||
|
||
it("renders code, message, and elementId without a file label for a single file", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [
|
||
finding("error", {
|
||
code: "missing-timeline",
|
||
message: "no timeline registered",
|
||
elementId: "main",
|
||
}),
|
||
],
|
||
},
|
||
]),
|
||
);
|
||
|
||
expect(lines).toHaveLength(1);
|
||
expect(lines[0]).toContain("✗");
|
||
expect(lines[0]).toContain("missing-timeline");
|
||
expect(lines[0]).toContain("[main]");
|
||
expect(lines[0]).toContain("no timeline registered");
|
||
expect(lines[0]).not.toContain("index.html");
|
||
});
|
||
|
||
it("labels each finding with its file when more than one file has results", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{ file: "index.html", findings: [finding("error")] },
|
||
{ file: "compositions/scene.html", findings: [finding("warning")] },
|
||
]),
|
||
);
|
||
|
||
expect(lines).toHaveLength(2);
|
||
expect(lines[0]).toContain("[index.html]");
|
||
expect(lines[1]).toContain("[compositions/scene.html]");
|
||
});
|
||
|
||
it("hides the elementId when showElementId is false", () => {
|
||
const result = project([
|
||
{ file: "index.html", findings: [finding("error", { elementId: "main" })] },
|
||
]);
|
||
|
||
const lines = formatLintFindings(result, { showElementId: false });
|
||
expect(lines[0]).not.toContain("[main]");
|
||
});
|
||
|
||
it("marks warnings with their own prefix and skips info findings by default", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("warning"), finding("info")],
|
||
},
|
||
]),
|
||
);
|
||
|
||
expect(lines).toHaveLength(1);
|
||
expect(lines[0]).toContain("⚠");
|
||
expect(lines[0]).toContain("warning message");
|
||
});
|
||
|
||
it("includes info findings when verbose", () => {
|
||
const lines = formatLintFindings(
|
||
project([{ file: "index.html", findings: [finding("info")] }]),
|
||
{ verbose: true },
|
||
);
|
||
|
||
expect(lines).toHaveLength(1);
|
||
expect(lines[0]).toContain("ℹ");
|
||
expect(lines[0]).toContain("info message");
|
||
});
|
||
|
||
it("keeps the input order by default", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("warning"), finding("error")],
|
||
},
|
||
]),
|
||
);
|
||
|
||
expect(lines).toHaveLength(2);
|
||
expect(lines[0]).toContain("warning message");
|
||
expect(lines[1]).toContain("error message");
|
||
});
|
||
|
||
it("groups errors before warnings per file when errorsFirst is set", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("warning"), finding("error")],
|
||
},
|
||
]),
|
||
{ errorsFirst: true },
|
||
);
|
||
|
||
expect(lines).toHaveLength(2);
|
||
expect(lines[0]).toContain("error message");
|
||
expect(lines[1]).toContain("warning message");
|
||
});
|
||
|
||
it("places info findings last under errorsFirst with verbose", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("info"), finding("warning"), finding("error")],
|
||
},
|
||
]),
|
||
{ errorsFirst: true, verbose: true },
|
||
);
|
||
|
||
expect(lines).toHaveLength(3);
|
||
expect(lines[0]).toContain("error message");
|
||
expect(lines[1]).toContain("warning message");
|
||
expect(lines[2]).toContain("info message");
|
||
});
|
||
|
||
it("appends an indented fix hint line directly after its finding", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("error", { fixHint: "add data-composition-id" }), finding("warning")],
|
||
},
|
||
]),
|
||
);
|
||
|
||
expect(lines).toHaveLength(3);
|
||
expect(lines[0]).toContain("error message");
|
||
expect(lines[1]).toContain("Fix: add data-composition-id");
|
||
expect(lines[2]).toContain("warning message");
|
||
});
|
||
|
||
it("appends a summary line with totals when showSummary is set", () => {
|
||
const lines = formatLintFindings(
|
||
project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("error"), finding("error"), finding("warning")],
|
||
},
|
||
]),
|
||
{ showSummary: true },
|
||
);
|
||
|
||
expect(lines.at(-2)).toBe("");
|
||
expect(lines.at(-1)).toContain("2 error(s), 1 warning(s)");
|
||
});
|
||
|
||
it("includes the info count in the summary only when verbose", () => {
|
||
const result = project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("error"), finding("info")],
|
||
},
|
||
]);
|
||
|
||
const quiet = formatLintFindings(result, { showSummary: true });
|
||
expect(quiet.at(-1)).not.toContain("info(s)");
|
||
|
||
const verbose = formatLintFindings(result, { showSummary: true, verbose: true });
|
||
expect(verbose.at(-1)).toContain("1 error(s), 0 warning(s), 1 info(s)");
|
||
});
|
||
});
|
||
|
||
describe("formatLintStartupMessage", () => {
|
||
const result = project([
|
||
{
|
||
file: "index.html",
|
||
findings: [finding("error"), finding("error"), finding("warning")],
|
||
},
|
||
]);
|
||
|
||
it("collapses to a one-line summary by default, pointing at the lint command (no Studio open)", () => {
|
||
const lines = formatLintStartupMessage(result, { kind: "summary" });
|
||
expect(lines).toHaveLength(1);
|
||
expect(lines[0]).toContain("2 error(s), 1 warning(s)");
|
||
expect(lines[0]).not.toContain("Studio");
|
||
expect(lines[0]).toContain("hyperframes lint");
|
||
});
|
||
|
||
it("does not name --lint-verbose, a flag lint and check do not take", () => {
|
||
for (const pointer of [undefined, "studio"] as const) {
|
||
const lines = formatLintStartupMessage(result, { kind: "summary", pointer });
|
||
expect(lines[0]).not.toContain("--lint-verbose");
|
||
}
|
||
});
|
||
|
||
it("names the Studio badge and the lint command when pointer is 'studio'", () => {
|
||
const lines = formatLintStartupMessage(result, { kind: "summary", pointer: "studio" });
|
||
expect(lines[0]).toContain("Lint badge in Studio");
|
||
expect(lines[0]).toContain("hyperframes lint");
|
||
});
|
||
|
||
it("does not print individual findings in the default summary", () => {
|
||
const lines = formatLintStartupMessage(result, { kind: "summary" });
|
||
expect(lines.join("\n")).not.toContain("error-code");
|
||
});
|
||
|
||
it("prints full per-finding output when verbose", () => {
|
||
const lines = formatLintStartupMessage(result, { kind: "verbose" });
|
||
expect(lines).toEqual(formatLintFindings(result));
|
||
expect(lines.length).toBeGreaterThan(1);
|
||
});
|
||
});
|
||
|
||
it("prints source coordinates for a single-file finding", () => {
|
||
const result = project([
|
||
{ file: "index.html", findings: [finding("error", { line: 5, column: 3 })] },
|
||
]);
|
||
expect(formatLintFindings(result)[0]).toContain("index.html:5:3");
|
||
});
|
||
|
||
describe("formatLintFindings on a real project", () => {
|
||
it("labels a draft section's missing image with the draft, not index.html", async () => {
|
||
const dir = mkdtempSync(join(tmpdir(), "hf-lint-format-draft-"));
|
||
onTestFinished(() => rmSync(dir, { recursive: true, force: true }));
|
||
mkdirSync(join(dir, "compositions"));
|
||
writeFileSync(
|
||
join(dir, "index.html"),
|
||
`<html><body><div data-composition-id="main" data-width="1920" data-height="1080"><div data-composition-src="compositions/draft.html" data-composition-id="draft" data-start="0" data-duration="5"></div></div></body></html>`,
|
||
);
|
||
writeFileSync(
|
||
join(dir, "compositions", "draft.html"),
|
||
`<html><body><div data-composition-id="draft" data-width="1920" data-height="1080"><img src="../assets/missing.png" /></div></body></html>`,
|
||
);
|
||
|
||
const lines = formatLintFindings(await lintProject(dir));
|
||
|
||
const line = lines.find((l) => l.includes("missing.png"));
|
||
expect(line).toContain("[compositions/draft.html]");
|
||
});
|
||
});
|