Documentation
¶
Overview ¶
Package report aggregates a check run into the shape a person reads: what was checked, what it rests on, and what to do about the parts that failed.
It lives in core/ rather than cmd/ so a second consumer can import it (agni issue 380), and it does no I/O of its own (CONSTRAINTS C1).
The aggregation here decides what a reader sees first; html.go only renders it, so the layout can change without re-deciding that. The page itself is described in docsite/content/guide/checks-and-reports.md#the-html-report.
Index ¶
- Constants
- Variables
- func ChecklistHTML(w io.Writer, c Checklist) error
- func DiffURL(meta, bmeta Report, renameApprox bool) string
- func HTML(w io.Writer, r Report) error
- func HierarchyCycles(blocks []*ir.UnexpandedHierarchy) bool
- func HierarchyNote(file string, blocks []*ir.UnexpandedHierarchy) string
- func HierarchyNoun(blocks []*ir.UnexpandedHierarchy) string
- func HierarchySummary(blocks []*ir.UnexpandedHierarchy) string
- func JoinCell(vals []string) string
- func QuerySetURL(meta Report, set, query string) string
- func QueryURL(meta Report, query, title string, binds []string) string
- func SanitizeCell(s string) string
- func TableCSV(w io.Writer, t Table) error
- func TableHTML(w io.Writer, t Table) error
- func TableMarkdown(w io.Writer, t Table) error
- func TableSetHTML(w io.Writer, s TableSet) error
- func TableSetMarkdown(w io.Writer, s TableSet) error
- func TableSetText(w io.Writer, s TableSet) error
- func TableText(w io.Writer, t Table) error
- func TraceURL(meta Report, from, to string, hops int) string
- func VerdictURL(meta Report, id, rule string, subjects []string) string
- func WitnessLines(ws []Witness) []string
- func WriteTraceText(w io.Writer, t check.Trace)
- type CSVWriter
- type Checklist
- type ChecklistArea
- type ChecklistEvidence
- type ChecklistItem
- type PinMap
- type PinMapRow
- type Report
- type Row
- type RuleReport
- type Table
- type TableRow
- type TableSection
- type TableSet
- type Term
- type Totals
- type Witness
Constants ¶
const MultiValueSep = "|"
MultiValueSep joins several values inside one cell. Not a comma, so a reader splitting a cell can tell it from the field delimiter.
const ProvenanceColumn = "provenance"
ProvenanceColumn is the name of the trailing column every renderer appends. Exported so a caller binding to the csv header does not have to spell it a second time.
const ViewerTarget = "agni-viewer"
ViewerTarget is the window name every report link opens in, so clicks reuse one viewer tab, or a frame of that name beside the report, rather than opening a tab each.
Variables ¶
var CSS string
CSS is the stylesheet both report pages share, so a pass is the same green on the check report and on the checklist. It is a file rather than a string literal so an editor treats it as CSS.
Functions ¶
func ChecklistHTML ¶
ChecklistHTML writes the checklist as one self-contained page.
html/template for the reason HTML gives, since titles, subjects and messages come from design files the engine did not author.
func DiffURL ¶ added in v0.3.5
DiffURL is the viewer link that compares two revisions, "" when this run cannot promise one (agni issue 1126). It opens meta's design and starts the viewer's Compare against bmeta's, as picking that design in the Compare picker does.
Like TraceURL it carries the QUESTION, so it takes no content hash, and the viewer compares the two designs as they are now. Both sides must be linkable on ONE server, since the viewer reads the second design through the mount table that serves the first, so a withheld link on either side, or two different bases, yields no link.
renameApprox carries the near-rename pairing the diff was asked for (--rename-approx, the MCP tool's rename_approx), so the viewer's comparison tables pair them too rather than leaving the reader to tick the option.
func HTML ¶
HTML writes the report as one self-contained page.
html/template rather than string building, because every subject, message and witness came out of a design file the engine did not author, and a net name holding an angle bracket or a quote would otherwise corrupt or inject into the page. html/template escapes per context (text, attribute, URL).
COLLAPSING IS <details>, NOT SCRIPT. The report has to survive being emailed, committed, opened from a file:// path and read with scripts disabled, and a section that cannot expand hides its rows. So it never DEPENDS on a script. A report that links into a viewer carries one script, which only moves a viewer already open rather than loading it again (viewerlink.js, agni issue 1156); with scripts off its links still open in that viewer's window. A report with no links carries none.
Self-contained, with no external CSS or fonts, so it renders with no network.
func HierarchyCycles ¶ added in v0.3.2
func HierarchyCycles(blocks []*ir.UnexpandedHierarchy) bool
HierarchyCycles reports whether every listed block was left out because it places itself, which is all a flattened read leaves out.
func HierarchyNote ¶ added in v0.2.4
func HierarchyNote(file string, blocks []*ir.UnexpandedHierarchy) string
HierarchyNote is the sentence saying a read left out hierarchical blocks, or "" when it left out none (agni issues 707, 717). file names the design, and only its last path element is printed, so a mount URI and a host path read alike.
It is ONE sentence for every surface that says it: the CLI's stderr note, the check and checklist HTML reports, and the viewer's canvas strip, which GetDesignResponse.hierarchy_note carries. Each surface frames it (the CLI prefixes "note: ") and none rewords it, so a reader who has seen it in one place recognises it in the next.
It takes the diagnostic rather than the design, so it reads nothing else. A hierarchical design is not a defect, so this is never a finding. The largest blocks are named first, because that is where most of the missing design is.
A flattened read lists only the blocks that place themselves (UNEXPANDED_REASON_CYCLE), and saying "only its top cell was read" there would be false, so those get a sentence of their own (agni issue 1102).
func HierarchyNoun ¶ added in v0.2.4
func HierarchyNoun(blocks []*ir.UnexpandedHierarchy) string
HierarchyNoun names the construct the way its format's users do, falling back to "block".
func HierarchySummary ¶ added in v0.2.4
func HierarchySummary(blocks []*ir.UnexpandedHierarchy) string
HierarchySummary is "2 sub-cells holding 13 instances", the count half of the note and of the `agni stats` line.
func JoinCell ¶
JoinCell renders several values into one cell, sanitizing the result rather than each part, since only the leading character of the finished cell can start a formula.
func QuerySetURL ¶ added in v0.2.4
QuerySetURL builds the link that opens one query of a project's query set in a running viewer, by the set's and the query's names, or "" when the caller gave no base. A set the project keeps has a name the viewer can find (QueryService.ListQuerySets), so the link stays short however long the query is, and follows the set's current text.
func QueryURL ¶ added in v0.2.4
QueryURL builds the link that asks a query again in a running viewer's query panel, or "" when the caller gave no base (agni issue 634). Like TraceURL it carries the QUESTION, so it takes no content hash: following it re-asks the query of the design as it is now. binds are the values the query was asked with, as `name=value` pairs spelled as `--bind` takes them, so the link asks the same question rather than a wider one; title is the view's heading, "" for none.
func SanitizeCell ¶
SanitizeCell makes a value safe to write into a spreadsheet cell.
A cell whose text begins with one of csvFormulaPrefixes is EXECUTED on open, so a net named "-VBUS" becomes a formula. A leading single quote marks it as text in every major spreadsheet. Escaping is unconditional because the values are net names and rule prose, which we do not control.
Leading whitespace is skipped when looking for the prefix, since some readers still parse whitespace ahead of a formula character as a formula.
func TableCSV ¶
TableCSV writes the rows as csv, header first, with every cell sanitized against spreadsheet formula execution (see SanitizeCell).
It emits THE TABLE AND NOTHING ELSE: no title, no query, no count, because whatever binds to a csv expects the header as its first row. A commented preamble is not portable across readers.
An empty result still writes the header, so it reads as a query that matched nothing rather than a run that failed.
func TableHTML ¶
TableHTML writes the view as one self-contained page on the stylesheet the check report and the checklist share. html/template for the reason stated on HTML.
func TableMarkdown ¶
TableMarkdown writes the view as a GitHub-flavoured markdown section: a heading, the query in a fence, then the table.
The empty case gets a SENTENCE, not an empty table, since a header with no rows reads as a broken generator.
func TableSetHTML ¶ added in v0.2.2
TableSetHTML writes the set as one self-contained page on the shared stylesheet.
func TableSetMarkdown ¶ added in v0.2.2
TableSetMarkdown writes the set as one markdown document: a title, the shared preamble, then a section per query carrying its question above its answer.
func TableSetText ¶ added in v0.2.2
TableSetText writes each section as a headed block in the aligned terminal format.
func TableText ¶
TableText writes the aligned terminal table: the projected columns plus provenance, then the count. Keep it byte-stable, since scripts parse `agni query` output.
func TraceURL ¶
TraceURL is the viewer link that re-asks a pin-to-pin question, "" when this run cannot promise one, under the same two conditions as VerdictURL.
It carries the QUESTION rather than an answer, so it takes no content hash and the viewer draws no stale-link banner for one; the pins are re-asked against whatever the design is now.
hops is written whenever the caller STATES one (> 0). The CLI always states the radius it searched at; the viewer states one only when the reader pinned it, since 0 there means the server default. Never drop a pinned radius, or the link re-asks a narrower question wider and can show a route the run said did not exist.
func VerdictURL ¶
VerdictURL builds the link that opens this verdict's proof in a running viewer, or "" when the caller gave no base.
Exported because three renderers use it. The html page and the terminal read Row.URL, and the csv writer composes the link per row because it emits in the run's order rather than the report's.
A MISSING LINK IS THE CORRECT ANSWER for a loose file, not a gap to fill with a guess (issue 392), because a URL built from an invented mount resolves on nobody's server. The content hash rides along so the viewer can flag a link computed against different bytes.
func WitnessLines ¶ added in v0.3.8
WitnessLines renders a row's witnesses as an indented tree, one line per fact, each child one level deeper than the fact it proves. A derived fact names its rule after `via`, a leaf its citations in brackets, and a negated leaf reads `not ... (absent)`.
Types ¶
type CSVWriter ¶
type CSVWriter struct {
// contains filtered or unexported fields
}
CSVWriter wraps encoding/csv so cells are sanitized on the way out and the first error is retained, letting a caller check once in Finish instead of after every row.
It lives here rather than in cmd/ so the CLI renderers and the query table share one escaping (agni issue 380).
func NewCSVWriter ¶
func (*CSVWriter) Finish ¶
Finish flushes and returns the first error seen, from any row or from the flush itself.
type Checklist ¶
type Checklist struct {
Design string // the design this run read, as the caller names it
Name string // the checklist's own name, from the manifest
Generated string // caller-supplied timestamp; empty is fine
ContentHash string // the bytes this run saw
URLBase string // empty means emit no links at all
MountPath string // empty means emit no links at all
// LinksWithheld is why this run promised no links, when it was asked for them and refused.
// Same as Report.LinksWithheld (issue 626).
LinksWithheld string
// HierarchyNote is Report.HierarchyNote for the read this checklist scored (agni issue 717).
HierarchyNote string
Summary string // the one-line tally, rendered by the caller so both surfaces read alike
Covered int
Answered int
Total int
Areas []ChecklistArea
}
Checklist is one review run, aggregated for reading.
It is a SECOND page shape over the same machinery, not a filter of the check report. The check report is rule-major (one section per rule); a checklist is question-major, the team's own items in the team's own order with the evidence for each.
The two share Design/Generated/ContentHash/URLBase/MountPath and the stylesheet, so a link means the same thing on both.
type ChecklistArea ¶
type ChecklistArea struct {
Name string
Summary string
Items []ChecklistItem
}
ChecklistArea is one group of items, in manifest order. Areas are NOT sorted by severity, unlike the check report's rules, because the order is the team's and sorting would move items every time the board changes.
type ChecklistEvidence ¶
type ChecklistEvidence struct {
Rule string
Subject string
Message string
URL string // empty when no link could be promised
}
ChecklistEvidence is one finding behind an item, with the link to its proof.
type ChecklistItem ¶
type ChecklistItem struct {
ID string // the team's own identifier, preserved from the manifest
Title string
Outcome string // review.Outcome as a string; the stylesheet keys off it
Note string // why it did not apply, or who owns it when nothing automated can answer
Evidence []ChecklistEvidence
}
ChecklistItem is one question and what the run made of it.
func (ChecklistItem) Failed ¶
func (i ChecklistItem) Failed() bool
Failed reports whether this item is worth opening on arrival. Everything that is not a plain pass qualifies, including an item nobody answered.
type PinMapRow ¶ added in v0.3.11
type PinMapRow struct {
Pin, Function, Net, WiredNet, FarEnd, Route string
PinCheck, NetCheck, FarEndCheck, FunctionCheck check.Outcome
Outcome check.Outcome
}
PinMapRow is one declared pin: what the map says, what the netlist has, and each IO-map rule's outcome on it. An empty check outcome means the run did not include that rule.
type Report ¶
type Report struct {
Design string // the design this run read, as the caller names it
Generated string // caller-supplied timestamp; empty is fine
ContentHash string // the bytes this run saw, so a stale link can be detected (issue 392)
URLBase string // e.g. "http://localhost:8080"; empty means emit no links at all
MountPath string // e.g. "demo/board.kicad_sch"; empty means emit no links at all
// LinksWithheld is why this run promised no links, when it was asked for them and refused.
// Empty when links were emitted, and empty when none were asked for. It travels in the report
// because the report is read long after the stderr that also said it is gone (issue 626).
LinksWithheld string
// HierarchyNote says the read left out hierarchical blocks (HierarchyNote's sentence), so every
// count on the page covers the top level alone. Empty for a flat design (agni issue 717).
HierarchyNote string
Totals Totals
// PinMaps are the design intent's IO map, one section per device, each row a declared pin beside
// what the netlist has there (agni issues 1188, 1189). Empty when the run checked no map.
PinMaps []PinMap
// QuerySets are the answers to the design project's query sets, when the caller ran them, one
// Queries section each after the rules (agni issue 1190). Empty leaves the page as it was.
QuerySets []TableSet
Rules []RuleReport
}
Report is one check run, aggregated.
Generated and Design are supplied by the caller because this package does no I/O and does not read the clock, so a report built twice from the same run is identical and a committed one diffs cleanly across board revisions.
func Build ¶
func Build(verdicts []check.Verdict, findings []check.Finding, rules []*check.Rule, meta Report) Report
Build aggregates a run into a Report.
verdicts come from check.RunVerdicts (rules that state a considered set) and findings from check.Run (every rule). A rule appears in the report if it produced either, so a findings-only rule is present and visibly labelled rather than silently absent.
ORDERING IS THE MAIN JUDGMENT HERE. Rules with something to act on come first, then the rest alphabetically; within a rule, failures and undecidables come before passes.
type Row ¶
type Row struct {
ID string
Outcome check.Outcome
// Subjects is what the row is about, in the rule's order: one entity for most rules, the whole
// tuple for a rule whose question is a relation, such as both nets of a copper-clearance row.
Subjects []check.Entity
Message string // the violation sentence, set on a failure
Witness string // what the outcome rests on
Reason string // why an undecidable subject could not be judged
Terms []Term
Context []string // other entities the proof names
URL string // empty when the caller supplied no base
}
Row is one subject's outcome under one rule.
func (Row) Detail ¶
Detail is the sentence a row leads with: the violation where there is one, else the proof, else the reason it could not be judged. A failing verdict carries both a Message and a Witness, and the Message wins.
func (Row) SubjectLabel ¶
SubjectLabel is a row's subject tuple as one string, joined the way both renderers spell it, so a relation-shaped rule names every entity. It lives on Row so the HTML template and the CLI share one spelling (agni issue 380).
type RuleReport ¶
type RuleReport struct {
Name string
Severity string
Summary string
Impact string
Remedy string
// StatesConsideredSet lets a reader tell "this rule examined 41 rails and cleared 39" from "this
// rule reported two problems and said nothing about what else it looked at". Collapsing the two
// would claim coverage the rule never checked.
StatesConsideredSet bool
Counts map[check.Outcome]int
Rows []Row
}
RuleReport is one rule's section.
func (RuleReport) Failed ¶
func (r RuleReport) Failed() bool
Failed reports whether this rule has anything a reader must act on.
type Table ¶
type Table struct {
// Title names the view, e.g. "Test point coverage". Empty for an ad-hoc query, the common CLI
// case.
Title string
// Query is the datalog that produced the rows, carried so an exported view states the question
// it answers and can be re-run.
Query string
// Bindings are the values the query's variables were bound to, each formatted `?n = "GND"`
// (agni issue 793). A parameterized view prints them under the query, since the query text alone
// no longer states the whole question.
Bindings []string
// Source names the design the query ran against. Rendered in the subtitle, not in a cell.
Source string
// Columns are the projected column names, in the query's own order. Provenance is NOT among
// them; every renderer appends it as the last column.
Columns []string
Rows []TableRow
// Total is how many rows the answer had before a limit cut it to Rows (agni issue 896), zero when
// nothing was cut. The count line then says how many were left out, so a page is never read as the
// whole answer.
Total int
}
Table is one query answer, ready to render in any format: the projected columns, the rows, and the question that produced them.
It is the query result's report shape, as Report is a check run's and Checklist a review's, so one value renders as text, csv, markdown or html. It lives here rather than in cmd/ so the renderers are not copied and left to drift (agni issue 380).
type TableRow ¶
type TableRow struct {
Cells []string
// Cites are the fact citations behind this row, rendered as one trailing column rather than as
// a footnote.
Cites []string
// Why aligns with Cells and says why an empty cell is absent, such as a sum over numbers in
// different units. A renderer prints the reason in the cell, so an absent answer is never a blank.
Why []string
// Witnesses say how the row holds, when the query asked for them (agni issue 794). text and html
// print the tree under the row, markdown in a section after the table, and csv never, since a
// csv holds the table alone.
Witnesses []Witness
}
TableRow is one answer: a cell per column, plus the provenance of the facts that produced it.
type TableSection ¶ added in v0.2.2
type TableSection struct {
Name string
Description string
// Table is the answer. Its Title and Source are ignored, since the section's name is its heading
// and the set carries the source.
Table Table
// Error, when set, replaces the table, so a failure never reads as a question that matched
// nothing. Markdown and html still show Table.Query above it; the text renderer does not.
Error string
}
TableSection is one named query's answer, or why it has none.
type TableSet ¶ added in v0.2.2
type TableSet struct {
// Title names the set. Empty renders as "Query set".
Title string
// Source names the design every section ran against, once for the document.
Source string
// Preamble is the rules the queries share, shown once above the sections so each query's text can
// be read against the relations it uses.
Preamble string
Sections []TableSection
}
TableSet is the answers to a named set of queries asked of one design, rendered as one document (agni issue 729).
Each section's table renders through the single-table renderer for its format, so a table in a set and the same query asked alone come out the same.
type Term ¶
type Term struct{ Label, Value string }
Term is one labelled fact behind a row's witness.
type Totals ¶
type Totals struct {
RulesReporting int // rules that stated a considered set
RulesFindingsOnly int // rules that reported violations without stating what they looked at
Considered int // verdicts from rules that state a considered set
Pass int
Fail int
NotConsidered int
NoLimit int
Inconclusive int
Findings int // every violation, including from rules that state no considered set
}
Totals are the run's headline numbers.
Considered and Findings are counted separately and neither is derivable from the other. A rule that states a considered set contributes to both; a rule that reports only failures contributes to Findings alone.
type Witness ¶ added in v0.3.8
type Witness struct {
Relation string
// Values are the proved tuple's values as cells spell them; "" is an argument a negation left
// unbound.
Values []string
Rule string
Negated bool
Cites []string
Children []Witness
}
Witness is how one fact behind an answer row holds (agni issue 794), as a document renders it: a leaf the design's relations gave, with its citations, or a derived fact with the rule that derived it and that rule's body witnesses in the order the rule is written. A `not` that held is a negated leaf, which proves an absence and so cites nothing.