
    i,                    d   U d Z ddlmZ ddlZddlmc mZ ddl	Z	ddl
Z
ddlmZ ddlZdZee	j                  vre	j                  j!                  de       ddlmZmZmZ  e       Zddd	d
ddZded<   d#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  Z)d! Z*d" Z+y)$u  
tests/track_b/test_story_7_04.py

Story B-7.04: PatchReconciler — Merged Patch Validator + Applier

Black Box Tests (BB1–BB5):
    BB1  Valid "add" op → valid=True, new_state contains the added key
    BB2  Patch op dict missing "op" key → valid=False, errors describe the issue
    BB3  State result contains "API_KEY" → axiom check fails, valid=False
    BB4  Valid "replace" op → valid=True, value replaced in new_state
    BB5  "remove" op on an existing key → valid=True, key absent from new_state

White Box Tests (WB1–WB4):
    WB1  Dry-run uses state.copy() — original state NOT mutated on failure
    WB2  All 3 validation steps run: schema + apply + axiom errors accumulated
    WB3  FORBIDDEN_PATTERNS contains "sqlite3", "API_KEY", "sk-"
    WB4  Schema check validates each patch op has both "op" and "path"

Package Tests:
    PKG1  PatchReconciler importable from core.merge
    PKG2  ReconcileResult importable from core.merge
    )annotationsN)Anyz/mnt/e/genesis-system)PatchReconcilerReconcileResultFORBIDDEN_PATTERNSactive   fast   moderetries)statusversionconfigdict
BASE_STATEc                 4    t        j                  t              S )zDReturn a deep copy of BASE_STATE so tests never share mutable state.)copydeepcopyr        6/mnt/e/genesis-system/tests/track_b/test_story_7_04.pyfresh_stater   C   s    ==$$r   c                    t               } ddddg}t        j                  | |      }|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }g }||k(  }|st	        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  }t        t	        j                  |            dx}x}}|j                  }d}||u}|st	        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  }t        t	        j                  |            dx}x}}|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}	}y)uD   BB1: Valid 'add' op → valid=True and new key present in new_state.addz/new_keyhellooppathvalueTisz-%(py2)s
{%(py2)s = %(py0)s.valid
} is %(py5)sresultpy0py2py5assert %(py7)spy7N==z.%(py2)s
{%(py2)s = %(py0)s.errors
} == %(py5)sis notz5%(py2)s
{%(py2)s = %(py0)s.new_state
} is not %(py5)snew_keyz%(py1)s == %(py4)spy1py4assert %(py6)spy6)r   
RECONCILERvalidate_and_applyvalid
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationerrors	new_statestatepatchr%   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert0@py_assert2@py_format5@py_format7s               r   'test_bb1_valid_add_op_returns_new_staterR   M   s   ME:@AE**5%8F<<4<4<466<4==B=B=B66=B'4'4''''4''''''6'''6''''''4'''''''I&1'1&'1111&'111&111'1111111r   c                 R   t               } dddg}t        j                  | |      }|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }t        |      }d}	||	kD  }
|
s
t	        j
                  d|
fd||	f      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                  |	      dz  }dd|iz  }t        t	        j                  |            dx}x}x}
}	dj                  |j                        }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)uP   BB2: Patch entry missing 'op' → valid=False, error references the missing key./statusinactiver    r!   Fr"   r$   r%   r&   r*   r+   Nz1%(py2)s
{%(py2)s = %(py0)s.new_state
} is %(py5)sr   >)zK%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.errors
})
} > %(py8)slen)r'   r5   py3r)   py8zassert %(py10)spy10 r   inz%(py1)s in %(py3)scombinedr5   r[   assert %(py5)sr)   )r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rD   rZ   join)rG   rH   r%   rI   rJ   rK   rL   rM   rO   @py_assert7@py_assert6@py_format9@py_format11rb   rN   @py_format4s                   r   'test_bb2_missing_op_key_returns_invalidrk   Z   s   ME*56E**5%8F<< 5 <5    <5      6   6   <   5       #t#t####t######6###6######t#######}}!3}!!!!!!!!!!!!3!!!3!!!!!!v!!!v!!!}!!!!!!!!!!!!!xx&H4848488r   c                    t               } ddddg}t        j                  | |      }|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}d |j                  D        }t        |      }|sddt        j                         v st	        j                  t              rt	        j                  t              ndt	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}}y)uJ   BB3: Adding a value containing 'API_KEY' → axiom violation, valid=False.r   z/secretMY_API_KEY_HEREr   Fr"   r$   r%   r&   r*   r+   NrW   c              3  $   K   | ]  }d |v  
 yw)API_KEYNr   ).0errs     r   	<genexpr>zJtest_bb3_forbidden_api_key_pattern_in_result_is_invalid.<locals>.<genexpr>s   s     9CyC9   ,assert %(py4)s
{%(py4)s = %(py0)s(%(py2)s)
}anyr'   r(   r6   )r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rD   ru   	rG   rH   r%   rI   rJ   rK   rL   rM   rP   s	            r   7test_bb3_forbidden_api_key_pattern_in_result_is_invalidrx   j   sm   ME97HIJE**5%8F<< 5 <5    <5      6   6   <   5       #t#t####t######6###6######t#######96==9939999999993999399999999999999r   c                    t               } ddddg}t        j                  | |      }|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }d}||u}|st	        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  }t        t	        j                  |            dx}x}}|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}	}y)uC   BB4: Valid 'replace' op → valid=True, value updated in new_state.replacerT   rU   r   Tr"   r$   r%   r&   r*   r+   Nr/   r1   r   r,   r3   r4   r7   r8   r   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rF   s               r   'test_bb4_valid_replace_op_updates_valuer|   v   s   MEy:FGE**5%8F<<4<4<466<4'4'4''''4''''''6'''6''''''4'''''''H%33%3333%333%3333333333?&h&?h&&&&?h&&&?&&&h&&&&&&&r   c                 D   t               } dddg}t        j                  | |      }|j                  }d}||u }|st	        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  }t        t	        j                  |            dx}x}}|j                  }d}||u}|st	        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  }t        t	        j                  |            dx}x}}d}|j                  }||v}	|	st	        j
                  d|	fd||f      t	        j                  |      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}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)uC   BB5: Valid 'remove' op on an existing key → valid=True, key gone.removez/versionr   r    Tr"   r$   r%   r&   r*   r+   Nr/   r1   r   not in)z5%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.new_state
})r5   r[   r)   r_   ra   rG   rc   rd   r)   r{   )rG   rH   r%   rI   rJ   rK   rL   rM   rN   rO   rj   s              r   test_bb5_remove_op_deletes_keyr      s   MEj12E**5%8F<<4<4<466<4'4'4''''4''''''6'''6''''''4''''''',F,,,9,,,,,9,,,,9,,,,,,F,,,F,,,,,,,,,,,999r   c                    ddd} t        j                  |       }ddddg}t        j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}| |k(  }|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|        dz   d|	iz  }
t        t        j                  |
            d}y)uK   WB1: Dry-run operates on state.copy() — original state is never modified.r	      )xyr   z/credszAPI_KEY=abc123r   Fr"   r$   r%   r&   r*   r+   Nr,   )z%(py0)s == %(py2)srG   state_snapshotr'   r(   zState was mutated! Before: z	, After: z
>assert %(py4)sr6   )r   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   _format_assertmsg)rG   r   rH   r%   rI   rJ   rK   rL   rM   @py_format3rP   s              r   .test_wb1_original_state_not_mutated_on_failurer      sk   !E]]5)N 86FGHE**5%8F<< 5 <5    <5      6   6   <   5       N"  5N                #    #    &n%5YugF    r   c                    ddi} ddddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}|j                  D cg c]	  }d|v s| }	}t        |	      }
d}|
|k\  }|st        j                  d|fd|
|f      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                  |      dz  }t        j                  d|j                         dz   d|iz  }t        t        j                  |            dx}
x}}yc c}w )u  
    WB2: All 3 validation steps run — if schema passes but axiom fails,
    both the dry-run result AND axiom errors are accumulated.

    We trigger this by supplying a structurally valid patch that produces a
    state containing the forbidden 'sqlite3' pattern.
    dbpostgresrz   /dbsqlite3_backendr   Fr"   r$   r%   r&   r*   r+   NrW   sqlite3r	   )>=)z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)srZ   axiom_errorsr'   r5   r[   r8   z'Expected axiom error for sqlite3, got: z
>assert %(py8)sr\   )r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rD   rZ   r   )rG   rH   r%   rI   rJ   rK   rL   rM   er   rO   @py_assert5rQ   rh   s                 r   /test_wb2_all_three_steps_run_errors_accumulatedr      s    :Eu7HIJE**5%8F
 << 5 <5    <5      6   6   <   5       #t#t####t######6###6######t#######%}}?!	QA?L?|\\!\\\\\\\\\3\\\3\\\\\\|\\\|\\\\\\\\\%LV]]O#\\\\\\\\ @s   >	LLc                    d} | t         v }|st        j                  d|fd| t         f      t        j                  |       dt	        j
                         v st        j                  t               rt        j                  t               nddz  }t        j                  d      dz   d|iz  }t        t        j                  |            d	x} }d
} | t         v }|st        j                  d|fd| t         f      t        j                  |       dt	        j
                         v st        j                  t               rt        j                  t               nddz  }t        j                  d      dz   d|iz  }t        t        j                  |            d	x} }d} | t         v }|st        j                  d|fd| t         f      t        j                  |       dt	        j
                         v st        j                  t               rt        j                  t               nddz  }t        j                  d      dz   d|iz  }t        t        j                  |            d	x} }y	)zMWB3: FORBIDDEN_PATTERNS module constant includes 'sqlite3', 'API_KEY', 'sk-'.r   r_   ra   r   rc   z$FORBIDDEN_PATTERNS missing 'sqlite3'z
>assert %(py5)sr)   Nro   z$FORBIDDEN_PATTERNS missing 'API_KEY'sk-z FORBIDDEN_PATTERNS missing 'sk-')
r   r<   r=   rA   r>   r?   r@   r   rB   rC   )rN   rO   rj   rL   s       r   5test_wb3_forbidden_patterns_contains_required_entriesr      s=   R9**RRR9*RRR9RRRRRR*RRR*RRRR,RRRRRRRR9**RRR9*RRR9RRRRRR*RRR*RRRR,RRRRRRRJ5&&JJJ5&JJJ5JJJJJJ&JJJ&JJJJ(JJJJJJJr   c                 (   t               } | j                  dddg      }t        |      }d}||kD  }|st        j                  d|fd||f      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                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}d |D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }	t        t        j                  |	            dx}}| j                  dddg      }
t        |
      }d}||kD  }|st        j                  d|fd||f      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                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}d |
D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }	t        t        j                  |	            dx}}| j                  ddig      }t        |      }d}||kD  }|st        j                  d|fd||f      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                  |      d	z  }d
d|iz  }t        t        j                  |            dx}x}}| j                  ddddg      }g }||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) zLWB4: Schema check rejects ops missing 'op', missing 'path', or missing both.z/xr	   rV   r   rX   )z/%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py6)srZ   errors_ar   zassert %(py8)sr\   Nc              3  $   K   | ]  }d |v  
 yw)r   Nr   rp   r   s     r   rr   zCtest_wb4_schema_check_validates_both_op_and_path.<locals>.<genexpr>   s     +Qtqy+rs   rt   ru   rv   r   )r   r!   errors_bc              3  $   K   | ]  }d |v  
 yw)r    Nr   r   s     r   rr   zCtest_wb4_schema_check_validates_both_op_and_path.<locals>.<genexpr>   s     -qv{-rs   r!   errors_cz/k*   r   r,   )z%(py0)s == %(py3)serrors_d)r'   r[   rd   r)   )r   _check_schemarZ   r<   r=   r>   r?   r@   rA   rB   rC   ru   )
reconcilerr   rO   r   rJ   rQ   rh   rI   rK   rP   r   r   r   rj   rL   s                  r   0test_wb4_schema_check_validates_both_op_and_pathr      s,    "J ''$)C(DEHx=1=1=133xx=1+(++3+++++++++3+++3++++++++++++++ '')B(CDHx=1=1=133xx=1-H--3---------3---3-------------- '''17Hx=1=1=133xx=1 ''tb)Q(RSH8r>8r88rr   c                    dddii} ddddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}|j                  d   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   }||v}	|	slt        j                  d|	fd||f      t        j                  |      t        j                  |      dz  }
dd|
iz  }t        t        j                  |            dx}x}	}y)z;Adding a key inside a nested dict via '/parent/child' path.r   r   slowr   z/config/debugTr   r"   r$   r%   r&   r*   r+   Ndebug)z%(py1)s is %(py4)sr4   r7   r8   r   )z%(py1)s not in %(py4)sr9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rF   s               r   test_nested_path_addr      sJ   '(E?TBCE**5%8F<<4<4<466<4H%g.6$6.$6666.$666.666$6666666)%/)7/))))7/)))7)))/)))))))r   c                    ddddi} ddddg}t         j                  | |      }|j                  }d	}||u }|st        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  }t        t        j                  |            dx}x}}|j                  d   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)zReplacing a nested key value.r   r   r   r   rz   z/config/moder
   r   Tr"   r$   r%   r&   r*   r+   Nr   r,   r3   r4   r7   r8   r   rF   s               r   test_nested_path_replacer      s    156E~GHE**5%8F<<4<4<466<4H%f-77-7777-777-7777777777r   c                 D   ddi} dddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}d |j                  D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)zFAttempting to remove a key that doesn't exist produces an apply error.r   r	   r~   z/nonexistentr   Fr"   r$   r%   r&   r*   r+   Nc              3  0   K   | ]  }d |v xs d|v   yw)nonexistentr~   Nr   r   s     r   rr   z<test_remove_nonexistent_key_returns_error.<locals>.<genexpr>  s!     Jq}!2X]2Js   rt   ru   rv   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   ru   rw   s	            r   )test_remove_nonexistent_key_returns_errorr      s    !HEn56E**5%8F<< 5 <5    <5      6   6   <   5       JFMMJJ3JJJJJJJJJ3JJJ3JJJJJJJJJJJJJJr   c                    ddi} ddddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}y)z8Replacing a key that doesn't exist is an RFC 6902 error.r   r	   rz   z/missing_keyc   r   Fr"   r$   r%   r&   r*   r+   N)r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   )rG   rH   r%   rI   rJ   rK   rL   rM   s           r   *test_replace_nonexistent_key_returns_errorr     s    !HE~CDE**5%8F<< 5 <5    <5      6   6   <   5       r   c                    ddi} t         j                  | g       }|j                  }d}||u }|st        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  }t        t        j                  |            d
x}x}}|j                  }ddi}||k(  }|st        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  }t        t        j                  |            d
x}x}}|j                  }g }||k(  }|st        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  }t        t        j                  |            d
x}x}}y
)zAAn empty patch list produces a valid result with state unchanged.ar	   Tr"   r$   r%   r&   r*   r+   Nr,   )z1%(py2)s
{%(py2)s = %(py0)s.new_state
} == %(py5)sr.   )r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rE   rD   )rG   r%   rI   rJ   rK   rL   rM   s          r   test_empty_patch_is_validr     sm   !HE**5"5F<<4<4<466<4'Qx'x''''x''''''6'''6''''''x'''''''==B=B=B66=Br   c                 8   ddi} t         j                  | d      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}d |j                  D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)z=If patch is not a list at all, schema check fails gracefully.r   r	   z
not-a-listFr"   r$   r%   r&   r*   r+   Nc              3  $   K   | ]  }d |v  
 yw)listNr   r   s     r   rr   z=test_patch_not_a_list_returns_schema_error.<locals>.<genexpr>  s     2qv{2rs   rt   ru   rv   r   )rG   r%   rI   rJ   rK   rL   rM   rP   s           r   *test_patch_not_a_list_returns_schema_errorr     s    !HE**5,?F<< 5 <5    <5      6   6   <   5       2FMM2232222222223222322222222222222r   c                 F   ddi} ddddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}d |j                  D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)zAValue containing 'sk-' (e.g. OpenAI key prefix) is axiom-blocked.r   okr   z/tokenzsk-abc123xyzr   Fr"   r$   r%   r&   r*   r+   Nc              3  $   K   | ]  }d |v  
 yw)r   Nr   r   s     r   rr   z1test_sk_dash_forbidden_pattern.<locals>.<genexpr>*  s     1auz1rs   rt   ru   rv   r   rw   s	            r   test_sk_dash_forbidden_patternr   "  s    $KE8nEFE**5%8F<< 5 <5    <5      6   6   <   5       16==1131111111113111311111111111111r   c                 F   ddi} ddddg}t         j                  | |      }|j                  }d}||u }|st        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  }t        t        j                  |            dx}x}}d |j                  D        }t        |      }|sddt        j                         v st        j                  t              rt        j                  t              ndt        j                  |      t        j                  |      dz  }t        t        j                  |            dx}}y)z,Value containing 'sqlite3' is axiom-blocked.r   r   rz   r   r   r   Fr"   r$   r%   r&   r*   r+   Nc              3  $   K   | ]  }d |v  
 yw)r   Nr   r   s     r   rr   z1test_sqlite3_forbidden_pattern.<locals>.<genexpr>5  s     5!yA~5rs   rt   ru   rv   r   rw   s	            r   test_sqlite3_forbidden_patternr   -  s    :EuyABE**5%8F<< 5 <5    <5      6   6   <   5       5v}}5535555555553555355555555555555r   c                    ddl m}  | t        u }|st        j                  d|fd| t        f      dt	        j
                         v st        j                  |       rt        j                  |       nddt	        j
                         v st        j                  t              rt        j                  t              nddz  }dd	|iz  }t        t        j                  |            d
}y
)z9PKG1: PatchReconciler importable from core.merge package.r   )r   r"   z%(py0)s is %(py2)sPRr   r   assert %(py4)sr6   N)

core.merger   r<   r=   r>   r?   r@   rA   rB   rC   )r   rI   r   rP   s       r   5test_pkg1_patch_reconciler_importable_from_core_merger   =  m    0    2      2   2                r   c                    ddl m}  | t        u }|st        j                  d|fd| t        f      dt	        j
                         v st        j                  |       rt        j                  |       nddt	        j
                         v st        j                  t              rt        j                  t              nddz  }dd	|iz  }t        t        j                  |            d
}y
)z9PKG2: ReconcileResult importable from core.merge package.r   )r   r"   r   RRr   r   r   r6   N)
r   r   r<   r=   r>   r?   r@   rA   rB   rC   )r   rI   r   rP   s       r   5test_pkg2_reconcile_result_importable_from_core_merger   C  r   r   )returnr   ),__doc__
__future__r   builtinsr>   _pytest.assertion.rewrite	assertionrewriter<   sysr   typingr   pytestGENESIS_ROOTr    insertcore.merge.patch_reconcilerr   r   r   r9   r   __annotations__r   rR   rk   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s   . #   
    'sxxHHOOA|$  
 
D %
2 	:'&"].K8
*8K!326 !!r   