#!/usr/bin/env python3
"""Targeted read-only lexical/snapshot boundary tests; no media or network calls."""
import json, runpy, tempfile, unittest
from pathlib import Path
HERE=Path(__file__).resolve().parent
MODULE=runpy.run_path(str(HERE/'run-study.py'))
RULES=json.loads((HERE/'coding-rules.json').read_text())
def labels(text): return MODULE['code_text'](text,RULES)[1]
class StudyBoundaries(unittest.TestCase):
 def test_negative_comparison_is_not_positive_promotion(self):
  self.assertNotIn('product_promotion',labels('The footage should not look refined and neat like a commercial ad.'))
 def test_chinese_prohibited_interface(self):
  self.assertNotIn('interface_game',labels('不得出现手机界面。不得出现电商界面。'))
 def test_positive_and_negative_roles_are_separate(self):
  actual=labels('制作产品广告。不得出现手机界面。')
  self.assertIn('product_promotion',actual);self.assertNotIn('interface_game',actual)
 def test_adversative_starts_a_new_clause(self):
  actual=labels('Do not make a commercial, instead make a music video.')
  self.assertNotIn('product_promotion',actual);self.assertIn('music_performance',actual)
 def test_multiple_labels_are_retained(self):
  actual=labels('A product commercial and a music video.')
  self.assertIn('product_promotion',actual);self.assertIn('music_performance',actual)
 def test_repeated_cues_count_one_membership(self):
  self.assertEqual(labels('Product product product advertisement.').count('product_promotion'),1)
 def test_unicode_width_and_whitespace_normalize(self):
  self.assertEqual(MODULE['normalize']('  ＭＶ\n  '),'mv')
  self.assertIn('music_performance',labels('ＭＶ'))
 def test_style_alone_is_not_purpose(self):
  self.assertEqual(labels('Cinematic light, slow camera movement, softly falling snow.'),[])
 def test_empty_text_stays_unmatched(self):
  self.assertEqual(labels('  \n '),[])
 def test_no_source_mode_guessing_is_inside_coding(self):
  self.assertEqual(labels('Use image one as the starting composition.'),[])
 def test_unmatched_is_not_semantic_rejection(self):
  self.assertEqual(labels('A fox jumps across a small stream.'),[])
 def test_wrong_snapshot_refused_before_analysis(self):
  with tempfile.TemporaryDirectory() as temporary:
   fake=Path(temporary)/'catalog.json';fake.write_text('[]')
   with self.assertRaisesRegex(ValueError,'Source bytes differ'):
    MODULE['make_study'](fake,HERE/'coding-rules.json',Path(temporary)/'out')
if __name__=='__main__':unittest.main()
