Deploy notifications 1bc6a84: redesigned PDF report
Browse files- automation/scripts/html-to-pdf.js +20 -4
- coworker/adapters/pdf.py +4 -2
- coworker/graph/nodes/report.py +23 -10
- coworker/platform/report_pdf.py +202 -0
- coworker/tests/test_report_pdf.py +62 -0
- web/e2e/coworker.e2e.ts +1 -1
automation/scripts/html-to-pdf.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
// Co-worker report export: render a local HTML report to PDF with Playwright's Chromium (already installed).
|
| 3 |
-
// Usage: node scripts/html-to-pdf.js <input.html> <output.pdf>. Local files only; no network.
|
|
|
|
|
|
|
| 4 |
const { chromium } = require('@playwright/test');
|
|
|
|
|
|
|
|
|
|
| 5 |
(async () => {
|
| 6 |
-
const [inp, out] = process.argv.slice(2);
|
| 7 |
-
if (!inp || !out) { console.error('usage: html-to-pdf.js <input.html> <output.pdf>'); process.exit(2); }
|
| 8 |
const b = await chromium.launch();
|
| 9 |
try {
|
| 10 |
const p = await b.newPage();
|
| 11 |
await p.goto('file:///' + inp.replace(/\\/g, '/'));
|
| 12 |
-
await p.pdf({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
} finally {
|
| 14 |
await b.close();
|
| 15 |
}
|
|
|
|
| 1 |
#!/usr/bin/env node
|
| 2 |
// Co-worker report export: render a local HTML report to PDF with Playwright's Chromium (already installed).
|
| 3 |
+
// Usage: node scripts/html-to-pdf.js <input.html> <output.pdf> [footer text]. Local files only; no network.
|
| 4 |
+
// The page size and margins come from the report's own @page rule; the optional footer is printed on every page with
|
| 5 |
+
// the page number ("<footer text> · Page 2 of 5").
|
| 6 |
const { chromium } = require('@playwright/test');
|
| 7 |
+
|
| 8 |
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 9 |
+
|
| 10 |
(async () => {
|
| 11 |
+
const [inp, out, footer] = process.argv.slice(2);
|
| 12 |
+
if (!inp || !out) { console.error('usage: html-to-pdf.js <input.html> <output.pdf> [footer text]'); process.exit(2); }
|
| 13 |
const b = await chromium.launch();
|
| 14 |
try {
|
| 15 |
const p = await b.newPage();
|
| 16 |
await p.goto('file:///' + inp.replace(/\\/g, '/'));
|
| 17 |
+
await p.pdf({
|
| 18 |
+
path: out,
|
| 19 |
+
format: 'A4',
|
| 20 |
+
printBackground: true,
|
| 21 |
+
preferCSSPageSize: true,
|
| 22 |
+
displayHeaderFooter: !!footer,
|
| 23 |
+
headerTemplate: '<span></span>',
|
| 24 |
+
footerTemplate: footer
|
| 25 |
+
? `<div style="width:100%;padding:0 16mm;font:7.5pt -apple-system,'Segoe UI','Liberation Sans',Arial,sans-serif;color:#8e8e93;display:flex;justify-content:space-between">`
|
| 26 |
+
+ `<span>${esc(footer)}</span><span>Page <span class="pageNumber"></span> of <span class="totalPages"></span></span></div>`
|
| 27 |
+
: '<span></span>',
|
| 28 |
+
});
|
| 29 |
} finally {
|
| 30 |
await b.close();
|
| 31 |
}
|
coworker/adapters/pdf.py
CHANGED
|
@@ -10,10 +10,12 @@ from ..platform import procs
|
|
| 10 |
SCRIPT = ROOT / "automation" / "scripts" / "html-to-pdf.js"
|
| 11 |
|
| 12 |
|
| 13 |
-
def html_to_pdf(html: Path, pdf: Path, timeout_s: int = 120) -> Path | None:
|
|
|
|
| 14 |
if not SCRIPT.exists():
|
| 15 |
return None
|
| 16 |
-
|
|
|
|
| 17 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **procs.popen_kwargs())
|
| 18 |
procs.register(p, "pdf")
|
| 19 |
try:
|
|
|
|
| 10 |
SCRIPT = ROOT / "automation" / "scripts" / "html-to-pdf.js"
|
| 11 |
|
| 12 |
|
| 13 |
+
def html_to_pdf(html: Path, pdf: Path, timeout_s: int = 120, footer: str | None = None) -> Path | None:
|
| 14 |
+
"""`footer` is printed on every page with the page number ("<footer> · Page 2 of 5"); plain text."""
|
| 15 |
if not SCRIPT.exists():
|
| 16 |
return None
|
| 17 |
+
args = ["node", str(SCRIPT), str(Path(html).resolve()), str(Path(pdf).resolve())] + ([footer] if footer else [])
|
| 18 |
+
p = subprocess.Popen(args, cwd=str(ROOT / "automation"),
|
| 19 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **procs.popen_kwargs())
|
| 20 |
procs.register(p, "pdf")
|
| 21 |
try:
|
coworker/graph/nodes/report.py
CHANGED
|
@@ -3,6 +3,7 @@ counts only; HTML bundle + PDF) -> learner (run history, failure patterns, label
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import html as _html
|
|
|
|
| 6 |
import json
|
| 7 |
import re
|
| 8 |
from pathlib import Path
|
|
@@ -12,12 +13,15 @@ from ...adapters.legacy import FRONTIER_COUNT_KEYS, is_redacted_counts
|
|
| 12 |
from ...adapters.pdf import html_to_pdf
|
| 13 |
from ...llm.base import LLMRequest, Sensitivity
|
| 14 |
from ...llm.schemas import ExecSummary
|
| 15 |
-
from ...
|
|
|
|
| 16 |
from .triage import run_triage
|
| 17 |
|
| 18 |
STUB_BANNER = "STUB RUN: synthetic results from p2p_graph.py stubs. No browser, no mock-app, no Fusion. Not evidence of anything."
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
| 21 |
TARGET_WORDS = {"fusion": "Results are from an Oracle Fusion test pod.", "mock": "Results are from the local mock app, not Oracle Fusion."}
|
| 22 |
|
| 23 |
|
|
@@ -103,15 +107,24 @@ def reporter(state, config, svc) -> dict:
|
|
| 103 |
body = h.read_text(encoding="utf-8")
|
| 104 |
inner = re.search(r"<body[^>]*>(.*)</body>", body, re.S)
|
| 105 |
bundle = out / "bundle.html"
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
h.write_text(h.read_text(encoding="utf-8").replace("<body>", "<body>" + brand.header_html(), 1).replace("</body>", brand.footer_html(target + ".") + "</body>"), encoding="utf-8")
|
| 116 |
summ = {"run_id": run_id, "module": m, "patch_id": state.get("patch_id"), "source": tri.get("source"),
|
| 117 |
"run_mode": tri.get("run_mode"), "target": target, "decision": s["decision"],
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import html as _html
|
| 6 |
+
import logging
|
| 7 |
import json
|
| 8 |
import re
|
| 9 |
from pathlib import Path
|
|
|
|
| 13 |
from ...adapters.pdf import html_to_pdf
|
| 14 |
from ...llm.base import LLMRequest, Sensitivity
|
| 15 |
from ...llm.schemas import ExecSummary
|
| 16 |
+
from ...chat.intent import MODULE_NAMES
|
| 17 |
+
from ...platform import brand, report_pdf
|
| 18 |
from .triage import run_triage
|
| 19 |
|
| 20 |
STUB_BANNER = "STUB RUN: synthetic results from p2p_graph.py stubs. No browser, no mock-app, no Fusion. Not evidence of anything."
|
| 21 |
|
| 22 |
|
| 23 |
+
log = logging.getLogger("fpt.report")
|
| 24 |
+
|
| 25 |
TARGET_WORDS = {"fusion": "Results are from an Oracle Fusion test pod.", "mock": "Results are from the local mock app, not Oracle Fusion."}
|
| 26 |
|
| 27 |
|
|
|
|
| 107 |
body = h.read_text(encoding="utf-8")
|
| 108 |
inner = re.search(r"<body[^>]*>(.*)</body>", body, re.S)
|
| 109 |
bundle = out / "bundle.html"
|
| 110 |
+
try: # the printable report: a summary page a reader can act on, then the QA rule's report as evidence
|
| 111 |
+
bundle.write_text(report_pdf.bundle_html(
|
| 112 |
+
run_id=run_id, module=m, area_name=MODULE_NAMES.get(m, m), decision=s["decision"],
|
| 113 |
+
decision_source=report_rule.DECISION_SOURCE, criteria=criteria[m], counts=counts, gaps=s["gaps"],
|
| 114 |
+
summary_text=summary_text, summary_route=f"{resp.route.value}/{resp.model}", target=target,
|
| 115 |
+
fusion=svc.fusion_pod_id(run_id) is not None, stub=not live, stub_banner=STUB_BANNER,
|
| 116 |
+
patch_id=state.get("patch_id"), test_data=test_data, report_html=body), encoding="utf-8")
|
| 117 |
+
except Exception: # noqa: BLE001 (never lose the report over its layout: fall back to the plain bundle)
|
| 118 |
+
log.exception("report layout failed for %s/%s; writing the plain bundle", run_id, m)
|
| 119 |
+
bundle.write_text(
|
| 120 |
+
"<!doctype html><html><head><meta charset='utf-8'><title>Go/no-go bundle " + _html.escape(m) + "</title></head><body>"
|
| 121 |
+
+ brand.header_html() +
|
| 122 |
+
f"<div style='background:#b00020;color:#fff;padding:8px;font-weight:bold'>{_html.escape(target.upper())}</div>"
|
| 123 |
+
f"<h1>{_html.escape(m)}: {_html.escape(s['decision'])} <small>(decision source: {_html.escape(report_rule.DECISION_SOURCE)})</small></h1>"
|
| 124 |
+
f"<h2>Executive summary</h2><p>{_html.escape(summary_text)}</p><p><i>Summary route: {resp.route.value}/{_html.escape(resp.model)}</i></p>"
|
| 125 |
+
+ _test_data_html(test_data) + "<hr>"
|
| 126 |
+
+ (inner.group(1) if inner else body) + brand.footer_html(target + ".") + "</body></html>", encoding="utf-8")
|
| 127 |
+
pdf = html_to_pdf(bundle, out / "go-no-go.pdf", footer=f"{brand.NAME} · {MODULE_NAMES.get(m, m)} · run {run_id}")
|
| 128 |
h.write_text(h.read_text(encoding="utf-8").replace("<body>", "<body>" + brand.header_html(), 1).replace("</body>", brand.footer_html(target + ".") + "</body>"), encoding="utf-8")
|
| 129 |
summ = {"run_id": run_id, "module": m, "patch_id": state.get("patch_id"), "source": tri.get("source"),
|
| 130 |
"run_mode": tri.get("run_mode"), "target": target, "decision": s["decision"],
|
coworker/platform/report_pdf.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The printable report (bundle.html → go-no-go.pdf): a one-page summary a reader can act on, then the full QA report as
|
| 2 |
+
evidence, typeset for A4.
|
| 3 |
+
|
| 4 |
+
Page one: where the results come from, the verdict in plain words with the exact rule result beside it, the key numbers,
|
| 5 |
+
the six exit criteria with met / not met, the executive summary and the run facts. Then "Full report": the QA rule's own
|
| 6 |
+
HTML (reports/generate_report.py), unchanged in content, restyled. The decision is never rewritten here: the word is a
|
| 7 |
+
label for the rule result (GO → Ready, NO-GO → Not ready, HELD → Held), and the rule result itself is printed.
|
| 8 |
+
|
| 9 |
+
Self-contained HTML (inline CSS, the logo as a data URI): the PDF converter loads a local file with no network.
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import html as _html
|
| 14 |
+
import re
|
| 15 |
+
from datetime import datetime
|
| 16 |
+
|
| 17 |
+
from . import brand
|
| 18 |
+
|
| 19 |
+
VERDICT = {"GO": ("Ready", "go"), "NO-GO": ("Not ready", "nogo"), "HELD": ("Held", "held")}
|
| 20 |
+
# the QA exit criteria (qa/test-strategy.md section 5) by code, in plain words; the full report keeps the rule's own wording
|
| 21 |
+
CRITERIA_NAMES = {"C1": "Coverage: every in-scope scenario has a script that ran", "C2": "Every in-scope P1 scenario passed",
|
| 22 |
+
"C3": "Flaky rate at most 5%, each flaky test has an owner", "C4": "False-fail rate reported",
|
| 23 |
+
"C5": "Counts match the independent audit", "C6": "Source of results and open gaps stated"}
|
| 24 |
+
COUNT_CARDS = (("executed", "Executed"), ("passed", "Passed"), ("failed", "Failed"), ("flaky", "Flaky"),
|
| 25 |
+
("real_defect", "Real defects"), ("deferred", "Deferred"))
|
| 26 |
+
|
| 27 |
+
CSS = """
|
| 28 |
+
@page { size: A4; margin: 18mm 16mm 20mm; }
|
| 29 |
+
* { box-sizing: border-box; }
|
| 30 |
+
html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
| 31 |
+
body { margin: 0; color: #1d1d1f; font: 10pt/1.45 "Inter", "Segoe UI", "Helvetica Neue", "Liberation Sans", Arial, sans-serif; }
|
| 32 |
+
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; color: #1d1d1f; }
|
| 33 |
+
code, .mono { font-family: "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Consolas, monospace; font-size: 0.88em; }
|
| 34 |
+
a { color: inherit; }
|
| 35 |
+
|
| 36 |
+
.top { display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid #ececee; }
|
| 37 |
+
.top img { height: 26px; display: block; }
|
| 38 |
+
.doc { font-size: 8.5pt; color: #636366; text-align: right; line-height: 1.35; }
|
| 39 |
+
.doc b { color: #1d1d1f; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; font-size: 7.5pt; }
|
| 40 |
+
|
| 41 |
+
.env { margin: 12px 0 0; padding: 7px 12px; border-radius: 8px; font-size: 9pt; font-weight: 600; }
|
| 42 |
+
.env.mock { background: #fff3e0; color: #8a4a00; border: 1px solid #f5d6a8; }
|
| 43 |
+
.env.fusion { background: #f2f2f4; color: #1d1d1f; border: 1px solid #dedee2; }
|
| 44 |
+
.stub { margin: 8px 0 0; padding: 7px 12px; border-radius: 8px; background: #fde8e8; color: #8b0010; border: 1px solid #f5c2c2; font-size: 9pt; font-weight: 600; }
|
| 45 |
+
|
| 46 |
+
.title { margin: 18px 0 2px; font-size: 20pt; line-height: 1.15; letter-spacing: -0.02em; }
|
| 47 |
+
.sub { color: #636366; font-size: 10pt; }
|
| 48 |
+
|
| 49 |
+
.verdict { margin: 14px 0 0; display: flex; align-items: stretch; border: 1px solid #ececee; border-radius: 12px; overflow: hidden; }
|
| 50 |
+
.verdict .word { padding: 14px 18px; min-width: 42%; display: flex; flex-direction: column; justify-content: center; }
|
| 51 |
+
.verdict .word small { font-size: 7.5pt; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; opacity: 0.85; }
|
| 52 |
+
.verdict .word strong { font-size: 24pt; line-height: 1.05; letter-spacing: -0.02em; font-weight: 700; }
|
| 53 |
+
.verdict.go .word { background: #e8f6ec; color: #17692d; }
|
| 54 |
+
.verdict.nogo .word { background: #fde8e8; color: #9b0012; }
|
| 55 |
+
.verdict.held .word { background: #fff3e0; color: #8a4a00; }
|
| 56 |
+
.verdict .why { padding: 12px 16px; font-size: 9pt; color: #3a3a3c; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
|
| 57 |
+
.verdict .why .rule { font-weight: 600; color: #1d1d1f; }
|
| 58 |
+
|
| 59 |
+
.stats { margin: 12px 0 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
|
| 60 |
+
.stat { border: 1px solid #ececee; border-radius: 10px; padding: 8px 10px; }
|
| 61 |
+
.stat span { display: block; font-size: 7.5pt; letter-spacing: 0.05em; text-transform: uppercase; color: #636366; font-weight: 600; }
|
| 62 |
+
.stat b { display: block; margin-top: 2px; font-size: 16pt; line-height: 1.1; font-weight: 650; }
|
| 63 |
+
.stat.bad b { color: #9b0012; }
|
| 64 |
+
|
| 65 |
+
h2.sec { margin: 18px 0 6px; font-size: 11pt; text-transform: uppercase; letter-spacing: 0.06em; color: #3a3a3c; }
|
| 66 |
+
.summary { margin: 0; font-size: 10pt; line-height: 1.55; }
|
| 67 |
+
.route { margin: 4px 0 0; color: #636366; font-size: 8pt; }
|
| 68 |
+
|
| 69 |
+
table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
|
| 70 |
+
th { text-align: left; font-weight: 600; color: #3a3a3c; font-size: 7.5pt; letter-spacing: 0.04em; text-transform: uppercase;
|
| 71 |
+
background: #f7f7f8; border-bottom: 1px solid #dedee2; padding: 6px 8px; }
|
| 72 |
+
td { padding: 6px 8px; border-bottom: 1px solid #ececee; vertical-align: top; overflow-wrap: anywhere; }
|
| 73 |
+
tr { break-inside: avoid; }
|
| 74 |
+
thead { display: table-header-group; }
|
| 75 |
+
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 7.5pt; font-weight: 650; letter-spacing: 0.03em; white-space: nowrap; }
|
| 76 |
+
.pill.ok { background: #e8f6ec; color: #17692d; }
|
| 77 |
+
.pill.no { background: #fde8e8; color: #9b0012; }
|
| 78 |
+
.crit td:first-child { width: 34%; font-weight: 600; }
|
| 79 |
+
.crit .code { display: inline-block; min-width: 22px; color: #636366; font-weight: 650; }
|
| 80 |
+
.crit td:nth-child(2) { width: 12%; }
|
| 81 |
+
|
| 82 |
+
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 18px; font-size: 8.5pt; }
|
| 83 |
+
.facts div { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px solid #f2f2f4; }
|
| 84 |
+
.facts dt { color: #636366; min-width: 92px; }
|
| 85 |
+
.facts dd { margin: 0; overflow-wrap: anywhere; }
|
| 86 |
+
.warn { color: #9b0012; font-weight: 600; }
|
| 87 |
+
|
| 88 |
+
.full { margin-top: 22px; }
|
| 89 |
+
.full > .lead { margin: 0 0 10px; padding: 10px 0 8px; border-top: 2px solid #1d1d1f; border-bottom: 1px solid #ececee; break-after: avoid; }
|
| 90 |
+
.full > .lead h2 { font-size: 15pt; }
|
| 91 |
+
.full > .lead p { margin: 2px 0 0; color: #636366; font-size: 9pt; }
|
| 92 |
+
.full h1 { font-size: 14pt; margin: 14px 0 6px; }
|
| 93 |
+
.full h2 { font-size: 11.5pt; margin: 14px 0 5px; padding-top: 4px; }
|
| 94 |
+
.full h3 { font-size: 10pt; margin: 10px 0 4px; }
|
| 95 |
+
.full h2, .full h3 { break-after: avoid; }
|
| 96 |
+
.full p, .full li { font-size: 9pt; }
|
| 97 |
+
.full ul { padding-left: 18px; margin: 4px 0; }
|
| 98 |
+
.full table { margin: 6px 0 10px; }
|
| 99 |
+
.full hr { border: 0; border-top: 1px solid #ececee; margin: 12px 0; }
|
| 100 |
+
|
| 101 |
+
.foot { margin-top: 18px; padding-top: 8px; border-top: 1px solid #ececee; color: #636366; font-size: 8pt; }
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def _e(v) -> str:
|
| 106 |
+
return _html.escape("" if v is None else str(v))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _crit_rows(criteria: dict) -> str:
|
| 110 |
+
rows = []
|
| 111 |
+
for name, c in criteria.items():
|
| 112 |
+
ok, detail = (c.get("ok"), c.get("detail")) if isinstance(c, dict) else c
|
| 113 |
+
pill = "<span class='pill ok'>Met</span>" if ok else "<span class='pill no'>Not met</span>"
|
| 114 |
+
code = str(name).split()[0] if str(name).strip() else str(name)
|
| 115 |
+
label = CRITERIA_NAMES.get(code)
|
| 116 |
+
shown = f"<span class='code'>{_e(code)}</span> {_e(label)}" if label else _e(name)
|
| 117 |
+
rows.append(f"<tr><td>{shown}</td><td>{pill}</td><td>{_e(detail)}</td></tr>")
|
| 118 |
+
return "".join(rows)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _facts(rows: list[tuple[str, str]]) -> str:
|
| 122 |
+
return "<dl class='facts'>" + "".join(f"<div><dt>{_e(k)}</dt><dd>{v}</dd></div>" for k, v in rows if v) + "</dl>"
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _strip_body(report_html: str) -> str:
|
| 126 |
+
"""The QA rule's report body, without its own document wrapper."""
|
| 127 |
+
m = re.search(r"<body[^>]*>(.*)</body>", report_html, re.S)
|
| 128 |
+
inner = m.group(1) if m else report_html
|
| 129 |
+
return inner.replace(brand.header_html(), "", 1) # one header per document: page one carries it
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def bundle_html(*, run_id: str, module: str, area_name: str, decision: str, decision_source: str, criteria: dict,
|
| 133 |
+
counts: dict, gaps: list | None, summary_text: str, summary_route: str, target: str, fusion: bool,
|
| 134 |
+
stub: bool, stub_banner: str, patch_id: str | None, test_data: dict | None, report_html: str,
|
| 135 |
+
generated: datetime | None = None) -> str:
|
| 136 |
+
generated = generated or datetime.now().astimezone()
|
| 137 |
+
word, tone = VERDICT.get(decision, (decision, "held"))
|
| 138 |
+
logo = brand.wordmark_data_uri()
|
| 139 |
+
logo_html = f"<img src='{logo}' alt='{_e(brand.NAME)}'>" if logo else f"<b>{_e(brand.NAME)}</b>"
|
| 140 |
+
failed = int(counts.get("failed", 0) or 0) + int(counts.get("real_defect", 0) or 0)
|
| 141 |
+
|
| 142 |
+
stats = "".join(
|
| 143 |
+
f"<div class='stat{' bad' if k in ('failed', 'real_defect') and int(counts.get(k, 0) or 0) > 0 else ''}'>"
|
| 144 |
+
f"<span>{_e(label)}</span><b>{_e(counts.get(k, 0))}</b></div>"
|
| 145 |
+
for k, label in COUNT_CARDS)
|
| 146 |
+
td = ""
|
| 147 |
+
if test_data:
|
| 148 |
+
left = test_data.get("left") or []
|
| 149 |
+
td_val = (f"{test_data.get('created', 0)} created, {len(test_data.get('cleaned') or [])} cleaned up"
|
| 150 |
+
+ (f"; <span class='warn'>may be left on the pod: {_e(', '.join(left))}</span>" if left else ""))
|
| 151 |
+
td = td_val
|
| 152 |
+
facts = _facts([
|
| 153 |
+
("Business area", _e(area_name)),
|
| 154 |
+
("Patch", _e(patch_id or "latest")),
|
| 155 |
+
("Environment", _e(target)),
|
| 156 |
+
("Test run", f"<span class='mono'>{_e(run_id)}</span>"),
|
| 157 |
+
("Generated", _e(generated.strftime("%d %b %Y, %H:%M %Z").strip())),
|
| 158 |
+
("Decision source", _e(decision_source)),
|
| 159 |
+
("Test data", td),
|
| 160 |
+
("Open gaps", _e(f"{len(gaps)} listed in the full report") if gaps else ""),
|
| 161 |
+
])
|
| 162 |
+
passed_line = ""
|
| 163 |
+
if counts.get("executed"):
|
| 164 |
+
passed_line = f"{counts.get('passed', 0)} of {counts.get('executed', 0)} executed scenarios passed"
|
| 165 |
+
if failed:
|
| 166 |
+
passed_line += f"; {counts.get('failed', 0)} failed"
|
| 167 |
+
|
| 168 |
+
return f"""<!doctype html>
|
| 169 |
+
<html lang="en"><head><meta charset="utf-8"><title>{_e(brand.NAME)} readiness report: {_e(area_name)} ({_e(word)})</title>
|
| 170 |
+
<style>{CSS}</style></head><body>
|
| 171 |
+
<header class="top">{logo_html}<div class="doc"><b>Patch readiness report</b><br>{_e(area_name)} · {_e(patch_id or "latest patch")}</div></header>
|
| 172 |
+
<p class="env {'fusion' if fusion else 'mock'}">{_e(target)}</p>
|
| 173 |
+
{f'<p class="stub">{_e(stub_banner)}</p>' if stub else ''}
|
| 174 |
+
|
| 175 |
+
<h1 class="title">{_e(area_name)} is {_e(word.lower())}</h1>
|
| 176 |
+
<p class="sub">{_e(passed_line) or 'No scenarios were executed.'}</p>
|
| 177 |
+
|
| 178 |
+
<section class="verdict {tone}" aria-label="Decision">
|
| 179 |
+
<div class="word"><small>Readiness</small><strong>{_e(word)}</strong></div>
|
| 180 |
+
<div class="why"><span class="rule">Rule result: {_e(decision)}</span>
|
| 181 |
+
<span>From the QA exit criteria C1 to C6. The person signing off makes the final call in {_e(brand.NAME)}.</span></div>
|
| 182 |
+
</section>
|
| 183 |
+
|
| 184 |
+
<div class="stats">{stats}</div>
|
| 185 |
+
|
| 186 |
+
<h2 class="sec">Run details</h2>
|
| 187 |
+
{facts}
|
| 188 |
+
|
| 189 |
+
<h2 class="sec">Executive summary</h2>
|
| 190 |
+
<p class="summary">{_e(summary_text)}</p>
|
| 191 |
+
<p class="route">Summary written by: {_e(summary_route)}</p>
|
| 192 |
+
|
| 193 |
+
<h2 class="sec">Exit criteria</h2>
|
| 194 |
+
<table class="crit"><thead><tr><th>Criterion</th><th>Result</th><th>Detail</th></tr></thead><tbody>{_crit_rows(criteria)}</tbody></table>
|
| 195 |
+
|
| 196 |
+
<section class="full">
|
| 197 |
+
<div class="lead"><h2>Full report</h2><p>The QA rule's complete report for this test run, kept as evidence.</p></div>
|
| 198 |
+
{_strip_body(report_html)}
|
| 199 |
+
</section>
|
| 200 |
+
|
| 201 |
+
<p class="foot">Generated by {_e(brand.NAME)} v{_e(brand.VERSION)} on {_e(generated.strftime("%d %b %Y"))}. {_e(target)}. {_e(brand.LEGAL)}</p>
|
| 202 |
+
</body></html>"""
|
coworker/tests/test_report_pdf.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The printable report (platform/report_pdf.py): the decision is the QA rule's, printed verbatim; nothing from the rule's own
|
| 2 |
+
report is dropped; text from the run or a model can never become markup."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from coworker.platform import brand, report_pdf
|
| 6 |
+
|
| 7 |
+
CRITERIA = {"C1": {"ok": True, "detail": "32/32 in scope"}, "C2": {"ok": False, "detail": "31 of 32 passed: P2P-APR-001 failed"},
|
| 8 |
+
"C3": {"ok": True, "detail": "0%"}, "C4": {"ok": True, "detail": "0/1"}, "C5": {"ok": True, "detail": "match"},
|
| 9 |
+
"C6": {"ok": True, "detail": "stated"}}
|
| 10 |
+
COUNTS = {"total": 65, "executed": 65, "passed": 64, "failed": 1, "flaky": 0, "skipped": 0, "real_defect": 1, "deferred": 96}
|
| 11 |
+
RULE_HTML = ("<!doctype html><html><body>" + brand.header_html() + "<h1>P2P patch test: go/no-go report</h1>"
|
| 12 |
+
"<p>Decision: NO-GO</p><table><tr><td>P2P-APR-001</td><td>failed</td></tr></table></body></html>")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _render(**over):
|
| 16 |
+
args = dict(run_id="r-1", module="P2P", area_name="Procure-to-Pay", decision="NO-GO",
|
| 17 |
+
decision_source="reports/generate_report.py (QA rule C1-C6)", criteria=CRITERIA, counts=COUNTS, gaps=["gap"],
|
| 18 |
+
summary_text="65 executed, 64 passed.", summary_route="stub/deterministic", target="Mock app, not Oracle Fusion",
|
| 19 |
+
fusion=False, stub=False, stub_banner="STUB", patch_id="26C", test_data=None, report_html=RULE_HTML)
|
| 20 |
+
args.update(over)
|
| 21 |
+
return report_pdf.bundle_html(**args)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_the_rule_result_is_printed_verbatim_with_its_plain_word():
|
| 25 |
+
for decision, word in (("GO", "Ready"), ("NO-GO", "Not ready"), ("HELD", "Held")):
|
| 26 |
+
out = _render(decision=decision)
|
| 27 |
+
assert f"Rule result: {decision}" in out
|
| 28 |
+
assert f"<strong>{word}</strong>" in out
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_an_unknown_rule_result_is_shown_as_is_never_mapped_to_a_verdict():
|
| 32 |
+
out = _render(decision="SOMETHING-NEW")
|
| 33 |
+
assert "Rule result: SOMETHING-NEW" in out and "<strong>SOMETHING-NEW</strong>" in out
|
| 34 |
+
assert "Ready" not in out.split("<section class=\"full\">")[0].replace("readiness report", "")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_every_criterion_is_listed_with_met_or_not_met():
|
| 38 |
+
out = _render()
|
| 39 |
+
for code in CRITERIA:
|
| 40 |
+
assert f"<span class='code'>{code}</span>" in out
|
| 41 |
+
assert out.count("pill ok'>Met<") == 5 and out.count("pill no'>Not met<") == 1
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def test_the_rule_report_is_kept_whole_with_one_header():
|
| 45 |
+
out = _render()
|
| 46 |
+
assert "P2P patch test: go/no-go report" in out and "P2P-APR-001" in out and "Decision: NO-GO" in out
|
| 47 |
+
assert out.count(brand.header_html()) == 0 # page one has its own header; the copied one is removed
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def test_text_from_the_run_or_a_model_is_escaped():
|
| 51 |
+
out = _render(summary_text="<script>alert(1)</script>", area_name="<img src=x onerror=1>",
|
| 52 |
+
criteria={"C1": {"ok": True, "detail": "<b>x</b>"}})
|
| 53 |
+
assert "<script>alert(1)</script>" not in out and "<script>" in out
|
| 54 |
+
assert "<img src=x" not in out and "<b>x</b>" not in out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_environment_stub_and_left_over_test_data_are_impossible_to_miss():
|
| 58 |
+
out = _render(stub=True, stub_banner="STUB RUN: synthetic", fusion=True, target="Oracle Fusion pod: dev2",
|
| 59 |
+
test_data={"created": 3, "cleaned": ["A"], "left": ["INV-9", "INV-10"]})
|
| 60 |
+
assert "class=\"stub\">STUB RUN: synthetic" in out
|
| 61 |
+
assert "class=\"env fusion\">Oracle Fusion pod: dev2" in out
|
| 62 |
+
assert "may be left on the pod: INV-9, INV-10" in out
|
web/e2e/coworker.e2e.ts
CHANGED
|
@@ -103,7 +103,7 @@ test('consultant flow: readiness, start a test run, scenario review, failure rev
|
|
| 103 |
await expect(page.getByTestId('rule-result').first()).toContainText('NO-GO');
|
| 104 |
await expect(page.getByTestId('exec-summary')).toContainText('mock app, not Oracle Fusion');
|
| 105 |
await expect(page.getByRole('table', { name: 'criteria' })).toContainText('C1');
|
| 106 |
-
await expect(page.frameLocator('iframe[title="P2P go/no-go report"]').locator('body')).toContainText(
|
| 107 |
const pdf = page.getByTestId('pdf-link');
|
| 108 |
const resp = await page.request.get((await pdf.getAttribute('href'))!);
|
| 109 |
expect(resp.headers()['content-type']).toBe('application/pdf');
|
|
|
|
| 103 |
await expect(page.getByTestId('rule-result').first()).toContainText('NO-GO');
|
| 104 |
await expect(page.getByTestId('exec-summary')).toContainText('mock app, not Oracle Fusion');
|
| 105 |
await expect(page.getByRole('table', { name: 'criteria' })).toContainText('C1');
|
| 106 |
+
await expect(page.frameLocator('iframe[title="P2P go/no-go report"]').locator('body')).toContainText(/not Oracle Fusion/i); // the report names where results come from
|
| 107 |
const pdf = page.getByTestId('pdf-link');
|
| 108 |
const resp = await page.request.get((await pdf.getAttribute('href'))!);
|
| 109 |
expect(resp.headers()['content-type']).toBe('application/pdf');
|