@@ -40,8 +40,15 @@ def environment(tmp_path, monkeypatch):
4040
4141
4242def cli (* args ):
43+ environment = {** os .environ , "LOOPX_USAGE_PING" : "0" }
44+ if os .name == "nt" :
45+ # Exercise native Windows locale decoding even if pytest uses -X utf8.
46+ environment ["PYTHONUTF8" ] = "0"
47+ # Keep captured CLI JSON decodable when the parent pytest uses UTF-8.
48+ environment ["PYTHONIOENCODING" ] = "utf-8"
4349 result = subprocess .run ([sys .executable , "-m" , "loopx.cli" , "--format" , "json" , * map (str , args )],
44- env = {** os .environ , "LOOPX_USAGE_PING" : "0" }, capture_output = True , text = True , timeout = 60 )
50+ env = environment , capture_output = True , text = True ,
51+ encoding = "utf-8" if os .name == "nt" else None , timeout = 60 )
4552 return result .returncode , json .loads (result .stdout )
4653
4754
@@ -67,8 +74,11 @@ def test_cli_export_verify_restore_and_occupied_target(environment, tmp_path):
6774 code , exported = cli (* arguments , "export" , "--output" , output , "--execute" )
6875 assert code == 0 and exported ["goal_count" ] == 1
6976 original = output .read_bytes ()
77+ assert "完整" .encode ("utf-8" ) in original
7078 assert cli (* arguments , "export" , "--output" , output , "--execute" )[0 ] == 1
71- assert output .read_bytes () == original and output .stat ().st_mode & 0o777 == 0o600
79+ assert output .read_bytes () == original
80+ if os .name != "nt" :
81+ assert output .stat ().st_mode & 0o777 == 0o600
7282 assert cli (* arguments , "verify" , "--input" , output )[0 ] == 0
7383 restore = (* arguments , "restore" , "--input" , output , "--expected-sha256" , exported ["sha256" ], "--destination" , tmp_path / "restored" )
7484 assert cli (* restore )[1 ]["written" ] is False
@@ -141,10 +151,18 @@ def post(operation, body):
141151 status , response = post ("restore" , body )
142152 assert status == 200 , response
143153 assert response ["status" ] == "preview"
144- assert not (runtime / "backups/configuration" ).exists ()
145- assert post ("restore" , {** body , "execute" : True })[1 ]["status" ] == "restored"
154+ checkpoint = runtime / "backups/configuration" / exported ["sha256" ]
155+ assert not checkpoint .exists ()
156+ assert post ("restore" , {** body , "expected_sha256" : "changed" , "execute" : True })[0 ] == 400
157+ assert not checkpoint .exists ()
158+ status , restored = post ("restore" , {** body , "execute" : True })
159+ assert status == 200 and restored ["status" ] == "restored"
160+ assert restored ["checkpoint_ref" ] == f"backups/configuration/{ exported ['sha256' ]} "
161+ saved = (checkpoint / "configuration-backup.json" ).read_bytes ()
162+ assert json .loads (saved .decode ("utf-8" )) == exported ["backup" ]
163+ assert "完整" .encode ("utf-8" ) in saved
146164 assert post ("restore" , {** body , "execute" : True })[0 ] == 400
147- assert post ( "restore" , { ** body , "expected_sha256" : "changed" })[ 0 ] == 400
165+ assert ( checkpoint / "configuration-backup.json" ). read_bytes () == saved
148166 finally :
149167 server .shutdown ()
150168 server .server_close ()
0 commit comments