diff

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package diff compares two crawl reports and describes what changed between them: which issues are new, which were resolved, which persist, plus summary and page-set deltas.

It is a pure transform over two *report.Report values — it never fetches, reads files, or mutates anything. The CLI's `compare` command and any future scheduled-comparison feature build on this seam, mirroring how the report and sitemap packages stay side-effect free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Base    Meta        `json:"base"`
	Current Meta        `json:"current"`
	Issues  IssueDiff   `json:"issues"`
	Summary SummaryDiff `json:"summary"`
	Pages   PageDiff    `json:"pages"`
}

Diff is the full comparison of a base report against a current one. "Base" is the earlier crawl and "current" the later one, so a resolved issue is present in base but gone in current, and a new issue is the reverse.

func Compare

func Compare(base, current *report.Report) *Diff

Compare diffs base (the earlier crawl) against current (the later one).

func (*Diff) Unchanged

func (d *Diff) Unchanged() bool

Unchanged reports whether nothing of substance differs between the two crawls.

type IssueDiff

type IssueDiff struct {
	New        []analyze.Issue `json:"new"`        // present now, absent before (regressions / freshly found)
	Resolved   []analyze.Issue `json:"resolved"`   // present before, absent now (fixed or no longer reached)
	Persisting []analyze.Issue `json:"persisting"` // present in both crawls
}

IssueDiff buckets issues by how they changed between the two crawls. Issue identity is (analyzer, code, url); message, severity, and data may shift without changing identity, so the current-crawl copy is kept for New and Persisting and the base copy for Resolved.

type JSONReporter

type JSONReporter struct{}

JSONReporter writes an indented JSON diff.

func (JSONReporter) Write

func (JSONReporter) Write(w io.Writer, d *Diff) error

Write implements Reporter.

type Meta

type Meta struct {
	Seed         string `json:"seed"`
	StartedAt    string `json:"started_at"`
	FinishedAt   string `json:"finished_at"`
	PagesCrawled int    `json:"pages_crawled"`
}

Meta identifies one side of a comparison.

type PageDiff

type PageDiff struct {
	Added   []string `json:"added"`   // crawled now, not before
	Removed []string `json:"removed"` // crawled before, not now
}

PageDiff reports which crawled URLs appeared or disappeared between the two crawls, drawn from each report's site-map entries. Nil site maps yield empty slices.

type Reporter

type Reporter interface {
	Write(w io.Writer, d *Diff) error
}

Reporter serializes a Diff to a writer.

func For

func For(format string) Reporter

For returns the Reporter for the given format ("text" or "json"; default text).

type SummaryDiff

type SummaryDiff struct {
	BySeverity map[string]int `json:"by_severity"`
	ByAnalyzer map[string]int `json:"by_analyzer"`
	ByStatus   map[string]int `json:"pages_by_status"`
	// NewBySeverity / ResolvedBySeverity tally the issues in IssueDiff.New / .Resolved by
	// severity, the headline "what got worse / better" numbers.
	NewBySeverity      map[string]int `json:"new_by_severity"`
	ResolvedBySeverity map[string]int `json:"resolved_by_severity"`
}

SummaryDiff reports count deltas. Each map is keyed the same way as report.Summary and holds current-minus-base, so positive means "more now". Keys present in only one side appear with the signed full count.

type TextReporter

type TextReporter struct {
	// MaxList caps how many issues/URLs are listed per section (0 = the default of 20).
	MaxList int
}

TextReporter writes a human-readable diff for the terminal.

func (TextReporter) Write

func (t TextReporter) Write(w io.Writer, d *Diff) error

Write implements Reporter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL