@@ -341,3 +341,172 @@ async def failing_clipcopier( content: str ) -> None:
341341 clipcopier = failing_clipcopier )
342342
343343 assert exc_info .value .code == 1
344+
345+
346+ @pytest .mark .asyncio
347+ async def test_400_create_deterministic_boundary_cli ( provide_tempdir ):
348+ ''' Create uses deterministic boundary when CLI flag is set. '''
349+ create = cache_import_module ( f"{ PACKAGE_NAME } .create" )
350+ import re
351+
352+ test_content = "test content\n "
353+ test_path = provide_tempdir / "test.txt"
354+ test_files = { "test.txt" : test_content }
355+ printed_content = [ ]
356+
357+ def mock_print ( content : str ):
358+ printed_content .append ( content )
359+
360+ with create_test_files ( provide_tempdir , test_files ):
361+ cmd = create .Command (
362+ sources = [ str ( test_path ) ],
363+ deterministic_boundary = True )
364+ with pytest .raises ( SystemExit ) as exc_info : # noqa: SIM117
365+ with pytest .MonkeyPatch ( ).context ( ) as mp :
366+ mp .setattr ( 'builtins.print' , mock_print )
367+ await create .create (
368+ MagicMock ( configuration = { } ),
369+ cmd )
370+
371+ assert exc_info .value .code == 0
372+ assert len ( printed_content ) == 1
373+ output = printed_content [ 0 ]
374+ boundary_pattern = r'--====MIMEOGRAM_([0-9a-f]{64})===='
375+ match = re .search ( boundary_pattern , output )
376+ assert match is not None , 'Should have deterministic boundary'
377+
378+
379+ @pytest .mark .asyncio
380+ async def test_410_create_deterministic_boundary_config ( provide_tempdir ):
381+ ''' Create uses deterministic boundary when config is set. '''
382+ create = cache_import_module ( f"{ PACKAGE_NAME } .create" )
383+ import re
384+
385+ test_content = "test content\n "
386+ test_path = provide_tempdir / "test.txt"
387+ test_files = { "test.txt" : test_content }
388+ printed_content = [ ]
389+
390+ def mock_print ( content : str ):
391+ printed_content .append ( content )
392+
393+ with create_test_files ( provide_tempdir , test_files ):
394+ cmd = create .Command ( sources = [ str ( test_path ) ] )
395+ with pytest .raises ( SystemExit ) as exc_info : # noqa: SIM117
396+ with pytest .MonkeyPatch ( ).context ( ) as mp :
397+ mp .setattr ( 'builtins.print' , mock_print )
398+ await create .create (
399+ MagicMock ( configuration = {
400+ 'create' : { 'deterministic-boundary' : True }
401+ } ),
402+ cmd )
403+
404+ assert exc_info .value .code == 0
405+ assert len ( printed_content ) == 1
406+ output = printed_content [ 0 ]
407+ boundary_pattern = r'--====MIMEOGRAM_([0-9a-f]{64})===='
408+ match = re .search ( boundary_pattern , output )
409+ assert match is not None , 'Should have deterministic boundary'
410+
411+
412+ @pytest .mark .asyncio
413+ async def test_420_create_deterministic_boundary_repeatability (
414+ provide_tempdir
415+ ):
416+ ''' Create produces identical output with deterministic boundary. '''
417+ create = cache_import_module ( f"{ PACKAGE_NAME } .create" )
418+
419+ test_content = "test content\n "
420+ test_path = provide_tempdir / "test.txt"
421+ test_files = { "test.txt" : test_content }
422+ printed_content1 = [ ]
423+ printed_content2 = [ ]
424+
425+ def mock_print1 ( content : str ):
426+ printed_content1 .append ( content )
427+
428+ def mock_print2 ( content : str ):
429+ printed_content2 .append ( content )
430+
431+ with create_test_files ( provide_tempdir , test_files ):
432+ cmd = create .Command (
433+ sources = [ str ( test_path ) ],
434+ deterministic_boundary = True )
435+
436+ # First run
437+ with pytest .raises ( SystemExit ): # noqa: SIM117
438+ with pytest .MonkeyPatch ( ).context ( ) as mp :
439+ mp .setattr ( 'builtins.print' , mock_print1 )
440+ await create .create (
441+ MagicMock ( configuration = { } ),
442+ cmd )
443+
444+ # Second run
445+ with pytest .raises ( SystemExit ): # noqa: SIM117
446+ with pytest .MonkeyPatch ( ).context ( ) as mp :
447+ mp .setattr ( 'builtins.print' , mock_print2 )
448+ await create .create (
449+ MagicMock ( configuration = { } ),
450+ cmd )
451+
452+ assert len ( printed_content1 ) == 1
453+ assert len ( printed_content2 ) == 1
454+ assert printed_content1 [ 0 ] == printed_content2 [ 0 ]
455+
456+
457+ @pytest .mark .asyncio
458+ async def test_430_create_deterministic_boundary_cli_overrides_config (
459+ provide_tempdir
460+ ):
461+ ''' CLI flag overrides configuration setting. '''
462+ create = cache_import_module ( f"{ PACKAGE_NAME } .create" )
463+ import re
464+
465+ test_content = "test content\n "
466+ test_path = provide_tempdir / "test.txt"
467+ test_files = { "test.txt" : test_content }
468+ printed_content = [ ]
469+
470+ def mock_print ( content : str ):
471+ printed_content .append ( content )
472+
473+ with create_test_files ( provide_tempdir , test_files ):
474+ cmd = create .Command (
475+ sources = [ str ( test_path ) ],
476+ deterministic_boundary = False )
477+ with pytest .raises ( SystemExit ) as exc_info : # noqa: SIM117
478+ with pytest .MonkeyPatch ( ).context ( ) as mp :
479+ mp .setattr ( 'builtins.print' , mock_print )
480+ await create .create (
481+ MagicMock ( configuration = {
482+ 'create' : { 'deterministic-boundary' : True }
483+ } ),
484+ cmd )
485+
486+ assert exc_info .value .code == 0
487+ assert len ( printed_content ) == 1
488+ output = printed_content [ 0 ]
489+ boundary_pattern = r'--====MIMEOGRAM_([0-9a-f]{32})===='
490+ match = re .search ( boundary_pattern , output )
491+ assert match is not None , (
492+ 'Should have random boundary due to CLI override' )
493+
494+
495+ def test_440_deterministic_boundary_configuration_edit ( ):
496+ ''' Command generates configuration edit for deterministic boundary. '''
497+ create = cache_import_module ( f"{ PACKAGE_NAME } .create" )
498+
499+ cmd = create .Command (
500+ sources = [ 'test.txt' ],
501+ deterministic_boundary = True )
502+ edits = cmd .provide_configuration_edits ( )
503+
504+ # Find the deterministic boundary edit
505+ deterministic_edit = None
506+ for edit in edits :
507+ if edit .address == ( 'create' , 'deterministic-boundary' ):
508+ deterministic_edit = edit
509+ break
510+
511+ assert deterministic_edit is not None
512+ assert deterministic_edit .value is True
0 commit comments