Skip to content

[Enhancement] Add snapshot diffing to CostReport::assert_snapshot with human-readable diff output #777

Description

@ekelemepraise-code

Summary

cost.assert_snapshot("name") currently fails with a raw numeric comparison error when costs regress:

assertion failed: snapshot 'heavy_computation_cost' cost regressed
  left:  5123456
  right: 4987654

This doesn't help the developer understand which instruction type increased or by how much.

Proposed Output

COST REGRESSION: heavy_computation_cost
┌─────────────────────┬────────────┬────────────┬──────────┐
│ Metric              │ Baseline   │ Current    │ Delta    │
├─────────────────────┼────────────┼────────────┼──────────┤
│ Instructions        │  4,987,654 │  5,123,456 │ +2.72% ⚠│
│ Memory (bytes)      │     98,304 │     98,304 │ +0.00%   │
│ Fee (stroops)       │      1,245 │      1,278 │ +2.65% ⚠│
└─────────────────────┴────────────┴────────────┴──────────┘
Threshold: 5.00% | Status: EXCEEDED on [Instructions, Fee]

Implementation Notes

  • Extend CostReport to store per-metric breakdowns
  • Snapshot file format should be JSON for easy parsing
  • Diff table should be printed to stderr on failure

Acceptance Criteria

  • Human-readable diff table emitted on regression
  • Snapshot format is stable JSON
  • Tolerance can be set per-metric, not just globally
  • Backwards compatible with existing snapshot files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions