Files
runner/src/Runner.Worker/Dap/StepCommands/StepChange.cs
Francesco Renzi 008594a3ee editing jobs
2026-01-21 23:19:25 +00:00

133 lines
4.3 KiB
C#

using System;
namespace GitHub.Runner.Worker.Dap.StepCommands
{
/// <summary>
/// Records a modification made to a step during a debug session.
/// Used for change tracking and export diff generation.
/// </summary>
public class StepChange
{
/// <summary>
/// The type of change made.
/// </summary>
public ChangeType Type { get; set; }
/// <summary>
/// The original 1-based index of the step (before any modifications).
/// For Added steps, this is -1.
/// </summary>
public int OriginalIndex { get; set; } = -1;
/// <summary>
/// The current 1-based index of the step (after all modifications).
/// For Removed steps, this is -1.
/// </summary>
public int CurrentIndex { get; set; } = -1;
/// <summary>
/// Snapshot of the step before modification (for Modified/Moved/Removed).
/// </summary>
public StepInfo OriginalStep { get; set; }
/// <summary>
/// The step after modification (for Added/Modified/Moved).
/// For Removed steps, this is null.
/// </summary>
public StepInfo ModifiedStep { get; set; }
/// <summary>
/// Timestamp when the change was made.
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
/// <summary>
/// Description of the change for display purposes.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Creates a change record for an added step.
/// </summary>
public static StepChange Added(StepInfo step, int index)
{
return new StepChange
{
Type = ChangeType.Added,
OriginalIndex = -1,
CurrentIndex = index,
ModifiedStep = step,
Description = $"Added step '{step.Name}' at position {index}"
};
}
/// <summary>
/// Creates a change record for a modified step.
/// </summary>
public static StepChange Modified(StepInfo original, StepInfo modified, string changeDescription = null)
{
return new StepChange
{
Type = ChangeType.Modified,
OriginalIndex = original.Index,
CurrentIndex = modified.Index,
OriginalStep = original,
ModifiedStep = modified,
Description = changeDescription ?? $"Modified step '{original.Name}' at position {original.Index}"
};
}
/// <summary>
/// Creates a change record for a removed step.
/// </summary>
public static StepChange Removed(StepInfo step)
{
return new StepChange
{
Type = ChangeType.Removed,
OriginalIndex = step.Index,
CurrentIndex = -1,
OriginalStep = step,
Description = $"Removed step '{step.Name}' from position {step.Index}"
};
}
/// <summary>
/// Creates a change record for a moved step.
/// </summary>
public static StepChange Moved(StepInfo original, int newIndex)
{
var modified = new StepInfo
{
Index = newIndex,
Name = original.Name,
Type = original.Type,
TypeDetail = original.TypeDetail,
Status = original.Status,
Action = original.Action,
Step = original.Step,
OriginalIndex = original.Index,
Change = ChangeType.Moved
};
return new StepChange
{
Type = ChangeType.Moved,
OriginalIndex = original.Index,
CurrentIndex = newIndex,
OriginalStep = original,
ModifiedStep = modified,
Description = $"Moved step '{original.Name}' from position {original.Index} to {newIndex}"
};
}
/// <summary>
/// Returns a human-readable summary of this change.
/// </summary>
public override string ToString()
{
return Description ?? $"{Type} step at index {OriginalIndex} -> {CurrentIndex}";
}
}
}