@@ -768,6 +768,94 @@ def test_success_is_explicitly_only_preflight(self):
768768 self .assertEqual (summary ['status' ], 'passed' )
769769 self .assertIn ('full verification still required' , summary ['scope' ])
770770
771+ def test_summary_and_stages_record_started_at_and_seconds_while_preserving_existing_keys (self ):
772+ iso_utc_second = re .compile (r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$' )
773+ observer_cmd = [
774+ sys .executable , '-c' ,
775+ 'import json, pathlib; '
776+ 'p = pathlib.Path("logs/preflight-summary.json"); '
777+ 'pathlib.Path("logs/mid-run.json").write_text(p.read_text())'
778+ ]
779+ code , summary , logs = self .run_preflight ([
780+ ('first' , [sys .executable , '-c' , 'pass' ]),
781+ ('second' , observer_cmd ),
782+ ])
783+ self .assertEqual (code , 0 )
784+ mid = json .loads ((logs / 'mid-run.json' ).read_text ())
785+
786+ # Mid-run summary: top-level startedAt is present, top-level seconds is not yet written.
787+ self .assertEqual (set (mid .keys ()),
788+ {'schemaVersion' , 'status' , 'scope' , 'stages' , 'startedAt' })
789+ self .assertEqual (mid ['schemaVersion' ], 'pineforge-ci-preflight/v1' )
790+ self .assertEqual (mid ['status' ], 'incomplete' )
791+ self .assertEqual (mid ['scope' ],
792+ 'workflow and source checks only; full verification still required' )
793+ self .assertIsInstance (mid ['startedAt' ], str )
794+ self .assertRegex (mid ['startedAt' ], iso_utc_second )
795+ self .assertEqual (len (mid ['stages' ]), 2 )
796+
797+ # While the second stage is running, the first stage already has its finished seconds
798+ # and the second stage has startedAt set and seconds null.
799+ finished_first = mid ['stages' ][0 ]
800+ self .assertIsInstance (finished_first ['startedAt' ], str )
801+ self .assertRegex (finished_first ['startedAt' ], iso_utc_second )
802+ self .assertIsInstance (finished_first ['seconds' ], float )
803+ self .assertNotIsInstance (finished_first ['seconds' ], bool )
804+ self .assertGreaterEqual (finished_first ['seconds' ], 0.0 )
805+ self .assertEqual (round (finished_first ['seconds' ], 3 ), finished_first ['seconds' ])
806+
807+ running = mid ['stages' ][1 ]
808+ self .assertEqual (set (running .keys ()),
809+ {'name' , 'argv' , 'status' , 'exitCode' , 'advisory' , 'log' ,
810+ 'startedAt' , 'seconds' })
811+ self .assertEqual (running ['name' ], 'second' )
812+ self .assertEqual (running ['argv' ], observer_cmd )
813+ self .assertEqual (running ['status' ], 'running' )
814+ self .assertIsNone (running ['exitCode' ])
815+ self .assertIs (running ['advisory' ], False )
816+ self .assertEqual (running ['log' ], 'second.log' )
817+ self .assertIsInstance (running ['startedAt' ], str )
818+ self .assertRegex (running ['startedAt' ], iso_utc_second )
819+ self .assertIsNone (running ['seconds' ])
820+
821+ # Finished summary: top-level startedAt and seconds are present alongside existing keys.
822+ self .assertEqual (set (summary .keys ()),
823+ {'schemaVersion' , 'status' , 'scope' , 'stages' , 'exitCode' ,
824+ 'startedAt' , 'seconds' })
825+ self .assertEqual (summary ['schemaVersion' ], 'pineforge-ci-preflight/v1' )
826+ self .assertEqual (summary ['status' ], 'passed' )
827+ self .assertEqual (summary ['scope' ],
828+ 'workflow and source checks only; full verification still required' )
829+ self .assertEqual (summary ['exitCode' ], 0 )
830+ self .assertEqual (summary ['startedAt' ], mid ['startedAt' ])
831+ self .assertIsInstance (summary ['seconds' ], float )
832+ self .assertNotIsInstance (summary ['seconds' ], bool )
833+ self .assertGreaterEqual (summary ['seconds' ], 0.0 )
834+ self .assertEqual (round (summary ['seconds' ], 3 ), summary ['seconds' ])
835+
836+ for index , (expected_name , expected_argv ) in enumerate ((
837+ ('first' , [sys .executable , '-c' , 'pass' ]),
838+ ('second' , observer_cmd ))):
839+ stage = summary ['stages' ][index ]
840+ self .assertEqual (set (stage .keys ()),
841+ {'name' , 'argv' , 'status' , 'exitCode' , 'advisory' , 'log' ,
842+ 'startedAt' , 'seconds' })
843+ self .assertEqual (stage ['name' ], expected_name )
844+ self .assertEqual (stage ['argv' ], expected_argv )
845+ self .assertEqual (stage ['status' ], 'passed' )
846+ self .assertEqual (stage ['exitCode' ], 0 )
847+ self .assertIs (stage ['advisory' ], False )
848+ self .assertEqual (stage ['log' ], f'{ expected_name } .log' )
849+ self .assertIsInstance (stage ['startedAt' ], str )
850+ self .assertRegex (stage ['startedAt' ], iso_utc_second )
851+ self .assertIsInstance (stage ['seconds' ], float )
852+ self .assertNotIsInstance (stage ['seconds' ], bool )
853+ self .assertGreaterEqual (stage ['seconds' ], 0.0 )
854+ self .assertEqual (round (stage ['seconds' ], 3 ), stage ['seconds' ])
855+ self .assertEqual (summary ['stages' ][0 ]['startedAt' ], finished_first ['startedAt' ])
856+ self .assertEqual (summary ['stages' ][0 ]['seconds' ], finished_first ['seconds' ])
857+ self .assertEqual (summary ['stages' ][1 ]['startedAt' ], running ['startedAt' ])
858+
771859
772860class PinnedLiveCurl (unittest .TestCase ):
773861 def test_all_live_profiles_use_the_shared_pinned_dependency (self ):
0 commit comments