Skip to content

Commit ffc54c7

Browse files
authored
refactor(core): extract maxEndTime+serialize to parsers/test-utils.ts (TU) (heygen-com#1261)
* test(studio): add T5b rotation+motion build-patches characterization Extends manualEditsDomPatches.test.ts with rotation and motion pairs. Same 4-pattern structure: populated, empty, clear restores originals, build/clear symmetry. Merges duplicate manualEditsTypes import block. * test(studio): add T5c review-fix gaps in manualEditsDomPatches characterization Fixes four gaps identified in max-setting code review: - Box-size clear: replace arrayContaining with full ordered toEqual (30 ops) - Box-size / pathOffset / rotation clear: add empty-string coercion tests (origVal||null must produce null, not set property to "") - Rotation clear: add test for absent STUDIO_ORIGINAL_ROTATION_TRANSFORM_ORIGIN_ATTR - Motion clear: prove input-independence by calling with both empty and populated element and asserting identical output * refactor(core): extract maxEndTime+serialize to parsers/test-utils.ts (TU) Deduplicate helpers shared by T1 (htmlParser.roundtrip.test.ts) and T2 (stableIds.test.ts). Both files inline identical implementations; extract to test-utils.ts so future parser tests (T6a…) import one copy. Also fix lefthook fallow command to unset GIT_DIR+GIT_INDEX_FILE before running — those vars are set by git in worktree hook context and block fallow’s internal temp-worktree creation.
1 parent 5b29bea commit ffc54c7

5 files changed

Lines changed: 42 additions & 37 deletions

File tree

lefthook.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ pre-commit:
1919
# fails on issues introduced by the branch, not inherited findings.
2020
fallow:
2121
glob: "packages/**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"
22-
run: bunx fallow audit --base origin/main --fail-on-issues
22+
# Unset git worktree env vars: fallow creates a temp worktree internally and
23+
# GIT_DIR/GIT_INDEX_FILE (set by git in worktree hook context) break that.
24+
# env -u is safe in non-worktree contexts (no-op when var is unset).
25+
run: env -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE bunx fallow audit --base origin/main --fail-on-issues
2326
filesize:
2427
# Scoped to packages/studio — the 600 LOC limit is a studio architecture
2528
# standard enforced as part of the App.tsx decomposition work. Player and

packages/core/src/parsers/htmlParser.roundtrip.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,8 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
99
import { dirname, join } from "node:path";
1010
import { fileURLToPath } from "node:url";
1111
import { parseHtml } from "./htmlParser.js";
12+
import { maxEndTime, serialize } from "./test-utils.js";
1213
import { generateHyperframesHtml } from "../generators/hyperframes.js";
13-
import type { ParsedHtml } from "./htmlParser.js";
14-
15-
function maxEndTime(elements: ParsedHtml["elements"]): number {
16-
if (elements.length === 0) return 0;
17-
return Math.max(...elements.map((e) => e.startTime + e.duration));
18-
}
19-
20-
function serialize(parsed: ParsedHtml): string {
21-
// Fixed compositionId prevents Date.now() churn from masking structural instability.
22-
// The compositionId generation instability itself is tracked as R1 (stable hf- ids).
23-
return generateHyperframesHtml(parsed.elements, maxEndTime(parsed.elements), {
24-
compositionId: "test-comp",
25-
resolution: parsed.resolution,
26-
styles: parsed.styles ?? undefined,
27-
keyframes: parsed.keyframes,
28-
stageZoomKeyframes: parsed.stageZoomKeyframes,
29-
});
30-
}
3114

3215
describe("T1 — parse→serialize round-trip (DOM/timing)", () => {
3316
it("preserves element count and ids through one round-trip", () => {

packages/core/src/parsers/stableIds.test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,7 @@
1313
*/
1414
import { describe, expect, it } from "vitest";
1515
import { parseHtml } from "./htmlParser.js";
16-
import { generateHyperframesHtml } from "../generators/hyperframes.js";
17-
import type { ParsedHtml } from "./htmlParser.js";
18-
19-
function maxEndTime(elements: ParsedHtml["elements"]): number {
20-
if (elements.length === 0) return 0;
21-
return Math.max(...elements.map((e) => e.startTime + e.duration));
22-
}
23-
24-
function serialize(parsed: ParsedHtml): string {
25-
return generateHyperframesHtml(parsed.elements, maxEndTime(parsed.elements), {
26-
compositionId: "test-comp",
27-
resolution: parsed.resolution,
28-
styles: parsed.styles ?? undefined,
29-
keyframes: parsed.keyframes,
30-
stageZoomKeyframes: parsed.stageZoomKeyframes,
31-
});
32-
}
16+
import { serialize } from "./test-utils.js";
3317

3418
describe("T2 — stable element ids (spec for R1)", () => {
3519
// --- Spec (red until R1) ---
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Shared test utilities for parser test suites (T1, T2, T6…).
3+
* Import from here rather than duplicating helpers across test files.
4+
*
5+
* Not part of the public package exports — consumed only by *.test.ts files.
6+
*/
7+
import { generateHyperframesHtml } from "../generators/hyperframes.js";
8+
import type { ParsedHtml } from "./htmlParser.js";
9+
10+
export function maxEndTime(elements: ParsedHtml["elements"]): number {
11+
if (elements.length === 0) return 0;
12+
return Math.max(...elements.map((e) => e.startTime + e.duration));
13+
}
14+
15+
/**
16+
* Round-trip serialize helper.
17+
* Fixed compositionId prevents Date.now() churn from masking structural instability.
18+
* The compositionId generation instability itself is tracked as R1 (stable hf- ids).
19+
*/
20+
export function serialize(parsed: ParsedHtml): string {
21+
return generateHyperframesHtml(parsed.elements, maxEndTime(parsed.elements), {
22+
compositionId: "test-comp",
23+
resolution: parsed.resolution,
24+
styles: parsed.styles ?? undefined,
25+
keyframes: parsed.keyframes,
26+
stageZoomKeyframes: parsed.stageZoomKeyframes,
27+
});
28+
}

packages/core/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@
1515
},
1616
"files": ["src/runtime/mediaVolumeEnvelope.ts"],
1717
"include": ["src/**/*"],
18-
"exclude": ["node_modules", "dist", "src/tests", "src/runtime", "**/*.test.ts"]
18+
"exclude": [
19+
"node_modules",
20+
"dist",
21+
"src/tests",
22+
"src/runtime",
23+
"**/*.test.ts",
24+
"src/parsers/test-utils.ts"
25+
]
1926
}

0 commit comments

Comments
 (0)