
    j                         d Z ddlZddlmc mZ ddlZddl	Z	ddl
Z
ddlmZ  ee      j                         j                  d   Zd Zd Zd Zd Zd	 Zy)
u<  
test_task_md_preservation_2569.py
MT-T1: RC-4 + AD-4 검증
  - protection-list.json에 task 관련 경로 포함
  - cleanup-workspace.py is_protected() 정상 동작
  - file_cleanup.py SafetyChecker.is_protected() 정상 동작
  - dispatch/__init__.py에 intent-to-add 호출 4회 이상 존재 (정적 검증)
    N)Path   c                  >   t         dz  dz  } t        j                  j                  d|       }g }d}||u}|}|r|j                  }d}||u}|}|st        j                  d|fd||f      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }	d	d
|	iz  }
|j                  |
       |rt        j                  dfdf      dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }|j                  |       t        j                  |d      i z  }t        j                  d|        dz   d|iz  }t        t        j                  |            dx}x}x}x}x}x}}t        j                  j!                  |      }|j                  j#                  |       |S )u3   importlib으로 cleanup-workspace.py 동적 로드.scriptszcleanup-workspace.pycleanup_workspaceN)is not)z%(py2)s is not %(py5)sspec)py2py5z%(py7)spy7)z5%(py11)s
{%(py11)s = %(py9)s.loader
} is not %(py14)s)py9py11py14z%(py16)spy16r   u   spec 로드 실패: z
>assert %(py19)spy19)	WORKSPACE	importlibutilspec_from_file_locationloader
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprappend_format_boolop_format_assertmsgAssertionError_format_explanationmodule_from_specexec_module)module_pathr	   @py_assert1@py_assert4@py_assert3@py_assert0@py_assert10@py_assert13@py_assert12@py_format6@py_format8@py_format15@py_format17@py_format18@py_format20mods                   F/home/jay/workspace/tests/regression/test_task_md_preservation_2569.py_load_cleanup_workspacer4      sD   i'*@@K>>112E{SD]t]4t]]4]4 7]]]]4t]]]]]]4]]]4]]]t]]]]]]]4]]]]]]]]]]]]]]]4]]]]]]]]]];OP[}9]]]]]]]]]
..
)
)$
/CKKC J    c                  v  
 t         dz  dz  dz  } | j                  } |       }|st        j                  d|        dz   dt	        j
                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}t        j                  | j                  d	
            }|j                  dg       }g d}|D ]  }|j                  d      
t        
fd|D              }|r+t        j                  d| d|       dz   ddt	        j
                         v st        j                  |      rt        j                  |      ndiz  }	t        t        j                  |	             y)u`   memory/specs/protection-list.json에 task 관련 보호 경로가 모두 포함되어야 한다.memoryspecszprotection-list.jsonu   protection-list.json 없음: C
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}
plist_pathpy0r
   py4Nutf-8encodingprotected_paths)zmemory/tasks/zmemory/plans/tasks/zmemory/reports/zmemory/specs//c              3      K   | ]:  }|j                  d       k(  xs  |j                  d       j                         < yw)rB   N)rstrip
startswith).0entry
normalizeds     r3   	<genexpr>z;test_protection_list_includes_task_paths.<locals>.<genexpr>0   sC      
 LL+Wu||C/@/K/KJ/WW
s   A Au)   protection-list.json protected_paths에 'u   ' 없음. 현재 목록: z
>assert %(py0)sr<   found)r   existsr   r   r   r   r   r   r    r!   jsonloads	read_textgetrD   any)r:   r%   r'   @py_format5datarA   required_prefixesrequiredrJ   @py_format1rH   s             @r3   (test_protection_list_includes_task_pathsrV      ss   X%/2HHJLLLL"?
| LLLLLLL:LLL:LLLLLLLLLLLL::j**G*<=D HH%6;O & 

__S)
 
(
 
  	
  8z B-.0	
 	
 
6	
 	
   	
 	
 
	  	
 	
 	
 	
 	


r5   c                     t               } t        | dd       t        dz  dz  dz  }| j                  |t              }d}||u }|st	        j
                  d|fd||f      d	t        j                         v st	        j                  |      rt	        j                  |      nd	t	        j                  |      d
z  }t	        j                  d| d      dz   d|iz  }t        t	        j                  |            dx}}y)uQ   cleanup-workspace.py is_protected()가 memory/tasks/task-9999.md → True 반환._PROTECTION_CACHENr7   taskstask-9999.mdTisz%(py0)s is %(py3)sresultr<   py3u   is_protected()가 um   에 대해 False를 반환했습니다. protection-list.json 또는 is_protected() 구현을 확인하세요.
>assert %(py5)sr   )r4   setattrr   is_protectedr   r   r   r   r   r   r   r    r!   )cwtask_md_pathr^   @py_assert2r%   @py_format4r,   s          r3   /test_cleanup_workspace_is_protected_for_task_mdrh   <   s     
!	"BB#T*x''1NBL__\95F 6T>  6T                  \N +P 	P    r5   c                  |   t        t        dz        } | t        j                  vr t        j                  j	                  d|        ddl}|j                  t              }t        dz  dz  dz  }|j                  |      }d}||u }|st        j                  d|fd	||f      d
t        j                         v st        j                  |      rt        j                  |      nd
t        j                  |      dz  }t        j                  d| d      dz   d|iz  }t        t        j                   |            dx}}y)uP   file_cleanup.py SafetyChecker.is_protected()가 memory/tasks/task-X.md → True.r   r   Nr7   rY   rZ   Tr[   r]   r^   r_   u    SafetyChecker.is_protected()가 u'   에 대해 False를 반환했습니다.ra   r   )strr   syspathinsertfile_cleanupSafetyCheckerrc   r   r   r   r   r   r   r   r    r!   )	scripts_dirrn   checkerre   r^   rf   r%   rg   r,   s	            r3   *test_file_cleanup_is_protected_for_task_mdrr   L   s   i)+,K#((";'((3Gx''1NBL!!,/F 6T>  6T                  +<.8_`    r5   c                  `   t         dz  dz  } | j                  } |       }|st        j                  d|        dz   dt	        j
                         v st        j                  |       rt        j                  |       ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}| j                  d	      }|j                  d
      }d}||k\  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        j                  d| d      dz   d|iz  }t        t        j                  |            dx}}y)ue   dispatch/__init__.py에 'intent-to-add' 문자열이 4회 이상 등장해야 한다 (정적 검증).dispatchz__init__.pyu   dispatch/__init__.py 없음: r9   dispatch_initr;   Nr>   r?   zintent-to-add   )>=)z%(py0)s >= %(py3)scountr_   u7   dispatch/__init__.py에 'intent-to-add' 등장 횟수: uD    (최소 4회 필요). RC-4 intent-to-add 구현을 확인하세요.ra   r   )r   rK   r   r   r   r   r   r   r    r!   rN   rx   r   )	ru   r%   r'   rQ   contentrx   rf   rg   r,   s	            r3   "test_dispatch_intent_to_add_calledrz   ^   sJ   
*]:MR!R!RR%B=/#RRRRRRR=RRR=RRRRRR!RRRRRR%%w%7GMM/*E 5A:  5A                  B% I8 	8    r5   )__doc__builtinsr   _pytest.assertion.rewrite	assertionrewriter   importlib.utilr   rL   rk   pathlibr   __file__resolveparentsr   r4   rV   rh   rr   rz    r5   r3   <module>r      sS        
 N""$,,Q/	

: $
r5   