@@ -328,6 +328,55 @@ def test_repeat_flag(self):
328328 }
329329 )
330330
331+ def test_spec_json_format (self ):
332+ """Verify test_spec and test_spec_sha keys in JSON output"""
333+
334+ self .env = os .environ .copy ()
335+ self .env ["NINEPM_TEST_DIR" ] = self .create_unique_subdir ()
336+
337+ result = subprocess .run (
338+ ["python3" , self .ninepm , "suites/test-spec.yaml" ],
339+ cwd = self .script_dir ,
340+ text = True ,
341+ env = self .env ,
342+ stdout = subprocess .PIPE ,
343+ stderr = subprocess .PIPE ,
344+ )
345+
346+ if VERBOSE :
347+ print (result .stdout )
348+ print (result .stderr , file = sys .stderr )
349+
350+ assert result .returncode == 0 , f"Failed with return code { result .returncode } "
351+
352+ json_path = os .path .join (os .path .expanduser ('~/.local/share/9pm/logs/last' ), 'result.json' )
353+ assert os .path .exists (json_path ), f"Could not find { json_path } "
354+
355+ with open (json_path , 'r' ) as f :
356+ data = json .load (f )
357+
358+ def find_test_spec (obj ):
359+ if isinstance (obj , dict ):
360+ if 'test_spec' in obj :
361+ return obj
362+ for value in obj .values ():
363+ result = find_test_spec (value )
364+ if result :
365+ return result
366+ elif isinstance (obj , list ):
367+ for item in obj :
368+ result = find_test_spec (item )
369+ if result :
370+ return result
371+ return None
372+
373+ case = find_test_spec (data ['suite' ])
374+ assert case is not None , "Could not find test_spec in JSON"
375+ assert 'test_spec' in case , "Missing test_spec key"
376+ assert 'test_spec_sha' in case , "Missing test_spec_sha key"
377+
378+ print_green (f"[PASS] Test spec JSON output" )
379+
331380 def cleanup (self ):
332381 """Cleanup temp directory after tests"""
333382 self .temp_dir_base .cleanup ()
@@ -357,6 +406,7 @@ def cleanup(self):
357406 tester .test_abort_flag ()
358407 tester .test_repeat_flag ()
359408 tester .test_proj_config ()
409+ tester .test_spec_json_format ()
360410 print_green ("All tests passed." )
361411 finally :
362412 tester .cleanup ()
0 commit comments