59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
"""Behavioral coverage of the ComfyTimeline model via Node's test runner.
|
|
|
|
The model state machine (playback loop, dt-clamp, load-clamp, serialize
|
|
round-trip, step wrap, Curve/CurveStore) is pure JS — the rest of the
|
|
suite can only grep-pin it. This shells out to `node --test` against
|
|
tests/js/model.test.mjs to actually run it.
|
|
|
|
Skipped cleanly when Node is absent or too old (the harness uses
|
|
module.register, Node >= 20.6), so it never breaks the suite in
|
|
environments without a JS runtime — it just adds real coverage where one
|
|
exists (dev machines / CI with Node).
|
|
"""
|
|
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_REPO = Path(__file__).resolve().parent.parent
|
|
_JS_DIR = _REPO / "tests" / "js"
|
|
_SETUP = _JS_DIR / "setup.mjs"
|
|
_TESTS = [
|
|
_JS_DIR / "model.test.mjs",
|
|
_JS_DIR / "shared.test.mjs",
|
|
]
|
|
|
|
|
|
def _node_version():
|
|
node = shutil.which("node")
|
|
if not node:
|
|
return None
|
|
try:
|
|
out = subprocess.run([node, "--version"], capture_output=True, text=True, timeout=15)
|
|
except (OSError, subprocess.SubprocessError):
|
|
return None
|
|
m = re.search(r"v(\d+)\.(\d+)", out.stdout or "")
|
|
return (int(m.group(1)), int(m.group(2))) if m else None
|
|
|
|
|
|
def test_timeline_model_behavior_runs_under_node():
|
|
ver = _node_version()
|
|
if ver is None:
|
|
pytest.skip("node not on PATH")
|
|
if ver < (20, 6):
|
|
pytest.skip(f"node {ver} < 20.6 (harness uses module.register)")
|
|
|
|
# --import needs a file:// URI: Node's ESM loader rejects absolute
|
|
# Windows paths (parses the drive letter as a URL scheme).
|
|
proc = subprocess.run(
|
|
["node", "--import", _SETUP.as_uri(), "--test", *map(str, _TESTS)],
|
|
capture_output=True, text=True, cwd=str(_REPO), timeout=120,
|
|
)
|
|
assert proc.returncode == 0, (
|
|
"node --test failed for the ComfyTimeline model:\n"
|
|
f"--- stdout ---\n{proc.stdout}\n--- stderr ---\n{proc.stderr}"
|
|
)
|