- src: phase_z2 composition/mapper/pipeline/placement_planner/retry, ai_fallback(prompts/schema/validate), mdx_text_atoms 신규 - Front: PipelineTracePanel 신규, FramePanel/SlideCanvas/Home/designAgentApi 등 갱신 + 테스트 4종 추가 - templates/phase_z2: catalog(component_expansion_registry, node_slot_mapping 신규), frames, families, slide_base 갱신 - tests/matching: phase2~26 매칭 실험 스크립트·리포트·온톨로지 전체 (미커밋 진행분) - tests: b4_v4 evidence, task5~28.5 시리즈, regression(imp95 baseline) 등 신규 테스트 대량 추가 - docs/reference: MDX 구조 인벤토리, MDX→Frame 구조 계약 문서 - scripts: mdx 계약/parity/coverage/viewport 체크, gitea comment, run sync 유틸 - .gitignore: tmp*.json, chromedriver, .orchestrator, *.pkl, Front_test* 등 임시/스냅샷 제외 미완성 작업의 보존용 스냅샷 커밋 (2026-07-02) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
198 lines
6.1 KiB
Python
198 lines
6.1 KiB
Python
"""IMP-33 u5 — AI fallback validator tests.
|
|
|
|
Scope (Stage 2 plan, u5):
|
|
- schema re-validation (defence-in-depth)
|
|
- builder whitelist (BUILDER_OPTIONS_PATCH)
|
|
- dropped-slot guard (PARTIAL_OVERRIDES / SLOT_MAPPING_PROPOSAL must keep
|
|
every declared sub_zone slot present)
|
|
- frame-swap guard (no payload.frame_id mutation; V4 rank-1 protected)
|
|
- Internal Region containment (payload.region_id must match declared id)
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from src.phase_z2_ai_fallback import AiFallbackProposal, ProposalKind
|
|
from src.phase_z2_ai_fallback.validate import (
|
|
AiFallbackValidationError,
|
|
validate_proposal,
|
|
)
|
|
|
|
|
|
_FRAME_CONTRACT = {
|
|
"frame_id": 1171281190,
|
|
"sub_zones": [
|
|
{"id": "pillar_1", "accepts": ["text_block"]},
|
|
{"id": "pillar_2", "accepts": ["text_block"]},
|
|
{"id": "pillar_3", "accepts": ["text_block"]},
|
|
],
|
|
"payload": {
|
|
"builder_options": {
|
|
"item_parser": "pillar_item",
|
|
"array_root": "pillars",
|
|
"role_field": "color_class",
|
|
},
|
|
},
|
|
}
|
|
|
|
_REGION = {"id": "zone_top.region_a"}
|
|
|
|
|
|
def _make(kind: ProposalKind, payload: dict) -> AiFallbackProposal:
|
|
return AiFallbackProposal(proposal_kind=kind, payload=payload)
|
|
|
|
|
|
def test_builder_options_patch_accepts_whitelisted_keys() -> None:
|
|
proposal = _make(
|
|
ProposalKind.BUILDER_OPTIONS_PATCH,
|
|
{"item_parser": "alt_pillar_item"},
|
|
)
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_builder_options_patch_rejects_unknown_key() -> None:
|
|
proposal = _make(
|
|
ProposalKind.BUILDER_OPTIONS_PATCH,
|
|
{"item_parser": "x", "padding_px": 10},
|
|
)
|
|
with pytest.raises(AiFallbackValidationError, match="builder whitelist"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_partial_overrides_requires_all_declared_slots() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{"slots": {"pillar_1": "a", "pillar_2": "b"}},
|
|
)
|
|
with pytest.raises(AiFallbackValidationError, match="dropped-slot guard"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_partial_overrides_with_all_slots_passes() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{"slots": {"pillar_1": "a", "pillar_2": "b", "pillar_3": "c"}},
|
|
)
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_slot_mapping_proposal_requires_slots_dict() -> None:
|
|
proposal = _make(ProposalKind.SLOT_MAPPING_PROPOSAL, {"slots": []})
|
|
with pytest.raises(AiFallbackValidationError, match="dropped-slot guard"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_frame_swap_guard_rejects_mismatched_frame_id() -> None:
|
|
proposal = _make(
|
|
ProposalKind.BUILDER_OPTIONS_PATCH,
|
|
{"frame_id": 9999, "item_parser": "x"},
|
|
)
|
|
with pytest.raises(AiFallbackValidationError, match="frame-swap guard"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_frame_swap_guard_accepts_matching_frame_id() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{
|
|
"frame_id": 1171281190,
|
|
"slots": {"pillar_1": "a", "pillar_2": "b", "pillar_3": "c"},
|
|
},
|
|
)
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_internal_region_containment_rejects_mismatch() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{
|
|
"slots": {"pillar_1": "a", "pillar_2": "b", "pillar_3": "c"},
|
|
"region_id": "zone_bottom.region_x",
|
|
},
|
|
)
|
|
with pytest.raises(AiFallbackValidationError, match="Internal Region"):
|
|
validate_proposal(
|
|
proposal,
|
|
frame_contract=_FRAME_CONTRACT,
|
|
internal_region=_REGION,
|
|
)
|
|
|
|
|
|
def test_internal_region_containment_accepts_match() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{
|
|
"slots": {"pillar_1": "a", "pillar_2": "b", "pillar_3": "c"},
|
|
"region_id": "zone_top.region_a",
|
|
},
|
|
)
|
|
validate_proposal(
|
|
proposal,
|
|
frame_contract=_FRAME_CONTRACT,
|
|
internal_region=_REGION,
|
|
)
|
|
|
|
|
|
def test_internal_region_check_skipped_when_no_region_supplied() -> None:
|
|
proposal = _make(
|
|
ProposalKind.PARTIAL_OVERRIDES,
|
|
{
|
|
"slots": {"pillar_1": "a", "pillar_2": "b", "pillar_3": "c"},
|
|
"region_id": "zone_top.region_a",
|
|
},
|
|
)
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_design_adaptation_plan_accepts_structure_only_operations() -> None:
|
|
proposal = _make(
|
|
ProposalKind.DESIGN_ADAPTATION_PLAN,
|
|
{
|
|
"operations": [
|
|
{
|
|
"op": "increase_repeat_count",
|
|
"target": "pillars",
|
|
"count": 6,
|
|
},
|
|
{
|
|
"op": "compact_spacing",
|
|
"target": "frame",
|
|
"level": "medium",
|
|
},
|
|
],
|
|
"region_id": "zone_top.region_a",
|
|
},
|
|
)
|
|
|
|
validate_proposal(
|
|
proposal,
|
|
frame_contract=_FRAME_CONTRACT,
|
|
internal_region=_REGION,
|
|
)
|
|
|
|
|
|
def test_design_adaptation_plan_rejects_generated_text_fields() -> None:
|
|
proposal = _make(
|
|
ProposalKind.DESIGN_ADAPTATION_PLAN,
|
|
{
|
|
"operations": [
|
|
{
|
|
"op": "increase_repeat_count",
|
|
"target": "pillars",
|
|
"count": 4,
|
|
"label": "AI가 만든 라벨",
|
|
}
|
|
],
|
|
},
|
|
)
|
|
|
|
with pytest.raises(AiFallbackValidationError, match="content-bearing fields"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|
|
|
|
|
|
def test_design_adaptation_plan_requires_operations() -> None:
|
|
proposal = _make(ProposalKind.DESIGN_ADAPTATION_PLAN, {"region_id": "zone_top.region_a"})
|
|
|
|
with pytest.raises(AiFallbackValidationError, match="operations"):
|
|
validate_proposal(proposal, frame_contract=_FRAME_CONTRACT)
|