fix: Improved metrics tracking behaviour on fs_undo#1489
Conversation
| let diff = DiffFormat::format( | ||
| output.after_undo.as_deref().unwrap_or(""), | ||
| output.before_undo.as_deref().unwrap_or(""), |
There was a problem hiding this comment.
The parameters in DiffFormat::format are reversed between the metrics calculation and display code. In the metrics calculation:
let diff = DiffFormat::format(
output.after_undo.as_deref().unwrap_or(""),
output.before_undo.as_deref().unwrap_or(""),
);But for display:
let diff = DiffFormat::format(before, after);This inconsistency will cause metrics to track the inverse of what's being displayed. Either swap the parameters in the metrics calculation to match the display order:
let diff = DiffFormat::format(
output.before_undo.as_deref().unwrap_or(""),
output.after_undo.as_deref().unwrap_or(""),
);Or adjust the metrics calculation to account for the reversed diff.
| let diff = DiffFormat::format( | |
| output.after_undo.as_deref().unwrap_or(""), | |
| output.before_undo.as_deref().unwrap_or(""), | |
| let diff = DiffFormat::format( | |
| output.before_undo.as_deref().unwrap_or(""), | |
| output.after_undo.as_deref().unwrap_or(""), |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
| forge_domain::ToolOutput::text(elm) | ||
| } | ||
| (Some(after), Some(before)) => { | ||
| (Some(before), Some(after)) => { |
There was a problem hiding this comment.
Lets add some failing tests for this change.
There was a problem hiding this comment.
After this point, it is only converted to a text element and returned, which should be captured in the new snapshots
Changes
Current metrics updation behaviour
i made diagram to better understand this, fs_undo changes were treated as any other changes

Updated behaviour
when fs_undo the changes will be subtracted from metrics instead of added, to correctly reflect the status of those files

as seen in this image the metrics will correctly reflect on the state of the file prior to the changes which are now undone
Fs_undo diffs
While doing this i also noticed Fs_undo diffs where off, specifically before and after was the other way around
like can be seen in this snapshot
Operation:
Output (current)
Output (newer)
Since
original contentis basically removed, and now the file containsModified content\n After restorattelater diff is more suitable.The diff is not seen in actual tool usage tho.