Frame-aware AI fallback module scaffolded under src/phase_z2_ai_fallback/ with master flag ai_fallback_enabled=False; normal-path AI call count remains 0. AI output constrained to builder_options_patch / partial_overrides / slot_mapping_proposal; MDX / frame_id / raw HTML / raw CSS mutations rejected at schema layer. IMP-46 cache gate (cache.py) raises AiFallbackCacheGateError unless visual_check_passed AND user_approved. Step 12 wires AI repair after IMP-30 provisional payload only; Step 17 stays blocked behind IMP-34 / IMP-35 prerequisites. AST isolation guard forbids fallback package from importing Phase Q / Kei / pipeline runtime symbols. Docs IMP-17 / IMP-31 bound to runtime module surface via 11-row structural test pin (test_docs_sync.py) so drift fails CI. Tests: 116 fallback / 161 phase_z2 regression / 526 scoped full sweep all passing. Existing pre-IMP-33 fixture issue in scripts/test_phase_t_* remains untouched (out of scope). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""IMP-33 u2 — AiFallbackProposal schema tests.
|
|
|
|
Scope (Stage 2 plan, u2):
|
|
- Whitelisted proposal_kind values are accepted.
|
|
- Forbidden output forms are rejected: mdx_text / frame_id_change / raw_html / raw_css.
|
|
- extra fields outside the declared schema are rejected (MDX read-only signal).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from src.phase_z2_ai_fallback import AiFallbackProposal, ProposalKind
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"kind_value",
|
|
[
|
|
"builder_options_patch",
|
|
"partial_overrides",
|
|
"slot_mapping_proposal",
|
|
],
|
|
)
|
|
def test_whitelisted_proposal_kinds_accepted(kind_value: str) -> None:
|
|
proposal = AiFallbackProposal(proposal_kind=kind_value)
|
|
assert proposal.proposal_kind == ProposalKind(kind_value)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"forbidden",
|
|
["mdx_text", "frame_id_change", "raw_html", "raw_css"],
|
|
)
|
|
def test_forbidden_proposal_kinds_rejected(forbidden: str) -> None:
|
|
with pytest.raises(ValidationError):
|
|
AiFallbackProposal(proposal_kind=forbidden)
|
|
|
|
|
|
def test_unknown_proposal_kind_rejected() -> None:
|
|
with pytest.raises(ValidationError):
|
|
AiFallbackProposal(proposal_kind="something_else")
|
|
|
|
|
|
def test_extra_fields_rejected() -> None:
|
|
"""`extra=forbid` keeps the AI from smuggling raw_html/mdx_text alongside a valid kind."""
|
|
with pytest.raises(ValidationError):
|
|
AiFallbackProposal(proposal_kind="partial_overrides", raw_html="<div/>")
|