Skip to content

Commit 2d31764

Browse files
committed
fix(check): report motion sidecars next to sub-compositions
1 parent 971499e commit 2d31764

7 files changed

Lines changed: 105 additions & 11 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,11 @@ edge, on any aspect ratio. Mark text that may sit outside them with
16401640
Layout sampling cannot catch a render-≠-preview bug: an entrance the seek lands
16411641
past, a broken stagger order, an element that drifts off-frame mid-tween, a shot
16421642
that freezes. Motion assertions can. Drop a `*.motion.json` sidecar next to the
1643-
composition and `check` evaluates it automatically — no flag, no changes to your
1644-
HTML. Without a sidecar, nothing changes.
1643+
entry composition (`index.html`) and `check` evaluates it automatically — no flag,
1644+
no changes to your HTML. A sidecar next to a sub-composition is not evaluated
1645+
yet: `check` reports it as an ignored warning, so move those assertions into
1646+
`index.motion.json` with root-timeline selectors and times. Without a sidecar,
1647+
nothing changes.
16451648

16461649
```json
16471650
{

‎packages/cli/src/commands/check.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,32 @@ describe("check pipeline", () => {
23342334
});
23352335
});
23362336

2337+
it("warns when a motion sidecar sits next to a sub-composition", async () => {
2338+
const dir = mkdtempSync(join(tmpdir(), "hf-check-nested-motion-"));
2339+
try {
2340+
writeFileSync(join(dir, "index.html"), "<html></html>");
2341+
mkdirSync(join(dir, "compositions"));
2342+
writeFileSync(
2343+
join(dir, "compositions", "scene-b.motion.json"),
2344+
JSON.stringify({ assertions: [{ kind: "appearsBy", selector: "#x", bySec: 1 }] }),
2345+
);
2346+
const { deps } = dependencies(fakeDriver());
2347+
2348+
const report = await runCheckPipeline(
2349+
{ dir, name: "nested-motion", indexPath: join(dir, "index.html") },
2350+
DEFAULT_CHECK_OPTIONS,
2351+
deps,
2352+
);
2353+
2354+
const warning = report.motion.findings.find((f) => f.code === "motion_spec_ignored");
2355+
expect(warning?.severity).toBe("warning");
2356+
expect(warning?.message).toContain("compositions/scene-b.motion.json");
2357+
expect(report.motion.warningCount).toBeGreaterThanOrEqual(1);
2358+
} finally {
2359+
rmSync(dir, { recursive: true, force: true });
2360+
}
2361+
});
2362+
23372363
it("marks browserSkipped true when the linter itself crashes", async () => {
23382364
const { deps } = dependencies(fakeDriver());
23392365
deps.lintProject = vi.fn(async () => {

‎packages/cli/src/utils/checkPipeline.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ import {
5959
type Canvas,
6060
type MotionFrame,
6161
} from "./motionAudit.js";
62-
import { findMotionSpec, readMotionSpec, type MotionAssertion } from "./motionSpec.js";
62+
import {
63+
findMotionSpec,
64+
findNestedMotionSpecs,
65+
readMotionSpec,
66+
type MotionAssertion,
67+
} from "./motionSpec.js";
6368
import { auditCraft } from "./craftAudit.js";
6469
import { inspectHdrAutoPromotion, remoteMediaNotInspected } from "./hdrPromotion.js";
6570
import { collectProjectMedia, type ProjectMedia } from "./projectMedia.js";
@@ -1812,8 +1817,9 @@ export async function runCheckPipeline(
18121817
}
18131818

18141819
const motion = dependencies.resolveMotionSpec(project.dir);
1815-
const specFindings =
1816-
motion.kind === "invalid"
1820+
const ignoredMotionSpecs = findNestedMotionSpecs(project.dir);
1821+
const specFindings = [
1822+
...(motion.kind === "invalid"
18171823
? [
18181824
findingAtRoot(
18191825
"motion_spec_invalid",
@@ -1822,7 +1828,17 @@ export async function runCheckPipeline(
18221828
relative(project.dir, motion.path) || "index.motion.json",
18231829
),
18241830
]
1825-
: [];
1831+
: []),
1832+
...ignoredMotionSpecs.map((path) => {
1833+
const file = (relative(project.dir, path) || path).replace(/\\/g, "/");
1834+
return findingAtRoot(
1835+
"motion_spec_ignored",
1836+
"warning",
1837+
`Motion spec ${file} is not evaluated: check reads only the sidecar next to the entry HTML. Move its assertions into index.motion.json, or apply them to the root timeline.`,
1838+
file,
1839+
);
1840+
}),
1841+
];
18261842

18271843
const deadline = new CheckDeadline(idleWindow(options.timeout), options.budget);
18281844
const forgetStop = onStopSignal(deadline.stop);

‎packages/cli/src/utils/motionSpec.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
1+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
22
import { tmpdir } from "node:os";
33
import { join } from "node:path";
44
import { describe, expect, it, onTestFinished } from "vitest";
5-
import { findMotionSpec, parseMotionSpec, readMotionSpec, type MotionSpec } from "./motionSpec.js";
5+
import {
6+
findMotionSpec,
7+
findNestedMotionSpecs,
8+
parseMotionSpec,
9+
readMotionSpec,
10+
type MotionSpec,
11+
} from "./motionSpec.js";
612

713
const RFC_SPEC = {
814
duration: 6,
@@ -25,6 +31,21 @@ function tempDir(prefix: string): string {
2531
return dir;
2632
}
2733

34+
describe("findNestedMotionSpecs", () => {
35+
it("reports sidecars next to sub-compositions but not the root sidecar", () => {
36+
const dir = tempDir("hf-motion-nested-");
37+
mkdirSync(join(dir, "compositions"));
38+
writeFileSync(join(dir, "index.motion.json"), "{}");
39+
writeFileSync(join(dir, "compositions", "scene-a.motion.json"), "{}");
40+
writeFileSync(join(dir, "compositions", "scene-b.motion.json"), "{}");
41+
42+
expect(findNestedMotionSpecs(dir)).toEqual([
43+
join(dir, "compositions", "scene-a.motion.json"),
44+
join(dir, "compositions", "scene-b.motion.json"),
45+
]);
46+
});
47+
});
48+
2849
describe("parseMotionSpec", () => {
2950
it("parses the RFC four-assertion spec", () => {
3051
const spec = expectOk(parseMotionSpec(RFC_SPEC));

‎packages/cli/src/utils/motionSpec.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync, readdirSync } from "node:fs";
22
import { readJsonFileText } from "./jsonFlag.js";
3-
import { basename, join } from "node:path";
3+
import { basename, dirname, join } from "node:path";
44

55
/**
66
* Declarative motion-verification spec (issue #1437). A sidecar JSON file
@@ -140,3 +140,31 @@ export function readMotionSpec(path: string): MotionSpecParse {
140140
}
141141
return parseMotionSpec(raw);
142142
}
143+
144+
/** Sidecars below the project root; findMotionSpec reads only the entry composition's. */
145+
export function findNestedMotionSpecs(projectDir: string): string[] {
146+
if (!existsSync(projectDir)) return [];
147+
const found: string[] = [];
148+
const pending = [projectDir];
149+
while (pending.length > 0) {
150+
const dir = pending.pop()!;
151+
let entries;
152+
try {
153+
entries = readdirSync(dir, { withFileTypes: true });
154+
} catch {
155+
continue;
156+
}
157+
for (const entry of entries) {
158+
if (entry.isDirectory()) {
159+
if (isSearchableDir(entry.name)) pending.push(join(dir, entry.name));
160+
} else if (entry.isFile() && entry.name.endsWith(".motion.json")) {
161+
found.push(join(dir, entry.name));
162+
}
163+
}
164+
}
165+
return found.filter((path) => dirname(path) !== projectDir).sort();
166+
}
167+
168+
function isSearchableDir(name: string): boolean {
169+
return name !== "node_modules" && name !== "dist" && !name.startsWith(".");
170+
}

‎skills-manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"files": 87
1111
},
1212
"hyperframes-cli": {
13-
"hash": "36ed7b39fe73ede2",
13+
"hash": "d5f48c97ae70e102",
1414
"files": 14
1515
},
1616
"hyperframes-registry": {

‎skills/hyperframes-cli/references/lint-validate-inspect.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ npx hyperframes check --frame-check # media (img/svg/video/canvas) out-of-fr
9191

9292
`check` verifies **motion intent** against the same seeked timeline the renderer uses — the closest automated proxy for "render the MP4 and watch it". It catches render-vs-preview bugs layout sampling can't: an entrance reveal the seek lands past, a broken stagger order, an element drifting off-frame mid-tween, a frozen shot.
9393

94-
Drop a `*.motion.json` sidecar next to the composition (matching the html basename when several compositions share a dir). `check` discovers it automatically — no flag, no authoring-framework changes. With no sidecar, `check` behaves exactly as before.
94+
Drop a `*.motion.json` sidecar next to the entry composition (`index.html`). When several compositions share the project root, the basename picks the matching composition. `check` discovers it automatically — no flag, no authoring-framework changes. Sidecars next to sub-compositions are currently reported as ignored warnings rather than evaluated, because selectors and assertion times are root-timeline relative; keep those assertions in the entry composition's sidecar. With no sidecar, `check` behaves exactly as before.
9595

9696
```json
9797
{

0 commit comments

Comments
 (0)