From 5a1a63857f7c4f1b38b0362dc5d1cda5d8da6221 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 16 Sep 2026 02:47:26 +0200 Subject: [PATCH] feat: restore legacy report presentation --- docs/report-contract.md | 1 + schema/report.schema.json | 17 ++++++++++++++++ templates/report.typ | 41 ++++++++++++++++++++++++++++++--------- tests/test_contract.py | 9 +++++++++ tools/validate.typ | 9 ++++++++- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/docs/report-contract.md b/docs/report-contract.md index 17d6d85..bc0f50e 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -52,6 +52,7 @@ Optional fields retain useful legacy structure: - `id`, `subtitle`, `report_type` (`technical` or `briefing`), `status`, `severity`. - `summary`, `closing`: supplied prose, never generated from technical observations. +- `metrics`: up to four supplied label/value cards with an optional severity tone. - `timeline`: rows with `time`, `event`, optional `notes`. - `findings`: title, optional ID/severity/status, separate `evidence` and `assessment`, and optional `evidence_refs` containing artifact, JSON pointer, and optional label. diff --git a/schema/report.schema.json b/schema/report.schema.json index 2e845bf..de937f1 100644 --- a/schema/report.schema.json +++ b/schema/report.schema.json @@ -137,6 +137,23 @@ "type": "string", "pattern": "\\S" }, + "metrics": { + "type": "array", + "items": { + "type": "object", + "properties": { + "label": { "type": "string", "pattern": "\\S" }, + "value": { "type": ["string", "number" ] }, + "tone": { + "enum": ["info", "low", "medium", "high", "critical", "warning", "ok", "success", "unanalysed"] + } + }, + "required": ["label", "value"], + "additionalProperties": false + }, + "minItems": 1, + "maxItems": 4 + }, "closing": { "type": "string", "pattern": "\\S" diff --git a/templates/report.typ b/templates/report.typ index c009cb9..9ca4d99 100644 --- a/templates/report.typ +++ b/templates/report.typ @@ -21,6 +21,8 @@ } else if value in ("ok", "success") { color("success", "#356344") } else { color("info", "#385f7a") } #let as-text(value) = str(value) +#let report-type-label(value) = if value == "technical" { "Technical report" + } else if value == "briefing" { "Stakeholder briefing" } else { str(value) } #let heading(title) = block(above: 12pt, below: 5pt)[ #text(size: 13pt, weight: "bold", fill: accent)[#as-text(title)] #line(length: 100%, stroke: 0.6pt + line-color) @@ -28,7 +30,7 @@ #let badge(value) = box(inset: (x: 5pt, y: 2pt), radius: 2pt, fill: severity-color(str(value)).lighten(85%), stroke: 0.5pt + severity-color(str(value)))[ - #text(size: 7.5pt, weight: "bold", fill: severity-color(str(value)))[#as-text(value)] + #text(size: 7.5pt, weight: "bold", fill: severity-color(str(value)))[#upper(as-text(value))] ] #let callout(body, kind: "info", title: none) = block(width: 100%, inset: 8pt, fill: severity-color(kind).lighten(92%), stroke: (left: 2pt + severity-color(kind)))[ @@ -55,7 +57,7 @@ #set page(paper: "a4", margin: (top: 20mm, bottom: 18mm, x: 20mm), header: context { grid(columns: (1fr, auto), align: (left, right + horizon), - text(size: 7.5pt, weight: "bold", fill: muted)[#as-text(organization)], + text(size: 7.5pt, weight: "bold", fill: muted)[#as-text(organization)#if "report_type" in report { [ — #report-type-label(report.report_type)] }], if logo != none { image(logo, height: 8mm, fit: "contain") }) v(3pt); line(length: 100%, stroke: 0.5pt + line-color) }, @@ -70,7 +72,7 @@ #if "report_type" in report or "status" in report or "severity" in report { v(7pt) for value in (get(report, "report_type"), get(report, "status"), get(report, "severity")) { - if value != none { badge(value); h(4pt) } + if value != none { badge(if value == get(report, "report_type") { report-type-label(value) } else { value }); h(4pt) } } } #v(10pt) @@ -80,18 +82,39 @@ #as-text(pair.at(1))])) ] #if "summary" in report { heading("Executive summary"); callout([#as-text(report.summary)]) } +#if "metrics" in report and report.metrics.len() > 0 { + v(7pt) + grid(columns: (1fr,) * report.metrics.len(), gutter: 5pt, + ..report.metrics.map(metric => { + let tone = severity-color(get(metric, "tone", default: "info")) + block(width: 100%, inset: 7pt, radius: 2pt, fill: tone.lighten(92%), stroke: 0.5pt + tone)[ + #text(size: 7.5pt, weight: "bold", fill: muted)[#upper(as-text(metric.label))] + #parbreak() + #text(size: 16pt, weight: "bold", fill: tone)[#as-text(metric.value)] + ] + })) +} #if "timeline" in report and report.timeline.len() > 0 { heading("Timeline") - for entry in report.timeline { block(below: 5pt)[#text(weight: "bold", fill: accent)[#as-text(entry.time)] - #h(6pt)#as-text(entry.event)#if "notes" in entry { [ — #as-text(entry.notes)] }] } + table(columns: (31mm, 1.1fr, 2fr), inset: 5pt, stroke: 0.45pt + line-color, + fill: (x, y) => if y == 0 { soft } else { none }, align: (left, left, left), + table.header([Time], [Event], [Notes]), + ..report.timeline.map(entry => ( + [#text(size: 8pt)[#as-text(entry.time)]], + [#as-text(entry.event)], + [#as-text(get(entry, "notes", default: ""))], + )).flatten()) } #if "findings" in report and report.findings.len() > 0 { heading("Findings") - for finding in report.findings { block(width: 100%, inset: 8pt, below: 6pt, + for finding in report.findings { block(width: 100%, inset: 8pt, below: 6pt, breakable: false, stroke: 0.5pt + line-color, radius: 2pt)[ - #text(weight: "bold")[#as-text(finding.title)] #if "severity" in finding { h(5pt); badge(finding.severity) } - #if "evidence" in finding { parbreak(); text(size: 8pt, fill: muted)[Evidence]; parbreak(); as-text(finding.evidence) } - #if "assessment" in finding { parbreak(); text(size: 8pt, fill: muted)[Assessment]; parbreak(); as-text(finding.assessment) } + #grid(columns: (1fr, auto, auto), gutter: 5pt, align: (left, center, center), + text(weight: "bold")[#as-text(finding.title)], + if "severity" in finding { badge(finding.severity) } else { [] }, + if "status" in finding { badge(finding.status) } else { [] }) + #if "evidence" in finding { parbreak(); text(size: 8pt, weight: "bold", fill: muted)[EVIDENCE]; parbreak(); as-text(finding.evidence) } + #if "assessment" in finding { parbreak(); text(size: 8pt, weight: "bold", fill: muted)[ASSESSMENT]; parbreak(); as-text(finding.assessment) } ] } } #for section in get(report, "sections", default: ()) { diff --git a/tests/test_contract.py b/tests/test_contract.py index d1a33b4..feecbaa 100644 --- a/tests/test_contract.py +++ b/tests/test_contract.py @@ -29,6 +29,15 @@ class ReportContractTests(unittest.TestCase): del self.document["branding"] self.assertEqual(validation.validate_document(self.document), []) + def test_summary_metrics_are_bounded_and_typed(self): + self.document["metrics"] = [ + {"label": "Critical", "value": 2, "tone": "critical"}, + {"label": "Confidence", "value": "85%", "tone": "info"}, + ] + self.assertEqual(validation.validate_document(self.document), []) + self.document["metrics"].append({"label": "Invalid", "value": [], "tone": "unknown"}) + self.assertTrue(validation.validate_document(self.document)) + def test_required_fields_and_versions(self): for path, value in [(("schema_version",), 2), (("schema_version",), True), (("title",), " "), (("metadata", "Author"), ""), diff --git a/tools/validate.typ b/tools/validate.typ index 93ad23e..6963683 100644 --- a/tools/validate.typ +++ b/tools/validate.typ @@ -38,7 +38,7 @@ for item in content { validate-block(item) } } -#assert(keys-allowed(report, ("schema_version", "title", "subtitle", "id", "report_type", "status", "severity", "metadata", "branding", "summary", "closing", "timeline", "findings", "sections", "appendices", "actions_title", "actions", "provenance")), message: "unsupported report field") +#assert(keys-allowed(report, ("schema_version", "title", "subtitle", "id", "report_type", "status", "severity", "metadata", "branding", "summary", "metrics", "closing", "timeline", "findings", "sections", "appendices", "actions_title", "actions", "provenance")), message: "unsupported report field") #assert(report.at("schema_version", default: none) == 1, message: "unsupported or missing schema_version") #assert(nonempty(report.at("title", default: none)), message: "title must be a non-empty string") #let report-metadata = report.at("metadata", default: none) @@ -46,6 +46,13 @@ #assert(report-metadata.Date.match(regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) != none, message: "metadata.Date must use YYYY-MM-DD") #assert(report.at("report_type", default: "technical") in ("technical", "briefing"), message: "unsupported report_type") #assert(report.at("severity", default: "info") in values, message: "unsupported severity") +#let metrics = report.at("metrics", default: ()) +#assert(type(metrics) == array and metrics.len() <= 4, message: "invalid metrics") +#for metric in metrics { + assert(keys-allowed(metric, ("label", "value", "tone")) and nonempty(metric.at("label", default: none)) and + type(metric.at("value", default: none)) in (str, int, float) and metric.at("tone", default: "info") in values, + message: "invalid metric") +} #let branding = report.at("branding", default: (:)) #assert(keys-allowed(branding, ("organization", "logo", "theme")), message: "invalid branding")