@@ -250,3 +250,66 @@ func TestParseBootMarkers_IgnoresStaleMarkersBeforeBootStart(t *testing.T) {
250250 assert .Equal (t , freshProgram .Format (time .RFC3339Nano ), programStartedAt .UTC ().Format (time .RFC3339Nano ))
251251 assert .Equal (t , freshAgent .Format (time .RFC3339Nano ), guestAgentReadyAt .UTC ().Format (time .RFC3339Nano ))
252252}
253+
254+ func TestParseBootMarkers_ReturnsLatestMarkerFromNewestLog (t * testing.T ) {
255+ t .Parallel ()
256+
257+ tmpDir := t .TempDir ()
258+ m := & manager {
259+ paths : paths .New (tmpDir ),
260+ }
261+
262+ id := "latest-marker-instance"
263+ logPath := m .paths .InstanceAppLog (id )
264+ rotatedLogPath := logPath + ".1"
265+ require .NoError (t , os .MkdirAll (filepath .Dir (logPath ), 0o755 ))
266+
267+ oldProgram := time .Date (2026 , 3 , 9 , 4 , 0 , 0 , 0 , time .UTC )
268+ oldAgent := oldProgram .Add (500 * time .Millisecond )
269+ newProgram := oldProgram .Add (3 * time .Second )
270+ newProgramLatest := oldProgram .Add (4 * time .Second )
271+ newAgent := oldProgram .Add (3500 * time .Millisecond )
272+
273+ require .NoError (t , os .WriteFile (rotatedLogPath , []byte (
274+ "HYPEMAN-PROGRAM-START ts=" + oldProgram .Format (time .RFC3339Nano )+ " mode=exec\n " +
275+ "HYPEMAN-AGENT-READY ts=" + oldAgent .Format (time .RFC3339Nano )+ "\n " ,
276+ ), 0o644 ))
277+
278+ require .NoError (t , os .WriteFile (logPath , []byte (
279+ "HYPEMAN-PROGRAM-START ts=" + newProgram .Format (time .RFC3339Nano )+ " mode=exec\n " +
280+ "HYPEMAN-AGENT-READY ts=" + newAgent .Format (time .RFC3339Nano )+ "\n " +
281+ "HYPEMAN-PROGRAM-START ts=" + newProgramLatest .Format (time .RFC3339Nano )+ " mode=exec\n " ,
282+ ), 0o644 ))
283+
284+ programStartedAt , guestAgentReadyAt := m .parseBootMarkers (id , true , true , nil )
285+ require .NotNil (t , programStartedAt )
286+ require .NotNil (t , guestAgentReadyAt )
287+ assert .Equal (t , newProgramLatest .Format (time .RFC3339Nano ), programStartedAt .UTC ().Format (time .RFC3339Nano ))
288+ assert .Equal (t , newAgent .Format (time .RFC3339Nano ), guestAgentReadyAt .UTC ().Format (time .RFC3339Nano ))
289+ }
290+
291+ func TestAppLogPathsForMarkerScan_IgnoresArchivedLogs (t * testing.T ) {
292+ t .Parallel ()
293+
294+ tmpDir := t .TempDir ()
295+ m := & manager {
296+ paths : paths .New (tmpDir ),
297+ }
298+
299+ id := "log-order-instance"
300+ logPath := m .paths .InstanceAppLog (id )
301+ require .NoError (t , os .MkdirAll (filepath .Dir (logPath ), 0o755 ))
302+
303+ for _ , p := range []string {
304+ logPath ,
305+ logPath + ".1" ,
306+ logPath + ".2" ,
307+ logPath + ".prev.12345" ,
308+ logPath + "-debug-copy" ,
309+ } {
310+ require .NoError (t , os .WriteFile (p , []byte ("x\n " ), 0o644 ))
311+ }
312+
313+ paths := m .appLogPathsForMarkerScan (id )
314+ require .Equal (t , []string {logPath + ".2" , logPath + ".1" , logPath }, paths )
315+ }
0 commit comments