Skip to content

Write HTML. Render video. Built for agents.

152 KB
Raw Blame
// fallow-ignore-file code-duplication
import { describe, it, expect } from "vitest";
import { lintHyperframeHtml } from "../hyperframeLinter.js";

describe("GSAP rules", () => {
  it("warns when a GSAP color tween uses an undefined CSS variable", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <h1 id="title">Visible text</h1>
  </div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { color: "var(--accent2)", duration: 0.5 }, 0);
    window.__timelines = { c1: tl };
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.find((finding) => finding.code === "gsap_undefined_css_variable"),
    ).toMatchObject({
      severity: "warning",
      selector: "#title",
    });
  });

  it("checks both ends of a fromTo color tween", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><h1 id="title">Text</h1></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#title", { color: "var(--missing-from)" }, { color: "#fff", duration: 0.5 }, 0);
    window.__timelines = { c1: tl };
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.find((finding) => finding.code === "gsap_undefined_css_variable")?.message,
    ).toContain("--missing-from");
  });

  it.each([
    ["style block", `<style>:root { --accent2: #ff3366; }</style>`],
    ["inline style", `<div style="--accent2: #ff3366"></div>`],
  ])("accepts a GSAP CSS variable defined in a %s", async (_source, definition) => {
    const html = `
<html><head>${definition}</head><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><h1 id="title">Text</h1></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { color: "var(--accent2)", duration: 0.5 }, 0);
    window.__timelines = { c1: tl };
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.find((finding) => finding.code === "gsap_undefined_css_variable"),
    ).toBeUndefined();
  });

  it("accepts an undefined CSS variable with a var() fallback", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><h1 id="title">Text</h1></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { color: "var(--accent2, #fff)", duration: 0.5 }, 0);
    window.__timelines = { c1: tl };
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.find((finding) => finding.code === "gsap_undefined_css_variable"),
    ).toBeUndefined();
  });

  it("accepts a CSS variable declared through data-composition-variables", async () => {
    const html = `
<html data-composition-variables='[{"id":"accent2","type":"color","label":"Accent","default":"#ff3366"}]'>
<body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><h1 id="title">Text</h1></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { color: "var(--accent2)", duration: 0.5 }, 0);
    window.__timelines = { c1: tl };
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.find((finding) => finding.code === "gsap_undefined_css_variable"),
    ).toBeUndefined();
  });

  it("errors when window.__timelines is registered BEFORE the fonts.ready build", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script>
    window.__timelines = window.__timelines || {};
    var tl = gsap.timeline({ paused: true });
    window.__timelines["c1"] = tl;
    document.fonts.ready.then(function () {
      tl.from("#editor", { opacity: 0, duration: 0.5 }, 0);
    });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_timeline_registered_before_async_build",
    );
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("does NOT error when window.__timelines is registered AFTER the fonts.ready build", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script>
    window.__timelines = window.__timelines || {};
    var tl = gsap.timeline({ paused: true });
    document.fonts.ready.then(function () {
      tl.from("#editor", { opacity: 0, duration: 0.5 }, 0);
      window.__timelines["c1"] = tl;
    });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_timeline_registered_before_async_build",
    );
    expect(finding).toBeUndefined();
  });

  it("does NOT error when GSAP animates opacity on a clip element (by id)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="overlay" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <h1>Hello</h1>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#overlay", { opacity: 0, duration: 0.5 }, 4.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT error when GSAP targets a clip element with safe properties (by class)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card" class="clip my-card" data-start="0" data-duration="5" data-track-index="0">
      <p>Content</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from(".my-card", { y: 100, duration: 0.3 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT flag GSAP targeting a child of a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="overlay" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <h1 class="title">Hello</h1>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(".title", { opacity: 1, duration: 0.5 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT flag GSAP targeting a nested selector like '#overlay .title'", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="overlay" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <h1 class="title">Hello</h1>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#overlay .title", { opacity: 1, duration: 0.5 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT error when GSAP targets a clip element with safe properties (class-only, no id)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="clip scene-card" data-start="0" data-duration="5" data-track-index="0">
      <p>Content</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(".scene-card", { y: -50, duration: 0.4 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("errors when a full-frame transition flash starts visible before GSAP controls it", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <div id="tr-flash-1" style="position:fixed;inset:0;background:#fff;pointer-events:none;z-index:990"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <section class="clip" data-start="8" data-duration="8"><h1>Scene 2</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#tr-flash-1", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to("#tr-flash-1", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_fullscreen_overlay_starts_visible",
    );
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#tr-flash-1");
    expect(finding?.message).toContain("blank/white video");
  });

  it("does not error when a full-frame transition flash is initially hidden", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <div id="tr-flash-1" style="position:fixed;inset:0;background:#fff;opacity:0;pointer-events:none;z-index:990"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <section class="clip" data-start="8" data-duration="8"><h1>Scene 2</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#tr-flash-1", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to("#tr-flash-1", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_fullscreen_overlay_starts_visible",
    );
    expect(finding).toBeUndefined();
  });

  it("does not error when GSAP hides a full-frame transition flash at frame zero", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <div id="tr-flash-1" style="position:fixed;inset:0;background:#fff;pointer-events:none;z-index:990"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <section class="clip" data-start="8" data-duration="8"><h1>Scene 2</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set("#tr-flash-1", { opacity: 0 }, 0);
    tl.to("#tr-flash-1", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to("#tr-flash-1", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_fullscreen_overlay_starts_visible",
    );
    expect(finding).toBeUndefined();
  });

  it("reports one full-frame transition flash finding when multiple scripts touch it", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <div id="tr-flash-1" style="position:fixed;inset:0;background:#fff;pointer-events:none;z-index:990"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <section class="clip" data-start="8" data-duration="8"><h1>Scene 2</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#tr-flash-1", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to("#tr-flash-1", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
  <script>
    const tl2 = gsap.timeline({ paused: true });
    tl2.to("#tr-flash-1", { opacity: 1, duration: 0.08 }, 9.92);
    tl2.to("#tr-flash-1", { opacity: 0, duration: 0.18 }, 10.00);
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(
      result.findings.filter((f) => f.code === "gsap_fullscreen_overlay_starts_visible"),
    ).toHaveLength(1);
  });

  it("errors when a grouped GSAP selector targets a visible full-frame flash", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <div id="tr-flash-1" style="position:fixed;inset:0;background:#fff;pointer-events:none;z-index:990"></div>
  <div id="unused"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#unused, #tr-flash-1", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to("#unused, #tr-flash-1", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_fullscreen_overlay_starts_visible",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#tr-flash-1");
  });

  it("errors when full-frame transition flash styles come from a style block", async () => {
    const html = `
<html><body data-composition-id="c1" data-width="1920" data-height="1080">
  <style>
    .tr-flash { position: fixed; inset: 0; background: #fff; pointer-events: none; z-index: 990; }
  </style>
  <div id="tr-flash-1" class="tr-flash"></div>
  <section class="clip" data-start="0" data-duration="8"><h1>Scene 1</h1></section>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(".tr-flash", { opacity: 1, duration: 0.08 }, 7.92);
    tl.to(".tr-flash", { opacity: 0, duration: 0.18 }, 8.00);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_fullscreen_overlay_starts_visible",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe(".tr-flash");
  });

  it("does NOT error when GSAP animates opacity on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <h1>Title</h1>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#title", { opacity: 0, y: -50, duration: 0.5 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT error when GSAP animates transform props on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="box" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <div>Box</div>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { scale: 1.2, x: 100, rotation: 45, duration: 0.5 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeUndefined();
  });

  it("does NOT require a local GSAP script for sub-compositions", async () => {
    const html = `<template id="intro-template">
  <div data-composition-id="intro" data-width="1920" data-height="1080">
    <div class="title">Hello</div>
    <script>
      window.__timelines = window.__timelines || {};
      const tl = gsap.timeline({ paused: true });
      tl.from(".title", { opacity: 0, duration: 1 });
      window.__timelines["intro"] = tl;
    </script>
  </div>
</template>`;

    const result = await lintHyperframeHtml(html, { isSubComposition: true });
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeUndefined();
  });

  it("does NOT require a local GSAP script when a template composition is linted in isolation", async () => {
    const html = `<template id="intro-template">
  <div data-composition-id="intro" data-width="1920" data-height="1080">
    <div class="title">Hello</div>
    <script>
      window.__timelines = window.__timelines || {};
      const tl = gsap.timeline({ paused: true });
      tl.from(".title", { opacity: 0, duration: 1 });
      window.__timelines["intro"] = tl;
    </script>
  </div>
</template>`;

    const result = await lintHyperframeHtml(html, { filePath: "compositions/intro.html" });
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeUndefined();
  });

  it("ERRORS when GSAP animates visibility on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="overlay" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <p>Overlay</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#overlay", { visibility: "hidden", duration: 0.3 }, 2.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#overlay");
    expect(finding?.message).toContain("visibility");
  });

  it("ERRORS when GSAP animates autoAlpha on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="incoming" class="clip" data-start="1.01" data-duration="5" data-track-index="1">
      <p>Incoming scene</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#incoming", { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.3 }, 1.01);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");

    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("autoAlpha");
    expect(finding?.fixHint).toContain("child");
  });

  it("does NOT flag autoAlpha on content inside a clip", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="incoming" class="clip" data-start="1.01" data-duration="5" data-track-index="1">
      <p id="content">Incoming scene</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#content", { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.3 }, 1.01);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;

    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");

    expect(finding).toBeUndefined();
  });

  it("ERRORS when GSAP animates display on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <p>Card</p>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#card", { display: "none", duration: 0.3 }, 3.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#card");
    expect(finding?.message).toContain("display");
  });

  it("ERRORS when GSAP tween mixes safe properties with visibility on a clip element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="overlay" class="clip" data-start="0" data-duration="5" data-track-index="0">
      <h1>Hello</h1>
    </div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#overlay", { opacity: 0, visibility: "hidden", duration: 0.3 }, 2.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_animates_clip_element");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("visibility");
  });

  it("warns when tl.to animates x on an element with CSS translateX", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style=""></div>
  </div>
  <style>
    #title { position: absolute; top: 240px; left: 50%; transform: translateX(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { x: 0, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#title");
    expect(finding?.fixHint).toMatch(/fromTo/);
    expect(finding?.fixHint).toMatch(/xPercent/);
  });

  it("warns when tl.to animates scale on an element with CSS scale transform", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="hero"></div>
  </div>
  <style>
    #hero { transform: scale(0.8); opacity: 0; }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#hero", { opacity: 1, scale: 1, duration: 0.5 }, 1.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#hero");
  });

  it("does NOT warn when tl.to targets element without CSS transform", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card"></div>
  </div>
  <style>
    #card { position: absolute; top: 100px; left: 100px; opacity: 0; }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#card", { x: 0, opacity: 1, duration: 0.3 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflict = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(conflict).toBeUndefined();
  });

  it("does NOT warn when tl.fromTo targets element WITH CSS transform (author owns both ends)", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title"></div>
  </div>
  <style>
    #title { position: absolute; left: 50%; transform: translateX(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#title", { xPercent: -50, x: -1000, opacity: 0 }, { xPercent: -50, x: 0, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflict = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(conflict).toBeUndefined();
  });

  it("does NOT warn when tl.from targets element WITH CSS transform (from() owns start values)", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="badge"></div>
  </div>
  <style>
    #badge { position: absolute; left: 50%; transform: translateX(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#badge", { xPercent: -50, x: -200, opacity: 0, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflict = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(conflict).toBeUndefined();
  });

  it("emits one warning when a combined CSS transform conflicts with multiple GSAP properties", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="hero"></div>
  </div>
  <style>
    #hero { transform: translateX(-50%) scale(0.8); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#hero", { x: 0, scale: 1, opacity: 1, duration: 0.5 }, 1.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflicts = result.findings.filter((f) => f.code === "gsap_css_transform_conflict");
    expect(conflicts).toHaveLength(1);
    expect(conflicts[0]?.message).toMatch(/x\/scale|scale\/x/);
  });

  it("does not duplicate the CSS transform text when one declaration matches both translate and scale", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="scene-1" class="scene-1">hi</div>
  </div>
  <style>
    .scene-1 { transform: scale(1.08) translate3d(1.5%, 0, 0); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(".scene-1", { duration: 1, x: 100, scale: 1.2 });
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflict = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(conflict).toBeDefined();
    const doubled = "scale(1.08) translate3d(1.5%, 0, 0) scale(1.08) translate3d(1.5%, 0, 0)";
    expect(conflict?.message).not.toContain(doubled);
    expect(conflict?.fixHint).not.toContain(doubled);
    expect(conflict?.message).toContain("transform: scale(1.08) translate3d(1.5%, 0, 0)");
  });

  // --- Inline style transform detection tests ---

  it("warns when inline style transform: translateX conflicts with GSAP x", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="centered" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">Text</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#centered", { x: 0, y: 0, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#centered");
  });

  it("warns when inline style transform: scale conflicts with GSAP scale", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="box" style="transform: scale(0.9);">Box</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { scale: 1, duration: 0.5 }, 1.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#box");
  });

  it("does not false-positive on inline transform: rotate when GSAP uses rotation", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="spinner" style="transform: rotate(12deg);">Icon</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#spinner", { rotation: 360, duration: 1 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    // rotation doesn't conflict with rotate() — GSAP handles rotation separately
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeUndefined();
  });

  it("detects conflict via class selector when element has multiple classes", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="card hero" style="transform: translateX(-50%);">Card</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(".hero", { x: 100, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
  });

  it("handles both style block and inline style on same selector without crash", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="dual" style="transform: scale(0.5);">Dual</div>
  </div>
  <style>
    #dual { transform: translateY(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#dual", { y: 0, scale: 1, duration: 0.5 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflicts = result.findings.filter((f) => f.code === "gsap_css_transform_conflict");
    expect(conflicts.length).toBeGreaterThanOrEqual(1);
  });

  it("detects conflict via a SCOPED descendant selector (tl.to)", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="lab">Label</div>
  </div>
  <style>
    .lab { transform: translateX(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#root .lab", { x: 40, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#root .lab");
  });

  it("detects conflict via a standalone gsap.set with a GROUPED scoped selector", async () => {
    // The exact shape that slipped through: centering seated with a standalone
    // gsap.set on a grouped, #root-scoped selector, against a CSS class transform.
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="lab">A</div><div class="sub">B</div>
  </div>
  <style>
    .lab { transform: translateX(-50%); }
    .sub { transform: translateX(-50%); }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    gsap.set("#root .lab, #root .sub", { xPercent: -50 });
    tl.to(".lab", { y: 0, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_css_transform_conflict" && f.selector === "#root .lab, #root .sub",
    );
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("does NOT false-positive when a scoped selector targets a class WITHOUT a CSS transform", async () => {
    const html = `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="lab">Label</div>
  </div>
  <style>
    .lab { opacity: 0; }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#root .lab", { x: 40, opacity: 1, duration: 0.4 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const conflict = result.findings.find((f) => f.code === "gsap_css_transform_conflict");
    expect(conflict).toBeUndefined();
  });

  it("reports error when GSAP is used without a GSAP script tag", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("GSAP");
  });

  it("does not report missing_gsap_script when GSAP CDN script is present", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeUndefined();
  });

  it("does not report missing_gsap_script when GSAP is bundled inline", async () => {
    // Simulate a large inline GSAP bundle (>5KB) with GreenSock marker
    const fakeGsapLib = "/* GreenSock GSAP */" + " ".repeat(6000);
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>${fakeGsapLib}</script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeUndefined();
  });

  it("does not report missing_gsap_script when producer inlined CDN script", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>/* inlined: https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js */
    !function(t,e){t.gsap=e()}(this,function(){return {}});
  </script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeUndefined();
  });

  it("still reports missing_gsap_script for small inline scripts that use but don't bundle GSAP", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_script");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("errors on repeat: -1 (infinite repeat breaks capture engine)", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#spinner", { rotation: 360, duration: 0.8, repeat: -1, ease: "none" }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_infinite_repeat");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("repeat: -1");
    expect(finding?.fixHint).toContain("Math.max(0, Math.floor");
  });

  it("warns on repeat: -1 when an explicit finite composition duration bounds export", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080" data-duration="8"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#spinner", { rotation: 360, duration: 0.8, repeat: -1, ease: "none" }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_infinite_repeat");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
    expect(finding?.message).toContain("finite 8s window");
    expect(finding?.fixHint).toContain("explicit finite composition");
  });

  it("does not error on finite repeat values", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#spinner", { rotation: 360, duration: 0.8, repeat: 4, ease: "none" }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_infinite_repeat");
    expect(finding).toBeUndefined();
  });

  it("warns when a computed finite repeat can fall through to GSAP's -1 sentinel", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    const duration = 0.5;
    const cycleDuration = 1;
    const tl = gsap.timeline({ paused: true, repeat: Math.floor(duration / cycleDuration) - 1 });
    window.__timelines = { main: tl };
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_repeat_floor_unclamped");
    expect(finding?.severity).toBe("warning");
    expect(finding?.fixHint).toContain("Math.max(0, Math.floor");
  });

  it("accepts a clamped computed finite repeat", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    const duration = 0.5;
    const cycleDuration = 1;
    const tl = gsap.timeline({
      paused: true,
      repeat: Math.max(0, Math.floor(duration / cycleDuration) - 1),
    });
    window.__timelines = { main: tl };
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_repeat_floor_unclamped");
    expect(finding).toBeUndefined();
  });

  it("does not error on repeat: -1 inside JavaScript comments", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    // avoid repeat:-1 anywhere in user code
    /*
      This rule should still allow comments mentioning repeat: -1.
    */
    tl.to("#spinner", { rotation: 360, duration: 0.8, repeat: 4, ease: "none" }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_infinite_repeat");
    expect(finding).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens when an object-target tween is interleaved (regression)", async () => {
    // Regression: a non-DOM-targeting tween like `tl.to({ _: 0 }, …)` (used to
    // anchor timeline duration) was matched by the regex but skipped by the
    // parser, drifting the index and making the second tween "see" the first
    // tween's selector — producing a phantom self-overlap warning.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="a" class="clip" data-start="0" data-duration="5" data-track-index="0"></div>
    <div id="b" class="clip" data-start="0" data-duration="5" data-track-index="1"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to({ _: 0 }, { _: 1, duration: 5, ease: "none" }, 0);
    tl.to("#a", { opacity: 1, duration: 0.5 }, 0);
    tl.to("#b", { opacity: 1, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens for two inline object proxies with the same values", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to({ _: 0 }, { _: 1, duration: 5, ease: "none" }, 0);
    tl.to({ _: 0 }, { _: 1, duration: 5, ease: "none" }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens for same-named constants in separate IIFEs", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="x"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    (() => { const T = 0; tl.to("#x", { opacity: 1, duration: 1 }, T + 0); })();
    (() => { const T = 10; tl.to("#x", { opacity: 0, duration: 1 }, T + 0); })();
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("detects overlapping_gsap_tweens between variable-target tweens", async () => {
    // Both tweens target the same element via a querySelector variable and their
    // windows overlap on `opacity`. The structure-driven window builder must see
    // through the variable target to flag the conflict.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="hero" class="hero" data-start="0" data-duration="5" data-track-index="0"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const hero = document.querySelector("#hero");
    tl.to(hero, { opacity: 1, duration: 1 }, 0);
    tl.to(hero, { opacity: 0.5, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeDefined();
  });

  it("does not report overlapping_gsap_tweens when tweens only meet at an endpoint", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="w-weeks"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#w-weeks", { scaleY: 0.18, scaleX: 1.25, duration: 0.22 }, 2.35);
    tl.to("#w-weeks", { scaleX: 0, scaleY: 0, duration: 0.14 }, 2.57);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("reports overlapping_gsap_tweens when shared properties overlap for real", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="w-weeks"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#w-weeks", { scaleX: 1.25, duration: 0.5 }, 2.35);
    tl.to("#w-weeks", { scaleX: 0, duration: 0.14 }, 2.57);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeDefined();
    expect(finding?.message).toContain("scaleX");
  });

  it("reports motionPath usage without MotionPathPlugin", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "missing_gsap_plugin");
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("MotionPathPlugin");
  });

  it("reports standalone gsap.to motionPath usage without MotionPathPlugin", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("reports ESM motionPath usage without importing MotionPathPlugin", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type="module">
    import { gsap } from "https://cdn.jsdelivr.net/npm/gsap@3/index.js";
    const tl = gsap.timeline({ paused: true });
    tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("accepts motionPath usage when MotionPathPlugin is loaded", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
  <script>
    gsap.registerPlugin(MotionPathPlugin);
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("reports MotionPathPlugin loaded after the animation script", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });</script>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it.each(["defer", "async", 'type="module"'])(
    "does not treat an earlier non-blocking %s plugin script as available to classic code",
    async (attribute) => {
      const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script ${attribute} src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });</script>
</body></html>`;
      const result = await lintHyperframeHtml(html);
      expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
    },
  );

  it("treats defer on an inline classic tween as blocking", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script defer src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
  <script defer>gsap.to("#dot", { motionPath: { path: "#route" } });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("accepts a deferred classic plugin before a non-async module tween", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script defer src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
  <script type="module">gsap.to("#dot", { motionPath: { path: "#route" } });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("ignores async and defer text inside quoted attribute values", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script data-note="foo async defer" src="https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js"></script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" } });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("recognizes valid unquoted module attributes", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type=module src=https://cdn.jsdelivr.net/npm/gsap@3/dist/MotionPathPlugin.min.js></script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" } });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("treats async on an inline classic plugin definition as blocking", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script async>const MotionPathPlugin = {};</script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" } });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("does not accept plugin-like substrings in import specifiers", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type="module">
    import kit from "./AutoMotionPathPluginKit.js";
    gsap.to("#dot", { motionPath: { path: "#route" } });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("accepts a static plugin import in the same async module as the tween", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script async type="module">
    import { gsap, MotionPathPlugin } from "gsap/all";
    gsap.registerPlugin(MotionPathPlugin);
    gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("reports an inline plugin definition that occurs after the tween", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>
    gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });
    const MotionPathPlugin = {};
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("does not treat a long comment-only MotionPathPlugin mention as a loaded bundle", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>${" ".repeat(5100)}// TODO load MotionPathPlugin</script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("does not treat a MotionPathPlugin string literal as a loaded bundle", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>const docs = "MotionPathPlugin";</script>
  <script>gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });</script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("still reports motionPath when code registers an unloaded plugin global", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    gsap.registerPlugin(MotionPathPlugin);
    const tl = gsap.timeline({ paused: true });
    tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
    window.__timelines = { main: tl };
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeDefined();
  });

  it("does not treat an unrelated motionPath object as GSAP plugin usage", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script>
    const mapOptions = { motionPath: { path: "#route" } };
    console.log("motionPath: disabled", mapOptions);
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("allows sub-compositions to inherit MotionPathPlugin from their host", async () => {
    const html = `
<template>
  <div data-composition-id="scene" data-width="1920" data-height="1080">
    <script>
      const tl = gsap.timeline({ paused: true });
      tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
      window.__timelines = { scene: tl };
    </script>
  </div>
</template>`;
    const result = await lintHyperframeHtml(html, { isSubComposition: true });
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("accepts an inline ESM import of MotionPathPlugin", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type="module">
    import { gsap } from "https://cdn.jsdelivr.net/npm/gsap@3/index.js";
    import { MotionPathPlugin } from "https://cdn.jsdelivr.net/npm/gsap@3/MotionPathPlugin.js";
    gsap.registerPlugin(MotionPathPlugin);
    const tl = gsap.timeline({ paused: true });
    tl.to("#dot", { motionPath: { path: "#route" }, duration: 1 }, 0);
    window.__timelines = { main: tl };
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("accepts a default-aliased ESM import sourced from MotionPathPlugin", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type="module">
    import { gsap } from "https://cdn.jsdelivr.net/npm/gsap@3/index.js";
    import MP from "https://cdn.jsdelivr.net/npm/gsap@3/MotionPathPlugin.js";
    gsap.registerPlugin(MP);
    gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("accepts a named MotionPathPlugin import from a barrel module", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script type="module">
    import { gsap, MotionPathPlugin as MP } from "./vendor";
    gsap.registerPlugin(MP);
    gsap.to("#dot", { motionPath: { path: "#route" }, duration: 1 });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.find((f) => f.code === "missing_gsap_plugin")).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens for distinct unresolved-target tweens", async () => {
    // Each tween targets a DIFFERENT element via a target the parser cannot resolve
    // statically (a helper call). Both collapse to the `__unresolved__` sentinel, but
    // they are not the same element, so an overlap must not be asserted between them.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="s0"><div class="hl"><span class="w">a</span></div></div>
    <div id="s1"><div class="hl"><span class="w">b</span></div></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const a = pickWord(0);
    const b = pickWord(1);
    tl.to(a, { x: 100, duration: 1 }, 0);
    tl.to(b, { x: 100, duration: 1 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens for distinct loop-built DOM targets", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="caption-card-0"></div>
    <div id="caption-card-1"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    for (let i = 0; i < 2; i++) {
      const card = document.getElementById("caption-card-" + i);
      tl.to(card, { opacity: 1, duration: 1 }, i * 0.5);
    }
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("does NOT report overlapping_gsap_tweens for distinct object proxy drivers", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const particles = { value: 0 };
    const grain = { value: 0 };
    tl.to(particles, { value: 1, duration: 2, ease: "none" }, 0);
    tl.to(grain, { value: 1, duration: 2, ease: "none" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("reports overlapping_gsap_tweens for the same object proxy driver", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const driver = { value: 0 };
    tl.to(driver, { value: 1, duration: 2, ease: "none" }, 0);
    tl.to(driver, { value: 2, duration: 2, ease: "none" }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeDefined();
  });

  it("does not conflate same-named object proxies from sibling scopes", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    (() => {
      const driver = { value: 0 };
      tl.to(driver, { value: 1, duration: 2, ease: "none" }, 0);
    })();
    (() => {
      const driver = { value: 0 };
      tl.to(driver, { value: 1, duration: 2, ease: "none" }, 0.5);
    })();
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "overlapping_gsap_tweens");
    expect(finding).toBeUndefined();
  });

  it("does not false-positive on repeat: -10 (invalid GSAP but not infinite)", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { x: 100, duration: 1, repeat: -10 }, 0);
    window.__timelines["main"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_infinite_repeat");
    expect(finding).toBeUndefined();
  });

  it("errors when CSS opacity:0 + gsap.from({opacity:0}) — invisible forever", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style="opacity: 0; font-size: 120px;">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#title", { opacity: 0, y: 30, duration: 0.5 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeDefined();
    expect(finding!.severity).toBe("error");
    expect(finding!.selector).toBe("#title");
  });

  it("errors when style block has opacity:0 + gsap.from({opacity:0})", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="hero">Hello</div>
  </div>
  <style>
    #hero { font-size: 200px; color: #fff; opacity: 0; }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#hero", { opacity: 0, scale: 3.5, duration: 0.25, ease: "expo.out" }, 0.1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeDefined();
  });

  it("errors when a style block's LAST declaration is opacity:0 without a semicolon", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="hero">Hello</div>
  </div>
  <style>
    #hero { font-size: 200px; opacity: 0 }
  </style>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#hero", { opacity: 0, duration: 0.25 }, 0.1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeDefined();
  });

  it("does NOT error for inline opacity: 0.98 + gsap.from({opacity:0}) — fractional is not zero", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <img id="image-clip" style="opacity: 0.98; filter: blur(23px);" src="x.png">
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#image-clip", { opacity: 0, duration: 0.8 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeUndefined();
  });

  it("still errors for inline opacity: 0 without a trailing semicolon", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style="font-size: 120px; opacity: 0">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#title", { opacity: 0, duration: 0.5 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeDefined();
  });

  it("does NOT error when gsap.from({opacity:0}) and CSS has no opacity:0", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style="font-size: 120px; color: #fff;">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#title", { opacity: 0, y: 30, duration: 0.5 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeUndefined();
  });

  it("does NOT error when gsap.fromTo({opacity:0}, {opacity:1}) — destination overrides CSS", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style="opacity: 0; font-size: 120px;">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#title", { opacity: 0, y: 30 }, { opacity: 1, y: 0, duration: 0.5 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeUndefined();
  });

  it("errors when CSS-hidden content has a fromTo reveal without a destination opacity", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card" style="opacity: 0">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5, immediateRender: false }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#card");
  });

  it("errors when standalone gsap.set hides a fromTo target with no destination opacity", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    gsap.set("#card", { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
  });

  it("errors when a grouped gsap.set array hides a fromTo target with no destination opacity", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="header">Header</div>
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const header = "#header";
    const card = "#card";
    gsap.set([header, card], { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#card");
  });

  it("errors when a single-element gsap.set array hides a from({opacity:0}) target", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card">Never visible</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const card = "#card";
    gsap.set([card], { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.from("#card", { opacity: 0, y: 30, duration: 0.5 }, 0.2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#card");
  });

  it("errors when a gsap.set array of quoted selectors hides a fromTo target", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="header">Header</div>
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    gsap.set(["#header", "#card"], { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#card");
  });

  it("errors when a comma-separated gsap.set selector string hides a fromTo target", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="header">Header</div>
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    gsap.set("#header, #card", { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#card");
  });

  it("does NOT error when a grouped gsap.set array sets a non-opacity property", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="header">Header</div>
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const header = "#header";
    const card = "#card";
    gsap.set([header, card], { scaleX: 0, transformOrigin: "left center" });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeUndefined();
  });

  it("keeps a later gsap.set hide visible when an earlier one has non-literal vars", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const staggerVars = { y: 20 };
    gsap.set(document.querySelectorAll(".row"), staggerVars);
    gsap.set("#card", { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeDefined();
    expect(finding?.selector).toBe("#card");
  });

  it("does NOT error when a grouped gsap.set hide sits inside a callback body", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="card">Visible after entrance</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const card = "#card";
    const tl = gsap.timeline({ paused: true });
    tl.eventCallback("onComplete", function () {
      gsap.set([card], { opacity: 0 });
    });
    tl.fromTo("#card", { opacity: 1, x: -60 }, { x: 0, duration: 0.5 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_cold_seek_hidden_fromto_missing_reveal",
    );
    expect(finding).toBeUndefined();
  });

  it("does NOT error when gsap.to() uses opacity:0 (exit animation)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="title" style="opacity: 0;">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#title", { opacity: 0, duration: 0.5 }, 4.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeUndefined();
  });

  it("does NOT error when gsap.from({opacity: 0.5}) — non-zero opacity is a valid reveal", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="ghost" style="opacity: 0;">Hello</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.from("#ghost", { opacity: 0.5, duration: 0.4 }, 0.1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_from_opacity_noop");
    expect(finding).toBeUndefined();
  });

  it("warns when gsap.timeline is created but not registered in __timelines", async () => {
    const html = `
<html><body>
  <div data-composition-id="root" data-width="1920" data-height="1080">
    <div id="box">Hello</div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { opacity: 0.5, duration: 2 });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_not_registered");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("does NOT warn when timeline is registered in __timelines", async () => {
    const html = `
<html><body>
  <div data-composition-id="root" data-width="1920" data-height="1080">
    <div id="box">Hello</div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { opacity: 0.5, duration: 2 });
    window.__timelines["root"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_not_registered");
    expect(finding).toBeUndefined();
  });

  it("does NOT warn when timeline is registered with dot property syntax", async () => {
    const html = `
<html><body>
  <div data-composition-id="root" data-width="1920" data-height="1080">
    <div id="box">Hello</div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { opacity: 0.5, duration: 2 });
    window.__timelines.root = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_not_registered");
    expect(finding).toBeUndefined();
  });

  it("does NOT warn when timeline is registered with a computed bracket key", async () => {
    const html = `
<html><body>
  <div data-composition-id="root" data-width="1920" data-height="1080">
    <div id="box">Hello</div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    var spec = { id: "root" };
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { opacity: 0.5, duration: 2 });
    window.__timelines[spec.id] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_not_registered");
    expect(finding).toBeUndefined();
  });

  it("does NOT warn for sub-compositions (template-based)", async () => {
    const html = `
<template>
  <div data-composition-id="sub" data-width="1920" data-height="1080">
    <div id="box">Hello</div>
  </div>
  <script>
    const tl = gsap.timeline({ paused: true });
    tl.to("#box", { opacity: 0.5, duration: 2 });
  </script>
</template>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_not_registered");
    expect(finding).toBeUndefined();
  });

  it("gsap_non_transform_motion: errors on layout-prop tweens (left/marginLeft) and roundProps", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div id="a"></div><div id="b"></div><div id="c"></div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#a", { left: 0 }, { left: 1300, duration: 5, ease: "expo.out" }, 0);
    tl.fromTo("#b", { marginLeft: 0 }, { marginLeft: 1300, duration: 5, ease: "expo.out" }, 0);
    tl.fromTo("#c", { x: 0 }, { x: 1300, duration: 5, ease: "expo.out", roundProps: "x" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_non_transform_motion");
    expect(findings).toHaveLength(3);
    expect(findings.every((f) => f.severity === "error")).toBe(true);
  });

  it("gsap_non_transform_motion: does NOT fire on transform x/y", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#a", { x: 0 }, { x: 1300, duration: 5, ease: "expo.out" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeUndefined();
  });

  it("gsap_non_transform_motion: does NOT fire on tl.set() (instantaneous, no stutter)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set("#a", { left: 100 }, 0);
    tl.fromTo("#a", { x: 0 }, { x: 1300, duration: 5 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeUndefined();
  });

  it("gsap_non_transform_motion: one tween with both a layout prop AND roundProps reports once", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#a", { left: 0 }, { left: 1300, duration: 5, roundProps: "left" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_non_transform_motion");
    expect(findings).toHaveLength(1);
  });

  it("gsap_non_transform_motion: catches standalone gsap.to() animating a layout prop", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#a", { opacity: 1, duration: 1 }, 0);
    gsap.to("#a", { left: 1300, duration: 5 });
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (f) => f.code === "gsap_non_transform_motion" && f.selector === "#a",
    );
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: does NOT fire on html-in-canvas elements (<canvas layoutsubtree>)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <canvas layoutsubtree width="1920" height="1080">
      <div class="liquid-glass" id="gp1"></div>
    </canvas>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#gp1", { left: 1340, duration: 5, ease: "expo.out" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeUndefined();
  });

  it("gsap_non_transform_motion: still fires on a grouped tween that also targets a plain-DOM element", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <canvas layoutsubtree width="1920" height="1080">
      <div class="liquid-glass" id="gp1"></div>
    </canvas>
    <div id="txt1">card</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to(["#gp1", "#txt1"], { left: 1340, duration: 5, ease: "expo.out" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: fires on a label-positioned tl tween (non-numeric timeline position)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="cursor"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.addLabel("hold6", 6);
    tl.to("#cursor", { left: 500, top: 580, duration: 1 }, "hold6");
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: fires on a tl tween whose vars contain a nested {} (onComplete body)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#a", { left: 1300, duration: 5, onComplete: function () { window.done = true; } }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: roundProps on an html-in-canvas element still fires (not exempt)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <canvas layoutsubtree width="1920" height="1080">
      <div class="liquid-glass" id="gp1"></div>
    </canvas>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#gp1", { x: 100, duration: 5, roundProps: "x" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: fires on a layout/reflow prop that appears only in a fromTo's from-object", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="t"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#t", { left: 100, letterSpacing: "0.3em" }, { opacity: 1, duration: 1 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: fires on text-reflow props (letterSpacing / fontSize)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="t"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#t", { letterSpacing: "-4px", duration: 4, ease: "power1.out" }, 0);
    tl.to("#t", { fontSize: 80, duration: 4 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_non_transform_motion");
    expect(findings).toHaveLength(2);
    expect(findings.every((f) => f.severity === "error")).toBe(true);
  });

  it("gsap_non_transform_motion: text-reflow props are NOT html-in-canvas-exempt", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <canvas layoutsubtree width="1920" height="1080">
      <div class="liquid-glass" id="gp1">label</div>
    </canvas>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to("#gp1", { letterSpacing: "-4px", duration: 4 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeDefined();
  });

  it("gsap_non_transform_motion: does NOT fire on the literal text 'roundProps:' inside a string", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const label = "roundProps: see the docs";
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#a", { x: 0 }, { x: 1300, duration: 5 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_non_transform_motion");
    expect(finding).toBeUndefined();
  });
});

describe("GSAP seek-order safety rules", () => {
  // ── gsap_relative_value_second_writer ──────────────────────────────────────

  it("gsap_relative_value_second_writer: flags a relative drift over an entrance tween writing the same property", async () => {
    // Distilled from a production composition: entrance writes y on .tech-node,
    // then an ambient drift uses y:"-=15" on one of those elements by id.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="tech-node" id="node-gmail"></div>
    <div class="tech-node" id="node-crm"></div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('.tech-node', { opacity: 1, y: 0, duration: 1, ease: "power3.out" }, 2);
    tl.to('#node-gmail', { y: "-=15", duration: 3, repeat: 2, yoyo: true, ease: "sine.inOut" }, 2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.selector).toBe("#node-gmail");
  });

  it("gsap_relative_value_second_writer: aggregates multiple relative props into ONE finding per tween pair", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="ball"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#ball', { xPercent: 50, yPercent: 0, duration: 0.55 }, 0.2);
    tl.to('#ball', { xPercent: "-=18", yPercent: "-=10", duration: 1 }, 0.7);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_relative_value_second_writer");
    expect(findings.length).toBe(1);
    expect(findings[0]?.message).toContain("xPercent");
    expect(findings[0]?.message).toContain("yPercent");
    expect(findings[0]?.message).toMatch(/between 0\.70s and 0\.75s/);
  });

  it("gsap_relative_value_second_writer: does NOT flag when the other writer is a build-time gsap.set (runs on every worker)", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="card"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    gsap.set('#card', { y: 20 });
    tl.to('#card', { y: "+=10", duration: 2 }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag back-to-back non-overlapping relative tweens", async () => {
    // Notification-chain pattern: nudge away, then nudge back, sequentially.
    // The first tween completes before the second starts, so bases are
    // identical on every seek path.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="toast"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#toast', { y: "+=10", duration: 0.4 }, 1);
    tl.to('#toast', { y: "-=10", duration: 0.4 }, 1.4);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag a writer that completes before the relative tween starts", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="chip"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#chip', { y: 0, duration: 0.5 }, 0);
    tl.to('#chip', { y: "-=15", duration: 2 }, 3);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: bails on descendant and composition-scoped selectors", async () => {
    // ".card-a .icon" and ".card-b .icon" are DIFFERENT elements; scoped
    // selectors across compositions are too. Token-based matching would
    // mis-join them — the rule must skip rather than guess.
    const html = `
<html><body>
  <div data-composition-id="a" data-width="1920" data-height="1080">
    <div class="card-a"><span class="icon"></span></div>
    <div class="card-b"><span class="icon"></span></div>
    <span class="dot"></span>
  </div>
  <div data-composition-id="b" data-width="1920" data-height="1080">
    <span class="dot"></span>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('.card-a .icon', { y: 0, duration: 2 }, 0);
    tl.to('.card-b .icon', { y: "-=15", duration: 2 }, 1);
    tl.to('[data-composition-id="a"] .dot', { x: 100, duration: 2 }, 0);
    tl.to('[data-composition-id="b"] .dot', { x: "+=40", duration: 2 }, 1);
    window.__timelines["a"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag a single-writer relative value", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1080" data-height="1920"><div id="hub-core"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#hub-core', { scale: 0 });
    tl.to('#hub-core', { y: "-=15", duration: 2, repeat: 1, yoyo: true, ease: "sine.inOut" }, 1.0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag a relative POSITION parameter", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { opacity: 0, duration: 1 }, 0);
    tl.to('#a', { opacity: 1, duration: 1 }, "+=0.5");
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag relative values in from()/fromTo()", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#a', { y: 10 }, 0);
    tl.from('#a', { y: "-=30", duration: 1 }, 0.5);
    tl.fromTo('#a', { y: 0 }, { y: "+=30", duration: 1 }, 2);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  it("gsap_relative_value_second_writer: does NOT flag when the relative writer has overwrite auto", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { y: 100, duration: 2 }, 0);
    tl.to('#a', { y: "-=15", duration: 1, overwrite: "auto" }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_relative_value_second_writer");
    expect(finding).toBeUndefined();
  });

  // ── gsap_repeat_refresh_relative_value ─────────────────────────────────────

  it("gsap_repeat_refresh_relative_value: flags repeatRefresh with a relative value in the same vars", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { x: "+=100", duration: 1, repeat: 4, repeatRefresh: true }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_repeat_refresh_relative_value");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("gsap_repeat_refresh_relative_value: does NOT flag relative values nested in callback vars", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="el"></div><div id="other"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#el', {
      x: 100,
      repeatRefresh: true,
      onComplete: () => gsap.to('#other', { y: "-=15" }),
    }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_repeat_refresh_relative_value");
    expect(finding).toBeUndefined();
  });

  it("gsap_repeat_refresh_relative_value: does NOT flag repeatRefresh without relative values", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { x: 100, duration: 1, repeat: 4, repeatRefresh: true }, 0);
    tl.to('#a', { y: "+=10", duration: 1 }, 6);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_repeat_refresh_relative_value");
    expect(finding).toBeUndefined();
  });

  // ── gsap_function_value_hazard ─────────────────────────────────────────────

  it("gsap_function_value_hazard: flags a function value that measures the DOM", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div class="chip"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('.chip', { x: (i, target) => target.getBoundingClientRect().width / 2, duration: 1 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_function_value_hazard");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("gsap_function_value_hazard: flags a method call on the first (index) parameter", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div class="chip"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('.chip', { x: (el) => el.getAttribute("data-x"), duration: 1 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_function_value_hazard");
    expect(finding).toBeDefined();
  });

  it("gsap_function_value_hazard: WARNS (not errors) on transform-invariant layout reads", async () => {
    // Marquee pattern: x: () => -track.offsetWidth is deterministic across
    // workers while the measured layout is static — warning severity.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="track"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const track = document.getElementById('track');
    const tl = gsap.timeline({ paused: true });
    tl.to('#track', { x: () => -track.offsetWidth, duration: 8, ease: "none" }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_function_value_hazard");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
  });

  it("gsap_function_value_hazard: does NOT flag pure-index arithmetic, ternaries, wrap, or closures", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div class="chip"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const baseOffset = 40;
    const tl = gsap.timeline({ paused: true });
    tl.to('.chip', { x: (i) => i * 20, duration: 1 }, 0);
    tl.to('.chip', { y: (i) => (i % 2 === 0 ? -50 : 50), duration: 1 }, 0);
    tl.to('.chip', { rotation: gsap.utils.wrap([-10, 10]), duration: 1 }, 1);
    tl.to('.chip', { scale: (i) => baseOffset + i * 0.1, duration: 1 }, 2);
    tl.to('.chip', { opacity: (i) => Number(i.toFixed(2)), duration: 1 }, 3);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_function_value_hazard");
    expect(finding).toBeUndefined();
  });

  // ── gsap_callback_dom_measurement ──────────────────────────────────────────

  it("gsap_callback_dom_measurement: flags a tl.add callback reaching measurement two hops away", async () => {
    // Distilled from a production composition: tl.add(() => setupConnectors())
    // where setupConnectors measures via getCenter -> getBoundingClientRect.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="p1"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    function getCenter(el) {
      const rect = el.getBoundingClientRect();
      return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
    }
    function setupConnectors() {
      const orb = document.querySelector('#p1');
      const center = getCenter(orb);
      const length = orb.getTotalLength();
      gsap.set(orb, { strokeDashoffset: length });
    }
    const tl = gsap.timeline({ paused: true });
    tl.add(() => setupConnectors(), 2.5);
    tl.to('#p1', { strokeDashoffset: 0, duration: 1 }, 3);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_callback_dom_measurement");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
    // The callback site is reported in the structured selector field (the
    // linter dedupes on code+selector+message).
    expect(finding?.selector).toContain("setupConnectors");
  });

  it("gsap_callback_dom_measurement: does NOT flag gsap.getProperty-driven derived-output callbacks", async () => {
    // Scramble/typewriter pattern: onUpdate reads the animated value to derive
    // text output — per-frame deterministic and seek-idempotent.
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="counter"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const state = { n: 0 };
    const el = document.getElementById('counter');
    const tl = gsap.timeline({ paused: true });
    tl.to(state, { n: 100, duration: 2, onUpdate: () => { el.textContent = String(Math.round(gsap.getProperty(state, "n"))); } }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_callback_dom_measurement");
    expect(finding).toBeUndefined();
  });

  it("gsap_callback_dom_measurement: flags onUpdate / eventCallback referencing a measuring function", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const measureNow = () => document.getElementById('a').offsetWidth;
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { x: 100, duration: 1, onUpdate: measureNow }, 0);
    tl.eventCallback("onComplete", () => { const h = document.getElementById('a').clientHeight; });
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_callback_dom_measurement");
    expect(findings.length).toBeGreaterThanOrEqual(2);
  });

  it("gsap_callback_dom_measurement: does NOT flag build-time measurement or non-measuring callbacks", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="p1" d="M 0 0 L 100 100"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const path = document.getElementById('p1');
    const length = path.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#p1', { strokeDasharray: length + " " + length, strokeDashoffset: length }, 0);
    tl.add("chapter-two", 2);
    tl.to('#p1', { strokeDashoffset: 0, duration: 1, onComplete: () => console.log("done") }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_callback_dom_measurement");
    expect(finding).toBeUndefined();
  });
});

describe("SVG draw-on rules", () => {
  // ── svg_drawon_css_dasharray_conflict ──────────────────────────────────────

  it("svg_drawon_css_dasharray_conflict: flags the draw-on trick over CSS 'stroke-dasharray: 10 10'", async () => {
    // Distilled from a production composition: script-created path gets the
    // sync-line class, whose CSS declares a decorative two-component dash.
    const html = `
<html><body>
  <style>
    .sync-line { stroke: rgba(0, 163, 255, 0.3); stroke-width: 2; fill: none; stroke-dasharray: 10 10; }
  </style>
  <div data-composition-id="c1" data-width="1080" data-height="1920"><svg id="svg-overlay"></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const svg = document.getElementById('svg-overlay');
    const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
    path.setAttribute("class", "sync-line");
    path.setAttribute("d", "M 210 410 L 540 960");
    svg.appendChild(path);
    const pathLength = path.getTotalLength();
    tl.set(path, { strokeDasharray: pathLength, strokeDashoffset: pathLength }, 0);
    tl.to(path, { strokeDashoffset: 0, duration: 1.2, ease: "power1.inOut" }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("svg_drawon_css_dasharray_conflict: flags a quoted-selector write over an inline multi-component dash", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <svg><path id="wire" style="stroke-dasharray: 8 8" d="M 0 0 L 100 100"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#wire', { strokeDasharray: 141.4, strokeDashoffset: 141.4 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeDefined();
  });

  it("svg_drawon_css_dasharray_conflict: does NOT flag a descendant-scoped CSS dasharray", async () => {
    const html = `
<html><body>
  <style>.decorative-frame .wire { stroke-dasharray: 10 10; }</style>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <svg><path id="line" class="wire" d="M 0 0 L 100 0"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#line', { strokeDasharray: 100 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeUndefined();
  });

  it("svg_drawon_css_dasharray_conflict: does NOT flag a single-component CSS dasharray", async () => {
    const html = `
<html><body>
  <style>.wire { stroke-dasharray: 12; }</style>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <svg><path id="wire" class="wire" d="M 0 0 L 100 100"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#wire', { strokeDasharray: 141.4, strokeDashoffset: 141.4 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeUndefined();
  });

  it("svg_drawon_css_dasharray_conflict: does NOT flag a full two-component GSAP value (the fix form)", async () => {
    const html = `
<html><body>
  <style>.wire { stroke-dasharray: 10 10; }</style>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <svg><path id="wire" class="wire" d="M 0 0 L 100 100"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const len = 141.4;
    tl.set('#wire', { strokeDasharray: \`\${len} \${len}\`, strokeDashoffset: len }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeUndefined();
  });

  it("svg_drawon_css_dasharray_conflict: treats an all-interpolation template id as unresolved (multi-composition safe)", async () => {
    // getElementById(\`\${name}\`) has no literal segment — it must NOT match
    // every id in the document (here it would mis-join to the OTHER
    // composition's dashed element).
    const html = `
<html><body>
  <style>.wire-b { stroke-dasharray: 10 10; }</style>
  <div data-composition-id="a" data-width="1920" data-height="1080">
    <svg><path id="line-a" d="M 0 0 L 100 100"/></svg>
  </div>
  <div data-composition-id="b" data-width="1920" data-height="1080">
    <svg><path id="line-b" class="wire-b" d="M 0 0 L 100 100"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    const name = "line-a";
    const target = document.getElementById(\`\${name}\`);
    tl.set(target, { strokeDasharray: 141.4, strokeDashoffset: 141.4 }, 0);
    window.__timelines["a"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_drawon_css_dasharray_conflict");
    expect(finding).toBeUndefined();
  });

  // ── gsap_timeline_set_initial_hide ─────────────────────────────────────────

  it("gsap_timeline_set_initial_hide: warns on tl.set hidden state at position 0", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1080" data-height="1920">
    <div class="floating-icon"></div><div id="hub-core"></div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('.floating-icon', { opacity: 0 });
    tl.set('#hub-core', { scale: 0 });
    tl.to('.floating-icon', { opacity: 1, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const findings = result.findings.filter((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(findings.length).toBe(2);
    expect(findings.every((f) => f.severity === "warning")).toBe(true);
  });

  it("gsap_timeline_set_initial_hide: does NOT warn on immediate gsap.set or mid-timeline sets", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div><div id="b"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    gsap.set('#a', { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
    tl.set('#b', { opacity: 0 }, 3);
    tl.set('#a', { x: 40 }, 0);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT warn when the target is already hidden by authored CSS", async () => {
    // Defensive re-assertion: frame 0 is hidden by CSS anyway.
    const html = `
<html><body>
  <style>.card { opacity: 0; }</style>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="card"></div><div id="pin" style="opacity: 0"></div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('.card', { opacity: 0 }, 0);
    tl.set('#pin', { scale: 0 }, 0);
    tl.to('.card', { opacity: 1, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT warn when a standalone gsap.set already hides the target", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    gsap.set('#a', { opacity: 0 });
    const tl = gsap.timeline({ paused: true });
    tl.set('#a', { opacity: 0 }, 0);
    tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT exempt a gsap.set nested inside a callback", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div><button id="btn"></button></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#a', { opacity: 0 }, 0);
    tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
    document.getElementById('btn').addEventListener('click', () => {
      gsap.set('#a', { opacity: 0 });
    });
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeDefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT warn when a load-time IIFE gsap.set already hides", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    (function () {
      window.__timelines = window.__timelines || {};
      gsap.set('#a', { opacity: 0 });
      const tl = gsap.timeline({ paused: true });
      tl.set('#a', { opacity: 0 }, 0);
      tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
      window.__timelines["c1"] = tl;
    })();
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT warn when immediateRender is true", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set('#a', { opacity: 0, immediateRender: true }, 0);
    tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_timeline_set_initial_hide: warns on zero-duration tl.to at position 0", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { opacity: 0, duration: 0 }, 0);
    tl.to('#a', { opacity: 1, duration: 1 }, 0.5);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeDefined();
  });

  it("gsap_timeline_set_initial_hide: does NOT warn on mutated position variables resolved as 0", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><div id="a"></div></div>
  <script>
    window.__timelines = window.__timelines || {};
    let outroStart = 0;
    const tl = gsap.timeline({ paused: true });
    tl.to('#a', { opacity: 1, duration: 1 }, 0);
    outroStart = 5;
    tl.set('#a', { opacity: 0 }, outroStart);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_timeline_set_initial_hide");
    expect(finding).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: warns for repeated future fromTo state", async () => {
    const html = `
<html><body>
  <style>#ring { opacity: 0; }</style>
  <div data-composition-id="main" data-width="1920" data-height="1080">
    <div id="ring"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0, scale: 1 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1, scale: 0.4 }, { opacity: 0, duration: 0.5 }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
    expect(finding?.selector).toBe("#ring");
    expect(finding?.fixHint).toContain("every fromTo except the earliest-positioned one (at 5s)");
    expect(finding?.fixHint).toContain("gsap_timeline_set_initial_hide");
  });

  it("does not warn when two fromTo calls on one element animate different properties", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="card"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#card", { y: 80, rotation: 8 }, { y: 0, rotation: 0, duration: 0.8 }, 0.3);
    tl.fromTo("#card", { scale: 0 }, { scale: 1, duration: 0.65 }, 0.3);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );
    expect(finding).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: accepts the hinted shape when the later tween is authored first", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 1 }, { opacity: 0, duration: 0.5, immediateRender: false }, 10);
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: accepts explicit immediateRender false", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5, immediateRender: false }, 5);
    tl.fromTo("#ring", { opacity: 1 }, { opacity: 0, duration: 0.5, immediateRender: false }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: accepts an earlier timeline set baseline", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.set("#ring", { opacity: 0, scale: 1 }, 0);
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1 }, { opacity: 0, duration: 0.5 }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: rejects an earlier standalone set", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    gsap.set("#ring", { opacity: 0, scale: 1 });
    tl.fromTo("#ring", { opacity: 0, scale: 1 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1, scale: 0.4 }, { opacity: 0, duration: 0.5 }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
  });

  it("gsap_repeated_fromto_without_baseline: rejects a later incomplete standalone set", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0, scale: 1 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1, scale: 0.4 }, { opacity: 0, duration: 0.5 }, 10);
    gsap.set("#ring", { x: 0 });
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
  });

  it("gsap_repeated_fromto_without_baseline: does not guess that a later standalone set is a timeline baseline", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0, scale: 1 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1, scale: 0.4 }, { opacity: 0, duration: 0.5 }, 10);
    gsap.set("#ring", { opacity: 0, scale: 1 });
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
  });

  it("gsap_repeated_fromto_without_baseline: does not treat a deferred callback set as baseline", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080">
    <div id="ring"></div><button id="reset"></button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    document.getElementById("reset").addEventListener("click", () => {
      gsap.set("#ring", { opacity: 0, scale: 1 });
    });
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1 }, { opacity: 0, duration: 0.5 }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
  });

  it("gsap_repeated_fromto_without_baseline: requires a timeline baseline to be authored first", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring", { opacity: 1 }, { opacity: 0, duration: 0.5 }, 10);
    tl.set("#ring", { opacity: 0 }, 0);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find(
      (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
    );

    expect(finding?.severity).toBe("warning");
  });

  it("gsap_repeated_fromto_without_baseline: accepts one future fromTo writer", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080"><div id="ring"></div></div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);

    expect(
      result.findings.find(
        (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
      ),
    ).toBeUndefined();
  });

  it("gsap_repeated_fromto_without_baseline: keeps different selectors independent", async () => {
    const html = `
<html><body>
  <div data-composition-id="main" data-width="1920" data-height="1080">
    <div id="ring-a"></div><div id="ring-b"></div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    tl.fromTo("#ring-a", { opacity: 0 }, { opacity: 1, duration: 0.5 }, 5);
    tl.fromTo("#ring-b", { opacity: 1 }, { opacity: 0, duration: 0.5 }, 10);
    window.__timelines.main = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);

    expect(
      result.findings.find(
        (candidate) => candidate.code === "gsap_repeated_fromto_without_baseline",
      ),
    ).toBeUndefined();
  });

  // ── svg_measure_before_path_d ──────────────────────────────────────────────

  it("svg_measure_before_path_d: ERROR when no d assignment exists anywhere", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="wave" class="line"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const wave = document.getElementById('wave');
    const length = wave.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#wave', { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
  });

  it("svg_measure_before_path_d: ERROR when only a different path has a d assignment", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <svg><path id="alpha"/><path id="beta"/></svg>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const alpha = document.getElementById('alpha');
    const beta = document.getElementById('beta');
    beta.setAttribute('d', 'M0 0 L10 10');
    const length = alpha.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#alpha', { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("error");
    expect(finding?.message).toContain("no d");
  });

  it("svg_measure_before_path_d: WARNING when d is only assigned inside a function body", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="wave"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const wave = document.getElementById('wave');
    function setupPath() {
      wave.setAttribute('d', 'M 0 0 L 500 500');
    }
    const tl = gsap.timeline({ paused: true });
    tl.add(setupPath, 2);
    const length = wave.getTotalLength();
    tl.to('#wave', { strokeDashoffset: 0, duration: 1 }, 3);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
  });

  it("svg_measure_before_path_d: no finding for a static d attribute in the HTML", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="wave" d="M 0 0 L 500 500"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const wave = document.getElementById('wave');
    const length = wave.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#wave', { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeUndefined();
  });

  it("svg_measure_before_path_d: no finding for top-level assign-then-measure", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="wave"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const wave = document.getElementById('wave');
    wave.setAttribute('d', 'M 0 0 L 500 500');
    const length = wave.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#wave', { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeUndefined();
  });

  it("svg_measure_before_path_d: no finding for a top-level GSAP attr-plugin d assignment before the measure", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg><path id="wave"/></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const wave = document.getElementById('wave');
    gsap.set(wave, { attr: { d: "M 0 0 L 100 100" } });
    const length = wave.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set('#wave', { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeUndefined();
  });

  it("svg_measure_before_path_d: no finding for createElementNS-built paths", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"><svg id="overlay"></svg></div>
  <script>
    window.__timelines = window.__timelines || {};
    const overlay = document.getElementById('overlay');
    const line = document.createElementNS("http://www.w3.org/2000/svg", "path");
    line.setAttribute("d", "M 0 0 L 100 100");
    overlay.appendChild(line);
    const length = line.getTotalLength();
    const tl = gsap.timeline({ paused: true });
    tl.set(line, { strokeDashoffset: length }, 1);
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "svg_measure_before_path_d");
    expect(finding).toBeUndefined();
  });

  describe("gsap_fullscreen_overlay_starts_visible — the from() shape is not a defect", () => {
    const overlay = (style: string, script: string) => `
<html><body>
  <div id="root" data-composition-id="c1" data-width="1920" data-height="1080" data-start="0" data-duration="10">
    <div id="flash" style="position:fixed;inset:0;background:#000;${style}"></div>
  </div>
  <script src="gsap.min.js"></script>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    ${script}
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;

    it("does not flag a from() reveal, which already seats opacity 0 at t=0", async () => {
      // This used to error, and BOTH its fixHints (authored CSS opacity:0, or an
      // immediate gsap.set) produce gsap_from_opacity_noop — whose own fixHint says
      // to remove exactly what was just added. Applying either hint looped forever.
      const result = await lintHyperframeHtml(
        overlay("", `tl.from("#flash", { opacity: 0, duration: 1 }, 2);`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_fullscreen_overlay_starts_visible"),
      ).toBeUndefined();
    });

    it("still flags an overlay that is revealed and later hidden again", async () => {
      const result = await lintHyperframeHtml(
        overlay(
          "",
          `tl.to("#flash", { opacity: 1, duration: 1 }, 2);\n    tl.to("#flash", { opacity: 0, duration: 1 }, 5);`,
        ),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_fullscreen_overlay_starts_visible"),
      ).toBeDefined();
    });

    it("does not flag a fromTo() at 0 whose from-vars are hidden, which also seats at t=0", async () => {
      const result = await lintHyperframeHtml(
        overlay(
          "",
          `tl.fromTo("#flash", { opacity: 0, scale: 1.04 }, { opacity: 1, scale: 1, duration: 1.15 }, 0);\n    tl.to("#flash", { opacity: 0, duration: 0.42 }, 4);`,
        ),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_fullscreen_overlay_starts_visible"),
      ).toBeUndefined();
    });

    it("does not flag an overlay hidden by an aliased standalone gsap.set", async () => {
      const result = await lintHyperframeHtml(
        overlay(
          "",
          `const flash = "#flash";\n    gsap.set(flash, { opacity: 0 });\n    tl.to("#flash", { opacity: 1, duration: 1 }, 2);\n    tl.to("#flash", { opacity: 0, duration: 1 }, 5);`,
        ),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_fullscreen_overlay_starts_visible"),
      ).toBeUndefined();
    });
  });
  describe("gsap_timeline_return_used_as_tween", () => {
    const composition = (body: string) => `
<html><body>
  <div data-composition-id="c1" data-width="1080" data-height="1920"></div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    ${body}
    window.__timelines["c1"] = tl;
  </script>
</body></html>`;

    it("errors when a rebuild collects tl.to() returns to kill them later", async () => {
      // The real shape this exists for: a caret-follow scroll rebuilt on document.fonts.ready.
      // Every pushed value is `tl`, so the rebuild called kill() on the master timeline 49 times
      // and then stacked its new keyframes on top of the ones it meant to replace.
      const result = await lintHyperframeHtml(
        composition(`
    let scrollTweens = [];
    const layout = () => {
      scrollTweens.forEach((tw) => tw.kill());
      scrollTweens = [];
      scrollTweens.push(tl.to("#typed", { x: -40, duration: 0.08 }, 1));
    };
    layout();
    document.fonts.ready.then(layout);`),
      );
      const finding = result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween");
      expect(finding).toBeDefined();
      expect(finding?.severity).toBe("error");
      expect(finding?.message).toContain("returns THE TIMELINE ITSELF");
    });

    it("errors when a bound tl.to() return is killed", async () => {
      const result = await lintHyperframeHtml(
        composition(`
    const fade = tl.to("#card", { opacity: 1, duration: 0.5 }, 0);
    document.fonts.ready.then(() => fade.kill());`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween"),
      ).toBeDefined();
    });

    it("accepts a nested timeline, which is what the fix hint prescribes", async () => {
      // A nested child is a real object: killing it replaces exactly its own keyframes and
      // cannot reach the parent. Adding it at 0 keeps every child's absolute time.
      const result = await lintHyperframeHtml(
        composition(`
    let caretTl = null;
    const layout = () => {
      if (caretTl) caretTl.kill();
      caretTl = gsap.timeline();
      caretTl.to("#typed", { x: -40, duration: 0.08 }, 1);
      tl.add(caretTl, 0);
    };
    layout();
    document.fonts.ready.then(layout);`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween"),
      ).toBeUndefined();
    });

    it("accepts gsap.to(), which really does return a tween", async () => {
      const result = await lintHyperframeHtml(
        composition(`
    const tween = gsap.to("#card", { opacity: 1, duration: 0.5, paused: true });
    tl.add(tween, 0);
    document.fonts.ready.then(() => tween.kill());`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween"),
      ).toBeUndefined();
    });

    it("does not flag Array.from or a chained tl.to() that is never captured", async () => {
      const result = await lintHyperframeHtml(
        composition(`
    const words = Array.from(document.querySelectorAll(".w"));
    tl.to(words, { opacity: 1, duration: 0.3 }, 0).to(words, { y: 0, duration: 0.3 }, 0.3);`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween"),
      ).toBeUndefined();
    });

    it("does not flag a bound return that is never treated as a tween", async () => {
      // Pointless but harmless: the value is just `tl` again, and nothing tween-scoped is
      // aimed at it. Flagging this would be noise.
      const result = await lintHyperframeHtml(
        composition(`
    const chain = tl.to("#card", { opacity: 1, duration: 0.5 }, 0);
    chain.to("#card2", { opacity: 1, duration: 0.5 }, 1);`),
      );
      expect(
        result.findings.find((f) => f.code === "gsap_timeline_return_used_as_tween"),
      ).toBeUndefined();
    });
  });
});

describe("audio_reactive_single_tween_per_group", () => {
  it("warns when an audio-reactive caption uses a single peak tween per group", async () => {
    const html = `<!DOCTYPE html>
<html>
<head>
  <style>.caption, .caption-group, .caption-line, .cg-1 { color: white; }</style>
</head>
<body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="caption">Test</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    window.__timelines["c1"] = tl;

    const AUDIO = getAudioData();
    captions.forEach(group => {
      // Missing inner loop, only tweens once at group.start
      gsap.to(group.element, { scale: peakBass, duration: 0.1 }, group.start);
    });
  </script>
</body>
</html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "audio_reactive_single_tween_per_group");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
  });

  it("does not warn when the group contains an inner sampling loop", async () => {
    const html = `<!DOCTYPE html>
<html>
<head>
  <style>.caption, .caption-group, .caption-line, .cg-1 { color: white; }</style>
</head>
<body>
  <div data-composition-id="c1" data-width="1920" data-height="1080">
    <div class="caption">Test</div>
  </div>
  <script>
    window.__timelines = window.__timelines || {};
    const tl = gsap.timeline({ paused: true });
    window.__timelines["c1"] = tl;

    const AUDIO = getAudioData();
    captions.forEach(group => {
      // Inner sampling loop prevents the warning
      for (var at = group.start; at < group.end; at += 0.1) {
        gsap.to(group.element, { scale: peakBass, duration: 0.1 }, at);
      }
    });
  </script>
</body>
</html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.some((f) => f.code === "audio_reactive_single_tween_per_group")).toBe(
      false,
    );
  });
});

describe("gsap_group_selector_keyframes", () => {
  it("warns when a tween uses a group selector and keyframes", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    // Selector has a comma, and config has keyframes
    tl.to(".box1, .box2", { keyframes: [{ x: 100 }, { x: 200 }] });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    const finding = result.findings.find((f) => f.code === "gsap_group_selector_keyframes");
    expect(finding).toBeDefined();
    expect(finding?.severity).toBe("warning");
    expect(finding?.message).toContain("shared keyframes");
  });

  it("does not warn when a tween uses a single selector with keyframes", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    // No comma in selector
    tl.to(".box1", { keyframes: [{ x: 100 }, { x: 200 }] });
    tl.to(".box2", { keyframes: [{ x: 100 }, { x: 200 }] });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.some((f) => f.code === "gsap_group_selector_keyframes")).toBe(false);
  });

  it("does not warn when a tween uses a group selector without keyframes", async () => {
    const html = `
<html><body>
  <div data-composition-id="c1" data-width="1920" data-height="1080"></div>
  <script>
    const tl = gsap.timeline({ paused: true });
    // Group selector, but standard properties instead of keyframes
    tl.to(".box1, .box2", { x: 100, y: 100 });
  </script>
</body></html>`;
    const result = await lintHyperframeHtml(html);
    expect(result.findings.some((f) => f.code === "gsap_group_selector_keyframes")).toBe(false);
  });
});