feat(IMP-09): PR 2 — 2-D dynamic dispatch for 5 preset families

Stage 3 lock implementation: extend build_layout_css dispatch beyond
the horizontal-2 / vertical-2 1-D dynamic paths. T / inverted-T /
side-T-left / side-T-right / 2x2 now flow through a 2-D track solver
instead of the fr_default sink, with length-locked heights_px (R) +
widths_px (C) on every return path (default and override).

PR 2 scope (u1~u5):
  - u1: _aggregate_zone_signals_per_track — per-row + per-col virtual
    zones via max(weight) + max(min_height_px) of single-span zones,
    falling back to all-span when a track has none.
  - u2: _build_grid_dynamic_2d default builder — feeds virtual zones
    into compute_zone_layout + compute_zone_layout_cols; emits
    computation="2d_dynamic_aggregated", dynamic_rows=True,
    dynamic_cols=True.
  - u3: _override_to_grid_tracks override builder — single-span
    aggregation (max h per row, max w per col), normalize, multiply
    by avail_h/avail_w, last-element diff absorb; emits
    computation="user_override_geometry"; falls back to u2 when
    total_h or total_w == 0.
  - u4: build_layout_css dispatcher wiring — topology in
    {T, inverted-T, side-T-left, side-T-right, 2x2} routes to
    _build_grid_dynamic_2d (default) or _override_to_grid_tracks
    (override); legacy [override-warning] stderr removed for the
    5 presets; step08 trace gains a 2-D-aware print line that fires
    before the dynamic_rows / dynamic_cols branches.
  - u5: PR 1 lock test test_top_1_bottom_2_fr_default_populates_geometry
    renamed to test_top_1_bottom_2_dynamic_2d_populates_geometry and
    flipped to PR 2 reality (computation="2d_dynamic_aggregated",
    dynamic_rows=True, dynamic_cols=True).

Fixtures: 10 build_layout_css (5 presets × {default, override}) +
5 retry_gate *_dynamic_2d.yaml locking the retry gate skip reason
"dynamic_cols (2-D topology) ... IMP-09 lock" for the 5 presets.

Tests: python -m pytest -q tests = 104 passed (Stage 2 baseline
10 RED → GREEN, 0 regressions). Kei archive
(build_containers_type_b / page_structure) untouched —
rg "build_containers_type_b|page_structure" src/phase_z2_pipeline.py
returns 0 hits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 18:51:23 +09:00
parent 201099e53b
commit 1fb973297f
17 changed files with 825 additions and 14 deletions

View File

@@ -0,0 +1,43 @@
input:
layout_preset: grid-2x2
zones_data:
- position: top-left
template_id: MOCK_top-left
content_weight:
score: 0.25
min_height_px: 200
- position: top-right
template_id: MOCK_top-right
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-left
template_id: MOCK_bottom-left
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-right
template_id: MOCK_bottom-right
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries: null
expected_layout_css:
areas: '"top-left top-right" "bottom-left bottom-right"'
cols: 583px 583px
rows: 286px 285px
heights_px:
- 286
- 285
widths_px:
- 583
- 583
ratios:
- 0.489
- 0.487
width_ratios:
- 0.494
- 0.494
computation: 2d_dynamic_aggregated
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,63 @@
input:
layout_preset: grid-2x2
zones_data:
- position: top-left
template_id: MOCK_top-left
content_weight:
score: 0.25
min_height_px: 200
- position: top-right
template_id: MOCK_top-right
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-left
template_id: MOCK_bottom-left
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-right
template_id: MOCK_bottom-right
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries:
top-left:
x: 0
y: 0
w: 0.55
h: 0.4
top-right:
x: 0.55
y: 0
w: 0.45
h: 0.4
bottom-left:
x: 0
y: 0.4
w: 0.55
h: 0.6
bottom-right:
x: 0.55
y: 0.4
w: 0.45
h: 0.6
expected_layout_css:
areas: '"top-left top-right" "bottom-left bottom-right"'
cols: 641px 525px
rows: 228px 343px
heights_px:
- 228
- 343
widths_px:
- 641
- 525
ratios:
- 0.4
- 0.6
width_ratios:
- 0.55
- 0.45
computation: user_override_geometry
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,38 @@
input:
layout_preset: left-1-right-2
zones_data:
- position: left
template_id: MOCK_left
content_weight:
score: 0.5
min_height_px: 200
- position: right-top
template_id: MOCK_right-top
content_weight:
score: 0.25
min_height_px: 200
- position: right-bottom
template_id: MOCK_right-bottom
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries: null
expected_layout_css:
areas: '"left right-top" "left right-bottom"'
cols: 777px 389px
rows: 286px 285px
heights_px:
- 286
- 285
widths_px:
- 777
- 389
ratios:
- 0.489
- 0.487
width_ratios:
- 0.658
- 0.33
computation: 2d_dynamic_aggregated
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,53 @@
input:
layout_preset: left-1-right-2
zones_data:
- position: left
template_id: MOCK_left
content_weight:
score: 0.5
min_height_px: 200
- position: right-top
template_id: MOCK_right-top
content_weight:
score: 0.25
min_height_px: 200
- position: right-bottom
template_id: MOCK_right-bottom
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries:
left:
x: 0
y: 0
w: 0.4
h: 1.0
right-top:
x: 0.4
y: 0
w: 0.6
h: 0.5
right-bottom:
x: 0.4
y: 0.5
w: 0.6
h: 0.5
expected_layout_css:
areas: '"left right-top" "left right-bottom"'
cols: 466px 700px
rows: 286px 285px
heights_px:
- 286
- 285
widths_px:
- 466
- 700
ratios:
- 0.5
- 0.5
width_ratios:
- 0.4
- 0.6
computation: user_override_geometry
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,38 @@
input:
layout_preset: left-2-right-1
zones_data:
- position: left-top
template_id: MOCK_left-top
content_weight:
score: 0.25
min_height_px: 200
- position: left-bottom
template_id: MOCK_left-bottom
content_weight:
score: 0.25
min_height_px: 200
- position: right
template_id: MOCK_right
content_weight:
score: 0.5
min_height_px: 200
override_zone_geometries: null
expected_layout_css:
areas: '"left-top right" "left-bottom right"'
cols: 389px 777px
rows: 286px 285px
heights_px:
- 286
- 285
widths_px:
- 389
- 777
ratios:
- 0.489
- 0.487
width_ratios:
- 0.33
- 0.658
computation: 2d_dynamic_aggregated
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,53 @@
input:
layout_preset: left-2-right-1
zones_data:
- position: left-top
template_id: MOCK_left-top
content_weight:
score: 0.25
min_height_px: 200
- position: left-bottom
template_id: MOCK_left-bottom
content_weight:
score: 0.25
min_height_px: 200
- position: right
template_id: MOCK_right
content_weight:
score: 0.5
min_height_px: 200
override_zone_geometries:
left-top:
x: 0
y: 0
w: 0.35
h: 0.6
left-bottom:
x: 0
y: 0.6
w: 0.35
h: 0.4
right:
x: 0.35
y: 0
w: 0.65
h: 1.0
expected_layout_css:
areas: '"left-top right" "left-bottom right"'
cols: 408px 758px
rows: 343px 228px
heights_px:
- 343
- 228
widths_px:
- 408
- 758
ratios:
- 0.6
- 0.4
width_ratios:
- 0.35
- 0.65
computation: user_override_geometry
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,38 @@
input:
layout_preset: top-1-bottom-2
zones_data:
- position: top
template_id: MOCK_top
content_weight:
score: 0.5
min_height_px: 200
- position: bottom-left
template_id: MOCK_bottom-left
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-right
template_id: MOCK_bottom-right
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries: null
expected_layout_css:
areas: '"top top" "bottom-left bottom-right"'
cols: 583px 583px
rows: 314px 257px
heights_px:
- 314
- 257
widths_px:
- 583
- 583
ratios:
- 0.537
- 0.439
width_ratios:
- 0.494
- 0.494
computation: 2d_dynamic_aggregated
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,53 @@
input:
layout_preset: top-1-bottom-2
zones_data:
- position: top
template_id: MOCK_top
content_weight:
score: 0.5
min_height_px: 200
- position: bottom-left
template_id: MOCK_bottom-left
content_weight:
score: 0.25
min_height_px: 200
- position: bottom-right
template_id: MOCK_bottom-right
content_weight:
score: 0.25
min_height_px: 200
override_zone_geometries:
top:
x: 0
y: 0
w: 1.0
h: 0.3
bottom-left:
x: 0
y: 0.3
w: 0.5
h: 0.7
bottom-right:
x: 0.5
y: 0.3
w: 0.5
h: 0.7
expected_layout_css:
areas: '"top top" "bottom-left bottom-right"'
cols: 583px 583px
rows: 171px 400px
heights_px:
- 171
- 400
widths_px:
- 583
- 583
ratios:
- 0.3
- 0.7
width_ratios:
- 0.5
- 0.5
computation: user_override_geometry
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,38 @@
input:
layout_preset: top-2-bottom-1
zones_data:
- position: top-left
template_id: MOCK_top-left
content_weight:
score: 0.25
min_height_px: 200
- position: top-right
template_id: MOCK_top-right
content_weight:
score: 0.25
min_height_px: 200
- position: bottom
template_id: MOCK_bottom
content_weight:
score: 0.5
min_height_px: 200
override_zone_geometries: null
expected_layout_css:
areas: '"top-left top-right" "bottom bottom"'
cols: 583px 583px
rows: 257px 314px
heights_px:
- 257
- 314
widths_px:
- 583
- 583
ratios:
- 0.439
- 0.537
width_ratios:
- 0.494
- 0.494
computation: 2d_dynamic_aggregated
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,53 @@
input:
layout_preset: top-2-bottom-1
zones_data:
- position: top-left
template_id: MOCK_top-left
content_weight:
score: 0.25
min_height_px: 200
- position: top-right
template_id: MOCK_top-right
content_weight:
score: 0.25
min_height_px: 200
- position: bottom
template_id: MOCK_bottom
content_weight:
score: 0.5
min_height_px: 200
override_zone_geometries:
top-left:
x: 0
y: 0
w: 0.6
h: 0.4
top-right:
x: 0.6
y: 0
w: 0.4
h: 0.4
bottom:
x: 0
y: 0.4
w: 1.0
h: 0.6
expected_layout_css:
areas: '"top-left top-right" "bottom bottom"'
cols: 700px 466px
rows: 228px 343px
heights_px:
- 228
- 343
widths_px:
- 700
- 466
ratios:
- 0.4
- 0.6
width_ratios:
- 0.6
- 0.4
computation: user_override_geometry
dynamic_rows: true
dynamic_cols: true

View File

@@ -0,0 +1,24 @@
case_id: grid-2x2_dynamic_2d
description: |
grid-2x2 (2x2 topology) is promoted to 2-D dynamic in IMP-09 PR 2.
Row-axis retry MUST be skipped by the gate with the
"dynamic_cols (2-D topology)" reason.
input_layout_css:
areas: '"top-left top-right" "bottom-left bottom-right"'
cols: 583px 583px
rows: 286px 285px
heights_px: [286, 285]
widths_px: [583, 583]
ratios: [0.489, 0.487]
width_ratios: [0.494, 0.494]
dynamic_rows: true
dynamic_cols: true
router_decision:
router_active: true
proposed_actions_summary: [zone_ratio_retry]
expected_gate:
retry_attempted: false
retry_skipped_reason_contains:
- "dynamic_cols"
- "2-D"
- "IMP-09"

View File

@@ -0,0 +1,24 @@
case_id: left-1-right-2_dynamic_2d
description: |
left-1-right-2 (side-T-left topology) is promoted to 2-D dynamic in
IMP-09 PR 2. Row-axis retry MUST be skipped by the gate with the
"dynamic_cols (2-D topology)" reason.
input_layout_css:
areas: '"left right-top" "left right-bottom"'
cols: 777px 389px
rows: 286px 285px
heights_px: [286, 285]
widths_px: [777, 389]
ratios: [0.489, 0.487]
width_ratios: [0.658, 0.33]
dynamic_rows: true
dynamic_cols: true
router_decision:
router_active: true
proposed_actions_summary: [zone_ratio_retry]
expected_gate:
retry_attempted: false
retry_skipped_reason_contains:
- "dynamic_cols"
- "2-D"
- "IMP-09"

View File

@@ -0,0 +1,24 @@
case_id: left-2-right-1_dynamic_2d
description: |
left-2-right-1 (side-T-right topology) is promoted to 2-D dynamic in
IMP-09 PR 2. Row-axis retry MUST be skipped by the gate with the
"dynamic_cols (2-D topology)" reason.
input_layout_css:
areas: '"left-top right" "left-bottom right"'
cols: 389px 777px
rows: 286px 285px
heights_px: [286, 285]
widths_px: [389, 777]
ratios: [0.489, 0.487]
width_ratios: [0.33, 0.658]
dynamic_rows: true
dynamic_cols: true
router_decision:
router_active: true
proposed_actions_summary: [zone_ratio_retry]
expected_gate:
retry_attempted: false
retry_skipped_reason_contains:
- "dynamic_cols"
- "2-D"
- "IMP-09"

View File

@@ -0,0 +1,26 @@
case_id: top-1-bottom-2_dynamic_2d
description: |
top-1-bottom-2 (T topology) is promoted to 2-D dynamic in IMP-09
PR 2 (dynamic_rows=True, dynamic_cols=True). Row-axis retry MUST be
skipped by the IMP-09 gate with the "dynamic_cols (2-D topology)"
skip reason, because row-only redistribution cannot reconcile both
axes simultaneously.
input_layout_css:
areas: '"top top" "bottom-left bottom-right"'
cols: 583px 583px
rows: 314px 257px
heights_px: [314, 257]
widths_px: [583, 583]
ratios: [0.537, 0.439]
width_ratios: [0.494, 0.494]
dynamic_rows: true
dynamic_cols: true
router_decision:
router_active: true
proposed_actions_summary: [zone_ratio_retry]
expected_gate:
retry_attempted: false
retry_skipped_reason_contains:
- "dynamic_cols"
- "2-D"
- "IMP-09"

View File

@@ -0,0 +1,24 @@
case_id: top-2-bottom-1_dynamic_2d
description: |
top-2-bottom-1 (inverted-T topology) is promoted to 2-D dynamic in
IMP-09 PR 2. Row-axis retry MUST be skipped by the gate with the
"dynamic_cols (2-D topology)" reason.
input_layout_css:
areas: '"top-left top-right" "bottom bottom"'
cols: 583px 583px
rows: 257px 314px
heights_px: [257, 314]
widths_px: [583, 583]
ratios: [0.439, 0.537]
width_ratios: [0.494, 0.494]
dynamic_rows: true
dynamic_cols: true
router_decision:
router_active: true
proposed_actions_summary: [zone_ratio_retry]
expected_gate:
retry_attempted: false
retry_skipped_reason_contains:
- "dynamic_cols"
- "2-D"
- "IMP-09"

View File

@@ -138,21 +138,21 @@ def test_vertical_2_override_keeps_fr_cols_legacy():
assert result["width_ratios"] == [0.4, 0.6]
# ────────────────────── fr_default sink (PR 1) ──────────────────────
# ────────────────────── 2-D dynamic dispatch (PR 2) ──────────────────────
def test_top_1_bottom_2_fr_default_populates_geometry():
"""T-shape (top-1-bottom-2) falls through to fr_default in PR 1
but heights_px / widths_px must be populated (length-locked to
grid R=2, C=2)."""
def test_top_1_bottom_2_dynamic_2d_populates_geometry():
"""T-shape (top-1-bottom-2) is dispatched through the 2-D dynamic
builder in PR 2: heights_px / widths_px length-locked to grid
R=2, C=2 with both dynamic flags True."""
zones = [
_zone("top", 0.5),
_zone("bottom-left", 0.25),
_zone("bottom-right", 0.25),
]
result = build_layout_css("top-1-bottom-2", zones)
assert result["computation"] == "fr_default_from_preset"
assert result["dynamic_rows"] is False
assert result["dynamic_cols"] is False
assert result["computation"] == "2d_dynamic_aggregated"
assert result["dynamic_rows"] is True
assert result["dynamic_cols"] is True
assert len(result["heights_px"]) == 2 # R rows
assert len(result["widths_px"]) == 2 # C cols