import { describe, expect, it } from "vitest";
import { renderOverlay, validateRenderInput, overlaySvg } from "./render.js";
const png = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
describe("overlay render job injection gates (installed sharp, isolated worker)", () => {
it.each(["lower_third", "chyron"])("renders %s hostile text as escaped text into an actual PNG", async templateId => {
const input = { templateId, fields: { title: ' & $(touch /tmp/owned)', subtitle: 'evil; [movie=/etc/passwd]; "', style: "red" } };
const svg = overlaySvg(validateRenderInput(input)).svg;
expect(svg).toContain("<script>"); expect(svg).not.toContain("', '',
'',
'',
'',
'',
'',
'',
'',
'', '', '',
])("rejects hostile SVG through the render job: %s", async svg => {
await expect(renderOverlay({ templateId: "logo", fields: { svg } })).rejects.toThrow();
});
it.each(["\u0000", "\n", "\u202e", "a".repeat(81)])("rejects invalid text %s before sharp", async title => {
await expect(renderOverlay({ templateId: "lower_third", fields: { title } })).rejects.toThrow("invalid overlay text");
});
});