§
    ªÇjë"  ã                   óô  — d Z ddlZddlZddlZddlZddlZddlmZ  ee¦  «         	                    ¦   «         j
        Zej
        Z ee¦  «        ej        vr$ej                             d ee¦  «        ¦  «          ee¦  «        ej        vr$ej                             d ee¦  «        ¦  «         ddlmZmZmZmZmZmZmZmZmZmZmZmZ  G d„ dej        ¦  «        Zedk    r ej         ¦   «          dS dS )z�
Tier 3: Cross-Feature Interactions Test Suite
Contains >= 13 pairwise cross-subsystem interaction tests (Total: 15 test cases).
é    N)ÚPath)ÚFILMMAKER_DIRÚPROMPTS_DIRÚ
ASSETS_DIRÚ	BIBLE_DIRÚPIPELINE_DIRÚEXPORTS_DIRÚWEB_REVIEW_DIRÚread_ep01_screenplayÚget_screenplay_scenesÚfind_male_crying_violationsÚload_muse_prompts_dataÚload_banana_prompts_datac                   ól   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚTestTier3InteractionszO
    Tier 3 tests exercise integration contracts across multiple features.
    c                 ó  — t          ¦   «         }t          |¦  «        }d„ |D ¦   «         }|                      t          |¦  «        dk    d¦  «         |d         d         }t	          t          j        d|t
          j        ¦  «        ¦  «        }t	          t          j        d|t
          j        ¦  «        ¦  «        }t	          t          j        d|t
          j        ¦  «        ¦  «        }|                      |o|o|d¦  «         d	S )
zYPairwise (F1 + F2): Expanded screenplay embeds the 3 canonical sub-beats within Scene 05.c                 ó:   — g | ]}d |d         v s
d|d         v ¯|‘ŒS ©u	   Cáº¢NH 05r   u   Cáº¢NH 5© ©Ú.0Úss     ú6C:\Projects\KieuStory\tests\test_tier3_interactions.pyú
<listcomp>z]TestTier3Interactions.test_f1_f2_screenplay_scene05_sub_beats_integration.<locals>.<listcomp>%   ó5   € ÐTÐTÐT˜1¨+¸¸1¼Ð*=Ð*=ÀÈqÐQRÌtÐASÐAS�QÐASÐASÐASó    r   z*Scene 05 must exist in expanded screenplayé   u   tiá»ƒu khÃª|bÆ°á»›c dáº§nu   sÃ¨ sÃ¨|náº¥m má»“|váº¯ng tanhu4   Ä‘au Ä‘á»›n thay|báº¡c má»‡nh|dáº¥u hÃ i|dáº¥u giÃ yz1Scene 05 must integrate all 3 canonical sub-beatsN)r   r   Ú
assertTrueÚlenÚboolÚreÚsearchÚ
IGNORECASE)ÚselfÚ
screenplayÚscenesÚ	sc5_tupleÚsc5_contentÚ
has_beat_aÚ
has_beat_bÚ
has_beat_cs           r   Ú3test_f1_f2_screenplay_scene05_sub_beats_integrationzITestTier3Interactions.test_f1_f2_screenplay_scene05_sub_beats_integration!   sÞ   € å)Ñ+Ô+ˆ
Ý& zÑ2Ô2ˆØTÐT ÐTÑTÔTˆ	Ø�Š�˜I™œ¨Ò*Ð,XÑYÔYÐYØ ”l 1”oˆÝ�"œ)Ð$@À+ÍrÌ}Ñ]Ô]Ñ^Ô^ˆ
Ý�"œ)Ð$EÀ{ÕTVÔTaÑbÔbÑcÔcˆ
Ý�"œ)Ð$[Ð]hÕjlÔjwÑxÔxÑyÔyˆ
Ø�Š˜
Ð@ zÐ@°jÐBuÑvÔvÐvÐvÐvr   c                 óŽ   — t          ¦   «         }t          |¦  «        }|                      t          |¦  «        dd|› �¦  «         dS )z_Pairwise (F1 + F3): Expanded 188-shot screenplay maintains 0% male crying across all 15 scenes.r   z4Found male tears violations in expanded screenplay: N)r   r   ÚassertEqualr   )r$   r%   Ú
violationss      r   Ú4test_f1_f3_screenplay_expansion_with_zero_male_tearszJTestTier3Interactions.test_f1_f3_screenplay_expansion_with_zero_male_tears-   sH   € å)Ñ+Ô+ˆ
Ý0°Ñ<Ô<ˆ
Ø×Ò�˜Z™œ¨!Ð-pÐdnÐ-pÐ-pÑqÔqÐqÐqÐqr   c                 óö   — t          ¦   «         }t          |¦  «        }d„ |D ¦   «         }|rM|d         d         }d„ t          |¦  «        D ¦   «         }|                      t	          |¦  «        dd¦  «         dS dS )uj   Pairwise (F2 + F3): VÆ°Æ¡ng Quan maintains feudal stoicism throughout the emotional Ä�áº¡m TiÃªn sequence.c                 ó:   — g | ]}d |d         v s
d|d         v ¯|‘ŒS r   r   r   s     r   r   zTTestTier3Interactions.test_f2_f3_dam_tien_sequence_male_stoicism.<locals>.<listcomp>7   r   r   r   r   c                 ó*   — g | ]}|d          dk    ¯|‘ŒS )Ú	characteru   VÆ¯Æ NG QUANr   )r   Úvs     r   r   zTTestTier3Interactions.test_f2_f3_dam_tien_sequence_male_stoicism.<locals>.<listcomp>:   s*   € ÐrÐrÐr 1ÐQRÐS^ÔQ_ÐcqÒQqÐQq˜QÐQqÐQqÐQqr   u/   VÆ°Æ¡ng Quan must maintain stoicism in Scene 05N)r   r   r   r.   r   )r$   r%   r&   r'   Úsc5_textÚvq_violationss         r   Ú*test_f2_f3_dam_tien_sequence_male_stoicismz@TestTier3Interactions.test_f2_f3_dam_tien_sequence_male_stoicism3   s’   € å)Ñ+Ô+ˆ
Ý& zÑ2Ô2ˆØTÐT ÐTÑTÔTˆ	Øð 	gØ  ”| A”ˆHØrÐrÕ(CÀHÑ(MÔ(MÐrÑrÔrˆMØ×Ò�S Ñ/Ô/°Ð4eÑfÔfÐfÐfÐfð	gð 	gr   c                 óø   — t           dz  }|                     ¦   «         r|                     d¬¦  «        nd}t          t	          j        d|t          j        ¦  «        ¦  «        }|                      |d¦  «         dS )z_Pairwise (F4 + F3): Universal Acting Directives in Bible explicitly mandate 0% male tears rule.úCHARACTER_BIBLE.mdúutf-8©ÚencodingÚ uQ   (Anti-Male-Tears|Nam nhÃ¢n tuyá»‡t Ä‘á»‘i khÃ´ng rÆ¡i lá»‡|khÃ´ng Ä‘Æ°á»£c khÃ³c)z:Bible must explicitly codify the Anti-Male-Tears directiveN©r   ÚexistsÚ	read_textr    r!   r"   r#   r   )r$   Ú
bible_pathÚcontentÚhas_rules       r   Ú4test_f4_f3_acting_directives_enforce_zero_male_tearszJTestTier3Interactions.test_f4_f3_acting_directives_enforce_zero_male_tears=   sŠ   € åÐ!5Ñ5ˆ
Ø<F×<MÒ<MÑ<OÔ<OÐW�*×&Ò&°Ð&Ñ8Ô8Ð8ÐUWˆÝ�œ	Ð"vÐxõ  BDô  BOñ  Pô  Pñ  Qô  QˆØ�Š˜Ð"^Ñ_Ô_Ð_Ð_Ð_r   c                 óf  — t           dz  }t           dz  }|                     ¦   «         r|                     d¬¦  «        nd|                     ¦   «         r|                     d¬¦  «        ndz   }t          t	          j        d|t          j        ¦  «        ¦  «        }|                      |d¦  «         dS )	zjPairwise (F4 + F6): Universal Acting Directives codify mandatory closed-lips rule for off-screen dialogue.zMASTER_BIBLE.mdr:   r;   r<   r>   u+   (khÃ³a kháº©u hÃ¬nh|closed.*lip|khÃ©p mÃ´i)z2Bible must codify lip-sync / closed-lips directiveNr?   )r$   Úmaster_bibleÚ
char_bibleÚcombinedÚhas_lip_rules        r   Ú2test_f4_f6_acting_directives_codify_lip_sync_guardzHTestTier3Interactions.test_f4_f6_acting_directives_codify_lip_sync_guardD   s²   € å Ð#4Ñ4ˆÝÐ!5Ñ5ˆ
Ø@L×@SÒ@SÑ@UÔ@UÐ]�L×*Ò*°GÐ*Ñ<Ô<Ð<Ð[]Ø>H×>OÒ>OÑ>QÔ>QÐY�J×(Ò(°'Ð(Ñ:Ô:Ð:ÐWYñ[ˆå�BœIÐ&TÐV^Õ`bÔ`mÑnÔnÑoÔoˆØ�Š˜Ð&ZÑ[Ô[Ð[Ð[Ð[r   c                 ó  — t          ¦   «         }t          ¦   «         }|                      t          |¦  «        dk    ot          |¦  «        dk    ¦  «         t	          j        |¦  «        }|                      d|v pd|v ¦  «         dS )zWPairwise (F5 + F7): Sweet-spot start frame protocol is registered in prompt registries.r   Ú1280x720Ú720pN)r   r   r   r   ÚjsonÚdumps)r$   Úbanana_dataÚ	muse_dataÚraw_bs       r   Ú5test_f5_f7_sweet_spot_start_frames_in_prompt_registryzKTestTier3Interactions.test_f5_f7_sweet_spot_start_frames_in_prompt_registryM   s|   € å.Ñ0Ô0ˆÝ*Ñ,Ô,ˆ	Ø�Š�˜KÑ(Ô(¨1Ò,ÐCµ°Y±´À!Ò1CÑDÔDÐDå”
˜;Ñ'Ô'ˆØ�Š˜
 eÐ+Ð>¨v¸¨Ñ?Ô?Ð?Ð?Ð?r   c                 ó|  ‡— t          ¦   «         }|                     di ¦  «        }d}d}|                     ¦   «         D ]^\  }}t          j        |d¬¦  «        Šd‰v sd‰v sd‰                     ¦   «         v r%|dz  }t          ˆfd	„d
D ¦   «         ¦  «        r|dz  }Œ_|dk    r|                      ||d¦  «         dS dS )zbPairwise (F6 + F7): Lip-sync guard is properly present in off-screen dialogue prompts in registry.Úmotion_promptsr   F)Úensure_asciiu   tá»« xau   ngoÃ i khungzv.o.r   c              3   ó    •K  — | ]}|‰v V — Œ	d S )Nr   )r   ÚwÚtexts     €r   ú	<genexpr>z]TestTier3Interactions.test_f6_f7_lip_sync_guard_present_in_prompt_registry.<locals>.<genexpr>`   s'   øè è € ÐmÐm Q�q˜D�yÐmÐmÐmÐmÐmÐmr   )u   khÃ©p cháº·tu
   khÃ©p mÃ´izlips closedu   khÃ´ng máº¥p mÃ¡yz-All off-screen dialogue shots must be guardedN)r   ÚgetÚitemsrO   rP   ÚlowerÚanyr.   )r$   rR   ÚpromptsÚoff_screen_countÚguarded_countÚkr5   rZ   s          @r   Ú4test_f6_f7_lip_sync_guard_present_in_prompt_registryzJTestTier3Interactions.test_f6_f7_lip_sync_guard_present_in_prompt_registryV   sò   ø€ å*Ñ,Ô,ˆ	Ø—-’-Ð 0°"Ñ5Ô5ˆØÐØˆØ—M’M‘O”Oð 	'ð 	'‰DˆAˆqÝ”:˜a¨eÐ4Ñ4Ô4ˆDØ˜DÐ Ð  N°dÐ$:Ð$:¸fÈÏ
Ê
ÉÌÐ>TÐ>TØ  AÑ%Ð ÝÐmÐmÐmÐmÐ*lÐmÑmÔmÑmÔmð 'Ø! QÑ&�MøØ˜aÒÐØ×Ò˜]Ð,<Ð>mÑnÔnÐnÐnÐnð  Ðr   c                 óÔ   — ddl m}m}m}  |¦   «         }|                      t          |¦  «        dd¦  «          |d¦  «        }|                      t          |¦  «        dd¦  «         dS )zZPairwise (F7 + F12): Prompt registry can be parsed and queried by production orchestrator.r   )Úload_muse_promptsÚget_all_shotsÚget_shots_for_scenez5Production orchestrator must load shots from registryÚep01_scene01z)Orchestrator must retrieve Scene 01 shotsN)Úproduction_orchestratorrf   rg   rh   ÚassertGreaterr   )r$   rf   rg   rh   r`   Úscene1_shotss         r   Ú0test_f7_f12_prompt_registry_consumable_by_runnerzFTestTier3Interactions.test_f7_f12_prompt_registry_consumable_by_runnere   s�   € àaÐaÐaÐaÐaÐaÐaÐaÐaÐaØ�-‘/”/ˆØ×Ò�3˜w™<œ<¨Ð,cÑdÔdÐdØ*Ð*¨>Ñ:Ô:ˆØ×Ò�3˜|Ñ,Ô,¨aÐ1\Ñ]Ô]Ð]Ð]Ð]r   c                 ó²   — ddl m}  |¦   «         }|                      t          |d¦  «        ¦  «         |                      t          |d¦  «        ¦  «         dS )ziPairwise (F8 + F9): Audio crossfade stitching preserves continuous background ambience without click/pop.r   ©ÚAudioContinuityEngineÚstitch_with_audio_crossfadeÚlayer_bgm_with_duckingN)Úaudio_continuity_enginerp   r   Úhasattr)r$   rp   Úengines      r   Ú<test_f8_f9_audio_crossfade_with_continuous_festival_ambiencezRTestTier3Interactions.test_f8_f9_audio_crossfade_with_continuous_festival_ambiencem   sb   € àAÐAÐAÐAÐAÐAØ&Ð&Ñ(Ô(ˆØ�Š� Ð(EÑFÔFÑGÔGÐGØ�Š� Ð(@ÑAÔAÑBÔBÐBÐBÐBr   c                 óz   — ddl }ddlm} |                     |j        ¦  «        }|                      d|¦  «         dS )zQPairwise (F8 + F10): stitch_with_audio_crossfade embeds EBU R128 loudnorm filter.r   Nro   úloudnorm=I=-14)Úinspectrs   rp   Ú	getsourcerq   ÚassertIn©r$   ry   rp   Úsrcs       r   Ú3test_f8_f10_crossfade_concat_complies_with_ebu_r128zITestTier3Interactions.test_f8_f10_crossfade_concat_complies_with_ebu_r128t   sO   € àˆˆˆØAÐAÐAÐAÐAÐAØ×ÒÐ 5Ô QÑRÔRˆØ�ŠÐ&¨Ñ,Ô,Ð,Ð,Ð,r   c                 óz   — ddl }ddlm} |                     |j        ¦  «        }|                      d|¦  «         dS )zLPairwise (F9 + F10): layer_bgm_with_ducking embeds EBU R128 loudnorm filter.r   Nro   rx   )ry   rs   rp   rz   rr   r{   r|   s       r   Ú9test_f9_f10_continuous_ambience_normalized_to_target_lufszOTestTier3Interactions.test_f9_f10_continuous_ambience_normalized_to_target_lufs{   sO   € àˆˆˆØAÐAÐAÐAÐAÐAØ×ÒÐ 5Ô LÑMÔMˆØ�ŠÐ&¨Ñ,Ô,Ð,Ð,Ð,r   c                 óè   — ddl m} ddlm}  ||¦  «        }|                     d¦  «        }|                      |j        d¦  «         |                     ¦   «         }|                      d|¦  «         dS )zQPairwise (F11 + F7): Web Review Studio /api/prompts exposes full prompt registry.r   )Úapp)Ú
TestClientz/api/promptséÈ   rV   N)	Úserverr‚   Ústarlette.testclientrƒ   r\   r.   Ústatus_coderO   r{   )r$   r‚   rƒ   ÚclientÚresÚdatas         r   Ú4test_f11_f7_web_studio_displays_full_prompt_registryzJTestTier3Interactions.test_f11_f7_web_studio_displays_full_prompt_registry‚   s„   € àÐÐÐÐÐØ3Ð3Ð3Ð3Ð3Ð3Ø�˜C‘”ˆØ�jŠj˜Ñ(Ô(ˆØ×Ò˜œ¨#Ñ.Ô.Ð.Ø�xŠx‰zŒzˆØ�ŠÐ&¨Ñ-Ô-Ð-Ð-Ð-r   c                 ó’   — ddl m}m}  |dd¬¦  «        }|                      |j        d¦  «         |                      d|¦  «         dS )zTPairwise (F11 + F12): Web Review Studio exports GenerateRequest and status tracking.r   )ÚGenerateRequestÚ	gen_statezTest promptri   )ÚpromptÚscene_idÚstatusN)r…   r�   rŽ   r.   r�   r{   )r$   r�   rŽ   Úreqs       r   Ú;test_f11_f12_web_studio_generate_triggers_production_runnerzQTestTier3Interactions.test_f11_f12_web_studio_generate_triggers_production_runnerŒ   s`   € à5Ð5Ð5Ð5Ð5Ð5Ð5Ð5Øˆo ]¸^ÐLÑLÔLˆØ×Ò˜œ ~Ñ6Ô6Ð6Ø�Š�h 	Ñ*Ô*Ð*Ð*Ð*r   c                 óô   — ddl }ddlm} |                     |¦  «        }|                      d|¦  «         |                      d|¦  «         |                      d|¦  «         |                      d|¦  «         dS )z^Pairwise (F12 + F13): Concat scene shots command enforces FFmpeg filter_complex concat [v][a].r   N)Úconcat_scene_shotsÚfilter_complexz	concat=n=Úlibx264Úaac)ry   rj   r•   rz   r{   )r$   ry   r•   r}   s       r   Ú9test_f12_f13_orchestrator_concat_produces_verified_masterzOTestTier3Interactions.test_f12_f13_orchestrator_concat_produces_verified_master“   sˆ   € àˆˆˆØ>Ð>Ð>Ð>Ð>Ð>Ø×ÒÐ 2Ñ3Ô3ˆØ�ŠÐ&¨Ñ,Ô,Ð,Ø�Š�k 3Ñ'Ô'Ð'Ø�Š�i Ñ%Ô%Ð%Ø�Š�e˜SÑ!Ô!Ð!Ð!Ð!r   c                 óV   — ddl m} |                      t          |¦  «        ¦  «         dS )z`Pairwise (F5 + F12): Production orchestrator correctly implements Head-Tail chaining resolution.r   )Úresolve_start_frameN)rj   r›   r   Úcallable)r$   r›   s     r   Ú8test_f5_f12_head_tail_chaining_resolves_via_orchestratorzNTestTier3Interactions.test_f5_f12_head_tail_chaining_resolves_via_orchestrator�   s5   € à?Ð?Ð?Ð?Ð?Ð?à�Š�Ð!4Ñ5Ô5Ñ6Ô6Ð6Ð6Ð6r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r0   r8   rE   rK   rT   rd   rm   rv   r~   r€   r‹   r“   r™   r�   r   r   r   r   r      s  € € € € € ðð ð
wð 
wð 
wðrð rð rðgð gð gð`ð `ð `ð\ð \ð \ð@ð @ð @ðoð oð oð^ð ^ð ^ðCð Cð Cð-ð -ð -ð-ð -ð -ð.ð .ð .ð+ð +ð +ð"ð "ð "ð7ð 7ð 7ð 7ð 7r   r   Ú__main__)!r¡   ÚosÚsysr!   rO   ÚunittestÚpathlibr   Ú__file__ÚresolveÚparentÚ	TESTS_DIRÚBASE_DIRÚstrÚpathÚinsertÚtestsr   r   r   r   r   r	   r
   r   r   r   r   r   ÚTestCaser   rž   Úmainr   r   r   ú<module>r²      sÄ  ððð ð
 
€	€	€	Ø 
€
€
€
Ø 	€	€	€	Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð ð ˆD�‰NŒN×"Ò"Ñ$Ô$Ô+€	ØÔ€Ø€3€x�=„=˜œÐ Ð Ø„H‡O‚O�A�s�s˜8‘}”}Ñ%Ô%Ð%Ø€3€y�>„>˜œÐ!Ð!Ø„H‡O‚O�A�s�s˜9‘~”~Ñ&Ô&Ð&ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðE7ð E7ð E7ð E7ð E7˜HÔ-ñ E7ô E7ð E7ðP ˆzÒÐØ€H„M�O„O€O€O€Oð Ðr   