feat(#74): IMP-45 u1~u8 slide-level CSS override (frontmatter slide_overrides.css + --override-slide-css/--slide-css-file + idempotent Step 13 injector)
Some checks failed
Multi-MDX Regression (IMP-91) / multi-mdx-regression (push) Failing after 22s

u1 KNOWN_AXES tuple gains slide_css entry in src/user_overrides_io.py
(snake_case parity with image_overrides); round-trip test extends
to 6 axes.
u2 src/mdx_normalizer.py surfaces nested slide_overrides.css from the
MDX frontmatter into the normalize_mdx_content return dict; absent
key -> {}, non-string css drops. 4 unit cases in tests/test_mdx_normalizer.py
(present / absent / non-string / title-only).
u3 src/slide_css_injector.py NEW (88 lines) mirrors the
inject_image_overrides_style contract from src/image_id_stamper.py:
marker pair <!--IMP45-SLIDE-CSS:OPEN--> / <!--IMP45-SLIDE-CSS:CLOSE-->,
idempotent re-injection, </head> > <body> > document-start three-tier
fallback, empty/None -> unchanged. 8 fixtures in
tests/test_slide_css_injector.py mirror test_image_id_stamper.py.
u4 run_phase_z2_mvp1 accepts override_slide_css: Optional[str] = None;
None -> frontmatter slide_overrides.css fallback. Step 13 calls
inject_slide_css after image override injection and before the
final.html disk write, so CLI/CI/regression renders observe the same
backend artifact.
u5 argparse adds mutually-exclusive --override-slide-css TEXT (inline
CSS, <style> wrapper optional) and --slide-css-file PATH (UTF-8 read,
fail-closed sys.exit(2) on missing path / decode error / both flags
present). Resolved string is forwarded as override_slide_css kwarg.
6 cases in tests/test_phase_z2_cli_overrides.py (inline / file / both
/ missing / non-utf8 / neither).
u6 samples/mdx_batch/04.mdx frontmatter gains slide_overrides.css
block (verbatim of the former MDX04_DEFAULT_OVERRIDE_CSS constant,
no sample/frame gate). Subprocess smoke in
tests/test_phase_z2_slide_css_smoke.py verifies the marker pair and
CSS substring land in final.html.
u7 Front/client removes the sample/frame-gated frontend-only injection:
Home.tsx drops the MDX04_DEFAULT_OVERRIDE_CSS constant and the
sample==="04"+frame==="process_product_two_way" branch (-28 lines);
SlideCanvas.tsx drops the iframe contentDocument.head injection of
that prop (-14 lines). Live preview now reads backend final.html only.
u8 tests/regression/fixtures/89a_pre_baseline_sha.json 04.mdx entry
resyncs to the live SHA ddb6bf2f... / 28042 bytes (overwrites the
earlier 5-byte-drift d02c76fd... / 28047). Other entries untouched.
Note: 01.mdx baseline drift (ad6f16a3... / 29089 -> live f26a7fac...
/ 29084) predates this branch and is split to a follow-up issue per
the closed-issue fresh validation rule.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-25 03:26:03 +09:00
parent b4be6c1cd0
commit 9062931863
14 changed files with 740 additions and 55 deletions

View File

@@ -56,6 +56,8 @@ def _exec_main_block(
override_zone_geometries=None,
override_section_assignments=None,
override_image_overrides=None,
override_slide_css=None,
reuse_from=None,
):
captured["mdx_path"] = mdx_path
captured["run_id"] = run_id
@@ -64,6 +66,8 @@ def _exec_main_block(
captured["override_zone_geometries"] = override_zone_geometries
captured["override_section_assignments"] = override_section_assignments
captured["override_image_overrides"] = override_image_overrides
captured["override_slide_css"] = override_slide_css
captured["reuse_from"] = reuse_from
monkeypatch.setattr(_pz2, "run_phase_z2_mvp1", _fake_run)
monkeypatch.setattr(sys, "argv", argv)
@@ -346,3 +350,136 @@ def test_image_override_does_not_leak_into_sibling_axes(tmp_path, monkeypatch):
assert captured["override_frames"] is None
assert captured["override_zone_geometries"] is None
assert captured["override_section_assignments"] is None
# -- IMP-45 (#74) u5 — slide-level CSS override CLI surface ----------------
#
# Six focused cases mirror the --override-image pattern above:
# 1. neither flag → kwarg None (fall-back to MDX frontmatter at u4)
# 2. --override-slide-css inline TEXT → kwarg passes verbatim
# 3. --slide-css-file PATH UTF-8 read → kwarg = file contents
# 4. both flags set → sys.exit(2) with mutual-exclusion stderr
# 5. --slide-css-file missing path → sys.exit(2) with not-found stderr
# 6. --slide-css-file non-UTF-8 bytes → sys.exit(2) with utf-8 stderr
def test_no_slide_css_override_forwards_none(tmp_path, monkeypatch):
"""Neither --override-slide-css nor --slide-css-file → kwarg = None."""
_redirect_overrides_root(tmp_path, monkeypatch)
captured: dict[str, Any] = {}
_exec_main_block(
captured, ["src.phase_z2_pipeline", "03.mdx"], monkeypatch,
)
assert captured["override_slide_css"] is None
def test_inline_slide_css_override_forwards_verbatim(tmp_path, monkeypatch):
"""--override-slide-css TEXT → kwarg = TEXT (verbatim, no `<style>` wrap)."""
_redirect_overrides_root(tmp_path, monkeypatch)
captured: dict[str, Any] = {}
_exec_main_block(
captured,
[
"src.phase_z2_pipeline",
"03.mdx",
"--override-slide-css",
".slide { background: red; }",
],
monkeypatch,
)
assert captured["override_slide_css"] == ".slide { background: red; }"
def test_slide_css_file_override_reads_utf8(tmp_path, monkeypatch):
"""--slide-css-file PATH → kwarg = UTF-8 decoded file contents."""
_redirect_overrides_root(tmp_path, monkeypatch)
css_payload = ".slide-body { color: #1e293b; } /* 한글 주석 */\n"
css_path = tmp_path / "slide_override.css"
css_path.write_text(css_payload, encoding="utf-8")
captured: dict[str, Any] = {}
_exec_main_block(
captured,
[
"src.phase_z2_pipeline",
"03.mdx",
"--slide-css-file",
str(css_path),
],
monkeypatch,
)
assert captured["override_slide_css"] == css_payload
def test_slide_css_both_flags_set_exits(tmp_path, monkeypatch, capsys):
"""--override-slide-css + --slide-css-file → sys.exit(2)."""
_redirect_overrides_root(tmp_path, monkeypatch)
css_path = tmp_path / "slide_override.css"
css_path.write_text(".slide { color: red; }\n", encoding="utf-8")
captured: dict[str, Any] = {}
with pytest.raises(SystemExit) as excinfo:
_exec_main_block(
captured,
[
"src.phase_z2_pipeline",
"03.mdx",
"--override-slide-css",
".slide { color: blue; }",
"--slide-css-file",
str(css_path),
],
monkeypatch,
)
assert excinfo.value.code == 2
err = capsys.readouterr().err
assert "--override-slide-css and --slide-css-file are mutually exclusive" in err
def test_slide_css_file_missing_path_exits(tmp_path, monkeypatch, capsys):
"""--slide-css-file with non-existent PATH → sys.exit(2)."""
_redirect_overrides_root(tmp_path, monkeypatch)
missing_path = tmp_path / "does_not_exist.css"
captured: dict[str, Any] = {}
with pytest.raises(SystemExit) as excinfo:
_exec_main_block(
captured,
[
"src.phase_z2_pipeline",
"03.mdx",
"--slide-css-file",
str(missing_path),
],
monkeypatch,
)
assert excinfo.value.code == 2
err = capsys.readouterr().err
assert "--slide-css-file path does not exist" in err
assert str(missing_path) in err
def test_slide_css_file_non_utf8_exits(tmp_path, monkeypatch, capsys):
"""--slide-css-file with non-UTF-8 bytes → sys.exit(2)."""
_redirect_overrides_root(tmp_path, monkeypatch)
bad_path = tmp_path / "latin1.css"
# 0xff is a stand-alone invalid UTF-8 start byte; strict decode raises.
bad_path.write_bytes(b".slide { color: \xff; }\n")
captured: dict[str, Any] = {}
with pytest.raises(SystemExit) as excinfo:
_exec_main_block(
captured,
[
"src.phase_z2_pipeline",
"03.mdx",
"--slide-css-file",
str(bad_path),
],
monkeypatch,
)
assert excinfo.value.code == 2
err = capsys.readouterr().err
assert "--slide-css-file must be UTF-8 encoded" in err