
    ;iH                     b   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
mZmZ ddlmZ  ed      Z ee      ej"                  vr"ej"                  j%                  d ee             ddlZ e ed            Z e
dd	d
dde      Zefdededede
def
dZd Zd Zd Zd Zd Zd Zd Zy)u  task-2395 회귀 테스트.

검증 대상:
1. archive_old_done_clear: 90일 이상 파일만 이동 (dummy 10개 검증)
2. archive_old_done_clear: 90일 미만 파일은 원위치 유지
3. check_phase_progress: 6개 중 N개 .done 진행률 정확
4. run_completion_checks: 6/6 도착 시 보고서 파일 존재 확인 분기
5. watch_once: 자동 dispatch.py 호출 시도 차단 (mock 검증)
6. archive: 삭제 함수 부재 확인 (history 보존 의무)
    N)datetime	timedeltatimezone)Pathz/home/jay/workspace/scripts	   )hoursi           )tzinfodir_namedays_agonowreturnc                     | | dz  }|j                  dd       |t        |      z
  j                         }t        j                  |||f       |S )Nz.done.clear zutf-8)encoding)days)
write_textr   	timestamposutime)r   r   r   r   ptargets         B/home/jay/workspace/tests/dev7/test_side_issues_cleanup_monitor.py_make_done_clearr      sS    ${##ALLgL&I8,,779FHHQ !H    c           	      
   | dz  }|dz  }|j                          t        d      D cg c]  }t        |d| dt               }}t        d      D cg c]  }t        |d| dt               }}t	        j
                  ||dt        	      }|d
   }d}||k(  }	|	slt        j                  d|	fd||f      t        j                  |      t        j                  |      dz  }
dd|
iz  }t        t        j                  |            d x}x}	}|d   }d}||k(  }	|	slt        j                  d|	fd||f      t        j                  |      t        j                  |      dz  }
dd|
iz  }t        t        j                  |            d x}x}	}|d   }|j                  } |       }t        |      }d}||k(  }|st        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}x}x}}|D ]  }|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}x}} |D ]  }|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}} d}|j%                         D ]7  }|j'                         s|t        d |j)                  d      D              z  }9 d}	||	k(  }|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  }t        t        j                  |            d x}}	y c c}w c c}w )%Neventsarchiver	   z	task-old-[   z	task-new-   Z   age_daysr   moved==z%(py1)s == %(py4)spy1py4assert %(py6)spy6skippedby_month)zd%(py8)s
{%(py8)s = %(py0)s(%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s.values
}()
})
} == %(py11)ssum)py0py2r-   r/   py8py11zassert %(py13)spy13z should have been movedzG
>assert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}r   r3   r4   r-   z should remainzC
>assert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}r   c              3       K   | ]  }d   yw)   N ).0_s     r   	<genexpr>z>test_archive_moves_files_older_than_90_days.<locals>.<genexpr>;   s     IQqIs   *.done.clear)z%(py0)s == %(py3)smoved_count)r3   py3assert %(py5)spy5)mkdirranger   NOWmonitorarchive_old_done_clear
@pytest_ar_call_reprcompare	_safereprAssertionError_format_explanationvaluesr2   @py_builtinslocals_should_repr_global_nameexists_format_assertmsgiterdiris_dirglob)tmp_path
events_dirarchive_rooti	old_files	new_filesresult@py_assert0@py_assert3@py_assert2@py_format5@py_format7@py_assert1@py_assert5@py_assert7@py_assert10@py_assert9@py_format12@py_format14r   @py_format6r@   	month_dir@py_format4s                           r   +test_archive_moves_files_older_than_90_daysrm   $   s   H$J	)LQVWXQYZA!*	!or3GZIZQVWXQYZA!*	!or3GZIZ++JrWZ[F'?a?a?a?a)!!!!!!!!!!!!!!!!!!!j!0!((0(*03*+0q0+q0000+q00000030003000!000(000*000+000q00000000 =88<8:<:~<~<<!$;<<<<<<<1<<<1<<<8<<<:<<<<<<=  0xx/xz/z//aS///////q///q///x///z//////0 K!))+ J	3I)..*HIIIKJ ;!;!;;!' [Zs   T;U c           	         | dz  }|dz  }|j                          t        d      D cg c]  }t        |d| dt               }}t	        j
                  ||dt              }|d   }d	}||k(  }|slt        j                  d
|fd||f      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            d x}x}}|d   }d}||k(  }|slt        j                  d
|fd||f      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            d x}x}}|d   }i }||k(  }|slt        j                  d
|fd||f      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            d x}x}}|D ]  }|j                  } |       }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }	t        t        j                  |	            d x}} |j                         r/|j                  }d} ||      }t!        |      }| }|sddt        j                         v st        j                  t               rt        j                  t               nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            d x}x}x}x}}y y c c}w )Nr    r!   r	   ztask-P   r$   r%   r'   r   r(   r*   r+   r.   r/   r0   r1   zAassert %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}r   r8   r?   ziassert not %(py9)s
{%(py9)s = %(py0)s(%(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.rglob
}(%(py5)s)
})
}anyrY   )r3   r,   rA   rC   py7py9)rD   rE   r   rF   rG   rH   rI   rJ   rK   rL   rM   rR   rO   rP   rQ   rglobrp   )rW   rX   rY   rZ   filesr]   r^   r_   r`   ra   rb   r   rc   @py_assert4@py_assert6@py_assert8rf   @py_format11s                     r   *test_archive_preserves_files_under_90_daysry   ?   s   H$J	)LINqRAjE!+r3?RER++JrWZ[F'?a?a?a?a)!!!!!!!!!!!!!!!!!!!*################### xxxzzqqxz #)):.:).9:39:::::::::::3:::3::::::|:::|:::):::.:::9:::::::::::  Ss   Oc                    | dz  }|j                          |dz  j                  d       |dz  j                  d       |dz  j                  d       t        j                  |      }|d   }d}||k(  }|slt	        j
                  d|fd	||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }d}||k(  }|slt	        j
                  d|fd	||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }d}||k(  }|slt	        j
                  d|fd	||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }d}||u }|slt	        j
                  d|fd||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }t        |      }g d}	||	k(  }
|
st	        j
                  d|
fd||	f      dt        j                         v st	        j                  t              rt	        j                  t              ndt	        j                  |      t	        j                  |      t	        j                  |	      dz  }dd|iz  }t        t	        j                  |            d x}x}x}
}	|d   }t        |      }g d}	||	k(  }
|
st	        j
                  d|
fd||	f      dt        j                         v st	        j                  t              rt	        j                  t              ndt	        j                  |      t	        j                  |      t	        j                  |	      dz  }dd|iz  }t        t	        j                  |            d x}x}x}
}	|dz  j                  d       |dz  j                  d       |d z  j                  d       t        j                  |      }|d   }d!}||u }|slt	        j
                  d|fd||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }d"}||k(  }|slt	        j
                  d|fd	||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}|d   }d}||k(  }|slt	        j
                  d|fd	||f      t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            d x}x}}y )#Nr    ztask-2389.doner   ztask-2390.dev1.doneztask-2391.dev2.donen_doner
   r(   r*   r+   r.   r/   n_total   ratioz3/6completeF)is)z%(py1)s is %(py4)sdone)	task-2389	task-2390	task-2391z0%(py4)s
{%(py4)s = %(py0)s(%(py2)s)
} == %(py7)ssortedr3   r4   r-   rq   assert %(py9)srr   pending)	task-2392	task-2393	task-2394ztask-2392.doneztask-2393.dev3.doneztask-2394.doneTz6/6)rD   r   rG   check_phase_progressrI   rJ   rK   rL   rM   r   rO   rP   rQ   )rW   rX   r]   r^   r_   r`   ra   rb   rc   rv   rd   @py_format8@py_format10result2s                 r   .test_check_phase_progress_partial_and_completer   S   s   H$J""..r2''33B7''33B7))*5F( q q    q      q       )!!!!!!!!!!!!!!!!!!!'?#e#?e####?e###?###e#######*&&&&&&&&&&&&&&&&&&&.L6.!L%LL!%LLLLL!%LLLLLLL6LLL6LLL.LLL!LLL%LLLLLLLL#O6#$O(OO$(OOOOO$(OOOOOOO6OOO6OOO#OOO$OOO(OOOOOOOO""..r2''33B7""..r2**:6G:&$&$&&&&$&&&&&&$&&&&&&&7$u$u$$$$u$$$$$$u$$$$$$$8!!!!!!!!!!!!!!!!!!!r   c                 ~   | dz  }|j                          |dz  j                  d       t        j                  |      }|d   }d}||k(  }|slt	        j
                  d|fd||f      t	        j                  |      t	        j                  |      dz  }d	d
|iz  }t        t	        j                  |            d x}x}}d}|d   }||v }|slt	        j
                  d|fd||f      t	        j                  |      t	        j                  |      dz  }d	d
|iz  }t        t	        j                  |            d x}x}}y )Nr    ztask-2389.done.clearr   r{   r   r(   r*   r+   r.   r/   r   r   inz%(py1)s in %(py4)s)	rD   r   rG   r   rI   rJ   rK   rL   rM   )rW   rX   r]   r^   r_   r`   ra   rb   s           r   ,test_check_phase_progress_ignores_done_clearr   n   s    H$J((44R8))*5F( q q    q      q       +&++;+++++;++++;+++++++++++r   c                    | dz  }|j                          | dz  }|j                          dD ]  }|| dz  j                  d| d        t        j                  ||      }|d   }t	        |      }d}||k(  }|st        j                  d	|fd
||f      dt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            d x}x}x}}|d   }dg}||k(  }|slt        j                  d	|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}|d   }d}||k(  }|slt        j                  d	|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}d}|d   }||v }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}d}|d   }||v }|slt        j                  d|fd||f      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}}y )Nreportsproj)r   r   r   r   r   z.mdz# 

reports_okr	   r(   r   lenr   r   rr   reports_missingr   r*   r+   r.   r/   
git_statuszno-gitpytestpytest_recommendationr   r   zbatch-ids-master.mdbatch_report_target)rD   r   rG   run_completion_checksr   rI   rJ   rO   rP   rQ   rK   rL   rM   )rW   reports_dirproject_roottidr]   rc   r_   rv   rd   r   r   r^   r`   ra   rb   s                  r   2test_run_completion_checks_detects_missing_reportsr   x   sJ   Y&Kf$LP =	#c{	"..C5|<= **;EFl#)3#$))$))))$))))))3)))3)))#)))$))))))))))#$55$5555$555$5555555555,+8+8++++8++++++8+++++++6v56686666686666866666666666 AF+@$AA $AAAAA $AAAA AAA$AAAAAAAAr   c                    | dz  }|j                          | dz  }|j                          | dz  }|j                          | dz  }dd lg j                  j                  fd}fd}fd}|j	                  d	|       |j	                  d
|       |j	                  d|       |j	                  t
        dd        t        j                  ||||d       D ]  \  }	}
t        |
t        t        f      rdj                  t        t        |
            n
t        |
      }d}||v}|st        j                  d|fd||f      t        j                  |      dt!        j"                         v st        j$                  |      rt        j                  |      nddz  }t        j&                  d|	 d|
       dz   d|iz  }t)        t        j*                  |            d x}}
 t-        j.                  t
              }d}||v}|st        j                  d|fd||f      t        j                  |      dt!        j"                         v st        j$                  |      rt        j                  |      nddz  }dd|iz  }t)        t        j*                  |            d x}}d}||v}|st        j                  d|fd||f      t        j                  |      dt!        j"                         v st        j$                  |      rt        j                  |      nddz  }dd|iz  }t)        t        j*                  |            d x}}y )Nr    r   r   z
state.jsonr   c                     j                  d| f       t        | t              r!dt        |       v rj	                  | ddd      S  | g|i |S )Nrundispatch.pyr   r   )append
isinstanceliststrCompletedProcess)argsakw_spcallsreal_runs      r   spy_runz9test_watch_once_does_not_invoke_dispatch.<locals>.spy_run   sT    eT]#dD!ms4y&@''aR88'q'B''r   c                 B    j                  d| f        | g|i |S )Npopenr   )r   r   r   r   
real_popens      r   	spy_popenz;test_watch_once_does_not_invoke_dispatch.<locals>.spy_popen   s(    gt_%$))b))r   c                 ,    j                  d| f       y)Ncallr   r   )r   _a_kwr   s      r   spy_callz:test_watch_once_does_not_invoke_dispatch.<locals>.spy_call   s    fd^$r   r   Popenr   send_telegram_notificationc                       y)NTr;   )r   r   s     r   <lambda>z:test_watch_once_does_not_invoke_dispatch.<locals>.<lambda>   s    r   F)rX   r   r   
state_filenotify r   not in)z%(py1)s not in %(py3)ss)r,   rA   zdispatch.py invoked via z: z
>assert %(py5)srC   zimport dispatchsrcrB   zfrom dispatch)rD   
subprocessr   r   setattrrG   
watch_oncer   r   tuplejoinmapr   rI   rJ   rK   rO   rP   rQ   rS   rL   rM   inspect	getsource)rW   monkeypatchrX   r   r   r   r   r   r   kindr   r   r^   r`   rl   rj   r   r   r   r   r   s                    @@@@r   (test_watch_once_does_not_invoke_dispatchr      s\   H$JY&Kf$LL(JEwwHJ(* UG,Wi0VX.!=?VW!  Q
d(24$(GCHHSd^$SQUYP}A%PPP}APPP}PPPPPPAPPPAPPPP)A$r$'PPPPPPPPQ 

G
$C'C''''C'''''''''C'''C'''''''%?#%%%%?#%%%?%%%%%%#%%%#%%%%%%%r   c                     t        j                  t              } g d}|D ]  }|| v}|st        j                  d|fd|| f      dt        j                         v st        j                  |      rt        j                  |      nddt        j                         v st        j                  |       rt        j                  |       nddz  }t        j                  d|       dz   d	|iz  }t        t        j                  |            d } t        t              D cg c]  }|j                  d
      r| }}|D ]  }|j                  }d}	 ||	      }
|
 }|st        j                  d|       dz   dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        t        j                  |            d x}x}	x}
}|j                  }d}	 ||	      }
|
 }|st        j                  d|       dz   dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |	      t        j                  |
      dz  }t        t        j                  |            d x}x}	x}
} y c c}w )N)z
os.remove(z
os.unlink(z	.unlink()zshutil.rmtree(r   )z%(py0)s not in %(py2)spatternr   )r3   r4   z Forbidden delete pattern found: z
>assert %(py4)sr-   r=   delete_zdelete_* function found: zR
>assert not %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.startswith
}(%(py4)s)
}r   )r3   r4   r-   r/   remove_zremove_* function found: )r   r   rG   rI   rJ   rO   rP   rQ   rK   rS   rL   rM   dir
startswith)r   forbidden_patternsr   rc   @py_format3ra   npublic_namesr   r_   rd   re   r   s                r   #test_module_has_no_delete_functionsr      s   


G
$C & Pc!OOOwcOOOOOOwOOOwOOOOOOcOOOcOOOO%EgY#OOOOOOOP  #7|E!1<<3DAELE R??Q9Q?9-Q--Q-QQ1J4&/QQQQQQQ4QQQ4QQQ?QQQ9QQQ-QQQQQQ??Q9Q?9-Q--Q-QQ1J4&/QQQQQQQ4QQQ4QQQ?QQQ9QQQ-QQQQQQQR Fs   K>4K>) __doc__builtinsrO   _pytest.assertion.rewrite	assertionrewriterI   r   sysr   r   r   r   pathlibr   SCRIPTS_DIRr   pathinsertids_phase_monitorrG   KSTrF   intr   rm   ry   r   r   r   r   r   r;   r   r   <module>r      s   	  	 
  2 2 01{388#HHOOAs;'( #yq!"tQ2q- LO 4 s c  SW 6;("6,B$0&fRr   