2
0
mirror of synced 2025-01-11 09:06:56 +00:00

Debugging transcripts for all tests

This commit is contained in:
benbierens 2024-07-26 10:56:22 +02:00
parent 1f72d4f37d
commit fb4d520ba4
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 54 additions and 15 deletions

View File

@ -38,7 +38,12 @@ namespace CodexPlugin.OverwatchSupport
foreach (var log in downloadedLogs)
{
writer.IncludeArtifact(log.GetFilepath());
converter.ProcessLog(log);
// Not all of these logs are necessarily Codex logs.
// Check, and process only the Codex ones.
if (IsCodexLog(log))
{
converter.ProcessLog(log);
}
}
}
@ -54,6 +59,11 @@ namespace CodexPlugin.OverwatchSupport
}
});
}
private bool IsCodexLog(IDownloadedLog log)
{
return log.GetLinesContaining("Run Codex node").Any();
}
}
public class CodexNodeTranscriptWriter : ICodexNodeHooks

View File

@ -4,7 +4,7 @@
public class OverwatchTranscript
{
public OverwatchHeader Header { get; set; } = new();
public OverwatchEvent[] Events { get; set; } = Array.Empty<OverwatchEvent>();
public OverwatchMoment[] Moments { get; set; } = Array.Empty<OverwatchMoment>();
}
[Serializable]
@ -21,9 +21,15 @@
}
[Serializable]
public class OverwatchEvent
public class OverwatchMoment
{
public DateTime Utc { get; set; }
public OverwatchEvent[] Events { get; set; } = Array.Empty<OverwatchEvent>();
}
[Serializable]
public class OverwatchEvent
{
public string Type { get; set; } = string.Empty;
public string Payload { get; set; } = string.Empty;
}

View File

@ -18,7 +18,7 @@ namespace OverwatchTranscript
private readonly Dictionary<string, Action<DateTime, string>> handlers = new Dictionary<string, Action<DateTime, string>>();
private readonly string workingDir;
private OverwatchTranscript model = null!;
private int eventIndex = 0;
private int momentIndex = 0;
private bool closed;
public TranscriptReader(string workingDir, string inputFilename)
@ -56,12 +56,12 @@ namespace OverwatchTranscript
public void Next()
{
CheckClosed();
if (eventIndex >= model.Events.Length) return;
if (momentIndex >= model.Moments.Length) return;
var @event = model.Events[eventIndex];
eventIndex++;
var moment = model.Moments[momentIndex];
momentIndex++;
PlayEvent(@event);
PlayMoment(moment);
}
public void Close()
@ -71,12 +71,20 @@ namespace OverwatchTranscript
closed = true;
}
private void PlayEvent(OverwatchEvent @event)
private void PlayMoment(OverwatchMoment moment)
{
foreach (var @event in moment.Events)
{
PlayEvent(moment.Utc, @event);
}
}
private void PlayEvent(DateTime utc, OverwatchEvent @event)
{
if (!handlers.ContainsKey(@event.Type)) return;
var handler = handlers[@event.Type];
handler(@event.Utc, @event.Payload);
handler(utc, @event.Payload);
}
private void LoadModel(string inputFilename)

View File

@ -16,7 +16,7 @@ namespace OverwatchTranscript
private readonly string transcriptFile;
private readonly string artifactsFolder;
private readonly Dictionary<string, string> header = new Dictionary<string, string>();
private readonly SortedList<DateTime, OverwatchEvent> buffer = new SortedList<DateTime, OverwatchEvent>();
private readonly SortedList<DateTime, List<OverwatchEvent>> buffer = new SortedList<DateTime, List<OverwatchEvent>>();
private readonly string workingDir;
private bool closed;
@ -37,12 +37,20 @@ namespace OverwatchTranscript
var typeName = payload.GetType().FullName;
if (string.IsNullOrEmpty(typeName)) throw new Exception("Empty typename for payload");
buffer.Add(utc, new OverwatchEvent
var newEvent = new OverwatchEvent
{
Utc = utc,
Type = typeName,
Payload = JsonConvert.SerializeObject(payload)
});
};
if (buffer.ContainsKey(utc))
{
buffer[utc].Add(newEvent);
}
else
{
buffer.Add(utc, new List<OverwatchEvent> { newEvent });
}
}
public void AddHeader(string key, object value)
@ -78,7 +86,14 @@ namespace OverwatchTranscript
};
}).ToArray()
},
Events = buffer.Values.ToArray()
Moments = buffer.Select(p =>
{
return new OverwatchMoment
{
Utc = p.Key,
Events = p.Value.ToArray()
};
}).ToArray()
};
header.Clear();