diff --git a/AGENT-TASKS.md b/AGENT-TASKS.md index 6c14ce5..c736153 100644 --- a/AGENT-TASKS.md +++ b/AGENT-TASKS.md @@ -1,10 +1,13 @@ -# Diagnostic plugin migration +# Renderer parity and shared styling -- [x] Tag the pre-migration integration revision as `v0.1.0-rc.4`. -- [x] Run the existing tests and build a 17-PDF baseline. -- [x] Move diagnostic analysis, rules, schema, and tests into `reports/plugins/diagnostics`. -- [x] Define a reusable Reportist plugin contract and route diagnostic inputs through it. -- [x] Consolidate diagnostic rendering on the Reportist report engine, retaining the useful theme choices and a similar PDF layout. -- [x] Update root commands, publication, validation, CI, bootstrap, and documentation. -- [x] Remove the diagnostic analysis submodule and all runtime references to it. -- [x] Run component and integration tests, compare generated diagnostic PDFs with the baseline, and commit the migration. +- [x] Generate the 17 reference PDFs with the legacy Typst project and record a reproducible comparison method. +- [x] Extract shared visual elements into a Typst module used by both report and diagnostic renderers. +- [x] Make reports and diagnostics independent renderers with their own document logic and simple launch commands. +- [x] Match every regular report to its legacy PDF, including text, pagination, and rendered pages. +- [x] Match every diagnostic to its legacy PDF, including text, pagination, and rendered pages. +- [x] Update commands, documentation, and validation checks; remove the report-shaped diagnostic plugin path from active commands. +- [x] Run all component and publication checks, then commit the migration. + +The retired Reportist IR adapter, report schema, old tests, fixtures, and +duplicate themes were removed after explicit user approval. The diagnostic +evidence schema and analyzer remain active. diff --git a/Jenkinsfile b/Jenkinsfile index c28b79d..3946bf4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,8 +43,8 @@ pipeline { steps { sh ''' set -eu - rm -rf "${CI_REPORT_DIR}" "${CI_ARTIFACT_DIR}" - ./beffroi.sh all "${CI_REPORT_DIR}" + rm -rf "${CI_ARTIFACT_DIR}" + ./beffroi.sh all "${CI_REPORT_DIR}" --replace ''' } } diff --git a/README.md b/README.md index abcdbfc..e5b8d9b 100644 --- a/README.md +++ b/README.md @@ -1,87 +1,64 @@ # Beffroi Reporting -Beffroi Reporting turns structured reports and Windows diagnostic captures into -PDFs. The root `beffroi.sh` command is the main entry point. +Beffroi Reporting builds PDF reports from authored YAML/JSON and raw +WinDiagnostics captures. The report and diagnostic plugins own their document +structure separately. Both import the visual elements and palettes in +[`reporter/visual`](reporter/visual). -## Generate one personal report - -Write a Reportist YAML or JSON file, then run: +## Render one report ```bash -./beffroi.sh report my-report.yaml my-report.pdf +./beffroi.sh report reports/reports/2026-09-04-clevo-handoff.yaml report.pdf ``` -See [`reporter/examples`](reporter/examples) for complete inputs. -To select a built-in palette in YAML, set `branding.theme` to `default` or -`teal`; an explicit theme object is also supported. +Authored reports use `organization`, `theme`, `metadata`, `summary`, `sections`, +`findings`, `actions`, and any report-specific fields. Available named palettes +are `default`, `cic`, and `eridani`; a custom theme dictionary is also accepted. +The report plugin is in [`reporter/plugins/report`](reporter/plugins/report). -## Generate one diagnostic report - -Render a normalized diagnostic JSON v1 through the shared Reportist engine: +## Render one diagnostic ```bash -./beffroi.sh diagnostic-pdf diagnostic.json diagnostic.pdf +./beffroi.sh diagnostic-pdf reports/diagnostics/windows_system_report_DESKTOP-SAU019H_20260915_121057.json diagnostic.pdf ``` -Set `DIAGNOSTICS_THEME=default`, `cic`, or `eridani` to choose a bundled palette. -Reportist can also emit its JSON intermediate directly: +`diagnostic-pdf` and `capture-pdf` accept **raw WinDiagnostics JSON v1 or v2**. +Set `DIAGNOSTICS_THEME=default`, `cic`, or `eridani`, and optionally +`DIAGNOSTICS_AUTHOR`, before rendering. The diagnostic plugin is in +[`reports/plugins/diagnostics`](reports/plugins/diagnostics). Its PDF renderer +uses the raw capture directly; its separate analyzer can also emit normalized +diagnostic JSON v1 for evidence processing: ```bash -./beffroi.sh report diagnostic.json diagnostic.pdf \ - --plugin reports/plugins/diagnostics --plugin-input theme=cic \ - --emit-ir diagnostic.report.json +./beffroi.sh diagnostic CAPTURE.json EVIDENCE_ROOT NEW_OUTPUT_DIR REFERENCE_TIME [AUTHOR] [THEME] ``` -For a raw WinDiagnostics capture, run `./beffroi.sh capture-pdf capture.json -diagnostic.pdf`. This analyzes the capture first, then renders the diagnostic. -For a persistent evidence-backed draft generation, run: +That command writes `diagnostic.json` and `report.pdf`. -```bash -./beffroi.sh diagnostic \ - capture.json /path/to/evidence /path/to/new-output \ - 2026-09-15T12:00:00Z 'Diagnostic review' 'Reviewer Name' 2026-09-15 -``` - -The generation includes normalized diagnostic JSON, a Reportist JSON draft, -evidence snapshots, a hash manifest, and a PDF. Custom reports can use the same -tables, progress bars, finding lists, and section page breaks; see -[`reporter/examples/diagnostic-style.yaml`](reporter/examples/diagnostic-style.yaml). - -## Generate every stored PDF - -Add report YAML files under -[`reports/reports`](reports/reports) -or diagnostic JSON captures under -[`reports/diagnostics`](reports/diagnostics), -commit them with the reports submodule update, and run: +## Build the publication ```bash ./beffroi.sh all build/publication +./beffroi.sh all build/publication --replace --include-json ``` -Stored report YAML is validated and rendered directly. Use `--include-json` to -export structured report JSON beside report PDFs and -the original diagnostic JSON beside diagnostic PDFs. Packaging includes these -JSON files, which is useful for downstream automation: +The build creates seven authored report PDFs and ten diagnostic PDFs from the +stored sources. `--include-json` exports authored report JSON and copies raw +diagnostic JSON alongside the PDFs. `--replace` stages a complete build before +replacing an existing output directory. -```bash -./beffroi.sh all build/publication --include-json - -Use `--replace` to rebuild an existing publication directory at the same path. -The previous build stays in place until the new PDFs are ready. -``` - -Jenkins runs the same build and publishes AES-encrypted `Reports.zip` and -`Diagnostics.zip` archives from `main` into the dedicated `work_reports` -destination. +Run `./beffroi.sh test` to test the plugins and compare every published PDF with +the original Typst renderer. When `legacy/typst_reporter/build` is present, the +comparison checks extracted text, page counts, and rasterized pages. Without +that local reference, it checks recorded original text hashes and page counts. ## Commands ```text -./beffroi.sh report INPUT OUTPUT.pdf [Reportist options] -./beffroi.sh diagnostic-pdf DIAGNOSTIC.json OUTPUT.pdf -./beffroi.sh capture-pdf CAPTURE OUTPUT.pdf -./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME TITLE AUTHOR DATE +./beffroi.sh report INPUT.yaml|json OUTPUT.pdf [--force] +./beffroi.sh diagnostic-pdf CAPTURE.json OUTPUT.pdf +./beffroi.sh capture-pdf CAPTURE.json OUTPUT.pdf +./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME [AUTHOR] [THEME] ./beffroi.sh all OUTPUT_DIR [--include-json] [--replace] ./beffroi.sh package BUILD_DIR ARTIFACT_DIR ./beffroi.sh test @@ -89,6 +66,4 @@ destination. ./beffroi.sh doctor ``` -The command reports missing tools for the requested operation. See -[`docs/development.md`](docs/development.md) for repository structure, testing, -publication details, and component development. +See [`docs/development.md`](docs/development.md) for implementation details. diff --git a/beffroi.sh b/beffroi.sh index e4b2a34..edc5760 100755 --- a/beffroi.sh +++ b/beffroi.sh @@ -5,10 +5,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")" usage() { cat <<'EOF' Usage: - ./beffroi.sh report INPUT OUTPUT.pdf [Reportist options] - ./beffroi.sh diagnostic-pdf DIAGNOSTIC.json OUTPUT.pdf + ./beffroi.sh report INPUT.yaml|json OUTPUT.pdf [--force] + ./beffroi.sh diagnostic-pdf CAPTURE.json OUTPUT.pdf ./beffroi.sh capture-pdf CAPTURE OUTPUT.pdf - ./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME TITLE AUTHOR DATE + ./beffroi.sh diagnostic CAPTURE EVIDENCE_ROOT OUTPUT_DIR REFERENCE_TIME [AUTHOR] [THEME] ./beffroi.sh all OUTPUT_DIR [--include-json] [--replace] ./beffroi.sh package BUILD_DIR ARTIFACT_DIR ./beffroi.sh test @@ -33,17 +33,14 @@ case "$command_name" in ;; diagnostic-pdf) [[ $# -eq 2 ]]||usage 2; require typst - reports/plugins/diagnostics/tools/validate.sh "$1" >/dev/null - reporter/render.sh "$1" --plugin reports/plugins/diagnostics \ - --plugin-input "author=${DIAGNOSTICS_AUTHOR:-Beffroi}" \ - --plugin-input "theme=${DIAGNOSTICS_THEME:-default}" --output "$2" + reports/plugins/diagnostics/render.sh "$1" --output "$2" ;; capture-pdf) [[ $# -eq 2 ]]||usage 2; require git typst scripts/render-capture.sh "$1" "$2" ;; diagnostic) - [[ $# -eq 7 ]]||usage 2; require git typst + [[ $# -ge 4 && $# -le 6 ]]||usage 2; require git typst scripts/workflow.sh all "$@" ;; all) @@ -55,7 +52,7 @@ case "$command_name" in scripts/package-reports.sh "$1" "$2" ;; test) - [[ $# -eq 0 ]]||usage 2; require git typst uv + [[ $# -eq 0 ]]||usage 2; require git typst scripts/check-components.sh ;; bootstrap) diff --git a/docs/development.md b/docs/development.md index ff42d90..f2624a3 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,60 +1,23 @@ -# Development +# Development and parity -This document covers contributor setup and verification for the Beffroi -Reporting integration workspace. User installation and report generation remain -in the main [README](../README.md). +`beffroi.sh` routes authored reports to `reporter/render.sh` and raw +WinDiagnostics captures to `reports/plugins/diagnostics/render.sh`. Each stages +its own Typst document model. The shared `reporter/visual/elements.typ` module +contains palette, badge, heading, panel, callout, code-block, and progress-bar +primitives. Report and diagnostic document assembly remain independent. -## Test dependencies +The original renderer is retained locally under `legacy/typst_reporter`. Run its +`render.sh --all` and `render-diagnostics.sh --all Beffroi` scripts to refresh +the reference PDFs. `./beffroi.sh test` builds the stored publication and runs +`scripts/check-legacy-parity.py` against all 17 PDFs. With the local reference +available, the check compares every page raster as well as extracted text and +pagination. Recorded original text hashes and page counts also guard CI builds +without the ignored legacy directory. -Tests require the runtime dependencies plus uv. Python is used only by the test -suites and always runs in virtual environments created by `uv venv` and -synchronized by `uv pip`. +The diagnostic analyzer at `reports/plugins/diagnostics/analyse.sh` produces a +normalized evidence artifact. It is separate from the PDF renderer. The +`diagnostic` workflow creates that artifact and a PDF from the same raw capture. -Reportist can use Poppler's `pdfinfo` and `pdftotext` for additional pagination -and extracted-text checks. Those checks are skipped when Poppler is unavailable. - -## Run the complete verification - -```bash -scripts/check-components.sh -``` - -This invokes the component suites and a sanitized capture-to-PDF integration -test. Coverage includes: - -- diagnostic contracts, evidence integrity, fixtures, and the rule catalog; -- draft generation, regeneration, branding, and unique destination handling; -- Reportist contract validation, rendering, assets, pagination, and standalone use; -- capture analysis, report adaptation, validation, and PDF rendering as one workflow. - -The same entry point is used by Jenkins through -`scripts/check-components.sh`. - -## Component changes - -Commit changes in the owning component repository first. Then commit its updated -submodule pin in this integration repository. Historical integration commits -must continue to identify exact compatible component revisions. - -Before committing an integration change, run: - -```bash -./bootstrap.sh --check -scripts/check-components.sh -git diff --check -git submodule status -``` - -Push component commits and the integration commit together with: - -```bash -git push --recurse-submodules=on-demand -``` - -## Repository boundaries - -Keep orchestration in this repository. Diagnostic analysis and rules belong in the Reports diagnostic plugin, -investigation content belongs in Beffroi Reports, and common rendering -logic belongs in Reportist. Additional plugins implement the same preparation -contract described in `reporter/README.md`. Do not introduce dependencies from a component back -to this workspace. +`./beffroi.sh all OUTPUT_DIR --replace` stages a new publication next to the +output directory and replaces it only after all PDFs are ready. `--include-json` +adds JSON source exports. diff --git a/reporter b/reporter index 127a74a..553b899 160000 --- a/reporter +++ b/reporter @@ -1 +1 @@ -Subproject commit 127a74ab29afacaa90c3683fea8f556f8207d92a +Subproject commit 553b899a61b88107f136a1dccd5d109ebe2ece30 diff --git a/reports b/reports index 1657828..1d0b1e1 160000 --- a/reports +++ b/reports @@ -1 +1 @@ -Subproject commit 16578288b267792bbdd2ca8bcb9dc38d15cbf954 +Subproject commit 1d0b1e12401ae944e7341438a5d0509a0aa1697e diff --git a/scripts/build-publication.sh b/scripts/build-publication.sh index c6c4ae3..c733bac 100755 --- a/scripts/build-publication.sh +++ b/scripts/build-publication.sh @@ -39,7 +39,6 @@ cleanup() { trap cleanup EXIT mkdir -p "$stage/reports" "$stage/diagnostics" -reporter/tools/validate-all.sh reports/reports reporter/tools/render-all.sh reports/reports --output-dir "$stage/reports/pdfs" count=0 while IFS= read -r -d '' source; do diff --git a/scripts/check-components.sh b/scripts/check-components.sh index ad07c68..de52622 100755 --- a/scripts/check-components.sh +++ b/scripts/check-components.sh @@ -1,75 +1,23 @@ #!/usr/bin/env bash -# Run the checks owned by the pinned components in separate environments. +# Check the independent Typst plugins and their source-faithful publication. set -euo pipefail - cd "$(dirname "${BASH_SOURCE[0]}")/.." -command -v uv >/dev/null 2>&1 || { - echo 'uv is required to prepare isolated component test environments.' >&2 - exit 1 -} - -for component in reports; do - if [[ ! -f "$component/tests/requirements.txt" || ! -x "$component/tests/test.sh" ]]; then - echo "Missing $component checks. Run: git submodule update --init --recursive" >&2 - exit 1 - fi +for command in git typst python3 pdfinfo pdftotext pdftoppm; do + command -v "$command" >/dev/null 2>&1 || { echo "Missing test dependency: $command" >&2; exit 1; } done -if [[ ! -f reporter/tests/requirements.txt || ! -x reporter/render.sh || ! -x reporter/tests/test.sh ]]; then - echo "Missing reporter entrypoint or checks. Run: git submodule update --init --recursive" >&2 - exit 1 -fi - -command -v typst >/dev/null 2>&1 || { - echo 'Typst is required for Reportist rendering checks.' >&2 - exit 1 -} -typst --version - -uv --version -for component in reports/plugins/diagnostics; do - echo "Checking $component ($(git -C reports rev-parse HEAD))" - "$component/tests/test.sh" +for component in reporter reports/plugins/diagnostics reports; do + "$component/tests/test.sh" done - -echo "Checking reporter ($(git -C reporter rev-parse HEAD))" -reporter/tests/test.sh - -echo "Checking reports ($(git -C reports rev-parse HEAD))" -DIAGNOSTIC_VALIDATOR="$(pwd)/reports/plugins/diagnostics/tools/validate.sh" \ -REPORT_VALIDATOR="$(pwd)/reporter/tools/validate.sh" \ -BRANDING="$(pwd)/reports/plugins/diagnostics/runtime/themes/default.json" \ -BRANDING_ROOT="$(pwd)/reports" \ -BRANDING_DIRECTORY="$(pwd)/reports/plugins/diagnostics/runtime/themes" \ - reports/tests/test.sh - -echo 'Checking stored Reportist YAML' -reporter/tools/validate-all.sh reports/reports -python3 scripts/check-regular-parity.py -python3 scripts/check-diagnostic-parity.py - -pipeline_check_parent="$(mktemp -d "${TMPDIR:-/tmp}/beffroi-pipeline-check.XXXXXX")" -trap 'rm -rf -- "$pipeline_check_parent"' EXIT -pipeline_check_root="$pipeline_check_parent/run" -bash scripts/workflow.sh all \ - reports/plugins/diagnostics/tests/fixtures/legacy/windiagnostics-v1.json \ - reports/plugins/diagnostics/tests/fixtures/legacy \ - "$pipeline_check_root" \ - 2026-09-15T12:00:00Z \ - 'Synthetic diagnostic draft' 'CI Test' 2026-09-15 -cp scripts/check-diagnostic.typ "$pipeline_check_root/check-diagnostic.typ" -typst eval --root "$pipeline_check_root" --input diagnostic=diagnostic.json \ - --in "$pipeline_check_root/check-diagnostic.typ" \ - 'query().first().value' >/dev/null -test "$(head -c 5 "$pipeline_check_root/report.pdf")" = '%PDF-' - -reporter/render.sh "$pipeline_check_root/diagnostic.json" \ - --plugin reports/plugins/diagnostics --plugin-input theme=eridani \ - --plugin-input 'author=CI Test' --output "$pipeline_check_parent/plugin.pdf" \ - --emit-ir "$pipeline_check_parent/plugin.ir.json" -reporter/tools/validate.sh "$pipeline_check_parent/plugin.ir.json" -reporter/render.sh "$pipeline_check_parent/plugin.ir.json" \ - --output "$pipeline_check_parent/replayed.pdf" -test "$(head -c 5 "$pipeline_check_parent/replayed.pdf")" = '%PDF-' -test "$(head -c 5 "$pipeline_check_parent/plugin.pdf")" = '%PDF-' - -echo 'Component suites and the raw-capture-to-PDF integration pipeline passed.' +work=$(mktemp -d "${TMPDIR:-/tmp}/beffroi-check.XXXXXXXX") +trap 'rm -rf -- "$work"' EXIT +scripts/workflow.sh all \ + reports/plugins/diagnostics/tests/fixtures/legacy/windiagnostics-v1.json \ + reports/plugins/diagnostics/tests/fixtures/legacy \ + "$work/workflow" 2026-09-15T12:00:00Z +cp scripts/check-diagnostic.typ "$work/workflow/check-diagnostic.typ" +typst eval --root "$work/workflow" --input diagnostic=diagnostic.json \ + --in "$work/workflow/check-diagnostic.typ" 'query().first().value' >/dev/null +[[ $(head -c 5 "$work/workflow/report.pdf") == '%PDF-' ]] +scripts/build-publication.sh "$work/publication" +python3 scripts/check-legacy-parity.py "$work/publication" +echo 'Component checks and all 17 legacy PDF parity checks passed.' diff --git a/scripts/check-diagnostic-parity.py b/scripts/check-diagnostic-parity.py index c965216..a832b76 100644 --- a/scripts/check-diagnostic-parity.py +++ b/scripts/check-diagnostic-parity.py @@ -1,73 +1,12 @@ #!/usr/bin/env python3 -"""Guard reviewed finding counts from the pre-plugin diagnostic renderer.""" - -import json +"""Compatibility entry point for the complete original-PDF parity check.""" from pathlib import Path import subprocess -import sys import tempfile - -ROOT = Path(__file__).resolve().parents[1] -CAPTURES = ROOT / "reports/diagnostics" -COUNTS = { - "hardware-17-tA6kwqAg-windows-system-report-desktop-2osf051-20260904-134702": (2, 10, 0), - "hardware-18-WHA8oUN2-windows-system-report-pcvid008-20260904-134729": (1, 9, 1), - "hardware-19-BOOso6wz-windows-system-report-desktop-dh4hot6-20260904-173202": (2, 11, 0), - "hardware-20-dlBVl76W-windows-system-report-desktop-pr71lgi-20260904-162618": (2, 7, 0), - "hardware-35-NSmkLXTb-windows-system-report-blin2-20260904-161637": (2, 6, 0), - "hardware-51-6M9gNOPR-windows-system-report-desktop-sau019h-20260904-164514": (3, 10, 0), - "hardware-53-AbCX84Q8-windows-system-report-desktop-3pptg49-20260904-135829": (1, 7, 0), - "windows_system_report_DESKTOP-SAU019H_20260914_163753": (2, 5, 0), - "windows_system_report_DESKTOP-SAU019H_20260915_113124": (0, 7, 0), - "windows_system_report_DESKTOP-SAU019H_20260915_121057": (1, 16, 0), -} - - -def main(): - captures = {path.stem: path for path in CAPTURES.glob("*.json")} - if set(captures) != set(COUNTS): - print("Stored diagnostic set changed; review the parity baseline", file=sys.stderr) - return 1 - with tempfile.TemporaryDirectory(prefix="beffroi-diagnostic-parity.") as directory: - latest_diagnostic = None - for name, expected in COUNTS.items(): - capture = captures[name] - collected = json.loads(capture.read_text(encoding="utf-8"))["generated_at"] - output = Path(directory) / f"{name}.json" - subprocess.run([str(ROOT / "reports/plugins/diagnostics/analyse.sh"), str(capture), - "--evidence-root", str(CAPTURES), "--output", str(output), - "--reference-time", collected, "--producer-version", "parity-check"], - check=True, stdout=subprocess.DEVNULL) - findings = json.loads(output.read_text(encoding="utf-8"))["findings"] - actual = tuple(sum(item["severity"] == severity for item in findings) - for severity in ("critical", "warning", "unanalysed")) - if actual != expected: - print(f"{name}: expected {expected}, got {actual}", file=sys.stderr) - return 1 - if name == "windows_system_report_DESKTOP-SAU019H_20260915_121057": - latest_diagnostic = output - ir = Path(directory) / "latest.report.json" - subprocess.run([str(ROOT / "reporter/render.sh"), str(latest_diagnostic), - "--plugin", str(ROOT / "reports/plugins/diagnostics"), - "--output", str(Path(directory) / "latest.pdf"), "--emit-ir", str(ir)], - check=True, stdout=subprocess.DEVNULL) - report = json.loads(ir.read_text(encoding="utf-8")) - assessment = report["sections"][0]["content"][0] - if assessment["title"] != "Diagnostic assessment" or "leading finding" not in assessment["text"]: - print("Latest capture: diagnostic assessment is missing", file=sys.stderr) - return 1 - if not report["sections"][0]["content"][3]["content"][0]["items"][0]["title"].startswith( - "Microsoft-Windows-WER-SystemErrorReporting ยท Event 1001"): - print("Latest capture: reliability event identity was lost", file=sys.stderr) - return 1 - score = report["sections"][0]["content"][1]["value"] - if score != 62: - print(f"Latest capture: expected pre-plugin signal score 62, got {score}", file=sys.stderr) - return 1 - print(f"All {len(COUNTS)} diagnostics retain pre-plugin critical/warning/unanalysed counts") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) +root = Path(__file__).resolve().parents[1] +with tempfile.TemporaryDirectory(prefix="beffroi-parity.") as directory: + output = Path(directory) / "publication" + subprocess.run([str(root / "scripts/build-publication.sh"), str(output)], check=True, + stdout=subprocess.DEVNULL) + subprocess.run(["python3", str(root / "scripts/check-legacy-parity.py"), str(output)], check=True) diff --git a/scripts/check-legacy-parity.py b/scripts/check-legacy-parity.py new file mode 100644 index 0000000..0168d66 --- /dev/null +++ b/scripts/check-legacy-parity.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Compare a publication with the original Typst renderer's 17 PDFs.""" + +import hashlib +from pathlib import Path +import subprocess +import sys +import tempfile + +ROOT = Path(__file__).resolve().parents[1] +REFERENCE = ROOT / "legacy/typst_reporter/build" +EXPECTED = { + "reports": { + "2026-09-04-clevo-handoff": (3, "a75ef856603ee60c232ee2297c1c6c7a804a5cbd70a39df6c3e17a2766da3db4"), + "2026-09-04-clevo-initial": (4, "e3f85a7ddaacd66b59c0e145b0986fbcca0e507670b03ef9f99dbe45aded6c83"), + "2026-09-04-report": (2, "077c992c3b224c93433d15a8acf2b1c170b78579a6803eca4bf29d3901bcc3d0"), + "2026-09-14-system-stability-diagnostic-notes": (9, "4d0c08493a152989b74c7632690f1c3483814f6232bc49e12afd4ccc50a55689"), + "2026-09-15-clevo-diagnostic-synthesis": (3, "48003a50448105c225c946dd89740b208d59fc2b8cc58b1b5c379d1b00173c96"), + "2026-09-15-clevo-manufacturer-report": (4, "d5747b6f8ad98f17327cda38c22127dfb045adafa4b31cc68760e767fd643c46"), + "2026-09-15-clevo-system-stability-diagnostic-notes": (9, "649c034fc99af8e0e42a9b81e52508313936bc09683283c5bcec0287a6f9b3af"), + }, + "diagnostics": { + "hardware-17-tA6kwqAg-windows-system-report-desktop-2osf051-20260904-134702": (8, "2cd2b1c73554ac8a58831f68f97bd7e83c66f05c9e0af5a1c6ee893169b8deab"), + "hardware-18-WHA8oUN2-windows-system-report-pcvid008-20260904-134729": (8, "7d74b28a2a7f615ff301691ea75dcb3cee3c4457ee6bf3210ef91c174b500a89"), + "hardware-19-BOOso6wz-windows-system-report-desktop-dh4hot6-20260904-173202": (8, "b5020fb8102114a26991d93cf2b19e413b08b078ca4f3a5a26be36b4dd18d7d6"), + "hardware-20-dlBVl76W-windows-system-report-desktop-pr71lgi-20260904-162618": (8, "4bd0c60bc165a0b062e5684a3032d871201e79d52d38eab8d7ad917e5f7bb60a"), + "hardware-35-NSmkLXTb-windows-system-report-blin2-20260904-161637": (8, "f128fed238a09496379a9802eeb3bcb1608aa239084218034ecbfe32b234531a"), + "hardware-51-6M9gNOPR-windows-system-report-desktop-sau019h-20260904-164514": (8, "def902addf516a26e6db086b3a89092329ab97f380434074954201bd6da00393"), + "hardware-53-AbCX84Q8-windows-system-report-desktop-3pptg49-20260904-135829": (8, "a0f4eb6d422511aa196886693dd5bc7a34cfa4a84ffef420ffc8dcbb0cee43ce"), + "windows_system_report_DESKTOP-SAU019H_20260914_163753": (8, "ddfec97f68fe5e8498be384a7b1a6291c9804735e9b52b1c99e6116592f99aff"), + "windows_system_report_DESKTOP-SAU019H_20260915_113124": (8, "c3bbaf37cefc8683d1cbb20797decf793ba98d7b0d70df8651f81b4182cb5169"), + "windows_system_report_DESKTOP-SAU019H_20260915_121057": (12, "38f8eca734f8891a5fae608c6ca27090fad1b5a50be3490402b43b4955b541e3"), + }, +} + + +def pages(pdf): + info = subprocess.check_output(["pdfinfo", str(pdf)], text=True) + return int(next(line.split(":", 1)[1] for line in info.splitlines() if line.startswith("Pages:"))) + + +def text_hash(pdf): + return hashlib.sha256(subprocess.check_output(["pdftotext", "-layout", str(pdf), "-"])).hexdigest() + + +def raster_equal(reference, current): + with tempfile.TemporaryDirectory(prefix="beffroi-raster-parity.") as directory: + subprocess.run(["pdftoppm", "-scale-to", "900", str(reference), f"{directory}/old"], check=True, stdout=subprocess.DEVNULL) + subprocess.run(["pdftoppm", "-scale-to", "900", str(current), f"{directory}/new"], check=True, stdout=subprocess.DEVNULL) + old = sorted(Path(directory).glob("old-*.ppm")) + new = sorted(Path(directory).glob("new-*.ppm")) + return len(old) == len(new) and all(a.read_bytes() == b.read_bytes() for a, b in zip(old, new)) + + +def main(): + if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} BUILD_ROOT", file=sys.stderr) + return 2 + build = Path(sys.argv[1]) + check_raster = REFERENCE.is_dir() + for category, documents in EXPECTED.items(): + folder = build / category / "pdfs" if category == "reports" else build / category + actual = {path.stem: path for path in folder.glob("*.pdf")} + if set(actual) != set(documents): + print(f"{category}: PDF set differs from the original", file=sys.stderr) + return 1 + for name, (wanted_pages, wanted_text) in documents.items(): + pdf = actual[name] + if (pages(pdf), text_hash(pdf)) != (wanted_pages, wanted_text): + print(f"{category}/{name}: page count or text differs", file=sys.stderr) + return 1 + if check_raster: + reference = REFERENCE / ("diagnostics" if category == "diagnostics" else "") / f"{name}.pdf" + if not raster_equal(reference, pdf): + print(f"{category}/{name}: rendered pages differ", file=sys.stderr) + return 1 + print("All 17 PDFs match original text and pagination" + (" and rendered pages" if check_raster else "")) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/check-regular-parity.py b/scripts/check-regular-parity.py index e880f17..a832b76 100644 --- a/scripts/check-regular-parity.py +++ b/scripts/check-regular-parity.py @@ -1,47 +1,12 @@ #!/usr/bin/env python3 -"""Guard the seven authored PDFs against the pre-plugin release's extracted text.""" - -import hashlib +"""Compatibility entry point for the complete original-PDF parity check.""" from pathlib import Path -import shutil import subprocess -import sys import tempfile - -ROOT = Path(__file__).resolve().parents[1] -TEXT_SHA256 = { - "2026-09-04-clevo-handoff": "6bb91e92caf442eaabacca61fbafca6b967bd4692877eee9efa5d3ff54686e5c", - "2026-09-04-clevo-initial": "2a05b6f93f8e5a5e0adf48fa2d83d3072fc404755654e8feb27eb5c592ec2ddf", - "2026-09-04-report": "e7dbaf7fa722fa18e333387f463622f7e082bd9a39dd785d5700965456a743ab", - "2026-09-14-system-stability-diagnostic-notes": "0fbe2dc9bd6044663c0bc026dc132eb69a7f8e4f8c4a9640914da9860aa9c11e", - "2026-09-15-clevo-diagnostic-synthesis": "c729ceca5c6e7481f16593af1113c94d03cee33d51af2556bd4c74a26155215a", - "2026-09-15-clevo-manufacturer-report": "01c522b83a14524bee1646c3f55c45bc0c96eec28696416054224958027d4d3d", - "2026-09-15-clevo-system-stability-diagnostic-notes": "32c88e56144aa15392e929a5d07a7f737e6397e37e65dae43d648429f8da1a7f", -} - - -def main(): - if not shutil.which("pdftotext"): - print("pdftotext is required for regular report parity checks", file=sys.stderr) - return 2 - inputs = {path.stem: path for path in (ROOT / "reports/reports").glob("*.yaml")} - if set(inputs) != set(TEXT_SHA256): - print("Authored report set changed; update the parity baseline deliberately", file=sys.stderr) - return 1 - with tempfile.TemporaryDirectory(prefix="beffroi-regular-parity.") as directory: - for name, expected in TEXT_SHA256.items(): - pdf = Path(directory) / f"{name}.pdf" - subprocess.run([str(ROOT / "reporter/render.sh"), str(inputs[name]), "--output", str(pdf)], - check=True, stdout=subprocess.DEVNULL) - extracted = subprocess.check_output(["pdftotext", "-layout", str(pdf), "-"]) - actual = hashlib.sha256(extracted).hexdigest() - if actual != expected: - print(f"{name}: extracted text differs from pre-plugin PDF", file=sys.stderr) - return 1 - print(f"All {len(TEXT_SHA256)} authored reports retain pre-plugin extracted text") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) +root = Path(__file__).resolve().parents[1] +with tempfile.TemporaryDirectory(prefix="beffroi-parity.") as directory: + output = Path(directory) / "publication" + subprocess.run([str(root / "scripts/build-publication.sh"), str(output)], check=True, + stdout=subprocess.DEVNULL) + subprocess.run(["python3", str(root / "scripts/check-legacy-parity.py"), str(output)], check=True) diff --git a/scripts/render-capture.sh b/scripts/render-capture.sh index ac346d2..825cd7f 100755 --- a/scripts/render-capture.sh +++ b/scripts/render-capture.sh @@ -1,19 +1,6 @@ #!/usr/bin/env bash -# Analyze a raw WinDiagnostics capture, then render its diagnostic JSON via Reportist. +# Render the raw WinDiagnostics capture with the diagnostic Typst plugin. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." [[ $# -eq 2 ]] || { echo "Usage: $0 CAPTURE OUTPUT.pdf" >&2; exit 2; } -capture=$(realpath "$1"); output=$2 -[[ -f "$capture" ]] || { echo "Missing capture: $capture" >&2; exit 1; } -stage=$(mktemp -d "${TMPDIR:-/tmp}/beffroi-capture.XXXXXXXX") -trap 'rm -rf "$stage"' EXIT -cp -- "$capture" "$stage/capture.json" -cp -- reports/plugins/diagnostics/tools/capture-info.typ "$stage/capture-info.typ" -collected=$(typst eval --root "$stage" --input capture=capture.json --in "$stage/capture-info.typ" 'query().first().value') -collected=${collected#\"}; collected=${collected%\"} -reports/plugins/diagnostics/analyse.sh "$capture" --evidence-root "$(dirname "$capture")" \ - --output "$stage/diagnostic.json" --reference-time "$collected" \ - --producer-version "$(git -C reports rev-parse HEAD)" >/dev/null -reporter/render.sh "$stage/diagnostic.json" --plugin reports/plugins/diagnostics \ - --plugin-input "author=${DIAGNOSTICS_AUTHOR:-Beffroi}" \ - --plugin-input "theme=${DIAGNOSTICS_THEME:-default}" --output "$output" +reports/plugins/diagnostics/render.sh "$1" --output "$2" diff --git a/scripts/workflow-all.sh b/scripts/workflow-all.sh index 63b2b3c..b94d68b 100755 --- a/scripts/workflow-all.sh +++ b/scripts/workflow-all.sh @@ -1,25 +1,24 @@ #!/usr/bin/env bash +# Build normalized diagnostic artifacts and source-faithful PDFs in bulk. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." -if [[ $# -ne 7 ]]; then - echo "Usage: $0 CAPTURE_DIR EVIDENCE_ROOT OUTPUT_ROOT REFERENCE_TIME TITLE AUTHOR DATE" >&2 +[[ $# -ge 4 && $# -le 6 ]] || { + echo "Usage: $0 CAPTURE_DIR EVIDENCE_ROOT NEW_OUTPUT_ROOT REFERENCE_TIME [AUTHOR] [THEME]" >&2 exit 2 -fi -capture_dir=$1; evidence_root=$2; output_root=$3; reference_time=$4; title=$5; author=$6; report_date=$7 -[[ ! -e "$output_root" ]]||{ echo "$output_root: output root already exists" >&2; exit 1; } -mkdir -p "$output_root" +} +capture_dir=$(realpath "$1") evidence_root=$(realpath "$2") output_root=$3 reference_time=$4 +author=${5:-${DIAGNOSTICS_AUTHOR:-Beffroi}} theme=${6:-${DIAGNOSTICS_THEME:-default}} +[[ ! -e "$output_root" ]] || { echo "$output_root: output root exists" >&2; exit 1; } +mkdir -p "$output_root/diagnostics" "$output_root/pdfs" reports/plugins/diagnostics/analyse-all.sh "$capture_dir" --evidence-root "$evidence_root" \ --output-dir "$output_root/diagnostics" --reference-time "$reference_time" \ --producer-version "$(git -C reports rev-parse HEAD)" -reports/plugins/diagnostics/tools/diagnostic-to-report-all.sh --diagnostic-dir "$output_root/diagnostics" \ - --evidence-root "$evidence_root" --output-root "$output_root/generations" \ - --title "$title" --author "$author" --date "$report_date" \ - --generator-version "$(git -C reports rev-parse HEAD)" \ - --diagnostic-validator "$PWD/reports/plugins/diagnostics/tools/validate.sh" \ - --report-validator "$PWD/reporter/tools/validate.sh" \ - --branding "$PWD/reports/plugins/diagnostics/runtime/themes/default.json" --branding-root "$PWD/reports" -while IFS= read -r -d '' report; do - relative=${report#"$output_root/generations/"}; relative=${relative%/report.draft.json} - reporter/render.sh "$report" --output "$output_root/pdfs/$relative.pdf" -done < <(find "$output_root/generations" -type f -name report.draft.json -print0 | sort -z) -echo "Created diagnostics, draft generations, and PDFs under $output_root" +count=0 +while IFS= read -r -d '' capture; do + relative=${capture#"$capture_dir/"} + output="$output_root/pdfs/${relative%.json}.pdf" + mkdir -p "$(dirname "$output")" + reports/plugins/diagnostics/render.sh "$capture" --output "$output" --author "$author" --theme "$theme" + ((count+=1)) +done < <(find "$capture_dir" -type f -name '*.json' -print0 | sort -z) +echo "Created $count diagnostic artifacts and PDFs under $output_root" diff --git a/scripts/workflow.sh b/scripts/workflow.sh index 36e2ff3..944db31 100755 --- a/scripts/workflow.sh +++ b/scripts/workflow.sh @@ -1,81 +1,35 @@ #!/usr/bin/env bash -# Compose the pinned component CLIs without owning their implementation. +# Compose diagnostic analysis with the independent diagnostic renderer. set -euo pipefail - cd "$(dirname "${BASH_SOURCE[0]}")/.." - usage() { - cat >&2 <<'EOF' -Usage: - scripts/workflow.sh analyse CAPTURE EVIDENCE_ROOT OUTPUT REFERENCE_TIME - scripts/workflow.sh draft DIAGNOSTIC EVIDENCE_ROOT OUTPUT_DIR TITLE AUTHOR DATE - scripts/workflow.sh render REPORT OUTPUT - scripts/workflow.sh all CAPTURE EVIDENCE_ROOT WORK_DIR REFERENCE_TIME TITLE AUTHOR DATE -EOF - exit 2 + echo "Usage: $0 analyse CAPTURE EVIDENCE_ROOT OUTPUT.json REFERENCE_TIME" >&2 + echo " $0 render REPORT.yaml|json OUTPUT.pdf" >&2 + echo " $0 all CAPTURE EVIDENCE_ROOT NEW_OUTPUT_DIR REFERENCE_TIME [AUTHOR] [THEME]" >&2 + exit 2 } - -require_values() { - for value in "$@"; do - [[ -n "$value" ]] || usage - done -} - -command -v typst >/dev/null || { echo "Missing runtime dependency: typst" >&2; exit 1; } - -analyse() { +command_name=${1:-}; [[ -n "$command_name" ]] || usage; shift +case $command_name in + analyse) [[ $# -eq 4 ]] || usage - require_values "$@" - bash reports/plugins/diagnostics/analyse.sh "$1" \ - --evidence-root "$2" --output "$3" --reference-time "$4" \ - --producer-version "$(git -C reports rev-parse HEAD)" -} - -draft() { - [[ $# -eq 6 ]] || usage - require_values "$@" - bash reports/plugins/diagnostics/tools/diagnostic-to-report.sh \ - --diagnostic "$1" --evidence-root "$2" --output-dir "$3" \ - --title "$4" --author "$5" --date "$6" \ - --generator-version "$(git -C reports rev-parse HEAD)" \ - --diagnostic-validator "$(pwd)/reports/plugins/diagnostics/tools/validate.sh" \ - --report-validator "$(pwd)/reporter/tools/validate.sh" \ - --branding reports/plugins/diagnostics/runtime/themes/default.json \ - --branding-root reports -} - -render() { + reports/plugins/diagnostics/analyse.sh "$1" --evidence-root "$2" --output "$3" \ + --reference-time "$4" --producer-version "$(git -C reports rev-parse HEAD)" + ;; + render) [[ $# -eq 2 ]] || usage - require_values "$@" - bash reporter/render.sh "$1" --output "$2" -} - -command_name="${1:-}" -[[ -n "$command_name" ]] || usage -shift -case "$command_name" in - analyse) analyse "$@" ;; - draft) draft "$@" ;; - render) render "$@" ;; - all) - [[ $# -eq 7 ]] || usage - require_values "$@" - capture=$1 - evidence_root=$2 - work_dir=$3 - reference_time=$4 - title=$5 - author=$6 - report_date=$7 - [[ ! -e "$work_dir" ]] || { - echo "$work_dir: work directory already exists" >&2 - exit 1 - } - mkdir -p "$work_dir" - analyse "$capture" "$evidence_root" "$work_dir/diagnostic.json" "$reference_time" - draft "$work_dir/diagnostic.json" "$evidence_root" "$work_dir/generation" \ - "$title" "$author" "$report_date" - render "$work_dir/generation/report.draft.json" "$work_dir/report.pdf" - ;; - *) usage ;; + reporter/render.sh "$1" --output "$2" + ;; + all) + [[ $# -ge 4 && $# -le 6 ]] || usage + capture=$1 evidence_root=$2 output_dir=$3 reference_time=$4 + author=${5:-${DIAGNOSTICS_AUTHOR:-Beffroi}} theme=${6:-${DIAGNOSTICS_THEME:-default}} + [[ ! -e "$output_dir" ]] || { echo "$output_dir: output directory exists" >&2; exit 1; } + mkdir -p "$output_dir" + reports/plugins/diagnostics/analyse.sh "$capture" --evidence-root "$evidence_root" \ + --output "$output_dir/diagnostic.json" --reference-time "$reference_time" \ + --producer-version "$(git -C reports rev-parse HEAD)" + reports/plugins/diagnostics/render.sh "$capture" --output "$output_dir/report.pdf" \ + --author "$author" --theme "$theme" + ;; + *) usage;; esac