feat(#65): IMP-36 fit/rotation generalization (u1~u8)
Generalize Phase Z frame partial responsive fit / rotation to four canonical
F13/F14/F20/F8 family partials. Surface = 13 canonical partials; 19
builder-only contracts remain explicitly out of scope.
u1 test_imp17_comment_anchor: re-pin L570->L578 (restructure+IMP-17),
L571->L579 (IMP-29 -> IMP-47B supersession). Stage 1 red baseline gate.
u2 frame_contracts.yaml: add rotation_eligible (P1) + body_fit_pattern2 (P2)
bool axes on 13 partial-backed contracts. P1 True: F13/F14/F20/F8 (4).
P2 True: F23 + P1_set (5). F29 columns[1].body_parser column_plain ->
column_with_transform (P3 parity).
u3 test_imp36_fit_rotation_generalization (NEW, 166 lines): static
parametrized assertions for P1 metadata + CQ presence, P1 opt-out
absence, P2 --max-body-lines + clamp + cqh, P2 opt-out absence, 19
builder-only exclusion.
u4 three_parallel_requirements (F13): introduce f13b-root container-name +
container-type:size + @container (aspect-ratio<1.5) rotation;
add inline --max-body-lines + body line-height clamp/cqh/calc.
u5 three_persona_benefits (F14): f14b-root P1 + P2 cqh/jinja body fit.
Persona colors (#285b4a/#445a2f/#743002) and circle SVG aspect 1/1
preserved.
u6 dx_sw_necessity_three_perspectives (F20): f20b-root P1 + P2 cqh/jinja
body fit under IMP-49 partial-fidelity lock.
u7 info_management_what_how_when (F8): f8b-root P1 + P2 cqh/jinja body fit.
u8 test_imp36_overflow_chain_self_fire (NEW, 299 lines): Selenium self-fire
harness for F13/F14/F20/F8 at aspect 1.78 vs 1.0. Asserts line-height
changes, font-size invariance across all 4 frames (no per-frame exempt),
grid columns rotate 3 -> 1, OVERFLOW_CASCADE_ORDER remains 4-tuple.
Stage 4 verification (HEAD 6f1c736 pre-commit baseline):
u1 2/2 PASS, u3 33/33 PASS, u8 9/9 PASS (live Chrome).
Regression sweep tests/phase_z2 + tests/orchestrator_unit 335/335 PASS.
font-size mutations introduced: 0.
Pre-existing red (test_imp47b_step12_ai_wiring x3, ai_fallback_master_flag
default_off x1) verified unchanged via stash swap -> not introduced.
Guardrails honored:
- cqh / clamp / container query only (no shared margin/padding/gap shrink).
- font-size invariant under aspect change (P2 mutates line-height +
--max-body-lines only).
- No cross-frame .fNb__ class borrowing (IMP-49 partial-fidelity lock).
- F14 circle SVG aspect 1/1 untouched; persona colors preserved.
- AI isolation: no HTML structure generation; AI calls remain zone-content.
- 1 turn = 1 step; commit excludes .claude/settings.json and all
out-of-scope untracked worktree per Stage 4 binding contract.
source_comment_ids: Stage 1 #13/#14; Stage 2 #21/#22; Stage 3 #4 + Codex #4
YES; Stage 4 Claude #1 + Codex #3 PASS.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,20 @@
|
||||
|
||||
Stage 1 finding: line 564 previously referenced a non-existent ID ("IMP-31").
|
||||
The legitimate slot is IMP-17 (Gitea #17, carve-out — AI fallback only, normal path 밖).
|
||||
Line 565 (IMP-29 frontend zone-level override) must remain untouched.
|
||||
The reject anchor previously referenced IMP-29 (frontend zone-level override); it has
|
||||
since been superseded by IMP-47B u1 (2026-05-21) which corrects the reject disposition
|
||||
to AI re-construction over the rank-1 reject frame.
|
||||
|
||||
Anchor re-pin (2026-05-20, IMP-30 u1 follow-up): V4Match.provisional field added at
|
||||
src/phase_z2_pipeline.py:179-184 shifted the route-hint table down by six lines.
|
||||
Pinned line numbers updated from 564/565 → 570/571 to track the actual anchor location.
|
||||
Pinned line numbers were updated 564/565 → 570/571.
|
||||
|
||||
Anchor re-pin (2026-05-22, IMP-36 u1 / Gitea #65 Stage 2): IMP-47B supersession at
|
||||
src/phase_z2_pipeline.py:579-582 expanded the reject hint comment by four lines, which
|
||||
shifted only the post-comment table downward. The restructure anchor itself moved from
|
||||
570 → 578 because additional comment context was inserted between the table header and
|
||||
the restructure line. Re-pinned 570 → 578 (restructure / IMP-17) and 571 → 579
|
||||
(reject / IMP-47B supersession of the prior IMP-29 reference).
|
||||
|
||||
Run: pytest -q tests/orchestrator_unit/test_imp17_comment_anchor.py
|
||||
"""
|
||||
@@ -20,14 +29,17 @@ def _lines() -> list[str]:
|
||||
return PIPELINE.read_text(encoding="utf-8").splitlines()
|
||||
|
||||
|
||||
def test_line_570_references_imp17_not_imp31():
|
||||
line = _lines()[569] # 1-indexed line 570
|
||||
assert "restructure" in line, f"line 570 anchor drifted: {line!r}"
|
||||
assert "IMP-17" in line, f"line 570 must reference IMP-17 (carve-out): {line!r}"
|
||||
assert "IMP-31" not in line, f"line 570 must not reference non-existent IMP-31: {line!r}"
|
||||
def test_line_578_references_imp17_not_imp31():
|
||||
line = _lines()[577] # 1-indexed line 578
|
||||
assert "restructure" in line, f"line 578 anchor drifted: {line!r}"
|
||||
assert "IMP-17" in line, f"line 578 must reference IMP-17 (carve-out): {line!r}"
|
||||
assert "IMP-31" not in line, f"line 578 must not reference non-existent IMP-31: {line!r}"
|
||||
|
||||
|
||||
def test_line_571_still_references_imp29():
|
||||
line = _lines()[570] # 1-indexed line 571
|
||||
assert "reject" in line, f"line 571 anchor drifted: {line!r}"
|
||||
assert "IMP-29" in line, f"line 571 must still reference IMP-29 frontend override: {line!r}"
|
||||
def test_line_579_references_imp47b_supersession():
|
||||
line = _lines()[578] # 1-indexed line 579
|
||||
assert "reject" in line, f"line 579 anchor drifted: {line!r}"
|
||||
assert "IMP-47B" in line, (
|
||||
f"line 579 must reference IMP-47B (supersedes prior IMP-29 reject disposition): "
|
||||
f"{line!r}"
|
||||
)
|
||||
|
||||
166
tests/phase_z2/test_imp36_fit_rotation_generalization.py
Normal file
166
tests/phase_z2/test_imp36_fit_rotation_generalization.py
Normal file
@@ -0,0 +1,166 @@
|
||||
"""IMP-36 (Gitea #65) — P1/P2 fit/rotation generalization static checks.
|
||||
|
||||
Coupled with u2 (frame_contracts.yaml two-bool axis + F29 P3 parity).
|
||||
Asserts:
|
||||
(1) contract-level axis booleans on the 13 partial-backed contracts and
|
||||
their absence on the 19 builder-only contracts;
|
||||
(2) F29 P3 parity (both columns declare column_with_transform);
|
||||
(3) partial-side CSS signatures —
|
||||
P1 (rotation_eligible=true) → ``container-name: f<N>b-root`` +
|
||||
``container-type: size`` + ``@container <name> (aspect-ratio < 1.5)``.
|
||||
P2 (body_fit_pattern2=true) → ``--max-body-lines`` + ``cqh`` + ``clamp(``
|
||||
in the body line-height clamp.
|
||||
|
||||
Per Stage 2 plan the partial-side P1/P2 assertions for F13/F14/F20/F8 begin
|
||||
passing only after u4-u7 land. F23 (Stage 1 canonical P2 source) already
|
||||
satisfies P2 at u3 time. F23 explicitly stays P1=false (no rotation rule)
|
||||
per the in-file lock at templates/phase_z2/families/app_sw_package_vs_solution.html
|
||||
line 64.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CONTRACTS_PATH = ROOT / "templates" / "phase_z2" / "catalog" / "frame_contracts.yaml"
|
||||
FAMILIES_DIR = ROOT / "templates" / "phase_z2" / "families"
|
||||
|
||||
|
||||
EXPECTED_P1_TRUE = {
|
||||
"three_parallel_requirements",
|
||||
"three_persona_benefits",
|
||||
"dx_sw_necessity_three_perspectives",
|
||||
"info_management_what_how_when",
|
||||
}
|
||||
EXPECTED_P1_FALSE = {
|
||||
"app_sw_package_vs_solution",
|
||||
"bim_current_problems_paired",
|
||||
"bim_dx_comparison_table",
|
||||
"bim_issues_quadrant_four",
|
||||
"construction_bim_three_usage",
|
||||
"construction_goals_three_circle_intersection",
|
||||
"pre_construction_model_info_stacked",
|
||||
"process_product_two_way",
|
||||
"sw_reality_three_emphasis",
|
||||
}
|
||||
EXPECTED_P2_TRUE = EXPECTED_P1_TRUE | {"app_sw_package_vs_solution"}
|
||||
EXPECTED_P2_FALSE = EXPECTED_P1_FALSE - {"app_sw_package_vs_solution"}
|
||||
|
||||
# P1 container-name convention = f<frame_id>b-root, declared in Stage 2 plan.
|
||||
CONTAINER_NAMES = {
|
||||
"three_parallel_requirements": "f13b-root",
|
||||
"three_persona_benefits": "f14b-root",
|
||||
"dx_sw_necessity_three_perspectives": "f20b-root",
|
||||
"info_management_what_how_when": "f8b-root",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def contracts() -> dict:
|
||||
return yaml.safe_load(CONTRACTS_PATH.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def partial_files() -> set[str]:
|
||||
return {p.stem for p in FAMILIES_DIR.glob("*.html")}
|
||||
|
||||
|
||||
# ─── contract metadata axis ────────────────────────────────────────────────
|
||||
def test_partial_backed_thirteen_carry_both_flags(contracts, partial_files):
|
||||
partial_backed = {k for k in contracts if k in partial_files}
|
||||
assert len(partial_backed) == 13, sorted(partial_backed)
|
||||
missing = [
|
||||
tid
|
||||
for tid in partial_backed
|
||||
if "rotation_eligible" not in contracts[tid]
|
||||
or "body_fit_pattern2" not in contracts[tid]
|
||||
]
|
||||
assert missing == [], missing
|
||||
bad_type = [
|
||||
tid
|
||||
for tid in partial_backed
|
||||
if not isinstance(contracts[tid]["rotation_eligible"], bool)
|
||||
or not isinstance(contracts[tid]["body_fit_pattern2"], bool)
|
||||
]
|
||||
assert bad_type == [], bad_type
|
||||
|
||||
|
||||
def test_builder_only_nineteen_carry_neither_flag(contracts, partial_files):
|
||||
builder_only = {k for k in contracts if k not in partial_files}
|
||||
assert len(builder_only) == 19, sorted(builder_only)
|
||||
leaked = [
|
||||
tid
|
||||
for tid in builder_only
|
||||
if "rotation_eligible" in contracts[tid] or "body_fit_pattern2" in contracts[tid]
|
||||
]
|
||||
assert leaked == [], leaked
|
||||
|
||||
|
||||
def test_rotation_eligible_true_set(contracts):
|
||||
actual = {k for k, v in contracts.items() if v.get("rotation_eligible") is True}
|
||||
assert actual == EXPECTED_P1_TRUE
|
||||
|
||||
|
||||
def test_rotation_eligible_false_set(contracts):
|
||||
actual = {k for k, v in contracts.items() if v.get("rotation_eligible") is False}
|
||||
assert actual == EXPECTED_P1_FALSE
|
||||
|
||||
|
||||
def test_body_fit_pattern2_true_set(contracts):
|
||||
actual = {k for k, v in contracts.items() if v.get("body_fit_pattern2") is True}
|
||||
assert actual == EXPECTED_P2_TRUE
|
||||
|
||||
|
||||
def test_body_fit_pattern2_false_set(contracts):
|
||||
actual = {k for k, v in contracts.items() if v.get("body_fit_pattern2") is False}
|
||||
assert actual == EXPECTED_P2_FALSE
|
||||
|
||||
|
||||
def test_f29_columns_both_with_transform(contracts):
|
||||
"""P3 parity — F29 (process_product_two_way) columns[*].body_parser symmetry."""
|
||||
cols = contracts["process_product_two_way"]["payload"]["builder_options"]["columns"]
|
||||
parsers = [c.get("body_parser") for c in cols]
|
||||
assert parsers == ["column_with_transform", "column_with_transform"], parsers
|
||||
|
||||
|
||||
# ─── partial-side CSS axis (u4-u7 progressively satisfy) ───────────────────
|
||||
@pytest.mark.parametrize("tid", sorted(EXPECTED_P1_TRUE))
|
||||
def test_p1_partial_declares_aspect_ratio_rotation(tid):
|
||||
"""P1=true partials declare ``container-name``/``container-type`` and an
|
||||
``@container <name> (aspect-ratio < 1.5)`` rotation rule. Satisfied by
|
||||
F13/F14/F20/F8 in u4-u7."""
|
||||
css = (FAMILIES_DIR / f"{tid}.html").read_text(encoding="utf-8")
|
||||
name = CONTAINER_NAMES[tid]
|
||||
assert f"container-name: {name}" in css, tid
|
||||
assert "container-type: size" in css, tid
|
||||
assert f"@container {name} (aspect-ratio < 1.5)" in css, tid
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tid", sorted(EXPECTED_P1_FALSE))
|
||||
def test_p1_false_partial_has_no_rotation_rule(tid):
|
||||
"""P1=false partials must not declare ``aspect-ratio < 1.5`` rotation
|
||||
rule. F23 may still keep its own container-name for P2 cqh — only the
|
||||
rotation rule signature is forbidden here."""
|
||||
css = (FAMILIES_DIR / f"{tid}.html").read_text(encoding="utf-8")
|
||||
assert "aspect-ratio < 1.5" not in css, tid
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tid", sorted(EXPECTED_P2_TRUE))
|
||||
def test_p2_partial_uses_cqh_clamp_max_body_lines(tid):
|
||||
"""P2=true partials declare ``--max-body-lines`` + ``cqh`` + ``clamp(``
|
||||
body line-height clamp. Satisfied by F23 today; F13/F14/F20/F8 land u4-u7."""
|
||||
css = (FAMILIES_DIR / f"{tid}.html").read_text(encoding="utf-8")
|
||||
assert "--max-body-lines" in css, tid
|
||||
assert "cqh" in css, tid
|
||||
assert "clamp(" in css, tid
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tid", sorted(EXPECTED_P2_FALSE))
|
||||
def test_p2_false_partial_has_no_max_body_lines(tid):
|
||||
"""P2=false partials must not declare ``--max-body-lines``."""
|
||||
css = (FAMILIES_DIR / f"{tid}.html").read_text(encoding="utf-8")
|
||||
assert "--max-body-lines" not in css, tid
|
||||
299
tests/phase_z2/test_imp36_overflow_chain_self_fire.py
Normal file
299
tests/phase_z2/test_imp36_overflow_chain_self_fire.py
Normal file
@@ -0,0 +1,299 @@
|
||||
"""IMP-36 (Gitea #65 u8) — Selenium self-fire for the P1/P2 generalization.
|
||||
|
||||
For each of the four P1+P2 partials (F13 ``three_parallel_requirements``,
|
||||
F14 ``three_persona_benefits``, F20 ``dx_sw_necessity_three_perspectives``,
|
||||
F8 ``info_management_what_how_when``), the partial's ``<style>`` block is
|
||||
rendered with a minimal structural skeleton inside a fixed-size outer div
|
||||
at two aspect ratios — wide (1200x675, aspect 1.78) and tall (600x600,
|
||||
aspect 1.0) — and verified live in headless Chrome:
|
||||
|
||||
* P1 (container-query rotation): grid-template-columns goes from 3 tracks
|
||||
(wide, aspect >= 1.5) to 1 track (tall, aspect < 1.5).
|
||||
* P2 (cqh/clamp line-height): computed line-height on the body text element
|
||||
differs between wide and tall because ``cqh`` scales with container height.
|
||||
* P2 invariant (Stage 2 guardrail #6 / IMP-36 contract): the additive P2
|
||||
rule body declares ``line-height: clamp(...)`` only — no ``font-size``
|
||||
mutation. Enforced by static text scan of each partial.
|
||||
|
||||
OVERFLOW_CASCADE_ORDER must remain a 4-tuple — the Step 17 cascade contract
|
||||
is not altered by IMP-36 (P1/P2 are CSS-only self-fire; no new Python stage
|
||||
is introduced — "no new Python surface" per Stage 2 plan).
|
||||
|
||||
Chromedriver resolution mirrors the pipeline order (``PROJECT_ROOT/
|
||||
chromedriver{,.exe}`` -> PATH -> Selenium Manager). When no driver resolves
|
||||
the suite skips; under ``PHASE_Z_REQUIRE_SELENIUM=1`` the skip becomes a
|
||||
strict xfail so CI cannot silently lose coverage.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.phase_z2_ai_fallback.step17 import OVERFLOW_CASCADE_ORDER
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
FAMILIES = PROJECT_ROOT / "templates" / "phase_z2" / "families"
|
||||
|
||||
|
||||
# ─── chromedriver guard (mirrors test_phase_z2_step14_image_check) ───
|
||||
|
||||
def _selenium_manager_resolvable() -> bool:
|
||||
try:
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options as _Opts
|
||||
except Exception:
|
||||
return False
|
||||
opts = _Opts()
|
||||
for arg in ("--headless=new", "--no-sandbox", "--disable-dev-shm-usage"):
|
||||
opts.add_argument(arg)
|
||||
try:
|
||||
drv = webdriver.Chrome(options=opts)
|
||||
except Exception:
|
||||
return False
|
||||
try:
|
||||
drv.quit()
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
|
||||
def _chromedriver_resolvable() -> bool:
|
||||
for candidate in (PROJECT_ROOT / "chromedriver", PROJECT_ROOT / "chromedriver.exe"):
|
||||
if candidate.is_file():
|
||||
return True
|
||||
if shutil.which("chromedriver") or shutil.which("chromedriver.exe"):
|
||||
return True
|
||||
return _selenium_manager_resolvable()
|
||||
|
||||
|
||||
_REQUIRE_SELENIUM = os.environ.get("PHASE_Z_REQUIRE_SELENIUM") == "1"
|
||||
_DRIVER_AVAILABLE = _chromedriver_resolvable()
|
||||
|
||||
if not _DRIVER_AVAILABLE:
|
||||
if _REQUIRE_SELENIUM:
|
||||
pytestmark = pytest.mark.xfail(
|
||||
strict=True,
|
||||
reason="PHASE_Z_REQUIRE_SELENIUM=1 but chromedriver is unresolvable",
|
||||
)
|
||||
else:
|
||||
pytestmark = pytest.mark.skip(
|
||||
reason=(
|
||||
"chromedriver unresolvable (PROJECT_ROOT/chromedriver{,.exe} + PATH + Selenium Manager); "
|
||||
"set PHASE_Z_REQUIRE_SELENIUM=1 to make this a hard failure"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# ─── frame harness table ─────────────────────────────────────────────
|
||||
# stem = partial filename (no .html)
|
||||
# root = top-level container-query class (target of container-type:size)
|
||||
# cols = grid class that rotates 3->1 under aspect < 1.5
|
||||
# col_inner = minimal markup for one column with one body text element.
|
||||
# The inline --max-body-lines value is chosen so the P2 clamp
|
||||
# does not saturate at both aspects (otherwise wide and tall
|
||||
# would compute identical line-height). F13 uses 20cqh / N so
|
||||
# N=8 splits the clamp band; F14/F20/F8 use 60cqh / N so N=20
|
||||
# splits theirs.
|
||||
# text_sel = CSS selector for the body text element to measure
|
||||
# p2_re = regex for the IMP-36 P2 rule body (must contain line-height
|
||||
# clamp and must NOT contain font-size)
|
||||
#
|
||||
# Font-size invariance is asserted uniformly for all four frames — IMP-36 P2
|
||||
# mutates line-height / --max-body-lines only (Stage 2 guardrail #6).
|
||||
FRAMES = [
|
||||
{
|
||||
"stem": "three_parallel_requirements",
|
||||
"root": "f13b",
|
||||
"cols": "f13b__cols",
|
||||
"col_inner": (
|
||||
'<div class="f13b__col"><div class="f13b__body">'
|
||||
'<div class="f13b__section"><div class="f13b__desc" '
|
||||
'style="--max-body-lines: 8;">'
|
||||
'<div class="text-line">line a</div>'
|
||||
'<div class="text-line">line b</div>'
|
||||
"</div></div></div></div>"
|
||||
),
|
||||
"text_sel": ".f13b__desc",
|
||||
"p2_re": r"\.f13b__desc\s*\{\s*line-height:\s*clamp\([^}]*\}",
|
||||
},
|
||||
{
|
||||
"stem": "three_persona_benefits",
|
||||
"root": "f14b",
|
||||
"cols": "f14b__cols",
|
||||
"col_inner": (
|
||||
'<div class="f14b__col"><div class="f14b__body" '
|
||||
'style="--max-body-lines: 20;">'
|
||||
'<div class="text-line">line a</div>'
|
||||
'<div class="text-line">line b</div>'
|
||||
"</div></div>"
|
||||
),
|
||||
"text_sel": ".f14b__body .text-line",
|
||||
"p2_re": r"\.f14b__body\s+\.text-line\s*\{\s*line-height:\s*clamp\([^}]*\}",
|
||||
},
|
||||
{
|
||||
"stem": "dx_sw_necessity_three_perspectives",
|
||||
"root": "f20b",
|
||||
"cols": "f20b__cols",
|
||||
"col_inner": (
|
||||
'<div class="f20b__col"><div class="f20b__body" '
|
||||
'style="--max-body-lines: 20;">'
|
||||
'<div class="text-line">line a</div>'
|
||||
'<div class="text-line">line b</div>'
|
||||
"</div></div>"
|
||||
),
|
||||
"text_sel": ".f20b__body .text-line",
|
||||
"p2_re": r"\.f20b__body\s+\.text-line\s*\{\s*line-height:\s*clamp\([^}]*\}",
|
||||
},
|
||||
{
|
||||
"stem": "info_management_what_how_when",
|
||||
"root": "f8b",
|
||||
"cols": "f8b__cols",
|
||||
"col_inner": (
|
||||
'<div class="f8b__col"><div class="f8b__body" '
|
||||
'style="--max-body-lines: 20;">'
|
||||
'<div class="text-line">line a</div>'
|
||||
'<div class="text-line">line b</div>'
|
||||
"</div></div>"
|
||||
),
|
||||
"text_sel": ".f8b__body .text-line",
|
||||
"p2_re": r"\.f8b__body\s+\.text-line\s*\{\s*line-height:\s*clamp\([^}]*\}",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _read_style_block(partial: Path) -> str:
|
||||
text = partial.read_text(encoding="utf-8")
|
||||
m = re.search(r"<style>(.*?)</style>", text, flags=re.DOTALL)
|
||||
assert m, f"<style> block missing in {partial}"
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def _harness_html(frame: dict, outer_w: int, outer_h: int) -> str:
|
||||
style = _read_style_block(FAMILIES / f"{frame['stem']}.html")
|
||||
cols_html = (
|
||||
f'<div class="{frame["cols"]}">' + (frame["col_inner"] * 3) + "</div>"
|
||||
)
|
||||
return (
|
||||
"<!doctype html><html><head><meta charset='utf-8'><style>"
|
||||
":root{"
|
||||
" --font-body:10px; --font-sub-title:12px; --font-zone-title:13px;"
|
||||
" --font-caption:10px;"
|
||||
" --lh-body:1.4; --lh-sub-title:1.3; --lh-zone-title:1.3;"
|
||||
"}"
|
||||
"html,body{margin:0;padding:0;font-size:10px;}"
|
||||
f".outer{{width:{outer_w}px;height:{outer_h}px;}}"
|
||||
f".outer > .{frame['root']}{{width:100%;height:100%;}}"
|
||||
f"{style}</style></head><body>"
|
||||
f'<div class="outer"><div class="{frame["root"]}">'
|
||||
f"{cols_html}"
|
||||
"</div></div></body></html>"
|
||||
)
|
||||
|
||||
|
||||
def _new_driver():
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options as _Opts
|
||||
opts = _Opts()
|
||||
for arg in ("--headless=new", "--no-sandbox", "--disable-dev-shm-usage"):
|
||||
opts.add_argument(arg)
|
||||
drv_path = None
|
||||
for cand in (PROJECT_ROOT / "chromedriver", PROJECT_ROOT / "chromedriver.exe"):
|
||||
if cand.is_file():
|
||||
drv_path = str(cand)
|
||||
break
|
||||
if drv_path is None:
|
||||
which = shutil.which("chromedriver") or shutil.which("chromedriver.exe")
|
||||
if which:
|
||||
drv_path = which
|
||||
if drv_path:
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
return webdriver.Chrome(service=Service(executable_path=drv_path), options=opts)
|
||||
return webdriver.Chrome(options=opts)
|
||||
|
||||
|
||||
def _measure(drv, frame: dict, html_path: Path) -> dict:
|
||||
drv.get(html_path.resolve().as_uri())
|
||||
cols_tpl = drv.execute_script(
|
||||
"return getComputedStyle(document.querySelector(arguments[0])).gridTemplateColumns;",
|
||||
f".{frame['cols']}",
|
||||
)
|
||||
lh = drv.execute_script(
|
||||
"var el = document.querySelector(arguments[0]); "
|
||||
"return el ? getComputedStyle(el).lineHeight : null;",
|
||||
frame["text_sel"],
|
||||
)
|
||||
fs = drv.execute_script(
|
||||
"var el = document.querySelector(arguments[0]); "
|
||||
"return el ? getComputedStyle(el).fontSize : null;",
|
||||
frame["text_sel"],
|
||||
)
|
||||
tracks = [t for t in (cols_tpl or "").split() if t]
|
||||
return {"cols": cols_tpl, "tracks": len(tracks), "lh": lh, "fs": fs}
|
||||
|
||||
|
||||
# ─── live (Selenium) parametrized check ──────────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.parametrize("frame", FRAMES, ids=[f["stem"] for f in FRAMES])
|
||||
def test_p1_rotation_and_p2_lineheight_self_fire(tmp_path: Path, frame: dict) -> None:
|
||||
"""P1: 3-track grid rotates to 1-track when aspect < 1.5.
|
||||
P2: line-height differs between aspects (cqh-driven clamp evaluates
|
||||
differently as container height changes).
|
||||
Font-size invariance is asserted uniformly for all four frames — IMP-36
|
||||
P2 mutates line-height / --max-body-lines only (Stage 2 guardrail #6)."""
|
||||
wide_path = tmp_path / f"{frame['stem']}_wide.html"
|
||||
tall_path = tmp_path / f"{frame['stem']}_tall.html"
|
||||
wide_path.write_text(_harness_html(frame, 1200, 600), encoding="utf-8")
|
||||
tall_path.write_text(_harness_html(frame, 400, 400), encoding="utf-8")
|
||||
|
||||
drv = _new_driver()
|
||||
try:
|
||||
drv.set_window_size(1400, 900)
|
||||
wide = _measure(drv, frame, wide_path)
|
||||
tall = _measure(drv, frame, tall_path)
|
||||
finally:
|
||||
try:
|
||||
drv.quit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
assert wide["tracks"] == 3, (frame["stem"], wide)
|
||||
assert tall["tracks"] == 1, (frame["stem"], tall)
|
||||
assert wide["lh"] is not None and tall["lh"] is not None, (frame["stem"], wide, tall)
|
||||
assert wide["lh"] != tall["lh"], (frame["stem"], wide, tall)
|
||||
assert wide["fs"] == tall["fs"], (frame["stem"], wide, tall)
|
||||
|
||||
|
||||
# ─── static (no-Selenium) guards ─────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.mark.parametrize("frame", FRAMES, ids=[f["stem"] for f in FRAMES])
|
||||
def test_p2_rule_declares_line_height_only(frame: dict) -> None:
|
||||
"""IMP-36 P2 invariant — the additive P2 rule body must contain
|
||||
``line-height: clamp(`` and must NOT declare ``font-size``."""
|
||||
body = (FAMILIES / f"{frame['stem']}.html").read_text(encoding="utf-8")
|
||||
m = re.search(frame["p2_re"], body, flags=re.DOTALL)
|
||||
assert m, f"{frame['stem']}: P2 clamp rule not located via /{frame['p2_re']}/"
|
||||
rule_body = m.group(0)
|
||||
assert "line-height:" in rule_body, f"{frame['stem']}: P2 rule missing line-height: {rule_body!r}"
|
||||
assert "clamp(" in rule_body, f"{frame['stem']}: P2 rule missing clamp(: {rule_body!r}"
|
||||
assert "font-size" not in rule_body, (
|
||||
f"{frame['stem']}: P2 rule must not declare font-size — got {rule_body!r}"
|
||||
)
|
||||
|
||||
|
||||
def test_overflow_cascade_order_is_four_tuple() -> None:
|
||||
"""IMP-36 must not alter the Step 17 cascade contract. P1/P2 are CSS-only
|
||||
self-fire (no new Python stage); the 4-tuple stays intact."""
|
||||
assert isinstance(OVERFLOW_CASCADE_ORDER, tuple)
|
||||
assert len(OVERFLOW_CASCADE_ORDER) == 4
|
||||
assert [stage.value for stage in OVERFLOW_CASCADE_ORDER] == [
|
||||
"deterministic",
|
||||
"popup",
|
||||
"ai_repair",
|
||||
"user_override",
|
||||
]
|
||||
Reference in New Issue
Block a user