Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xSteph Pentest ai compute diff

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Data_Management
Last Updated 2026-10-23 12:00 GMT

Overview

Concrete diff function that compares findings from two engagements and buckets them into new, resolved, and unchanged using the dedup fingerprint.

Description

compute_diff takes findings from a previous engagement and a current engagement, indexes them by fingerprint, and computes set differences:

  • new: Findings in current but not in previous
  • resolved: Findings in previous but not in current
  • unchanged: Findings in both

The EngagementDiff dataclass holds the results with convenience properties (total_new, total_resolved, total_unchanged), per-bucket severity counts, and a `to_dict()` method for JSON serialization.

This is the engine behind `ptai retest` and `ptai diff`.

Usage

Import this when you need to:

  • Compare findings between two engagement runs
  • Identify new, resolved, and unchanged vulnerabilities
  • Implement retest/diff functionality

Code Reference

Source Location

Signature

@dataclass
class EngagementDiff:
    prev_engagement_id: str
    curr_engagement_id: str
    new: list[dict[str, Any]] = field(default_factory=list)
    resolved: list[dict[str, Any]] = field(default_factory=list)
    unchanged: list[dict[str, Any]] = field(default_factory=list)

    @property
    def total_new(self) -> int:
    @property
    def total_resolved(self) -> int:
    @property
    def total_unchanged(self) -> int:

    def severity_counts(self, bucket: str) -> dict[str, int]:
    def to_dict(self) -> dict[str, Any]:

def compute_diff(
    prev_engagement_id: str,
    curr_engagement_id: str,
    prev_findings: list[dict[str, Any]],
    curr_findings: list[dict[str, Any]],
) -> EngagementDiff:
    """Bucket findings into new / resolved / unchanged via dedup fingerprint."""

Import

from engine.diff import compute_diff, EngagementDiff

I/O Contract

Inputs

Name Type Required Description
prev_engagement_id str Yes Previous engagement ID
curr_engagement_id str Yes Current engagement ID
prev_findings list[dict] Yes Findings from previous run
curr_findings list[dict] Yes Findings from current run

Outputs

Name Type Description
returns new, resolved, unchanged finding lists + severity counts

Usage Examples

Computing a Retest Diff

from engine.diff import compute_diff

prev = await db.get_findings(engagement_id="prev-eng")
curr = await db.get_findings(engagement_id="curr-eng")
diff = compute_diff("prev-eng", "curr-eng", prev, curr)

print(f"New: {diff.total_new}")
print(f"Resolved: {diff.total_resolved}")
print(f"Unchanged: {diff.total_unchanged}")
print(f"By severity (new): {diff.severity_counts('new')}")

# Serialize for CI output
import json
print(json.dumps(diff.to_dict()))

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment