', ""))
+ for changed in mutations:
+ with self.subTest(markup=changed):
+ issues = self.sct_parity_issues(data, changed)
+ self.assertIn("Raw and detailed HTML result identities differ",
+ [i["issue"] for i in issues])
+
+ def test_sct_childless_heading_duplicate_multiplicity_is_preserved(self):
+ """Check SCT childless heading duplicate multiplicity is preserved."""
+ entry = {"Test_case": "SCT-01", "Test_case_description": "Parent check",
+ "test_result": "IGNORED", "subtests": []}
+ text = self.sct_heading_page()
+ self.assertEqual([], self.sct_parity_issues({"test_results": [entry, entry]}, text + text))
+ self.assertTrue(self.sct_parity_issues({"test_results": [entry, entry]}, text))
+ self.assertTrue(self.sct_parity_issues({"test_results": [entry]}, text + text))
+
+ def test_sct_heading_contract_is_not_applied_to_other_renderers(self):
+ """Check SCT heading contract is not applied to other renderers."""
+ actual, _ = doctor_artifacts._html_detail_records(
+ doctor_artifacts.ReportHTML(self.sct_heading_page()))
+ self.assertEqual(Counter(), actual)
+
+ def test_chart_total_is_derived_when_raw_has_only_status_counts(self):
+ """Check chart total is derived when raw has only status counts."""
+ data = {
+ "suite_summary": {
+ "total_passed": 8,
+ "total_failed": 1,
+ "total_failed_with_waiver": 2
+ }
+ }
+ registry = [{"canonical": "FWTS", "summary_html": "fwts_summary.html"}]
+ text = ('
Total Tests
11
'
+ '
Passed
8
Failed
1
'
+ '
Failed with Waiver
2
')
+ issues, coverage = [], []
+ doctor_artifacts._inspect_html(Path("fwts_summary.html"), doctor_artifacts.ReportHTML(text),
+ {}, {"FWTS": data}, registry, issues, coverage)
+ self.assertEqual([], issues)
+ doctor_artifacts._inspect_html(Path("fwts_summary.html"),
+ doctor_artifacts.ReportHTML(text.replace('>11<', '>9<')), {},
+ {"FWTS": data}, registry, issues, coverage)
+ difference = next(i for i in issues if i["issue"] == "Chart differs from raw suite summary")
+ self.assertEqual("total", difference["count"])
+ self.assertEqual(11, difference["expected"])
+ self.assertEqual(9, difference["actual"])
+
+ def test_sbmr_zero_ignored_counter_has_no_required_chart_row(self):
+ """Check SBMR zero ignored counter has no required chart row."""
+ registry = [{"canonical": "SBMR-IB", "summary_html": "sbmr_ib_summary.html"}]
+ data = {"suite_summary": {"total_passed": 1, "total_ignored": 0}}
+ text = ('
Total Tests
1
'
+ '
Passed
1
')
+ issues, coverage = [], []
+ doctor_artifacts._inspect_html(Path("sbmr_ib_summary.html"),
+ doctor_artifacts.ReportHTML(text), {}, {"SBMR-IB": data},
+ registry, issues, coverage)
+ self.assertEqual([], issues)
+ data["suite_summary"]["total_ignored"] = 2
+ doctor_artifacts._inspect_html(Path("sbmr_ib_summary.html"),
+ doctor_artifacts.ReportHTML(text), {}, {"SBMR-IB": data},
+ registry, issues, coverage)
+ differences = [i for i in issues if i["issue"] == "Chart differs from raw suite summary"]
+ self.assertEqual({"total", "ignored"}, {i["count"] for i in differences})
+
+
+# Browser and PDF evidence: successful commands alone are not proof of success.
+
+def marker(checks=8, failures=None):
+ """Build the result marker that Doctor expects from its browser checks."""
+ return '
' + json.dumps({
+ "checks": checks, "failures": failures if failures is not None else []}) + '
'
+
+
+def pdf_text(prefix="SBBR", outcome="fail"):
+ """Build sample extracted PDF text with known counts and compliance."""
+ passed, failed, waived, compliance = visual.OUTCOMES[outcome]
+ return (prefix + "-FWTS Test Summary\nSRS requirements compliance results\n"
+ + compliance + "\nTotal Tests 2\nPassed " + str(passed) + "\nFailed "
+ + str(failed) + "\nFailed with Waiver " + str(waived))
+
+
+class BrowserResultTests(unittest.TestCase):
+ """Reject browser output unless the requested checks actually reported results."""
+
+ def test_executed_positive_control(self):
+ """Check executed positive control."""
+ self.assertEqual(visual.browser_result(marker()), {"checks": 8, "failures": []})
+
+ def test_reported_assertion_failures_are_preserved(self):
+ """Check reported assertion failures are preserved."""
+ self.assertEqual(visual.browser_result(marker(failures=["Wrong chart count"]))["failures"],
+ ["Wrong chart count"])
+
+ def test_no_marker_cannot_be_a_successful_browser_run(self):
+ """Check no marker cannot be a successful browser run."""
+ for text in ("", "Nice report", "Chrome exited normally"):
+ with self.subTest(text=text):
+ with self.assertRaisesRegex(ValueError, "without running"):
+ visual.browser_result(text)
+
+ def test_zero_few_boolean_and_noninteger_checks_are_incomplete(self):
+ """Check zero few boolean and noninteger checks are incomplete."""
+ for checks in (0, 1, 3, -1, True, 4.0, "8", None):
+ with self.subTest(checks=checks):
+ with self.assertRaises(ValueError):
+ visual.browser_result(marker(checks=checks))
+
+ def test_failures_must_be_a_list(self):
+ """Check failures must be a list."""
+ for failures in ("", "no failure", {}, False):
+ with self.subTest(failures=failures):
+ with self.assertRaises(ValueError):
+ visual.browser_result(marker(failures=failures))
+
+ def test_bad_json_and_non_object_payloads_are_controlled_errors(self):
+ """Check bad JSON and non object payloads are controlled errors."""
+ for payload in ("broken", "[]", "null", "1", '"text"', '{}'):
+ with self.subTest(payload=payload):
+ with self.assertRaises(ValueError):
+ visual.browser_result('
' + payload + '
')
+
+ def test_dom_encoded_json_is_decoded(self):
+ """Check dom encoded JSON is decoded."""
+ text = marker(failures=["Expected A & B"]).replace("&", "&")
+ self.assertEqual(visual.browser_result(text)["failures"], ["Expected A & B"])
+
+
+class PdfContractTests(unittest.TestCase):
+ """Check that PDF text retains suite names, exact counts and compliance."""
+
+ def test_positive_controls_for_both_modes_and_all_outcomes(self):
+ """Check positive controls for both modes and all outcomes."""
+ for prefix in ("EBBR", "SBBR"):
+ for outcome in visual.OUTCOMES:
+ with self.subTest(prefix=prefix, outcome=outcome):
+ self.assertEqual(
+ visual.pdf_problems(pdf_text(prefix, outcome), prefix, outcome), [])
+
+ def test_print_wrapping_and_extra_whitespace_do_not_change_semantics(self):
+ """Check print wrapping and extra whitespace do not change semantics."""
+ text = pdf_text().replace(" ", " \n ")
+ self.assertEqual(visual.pdf_problems(text, "SBBR", "fail"), [])
+
+ def test_wrong_or_missing_suite_identity_is_detected(self):
+ """Check wrong or missing suite identity is detected."""
+ for replacement in ("EBBR-FWTS", "SBBR-SCT", "", "NOT-SBBR-FWTS"):
+ with self.subTest(replacement=replacement):
+ text = pdf_text().replace("SBBR-FWTS", replacement)
+ self.assertTrue(any("suite identity" in issue
+ for issue in visual.pdf_problems(text, "SBBR", "fail")))
+
+ def test_noncompliant_is_not_accepted_as_compliant_substring(self):
+ """Check noncompliant is not accepted as compliant substring."""
+ self.assertTrue(
+ any("Expected overall Compliant" in issue
+ for issue in visual.pdf_problems(pdf_text(outcome="fail"), "SBBR", "pass")))
+
+ def test_waiver_status_must_not_be_reduced_to_plain_compliant(self):
+ """Check waiver status must not be reduced to plain compliant."""
+ text = pdf_text(outcome="waived").replace("Compliant with waivers", "Compliant")
+ self.assertTrue(any("Expected overall Compliant with waivers" in issue
+ for issue in visual.pdf_problems(text, "SBBR", "waived")))
+
+ def test_missing_compliance_heading_cannot_match_unrelated_status(self):
+ """Check missing compliance heading cannot match unrelated status."""
+ text = pdf_text().replace("SRS requirements compliance results", "Unrelated test output")
+ self.assertTrue(
+ any("actual missing" in issue for issue in visual.pdf_problems(text, "SBBR", "fail")))
+
+ def test_each_exact_counter_is_independently_checked(self):
+ """Check each exact counter is independently checked."""
+ for label in ("Total Tests 2", "Passed 1", "Failed 1", "Failed with Waiver 0"):
+ with self.subTest(label=label):
+ text = pdf_text().replace(label, label.rsplit(" ", 1)[0] + " 9")
+ self.assertTrue(any("Expected PDF count" in issue
+ for issue in visual.pdf_problems(text, "SBBR", "fail")))
+
+ def test_count_prefix_does_not_accept_ten_as_one(self):
+ """Check count prefix does not accept ten as one."""
+ text = pdf_text().replace("Passed 1", "Passed 10")
+ self.assertTrue(
+ any("Passed=1" in issue for issue in visual.pdf_problems(text, "SBBR", "fail")))
+
+ def test_contradictory_duplicate_count_cannot_hide_behind_matching_count(self):
+ """Check contradictory duplicate count cannot hide behind matching count."""
+ self.assertTrue(visual.pdf_problems(pdf_text() + "\nPassed 9", "SBBR", "fail"))
+
+ def test_empty_pdf_text_never_passes(self):
+ """Check empty PDF text never passes."""
+ self.assertGreaterEqual(len(visual.pdf_problems("", "SBBR", "fail")), 6)
+
+
+class BrowserExecutionTests(unittest.TestCase):
+ """Check browser setup and outcomes using fake server and command responses."""
+
+ def invoke(self, stdout, returncode=0):
+ """Simulate both browser sizes without launching a browser or HTTP server."""
+ folder = tempfile.TemporaryDirectory()
+ self.addCleanup(folder.cleanup)
+ root = Path(folder.name)
+ source, destination = root / "source", root / "browser"
+ source.mkdir()
+ destination.mkdir()
+ page = source / "fwts_detailed.html"
+ content = 'Results
FWTS
'
+ page.write_text(content)
+ ctx = Context(root, root)
+ ctx.run = mock.Mock(return_value=subprocess.CompletedProcess([], returncode, stdout))
+ server = mock.Mock(server_port=41111)
+ with mock.patch.object(visual, "ThreadingHTTPServer", return_value=server), \
+ mock.patch.object(visual, "Thread") as thread:
+ visual.check_browser(ctx, "/browser", page, destination, "SR", "fail")
+ self.assertEqual(page.read_text(), content,
+ "Original generated report must not be instrumented in place")
+ self.assertIn("doctor-browser-result", (destination / page.name).read_text())
+ self.assertIn("window.doctorErrors", (destination / page.name).read_text())
+ server.shutdown.assert_called_once()
+ server.server_close.assert_called_once()
+ thread.return_value.join.assert_called_once()
+ return ctx
+
+ def test_both_viewports_must_execute_and_pass(self):
+ """Check both viewports must execute and pass."""
+ ctx = self.invoke(marker())
+ self.assertEqual(len(ctx.findings), 2)
+ self.assertTrue(all(finding.status == "PASS" for finding in ctx.findings))
+ sizes = {next(str(arg) for arg in call.args[0] if str(arg).startswith("--window-size="))
+ for call in ctx.run.call_args_list}
+ self.assertEqual(sizes, {"--window-size=1600,900", "--window-size=430,900"})
+
+ def test_javascript_assertion_failure_is_failure(self):
+ """Check javascript assertion failure is failure."""
+ ctx = self.invoke(marker(failures=["Report overflows viewport"]))
+ self.assertTrue(all(finding.status == "FAIL" for finding in ctx.findings))
+ self.assertTrue(all("overflows" in finding.actual for finding in ctx.findings))
+
+ def test_successful_process_without_assertions_is_failure(self):
+ """Check successful process without assertions is failure."""
+ ctx = self.invoke("Uninitialized report")
+ self.assertTrue(all(finding.status == "FAIL" for finding in ctx.findings))
+
+ def test_nonzero_browser_exit_cannot_pass_matching_marker(self):
+ """Check nonzero browser exit cannot pass matching marker."""
+ ctx = self.invoke(marker(), returncode=1)
+ self.assertTrue(all(finding.status == "FAIL" for finding in ctx.findings))
+
+
+class VisualDependencyTests(unittest.TestCase):
+ """Keep browser and PDF checks independent when one tool is unavailable."""
+
+ def setUp(self):
+ self.folder = tempfile.TemporaryDirectory()
+ self.addCleanup(self.folder.cleanup)
+ self.root = Path(self.folder.name)
+ self.ctx = Context(self.root / "source", self.root / "output", modes=("DT",))
+ self.ctx.portable_parser = self.root / "package" / "log_parser"
+
+ def completed(self, code=0, text="ok"):
+ """Return a fake command result for a dependency or generation step."""
+ return subprocess.CompletedProcess([], code, text)
+
+ def test_no_verified_package_is_blocked_and_does_not_invoke_tools(self):
+ """Check no verified package is blocked and does not invoke tools."""
+ self.ctx.portable_parser = None
+ self.ctx.run = mock.Mock()
+ visual.run_visual(self.ctx)
+ self.assertEqual(self.ctx.findings[0].check_id, "VISUAL_PACKAGE")
+ self.assertEqual(self.ctx.findings[0].status, "BLOCKED")
+ self.ctx.run.assert_not_called()
+
+ def test_absent_browser_and_pdf_dependencies_are_both_blocked(self):
+ """Check absent browser and PDF dependencies are both blocked."""
+ self.ctx.run = mock.Mock(return_value=self.completed(1, "missing package"))
+ with mock.patch.object(visual.shutil, "which", return_value=None):
+ visual.run_visual(self.ctx)
+ self.assertEqual({finding.check_id: finding.status for finding in self.ctx.findings}, {
+ "VISUAL_BROWSER_DEPENDENCY": "BLOCKED", "VISUAL_PDF_DEPENDENCY": "BLOCKED"})
+ self.ctx.run.assert_called_once()
+
+ def test_missing_browser_does_not_suppress_available_pdf_checks(self):
+ """Check missing browser does not suppress available PDF checks."""
+ calls = []
+
+ def invoke(command, directory, name, **kwargs):
+ """Simulate PDF text extraction while leaving browser checks unavailable."""
+ calls.append(name)
+ if name == "pdf-read":
+ outcome = Path(directory).name.split("_", 1)[1]
+ (Path(directory) / "pdf-text.txt").write_text(pdf_text("EBBR", outcome))
+ return self.completed()
+
+ self.ctx.run = invoke
+ with mock.patch.object(visual.shutil, "which", return_value=None):
+ visual.run_visual(self.ctx)
+ self.assertEqual(calls.count("pdf-read"), 3)
+ self.assertEqual([finding.status for finding in self.ctx.findings
+ if finding.check_id == "VISUAL_BROWSER_DEPENDENCY"], ["BLOCKED"])
+ self.assertEqual([finding.status for finding in self.ctx.findings
+ if finding.check_id == "VISUAL_PDF"], ["PASS", "PASS", "PASS"])
+
+ def test_missing_pdf_dependencies_do_not_suppress_available_browser_checks(self):
+ """Check missing PDF dependencies do not suppress available browser checks."""
+ browser = self.root / "chromium"
+ browser.write_text("synthetic executable path; never invoked")
+ self.ctx.browser = browser
+
+ def invoke(command, directory, name, **kwargs):
+ """Provide generated HTML while simulating a missing PDF dependency."""
+ if name == "pdf-dependencies":
+ return self.completed(1, "pypdf missing")
+ if name == "generate":
+ reports = Path(directory) / "output" / "html_detailed_summaries"
+ reports.mkdir(parents=True)
+ for page in ("acs_summary.html", "fwts_detailed.html"):
+ (reports / page).write_text("Generated report")
+ return self.completed()
+
+ self.ctx.run = invoke
+ with mock.patch.object(visual, "check_browser") as check:
+ visual.run_visual(self.ctx)
+ self.assertEqual(check.call_count, 6)
+ self.assertEqual([finding.status for finding in self.ctx.findings
+ if finding.check_id == "VISUAL_PDF_DEPENDENCY"], ["BLOCKED"])
+ self.assertFalse(any(finding.check_id == "VISUAL_PDF" for finding in self.ctx.findings))
+
+ def test_failed_generation_does_not_create_green_browser_results(self):
+ """Check failed generation does not create green browser results."""
+ browser = self.root / "chromium"
+ browser.write_text("synthetic")
+ self.ctx.browser = browser
+ self.ctx.run = mock.Mock(side_effect=[self.completed(1)] + [self.completed(5)] * 3)
+ with mock.patch.object(visual, "check_browser") as check:
+ visual.run_visual(self.ctx)
+ check.assert_not_called()
+ blocked = [
+ finding for finding in self.ctx.findings
+ if finding.check_id == "VISUAL_DEPENDENT_CHECKS"
+ ]
+ self.assertEqual(len(blocked), 3)
+ self.assertTrue(all(finding.status == "BLOCKED" for finding in blocked))
+
+ def test_generated_category_has_description_required_by_raw_schema(self):
+ """Check generated category has description required by raw schema."""
+ self.ctx.run = mock.Mock(return_value=self.completed())
+ with mock.patch.object(visual.shutil, "which", return_value=None):
+ visual.run_visual(self.ctx)
+ category = json.loads(
+ (self.ctx.output_dir / "evidence/visual/DT_pass/category.json").read_text())
+ self.assertEqual(category["doctor"][0]["Description"],
+ ["Doctor synthetic FWTS interface checks"])
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/common/log_parser/doctor.py b/common/log_parser/doctor.py
new file mode 100644
index 00000000..de0231c5
--- /dev/null
+++ b/common/log_parser/doctor.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+# Copyright (c) 2026, Arm Limited or its affiliates. All rights reserved.
+# SPDX-License-Identifier : Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Keep the existing optional Doctor entry point while its code lives in one folder.
+
+Normal parser commands only register Doctor's flags. Health checks run only
+when explicitly requested; importing this launcher never starts them.
+"""
+
+import sys
+
+from doctor_checks.core import Context, Finding, add_arguments, main, run_health
+
+# These imports are the existing public entry points, not unused local helpers.
+__all__ = ("Context", "Finding", "add_arguments", "main", "run_health", "sys")
+
+
+if __name__ == "__main__":
+ sys.dont_write_bytecode = True
+ sys.exit(main())
diff --git a/common/log_parser/doctor_checks/__init__.py b/common/log_parser/doctor_checks/__init__.py
new file mode 100644
index 00000000..66bc153f
--- /dev/null
+++ b/common/log_parser/doctor_checks/__init__.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+# Copyright (c) 2026, Arm Limited or its affiliates. All rights reserved.
+# SPDX-License-Identifier : Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Optional Doctor checks; importing this package does not start any checks."""
+
+# License metadata only; importing this package never starts health checks.
+__license__ = "Apache-2.0"
diff --git a/common/log_parser/doctor_checks/artifacts.py b/common/log_parser/doctor_checks/artifacts.py
new file mode 100644
index 00000000..14f5b8c0
--- /dev/null
+++ b/common/log_parser/doctor_checks/artifacts.py
@@ -0,0 +1,1275 @@
+#!/usr/bin/env python3
+# Copyright (c) 2026, Arm Limited or its affiliates. All rights reserved.
+# SPDX-License-Identifier : Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Check that saved JSON, HTML and optional PDF reports agree with their inputs.
+
+Doctor calls these checks only when the user selects them. Saved report packages
+are read without changing them or running their scripts. Findings and supporting
+files are written to Doctor's output folder. Browser and PDF checks use separate
+sample reports created by Doctor, never the supplied reports.
+"""
+
+import argparse
+from collections import Counter, defaultdict
+from concurrent.futures import ThreadPoolExecutor
+from copy import deepcopy
+from functools import partial
+import hashlib
+import html
+from html.parser import HTMLParser
+from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
+import json
+import math
+from pathlib import Path
+import re
+import shutil
+from threading import Thread
+from urllib.parse import unquote, urlsplit
+
+from .core import load_json
+
+_strict_json = load_json
+
+
+# ---------------------------------------------------------------------------
+# Check which category file the run used before applying its schema requirements.
+# ---------------------------------------------------------------------------
+
+MANIFEST = "config/parser_run.json"
+INFO_FIELD = "Test_suite_info"
+
+
+def _contained_file(root, relative):
+ """Allow evidence files inside the supplied package, not outside symlink targets."""
+ if (not isinstance(relative, str) or not relative or "\\" in relative
+ or Path(relative).is_absolute() or ".." in Path(relative).parts):
+ raise ValueError("Category evidence path must be relative to the report package")
+ path = root / relative
+ if root not in path.resolve().parents:
+ raise ValueError("Category evidence path escapes the report package")
+ if not path.is_file():
+ raise ValueError("Category evidence file is missing: " + relative)
+ return path
+
+
+def category_provenance(report_root, mode):
+ """Read the run's saved category choice and verify any supplied-file copy.
+
+ Current repository defaults cannot tell us which file an older run used.
+ """
+ root = Path(report_root).resolve()
+ result = {"source": "unknown", "manifest": str(root / MANIFEST),
+ "invalid": False, "message": "Run category provenance is unavailable"}
+ manifest = root / MANIFEST
+ if not manifest.exists() and not manifest.is_symlink():
+ return result
+ try:
+ data = load_json(_contained_file(root, MANIFEST))
+ if not isinstance(data, dict) or type(data.get("format_version")) is not int or data["format_version"] != 1:
+ raise ValueError("Unsupported parser-run provenance format")
+ if data.get("mode") != mode:
+ raise ValueError("Parser-run provenance mode does not match " + mode)
+ category = data.get("test_category")
+ if not isinstance(category, dict) or category.get("source") not in {"explicit", "bundled"}:
+ raise ValueError("Parser-run category source must be explicit or bundled")
+ if category["source"] == "explicit":
+ # A supplied category only counts as evidence if its saved copy matches
+ # the checksum recorded when that run was generated.
+ snapshot = _contained_file(root, category.get("path"))
+ digest = category.get("sha256")
+ if not isinstance(digest, str) or not re.fullmatch(r"[0-9a-f]{64}", digest):
+ raise ValueError("Explicit category snapshot has no valid SHA-256")
+ if hashlib.sha256(snapshot.read_bytes()).hexdigest() != digest:
+ raise ValueError("Explicit category snapshot SHA-256 does not match")
+ if not isinstance(load_json(snapshot), dict):
+ raise ValueError("Explicit category snapshot must be a JSON object")
+ result.update(snapshot=str(snapshot), sha256=digest)
+ result.update(source=category["source"], message=(
+ "Category explicitly supplied to the generating run" if category["source"] == "explicit"
+ else "Generating run used its bundled category"))
+ except (OSError, ValueError, TypeError) as error:
+ result.update(invalid=True, message="Invalid run category provenance: " + str(error))
+ return result
+
+
+def applicable_schema(schema):
+ """Return a copy that does not require missing Test_suite_info fields.
+
+ Only schema rules are visited. Example data and the original schema stay intact.
+ """
+ result = deepcopy(schema)
+
+ def visit(node):
+ if not isinstance(node, dict):
+ return
+ if isinstance(node.get("required"), list):
+ node["required"] = [key for key in node["required"] if key != INFO_FIELD]
+ for keyword in ("$defs", "definitions", "properties", "patternProperties",
+ "dependentSchemas", "dependencies"):
+ children = node.get(keyword)
+ if isinstance(children, dict):
+ for child in children.values():
+ visit(child)
+ for keyword in ("allOf", "anyOf", "oneOf", "prefixItems"):
+ children = node.get(keyword)
+ if isinstance(children, list):
+ for child in children:
+ visit(child)
+ for keyword in ("items", "additionalItems", "contains", "additionalProperties",
+ "unevaluatedProperties", "unevaluatedItems", "propertyNames",
+ "if", "then", "else", "not", "contentSchema"):
+ child = node.get(keyword)
+ if isinstance(child, list):
+ for item in child:
+ visit(item)
+ else:
+ visit(child)
+
+ visit(result)
+ return result
+
+
+def _pointer(path):
+ return "/" + "/".join(str(part).replace("~", "~0").replace("/", "~1") for part in path)
+
+
+def _all_errors(errors):
+ for error in errors:
+ yield error
+ yield from _all_errors(error.context)
+
+
+def flatten_errors(errors):
+ """Keep parent and nested schema errors with their exact JSON field paths."""
+ return [{"path": _pointer(error.absolute_path), "message": error.message,
+ "validator": error.validator} for error in _all_errors(errors)]
+
+
+def evaluate_schema(schema_path, fragment, data, provenance):
+ """Check the schema using the generating run's category-file information.
+
+ Keep the strict error count as evidence. Relax only the requirement for a
+ missing Test_suite_info when no explicitly supplied category is confirmed.
+ """
+ from jsonschema import Draft202012Validator
+ from validate import _load_schema
+
+ _, strict = _load_schema(Path(schema_path), fragment)
+ strict_errors = list(strict.iter_errors(data))
+ omitted = []
+ errors = strict_errors
+ if provenance["source"] != "explicit":
+ omitted = sorted({_pointer(error.absolute_path) for error in _all_errors(strict_errors)
+ if error.validator == "required" and INFO_FIELD in error.validator_value
+ and isinstance(error.instance, dict) and INFO_FIELD not in error.instance})
+ if omitted:
+ # The copy includes all locally referenced schema definitions. A new
+ # validator prevents references from returning to the unchanged schema.
+ effective = applicable_schema(strict.schema)
+ Draft202012Validator.check_schema(effective)
+ errors = list(Draft202012Validator(effective).iter_errors(data))
+ return {"errors": flatten_errors(errors), "strict_error_count": len(flatten_errors(strict_errors)),
+ "omitted_missing_info_paths": omitted, "category_provenance": provenance}
+
+
+def schema_policy_main():
+ """Expose the same schema check to Doctor's packaged-parser subprocess."""
+ parser = argparse.ArgumentParser(description="Doctor-only applicability of Test_suite_info, without changing "
+ "result/schema files.")
+ parser.add_argument("--schema-policy", action="store_true",
+ required=True, help=argparse.SUPPRESS)
+ parser.add_argument("--registry", required=True)
+ parser.add_argument("--report", required=True)
+ parser.add_argument("--mode", choices=("DT", "SR"), required=True)
+ parser.add_argument("json_file")
+ args = parser.parse_args()
+ try:
+ from suite_registry import load_registry
+ from validate import _build_file_schema_index, _find_schema_for_file
+
+ registry = load_registry(args.registry)
+ exact, patterns = _build_file_schema_index(registry, args.registry)
+ info = _find_schema_for_file(args.json_file, exact, patterns)
+ if not info:
+ raise ValueError("No registered raw schema for " + Path(args.json_file).name)
+ result = evaluate_schema(info["schema"], info["schema_fragment"], load_json(args.json_file),
+ category_provenance(args.report, args.mode))
+ print(json.dumps(result, indent=2))
+ return 0
+ except (OSError, ValueError, TypeError, KeyError, ImportError) as error:
+ print(json.dumps({"error": str(error)}))
+ return 2
+
+
+# ---------------------------------------------------------------------------
+# Compare saved report content without executing HTML or changing input files.
+# ---------------------------------------------------------------------------
+
+def identity(value):
+ """Match display spelling without changing a compliance decision."""
+ return re.sub(r"[^A-Z0-9]", "", str(value).upper())
+
+
+def decision(value):
+ text = str(value).lower()
+ if text.startswith("not compliant"):
+ return "Not Compliant"
+ if text.startswith("compliant with waiver"):
+ return "Compliant with waivers"
+ if text.startswith("compliant"):
+ return "Compliant"
+ if "not run" in text:
+ return "Not Run"
+ return "Unknown"
+
+
+class ReportHTML(HTMLParser):
+ """Collect table text, badges and local links without running page scripts."""
+
+ def __init__(self, text):
+ super().__init__(convert_charrefs=True)
+ self.stack, self.tables, self.badges, self.links = [], [], [], []
+ self.ids, self.anchors = Counter(), set()
+ self.active_tables = []
+ self.badge = None
+ self.detail_headings, self.heading, self.detail_heading = [], None, None
+ self.feed(text)
+ self.close()
+
+ def handle_starttag(self, tag, attrs):
+ attrs = dict(attrs)
+ classes = attrs.get("class", "").split()
+ if attrs.get("id"):
+ self.ids[attrs["id"]] += 1
+ if tag == "a" and attrs.get("name"):
+ self.anchors.add(attrs["name"])
+ card = next((item[2] for item in reversed(self.stack) if item[2]), "")
+ if "summary" in classes and attrs.get("id"):
+ card = attrs["id"]
+ for key in ("href", "src"):
+ if attrs.get(key):
+ self.links.append(attrs[key])
+ if tag == "table":
+ # Nested tables have separate rows. Mark the outer cell so its wrapper
+ # is not mistaken for an extra test result later.
+ if self.active_tables and self.active_tables[-1]["cell"] is not None:
+ self.active_tables[-1]["cell"]["nested"] = True
+ table = {"kind": "compliance" if "acs-compliance-table" in classes
+ else "counts" if "summary-table" in classes else "detail",
+ "card": card, "rows": [], "cells": [], "row": None, "cell": None}
+ self.tables.append(table)
+ self.active_tables.append(table)
+ if table["kind"] == "detail" and self.detail_heading is not None:
+ self.detail_heading["tables"].append(table)
+ if self.active_tables:
+ table = self.active_tables[-1]
+ if tag == "tr":
+ table["row"] = []
+ elif tag in ("td", "th") and table["row"] is not None:
+ table["cell"] = {"tag": tag, "text": [], "nested": False}
+ if "acs-suite-compliance" in classes:
+ self.badge = {"card": card, "context": attrs.get("title", ""),
+ "text": []}
+ if "heading" in classes:
+ self.heading = {"tag": tag, "depth": len(self.stack), "text": []}
+ if tag not in {"area", "base", "br", "col", "embed", "hr", "img",
+ "input", "link", "meta", "param", "source", "wbr"}:
+ self.stack.append((tag, classes, card))
+
+ def handle_data(self, data):
+ # BSA/SBSA reason buttons display the actual rule ID. Other buttons
+ # contain hierarchy/action controls, not result-cell content.
+ if self.active_tables and not any(item[0] == "button" and "reason-rule-toggle" not in item[1]
+ for item in self.stack):
+ cell = self.active_tables[-1]["cell"]
+ if cell is not None:
+ cell["text"].append(data)
+ if self.badge is not None:
+ self.badge["text"].append(data)
+ if self.heading is not None:
+ self.heading["text"].append(data)
+
+ def handle_endtag(self, tag):
+ if (self.heading is not None and tag == self.heading["tag"]
+ and len(self.stack) == self.heading["depth"] + 1):
+ label, separator, value = " ".join("".join(self.heading["text"]).split()).partition(":")
+ if separator:
+ field = identity(label)
+ if field == "TESTCASE":
+ self.detail_heading = {"id": value.strip(), "description": "",
+ "status": "", "tables": []}
+ self.detail_headings.append(self.detail_heading)
+ elif self.detail_heading is not None:
+ if field == "TESTCASEDESCRIPTION":
+ self.detail_heading["description"] = value.strip()
+ elif field == "TESTRESULT":
+ self.detail_heading["status"] = value.strip()
+ self.heading = None
+ if self.active_tables:
+ table = self.active_tables[-1]
+ if tag in ("td", "th") and table["cell"] is not None:
+ cell = table["cell"]
+ cell["text"] = " ".join("".join(cell["text"]).split())
+ table["row"].append(cell)
+ table["cell"] = None
+ elif tag == "tr" and table["row"] is not None:
+ table["cells"].append(table["row"])
+ table["rows"].append([cell["text"] for cell in table["row"]])
+ table["row"] = None
+ elif tag == "table":
+ self.active_tables.pop()
+ if tag == "span" and self.badge is not None:
+ self.badge["text"] = " ".join("".join(self.badge["text"]).split())
+ self.badges.append(self.badge)
+ self.badge = None
+ for index in range(len(self.stack) - 1, -1, -1):
+ if self.stack[index][0] == tag:
+ del self.stack[index:]
+ break
+
+
+def _records(merged):
+ """Read suite requirements and decisions recorded in the merged summary."""
+ info = merged.get("Suite_Name: acs_info", {})
+ summary = info.get("ACS Results Summary", {}) if isinstance(info, dict) else {}
+ if not isinstance(summary, dict):
+ return {}
+ records = {}
+ for key, value in summary.items():
+ match = re.fullmatch(r"Suite_Name:\s*(.*?)\s*:\s*(.*?)_compliance", key)
+ if match:
+ requirement, suite = match.groups()
+ records[identity(suite)] = {"suite": suite, "requirement": requirement,
+ "value": str(value)}
+ return records
+
+
+def _record_names(suite):
+ names = [suite["canonical"], suite.get("requirement_key", "")]
+ if suite["canonical"] in ("FWTS", "SCT"):
+ names.extend(prefix + "-" + suite["canonical"] for prefix in ("EBBR", "SBBR"))
+ if suite["canonical"] == "OS-TESTS":
+ names.extend(("OS_TEST", "OS Tests"))
+ return [identity(name) for name in names]
+
+
+def _counts(raw):
+ """Normalize counter names so JSON and chart labels can be compared."""
+ aliases = {"totalrulesrun": "total", "totaltests": "total", "total": "total",
+ "failedwithwaiver": "failedwithwaiver"}
+ result = {}
+ summary = raw.get("suite_summary", {})
+ if not isinstance(summary, dict):
+ return result
+ for key, value in summary.items():
+ name = identity(key).lower()
+ name = aliases.get(name, name[5:] if name.startswith("total") else name)
+ if isinstance(value, (int, float)) and not isinstance(value, bool) and math.isfinite(value):
+ result[name] = value
+ return result
+
+
+def _chart_counts(table):
+ result = {}
+ for row in table["rows"]:
+ if len(row) == 2 and re.fullmatch(r"\d[\d,]*", row[1]):
+ name = identity(row[0]).lower()
+ result["total" if name in ("totaltests", "totalrulesrun") else name] = int(
+ row[1].replace(",", ""))
+ return result
+
+
+def _result_payload(value):
+ """Keep result and waiver data, excluding metadata added during merging."""
+ enriched = {"Waivable", "SRS scope", "Test_suite_info", "Main Readiness Grouping"}
+ if isinstance(value, dict):
+ return {key: _result_payload(child) for key, child in value.items() if key not in enriched}
+ if isinstance(value, list):
+ return [_result_payload(child) for child in value]
+ return value
+
+
+def _json_inventory(values):
+ return Counter(json.dumps(_result_payload(value), sort_keys=True, ensure_ascii=True)
+ for value in values)
+
+
+def _result_entries(data):
+ """Do not iterate malformed result collections as if they were test records."""
+ value = data.get("test_results", [])
+ return value if isinstance(value, list) else None
+
+
+def _first_difference(expected, actual, path=""):
+ """Point to the first changed JSON field without changing either input."""
+ if type(expected) is not type(actual):
+ return {"path": path or "/", "expected": type(expected).__name__, "actual": type(actual).__name__}
+ if isinstance(expected, dict):
+ for key in sorted(set(expected) | set(actual)):
+ pointer = path + "/" + key.replace("~", "~0").replace("/", "~1")
+ if key not in expected or key not in actual:
+ return {"path": pointer, "expected": "Present" if key in expected else "Absent",
+ "actual": "Present" if key in actual else "Absent"}
+ different = _first_difference(expected[key], actual[key], pointer)
+ if different:
+ return different
+ elif isinstance(expected, list):
+ if len(expected) != len(actual):
+ return {"path": path, "expected": f"{len(expected)} entries", "actual": f"{len(actual)} entries"}
+ for index, (left, right) in enumerate(zip(expected, actual)):
+ different = _first_difference(left, right, path + "/" + str(index))
+ if different:
+ return different
+ elif expected != actual:
+ return {"path": path, "expected": expected, "actual": actual}
+ return None
+
+
+def _merged_parity(root, raw_files, merged, registry, issues):
+ """Check that merging preserves each raw result, not just the total counts."""
+ by_suite = {suite["canonical"]: suite for suite in registry}
+ expected = defaultdict(list)
+ merged_path = root / "acs_jsons" / "merged_results.json"
+ for canonical, items in raw_files.items():
+ suite = by_suite[canonical]
+ for path, data in items:
+ if suite.get("waiver_suite") == "Standalone":
+ destination = "Suite_Name: Standalone"
+ elif canonical == "OS-TESTS" and path.name != suite.get("json_output"):
+ destination = "Suite_Name: OS Tests - " + path.stem
+ else:
+ matches = [key for key in merged if key.startswith("Suite_Name: ")
+ and identity(key[len("Suite_Name: "):]) in _record_names(suite)]
+ if len(matches) != 1:
+ issues.append({"file": str(merged_path), "issue": "Raw suite has no unique merged section",
+ "suite": canonical, "expected": str(path), "actual": matches})
+ continue
+ destination = matches[0]
+ expected[destination].append((path, data))
+ for destination, items in expected.items():
+ actual = merged.get(destination)
+ if destination == "Suite_Name: Standalone":
+ # Standalone combines several input files into one list. Compare the
+ # records without assuming that their order stays the same.
+ collections = [_result_entries(data) for _, data in items]
+ if any(entries is None for entries in collections):
+ # The input-shape finding is kept by run_reports. This comparison
+ # cannot run, but other suites and supplied packages still can.
+ continue
+ entries = [entry for collection in collections for entry in collection]
+ equivalent = isinstance(actual, list) and _json_inventory(
+ entries) == _json_inventory(actual)
+ else:
+ # OS distributions have separate sections; duplicate non-aggregate producers
+ # are ambiguous, never silently overwritten by the last filename.
+ equivalent = len(items) == 1 and _result_payload(items[0][1]) == _result_payload(actual)
+ if not equivalent:
+ difference = (_first_difference(_result_payload(items[0][1]), _result_payload(actual))
+ if len(items) == 1 and destination != "Suite_Name: Standalone" else None)
+ issues.append({"file": str(merged_path), "issue": "Raw and merged result records differ",
+ "suite": destination, "expected": "Identical identities, nested results, statuses and waiver evidence",
+ "actual": difference or "Missing, extra or changed records; compare raw files " +
+ ", ".join(path.name for path, _ in items)})
+ expected_names = set(expected)
+ for destination in sorted(set(merged) - {"Suite_Name: acs_info"} - expected_names):
+ # Report stale/unregistered result sections even if the suite counters happen to match.
+ issues.append({"file": str(merged_path), "issue": "Merged result section has no matching raw input",
+ "suite": destination, "expected": "Every result section is traceable to current raw JSON",
+ "actual": destination})
+
+
+def _local_links(path, parsed, root, documents, issues, coverage):
+ """Check local files and anchors; report links outside the package as unchecked."""
+ for anchor, count in sorted(parsed.ids.items()):
+ if count > 1:
+ issues.append({"file": str(path), "issue": "Duplicate HTML element ID",
+ "expected": "One unique element", "actual": {"id": anchor, "count": count}})
+ for link in sorted(set(parsed.links)):
+ try:
+ target = urlsplit(link)
+ if target.scheme or target.netloc:
+ continue # Never fetch remote content or execute a URL.
+ destination = (path.parent / unquote(target.path)
+ ).resolve() if target.path else path.resolve()
+ if root != destination and root not in destination.parents:
+ coverage.append(
+ path.name + ": link outside supplied package not inspected: " + link)
+ continue
+ if not destination.is_file() or not destination.stat().st_size:
+ issues.append({"file": str(path), "issue": "Broken local HTML link",
+ "expected": "A non-empty local file", "actual": link})
+ continue
+ if target.fragment:
+ if destination.suffix.lower() not in (".html", ".htm"):
+ coverage.append(path.name + ": non-HTML fragment not inspected: " + link)
+ continue
+ if destination not in documents:
+ documents[destination] = ReportHTML(destination.read_text(encoding="utf-8"))
+ document = documents[destination]
+ anchor = unquote(target.fragment)
+ if document.ids[anchor] != 1 and anchor not in document.anchors:
+ issues.append({"file": str(path), "issue": "Broken local HTML fragment",
+ "expected": "Exactly one local anchor", "actual": link})
+ except (OSError, ValueError, UnicodeError) as error:
+ issues.append({"file": str(path), "issue": "Local HTML link could not be inspected",
+ "actual": link + ": " + str(error)})
+
+
+def _status(value):
+ token = identity(value)
+ aliases = {"PASS": "PASSED", "FAIL": "FAILED", "WARNING": "WARNINGS",
+ "SKIP": "SKIPPED", "ABORT": "ABORTED", "WAIVED": "FAILEDWITHWAIVER",
+ "FAILWITHWAIVER": "FAILEDWITHWAIVER", "TESTNOTIMPLEMENTED": "NOTIMPLEMENTED",
+ "NOTTESTEDTESTNOTIMPLEMENTED": "NOTIMPLEMENTED",
+ "NOTTESTEDPALNOTSUPPORTED": "PALNOTSUPPORTED"}
+ if token.startswith("KNOWN") and token.endswith("LIMITATION"):
+ return "IGNORED"
+ return aliases.get(token, token)
+
+
+def _display_status(value, renderer):
+ if not isinstance(value, dict):
+ return _status(value)
+ positive = {_status(key) for key, count in value.items()
+ if isinstance(count, (int, float)) and not isinstance(count, bool) and count > 0}
+ if not positive:
+ return "INFO" if renderer.endswith("os_tests/json_to_html.py") else "UNKNOWN"
+ order = ["PASSED", "FAILEDWITHWAIVER", "FAILED", "ABORTED", "SKIPPED", "WARNINGS",
+ "IGNORED", "PASSEDPARTIAL", "NOTIMPLEMENTED", "PALNOTSUPPORTED", "NOTTESTED"]
+ if renderer.endswith("bbr/fwts/json_to_html.py"):
+ order[:3] = ["FAILED", "PASSED", "FAILEDWITHWAIVER"]
+ elif renderer.endswith(("post_script/json_to_html.py", "os_tests/json_to_html.py")):
+ order[:3] = ["PASSED", "FAILED", "FAILEDWITHWAIVER"]
+ return next((status for status in order if status in positive), "UNKNOWN")
+
+
+def _raw_detail_records(value, renderer):
+ """Build expected visible rows from raw results without calling the renderer.
+
+ BSA displays parent and child results. Other supported pages display the
+ deepest result rows, with a parent used only when it has no result children.
+ """
+ records = []
+ def visit(node, position=None):
+ if isinstance(node, list):
+ for index, child in enumerate(node, 1):
+ visit(child, index)
+ elif isinstance(node, dict):
+ fields = {identity(key): child for key, child in node.items()}
+ result_keys = [key for key in fields if key in ("TESTRESULT", "SUBTESTRESULT")]
+ before = len(records)
+ for key, child in node.items():
+ if identity(key) not in result_keys:
+ visit(child)
+ if not result_keys or (len(records) != before and not renderer.endswith("bsa/json_to_html.py")):
+ return
+ def field(names):
+ return next((" ".join(str(fields[name]).split()) for name in names
+ if fields.get(name) not in (None, "")), "")
+ identifier = field(("SUBTESTGUID", "SUBTESTNUMBER", "TESTCASENUMBER",
+ "TESTNUMBER", "TESTID", "TESTCASE", "GUID", "ID"))
+ if renderer.endswith("bbr/tpm/json_to_html.py"):
+ identifier = str(position)
+ if not identifier:
+ raise ValueError("Result record lacks a stable visible ID: " + ", ".join(node))
+ description = field(("SUBTESTDESCRIPTION", "TESTCASEDESCRIPTION",
+ "TESTDESCRIPTION", "DESCRIPTION", "NAME"))
+ records.append((identifier, description, _display_status(
+ fields[result_keys[0]], renderer)))
+ visit(value)
+ return Counter(records)
+
+
+def _html_detail_records(parsed, sct_headings=False):
+ """Read displayed IDs, descriptions and statuses, including SCT parent headings."""
+ records, tables = [], 0
+ populated_tables = set()
+ for table in (table for table in parsed.tables if table["kind"] == "detail"):
+ columns = None
+ for row in table["cells"]:
+ if any(cell["tag"] == "th" for cell in row):
+ headers = [identity(cell["text"]) for cell in row]
+ results = [i for i, name in enumerate(headers) if name in (
+ "TESTRESULT", "SUBTESTRESULT", "RESULT", "STATUS", "OUTCOME")]
+ if not results:
+ continue
+ ids = [i for i, name in enumerate(headers) if name in ("TESTCASE", "SUBTEST", "TEST", "ID", "GUID", "SUBTESTGUID")
+ or name.endswith("NUMBER") or "#" in row[i]["text"]]
+ descriptions = [i for i, name in enumerate(
+ headers) if "DESCRIPTION" in name or name == "NAME"]
+ if len(ids) > 1:
+ ids = [i for i in ids if "GUID" in headers[i]]
+ if len(results) != 1 or len(ids) != 1 or len(descriptions) != 1:
+ raise ValueError("Ambiguous result table columns: " + ", ".join(headers))
+ columns = ids[0], descriptions[0], results[0]
+ tables += 1
+ elif columns and row:
+ if len(row) == 1 and row[0]["nested"]:
+ continue
+ if max(columns) >= len(row):
+ raise ValueError("Result row is missing ID, description or status cells")
+ records.append((row[columns[0]]["text"], row[columns[1]]
+ ["text"], _status(row[columns[2]]["text"])))
+ populated_tables.add(id(table))
+ if sct_headings:
+ for heading in parsed.detail_headings:
+ # SCT renders a parent result in headings, and child outcomes in the
+ # following table. Count the parent only when that table has no rows.
+ if not any(id(table) in populated_tables for table in heading["tables"]):
+ records.append((heading["id"], heading["description"], _status(heading["status"])))
+ tables += 1
+ return Counter(records), tables
+
+
+def _detail_parity(path, parsed, raw_files, registry, issues, coverage):
+ """Report missing or changed result rows between raw JSON and detailed HTML."""
+ suites = [suite for suite in registry if suite.get("detailed_html") == path.name
+ and suite["canonical"] in raw_files]
+ if path.name == "sbmr_detailed.html":
+ suites = [suite for suite in registry if suite["canonical"] in ("SBMR-IB", "SBMR-OOB")
+ and suite["canonical"] in raw_files]
+ if not suites:
+ return
+ try:
+ expected = Counter()
+ for suite in suites:
+ for _, data in raw_files[suite["canonical"]]:
+ expected.update(_raw_detail_records(data, suite.get("json_to_html", "")))
+ actual, tables = _html_detail_records(parsed, sct_headings=all(
+ suite.get("json_to_html", "").endswith("bbr/sct/json_to_html.py") for suite in suites))
+ if expected and not tables:
+ issues.append({"file": str(path), "issue": "Detailed result rows are missing",
+ "expected": sum(expected.values()), "actual": 0})
+ elif expected != actual:
+ issues.append({"file": str(path), "issue": "Raw and detailed HTML result identities differ",
+ "expected": {"missing": list((expected - actual).elements())[:10]},
+ "actual": {"extra_or_changed": list((actual - expected).elements())[:10]}})
+ except ValueError as error:
+ issues.append({"file": str(path), "issue": "Detailed identity comparison could not execute",
+ "blocked": True, "expected": "A supported unambiguous result-row identity contract",
+ "actual": str(error)})
+
+
+def _raw_integrity(path, data, record, issues, sr_os=False):
+ """Check counter totals and flag clear contradictions with suite compliance."""
+ counts = _counts(data)
+ categories = {"passed", "failed", "failedwithwaiver", "aborted", "skipped",
+ "warnings", "passedpartial", "notimplemented", "palnotsupported", "ignored"}
+ summary = data.get("suite_summary", {})
+ for name, value in summary.items() if isinstance(summary, dict) else []:
+ if (not isinstance(value, (int, float)) or isinstance(value, bool) or
+ not math.isfinite(value) or value < 0 or int(value) != value):
+ issues.append({"file": str(path), "issue": "Invalid suite counter", "count": name,
+ "expected": "A non-negative whole number", "actual": value})
+ if "total" in counts and set(counts) <= categories | {"total"}:
+ summed = sum(value for key, value in counts.items() if key != "total")
+ if summed != counts["total"]:
+ issues.append({"file": str(path), "issue": "Suite categories do not sum to declared total",
+ "expected": counts["total"], "actual": summed})
+ def unknown(node):
+ if isinstance(node, dict):
+ for key, value in node.items():
+ if key.lower() in ("test_result", "sub_test_result") and value == "UNKNOWN":
+ return True
+ if unknown(value):
+ return True
+ elif isinstance(node, list):
+ return any(unknown(value) for value in node)
+ return False
+ if record and decision(record["value"]).startswith("Compliant") and unknown(data):
+ issues.append({"file": str(path), "issue": "UNKNOWN result is reported as compliant",
+ "expected": "Unknown execution evidence must not silently become success",
+ "actual": record["value"]})
+ if record and decision(record["value"]).startswith("Compliant"):
+ if data.get("test_results") == []:
+ issues.append({"file": str(path), "issue": "Empty execution evidence is reported as compliant",
+ "actual": record["value"]})
+ if counts.get("failed", 0) > 0 and not sr_os:
+ issues.append({"file": str(path), "issue": "Unwaived suite failures are reported as compliant",
+ "expected": "Not Compliant at suite level; Recommended may remain non-blocking "
+ "overall",
+ "actual": {"failed": counts["failed"], "compliance": record["value"]}})
+
+
+def _aggregate(records):
+ """Calculate the expected combined display badge, not overall SRS compliance."""
+ mandatory = [r for r in records if r["requirement"] in (
+ "Mandatory", "Conditional-Mandatory")]
+ relevant = mandatory or records
+ requirements = sorted({r["requirement"] for r in relevant})
+ requirement = "Mandatory" if "Mandatory" in requirements else " / ".join(requirements)
+ if all("not run" in r["value"].lower() for r in records):
+ status = "Not Run"
+ elif any(decision(r["value"]) == "Not Compliant" for r in relevant):
+ status = "Not Compliant"
+ elif any(decision(r["value"]) == "Unknown" for r in relevant):
+ status = "Unknown"
+ elif any(decision(r["value"]) == "Compliant with waivers" for r in relevant):
+ status = "Compliant with waivers"
+ else:
+ status = "Compliant"
+ return requirement + " (" + status + ")"
+
+
+def _inspect_html(path, parsed, records, raw_by_suite, registry, issues, coverage,
+ overall=None):
+ """Compare HTML compliance with merged JSON and chart totals with raw JSON."""
+ if path.name == "acs_summary.html" and overall is not None:
+ # Compare the displayed SRS decision, not a suite badge or extension's
+ # verdict. The report may omit the explanatory suffix after the decision.
+ displayed = [row[1] for table in parsed.tables for row in table["rows"]
+ if len(row) >= 2 and identity(row[0]) == "SRSREQUIREMENTSCOMPLIANCERESULTS"]
+ if len(displayed) != 1:
+ issues.append({"file": str(path), "issue": "Main HTML overall compliance verdict is missing or ambiguous",
+ "expected": decision(overall), "actual": displayed})
+ elif decision(displayed[0]) != decision(overall):
+ issues.append({"file": str(path), "issue": "Overall HTML compliance differs from merged JSON",
+ "expected": decision(overall), "actual": displayed[0]})
+ aliases = {name: record for suite in registry for name in _record_names(suite)
+ for key, record in records.items() if key in _record_names(suite)}
+ aliases.update(records)
+ detail_rows = [row for table in parsed.tables if table["kind"] == "compliance"
+ for row in table["rows"] if len(row) == 3 and row[1] != "Requirement"]
+ for name, requirement, status in detail_rows:
+ record = aliases.get(identity(name))
+ if record is None:
+ coverage.append(str(path.name) + ": unmapped compliance row " + name)
+ elif (identity(requirement), decision(status), "not run" in status.lower()) != (
+ identity(record["requirement"]), decision(record["value"]),
+ "not run" in record["value"].lower()):
+ issues.append({"file": str(path), "issue": "Detail compliance differs from merged JSON",
+ "suite": name, "expected": record, "actual": [requirement, status]})
+ if path.name == "sbmr_detailed.html":
+ expected_rows = {key for key in ("SBMRIB", "SBMROOB") if key in records}
+ elif path.name == "standalone_tests_detailed.html":
+ expected_rows = {name for suite in registry if suite.get("waiver_suite") == "Standalone"
+ for name in _record_names(suite) if name in records and (
+ suite["canonical"] in raw_by_suite or (
+ records[name]["requirement"] == "Mandatory" and
+ "not run" in records[name]["value"].lower()))}
+ else:
+ expected_rows = set()
+ present_rows = {identity(row[0]) for row in detail_rows}
+ present_rows.update(identity(aliases[name]["suite"])
+ for name in list(present_rows) if name in aliases)
+ for missing in sorted(expected_rows - present_rows):
+ issues.append({"file": str(path), "issue": "Applicable compliance row is missing",
+ "expected": records[missing], "actual": "No row for " + records[missing]["suite"]})
+ if path.name.endswith("_detailed.html") and not detail_rows:
+ issues.append({"file": str(path), "issue": "Detailed report has no compliance rows"})
+ if path.name == "acs_summary.html" and records and not parsed.badges:
+ issues.append({"file": str(path), "issue": "Main report has no suite compliance badges"})
+ for badge in parsed.badges:
+ names = re.findall(r"(?:^|; )([^:;]+): (?:Mandatory|Recommended|Extension|Conditional-Mandatory)\s*\(",
+ badge["context"])
+ rows = [aliases[identity(name)] for name in names if identity(name) in aliases]
+ if len(rows) != len(names) or not rows:
+ coverage.append(path.name + ": unmapped summary badge " + badge["card"])
+ elif badge["text"] != _aggregate(rows):
+ issues.append({"file": str(path), "issue": "Summary badge differs from merged JSON",
+ "card": badge["card"], "expected": _aggregate(rows), "actual": badge["text"]})
+ for table in (table for table in parsed.tables if table["kind"] == "counts"):
+ filename = table["card"] + ".html" if table["card"] else path.name
+ suites = [s for s in registry if filename in (s.get("summary_html"), s.get("detailed_html"))
+ and s["canonical"] in raw_by_suite]
+ if filename in ("sbmr_summary.html", "sbmr_detailed.html"):
+ suites = [s for s in registry if s["canonical"] in ("SBMR-IB", "SBMR-OOB")
+ and s["canonical"] in raw_by_suite]
+ if not suites or any(s.get("waiver_suite") == "Standalone" or
+ s["canonical"] == "OS-TESTS" for s in suites):
+ coverage.append(path.name + ": aggregate/unmapped chart " + filename)
+ continue
+ expected = Counter()
+ for suite in suites:
+ counts = _counts(raw_by_suite[suite["canonical"]])
+ # Most producers store status counters only; HTML derives its Total
+ # Tests row from those counters rather than a missing JSON total=0.
+ categories = {"passed", "failed", "failedwithwaiver", "aborted", "skipped",
+ "warnings", "passedpartial", "notimplemented", "palnotsupported", "ignored"}
+ if counts and "total" not in counts and set(counts) <= categories:
+ counts["total"] = sum(counts.values())
+ # The SBMR renderer has no Ignored row. Its schema includes the
+ # unused zero counter; a nonzero value must still be reported.
+ if suite["canonical"] in ("SBMR-IB", "SBMR-OOB") and counts.get("ignored") == 0:
+ counts.pop("ignored")
+ expected.update(counts)
+ actual = _chart_counts(table)
+ if not actual or not expected:
+ coverage.append(path.name + ": no comparable suite-summary counts " + filename)
+ continue
+ for key in sorted(set(expected) | set(actual)):
+ value = expected.get(key, 0)
+ if (key in expected and key not in actual) or actual.get(key, 0) != value:
+ issues.append({"file": str(path), "issue": "Chart differs from raw suite summary",
+ "chart": filename, "count": key, "expected": value,
+ "actual": actual.get(key, "Missing chart category")})
+
+
+def run_reports(ctx):
+ """Inspect user-supplied reports and save findings in Doctor's output folder."""
+ if not ctx.report_inputs:
+ ctx.add("ARTIFACT.INPUT", "WARN", "Real-capture artifact checks were not run",
+ "Supply --doctor-report DT=/path or SR=/path to a report package",
+ "No report input supplied; synthetic probes are separate")
+ return
+ from validate import _build_file_schema_index, _find_schema_for_file
+ from suite_registry import load_registry
+ registry = load_registry(ctx.parser_dir / "suite_registry.json")
+ exact, patterns = _build_file_schema_index(registry, ctx.parser_dir / "suite_registry.json")
+ for index, (mode, supplied) in enumerate(ctx.report_inputs):
+ if mode not in ctx.modes:
+ continue
+ root = Path(supplied).resolve()
+ if not (root / "acs_jsons").is_dir() and (root / "acs_summary" / "acs_jsons").is_dir():
+ root = root / "acs_summary"
+ evidence_dir = ctx.case_dir("artifacts/" + str(index) + "_" + mode)
+ issue_file = evidence_dir / "issues.json"
+ issues, coverage, raw, merged, json_count = [], [], {}, None, 0
+ provenance = category_provenance(root, mode)
+ schema_checks = []
+ if provenance["invalid"]:
+ issues.append({"file": provenance["manifest"], "issue": "Invalid category provenance",
+ "actual": provenance["message"]})
+ raw_files = defaultdict(list)
+ json_dir = root / "acs_jsons"
+ if not json_dir.is_dir():
+ ctx.add("ARTIFACT.INPUT", "BLOCKED", "Report JSON directory is missing",
+ "A report package containing acs_jsons/merged_results.json", str(root), mode)
+ continue
+ for path in sorted(json_dir.glob("*.json")):
+ # Even an in-package filename can point outside the package through a
+ # symlink. Do not follow those links into unrelated user data.
+ if root not in path.resolve().parents:
+ issues.append({"file": str(path), "issue": "Report input escapes supplied package",
+ "actual": "External symlink target was not read"})
+ continue
+ info = _find_schema_for_file(path, exact, patterns)
+ is_merged = path.name == "merged_results.json"
+ if not info and not is_merged:
+ if path.name not in ("acs_info.json", "edk2_test_parser.json"):
+ coverage.append("No registered raw schema for " + path.name)
+ continue
+ json_count += 1
+ schema_path = (ctx.parser_dir / "acs-results-schema.json"
+ if is_merged else info["schema"])
+ fragment = "" if is_merged else info["schema_fragment"]
+ try:
+ data = _strict_json(path)
+ if not isinstance(data, dict):
+ raise ValueError("Expected a JSON object, got " + type(data).__name__)
+ except (OSError, ValueError) as error:
+ issues.append(
+ {"file": str(path), "issue": "Malformed report JSON", "actual": str(error)})
+ continue
+ try:
+ evaluation = evaluate_schema(schema_path, fragment, data, provenance)
+ errors = evaluation["errors"]
+ schema_checks.append({"file": str(path), "strict_error_count": evaluation["strict_error_count"],
+ "applicable_error_count": len(errors),
+ "omitted_missing_info_paths": evaluation["omitted_missing_info_paths"]})
+ if errors:
+ issues.append({"file": str(path), "issue": "JSON schema validation failed",
+ "schema": str(schema_path) + fragment, "errors": errors})
+ except Exception as error: # A broken schema must not suppress the other supplied checks.
+ issues.append({"file": str(path), "issue": "Schema validation could not execute",
+ "actual": str(error)})
+ if is_merged:
+ merged = data
+ else:
+ if _result_entries(data) is None:
+ issues.append({"file": str(path), "issue": "Invalid result collection",
+ "suite": info["canonical"], "expected": "test_results is an array of test records",
+ "actual": "test_results is " + type(data["test_results"]).__name__})
+ raw_files[info["canonical"]].append((path, data))
+ # Charts need combined counts, while exact parity retains every input file.
+ for canonical, items in raw_files.items():
+ if len(items) == 1:
+ raw[canonical] = items[0][1]
+ else:
+ counters = Counter()
+ entries = []
+ for _, data in items:
+ counters.update(_counts(data))
+ values = _result_entries(data)
+ if values is not None:
+ entries.extend(values)
+ raw[canonical] = {"suite_summary": dict(counters), "test_results": entries}
+ if merged is None:
+ issues.append({"file": str(json_dir / "merged_results.json"),
+ "issue": "Merged JSON is missing or unreadable"})
+ if not raw:
+ issues.append(
+ {"file": str(json_dir), "issue": "No readable registered raw suite JSON found"})
+ if merged is not None:
+ _merged_parity(root, raw_files, merged, registry, issues)
+ records = _records(merged or {})
+ info = (merged or {}).get("Suite_Name: acs_info", {})
+ results = info.get("ACS Results Summary", {}) if isinstance(info, dict) else {}
+ band = str(results.get("Band", "")) if isinstance(results, dict) else ""
+ detected_mode = "DT" if "devicetree" in band.lower() else "SR" if band == "SystemReady band" else mode
+ if detected_mode != mode:
+ issues.append({"file": str(json_dir / "merged_results.json"), "issue": "Supplied mode does not match report band",
+ "expected": mode, "actual": band})
+ if not records:
+ issues.append({"file": str(json_dir / "merged_results.json"),
+ "issue": "No run-specific compliance decisions found"})
+ html_dir = root / "html_detailed_summaries"
+ for suite in registry:
+ canonical = suite["canonical"]
+ if canonical not in raw:
+ continue
+ record = next((records[name] for name in _record_names(suite) if name in records), None)
+ for source, data in raw_files[canonical]:
+ _raw_integrity(source, data, record, issues,
+ sr_os=detected_mode == "SR" and canonical == "OS-TESTS")
+ detail = suite.get("detailed_html", "")
+ if canonical.startswith("SBMR-") and (html_dir / "sbmr_detailed.html").is_file():
+ detail = "sbmr_detailed.html"
+ if detail and raw[canonical].get("test_results") and not (html_dir / detail).is_file():
+ issues.append({"file": str(html_dir / detail), "issue": "Detailed HTML for collected results is missing",
+ "suite": canonical})
+ merged_suite = next((value for key, value in (merged or {}).items()
+ if key.startswith("Suite_Name: ") and
+ identity(key[len("Suite_Name: "):]) in _record_names(suite)), None)
+ if isinstance(merged_suite, dict) and _counts(raw[canonical]) != _counts(merged_suite):
+ issues.append({"file": str(source), "issue": "Raw and merged suite counters differ",
+ "suite": canonical, "expected": _counts(raw[canonical]),
+ "actual": _counts(merged_suite)})
+ pages = list(sorted(html_dir.glob("*.html")))
+ if not (html_dir / "acs_summary.html").is_file():
+ issues.append({"file": str(html_dir / "acs_summary.html"),
+ "issue": "Main HTML report is missing"})
+ documents = {}
+ for path in pages:
+ try:
+ if root not in path.resolve().parents:
+ issues.append({"file": str(path), "issue": "Report input escapes supplied package",
+ "actual": "External HTML symlink target was not read"})
+ continue
+ parsed = ReportHTML(path.read_text(encoding="utf-8"))
+ documents[path.resolve()] = parsed
+ _inspect_html(path, parsed, records, raw, registry, issues, coverage,
+ overall=results.get("Overall Compliance Result") if isinstance(results, dict) else None)
+ _detail_parity(path, parsed, raw_files, registry, issues, coverage)
+ _local_links(path, parsed, root, documents, issues, coverage)
+ except (OSError, ValueError, TypeError, AttributeError) as error:
+ issues.append(
+ {"file": str(path), "issue": "HTML could not be inspected", "actual": str(error)})
+ issue_file.write_text(json.dumps({"source": str(root), "mode": mode,
+ "not_checked": ["Browser rendering, PDF output, external URLs and JavaScript-created "
+ "anchors",
+ "Standalone component chart totals and multi-file OS aggregate chart "
+ "totals"],
+ "issues": issues, "coverage_gaps": sorted(set(coverage)),
+ "category_provenance": provenance, "schema_policy_checks": schema_checks}, indent=2) + "\n", encoding="utf-8")
+ for item in issues:
+ # Keep each concrete issue separate. The package-level result below is
+ # only a summary and must not be mistaken for another distinct bug.
+ if item["issue"] == "JSON schema validation failed":
+ first = item["errors"][0]
+ ctx.add("ARTIFACT.SCHEMA", "FAIL", Path(item["file"]).name + " violates applicable Doctor schema checks",
+ "Registered schema; missing Test_suite_info is required only for an "
+ "explicitly supplied category",
+ f'{first["path"]}: {first["message"][:220]}; {len(item["errors"])} error records in evidence',
+ mode, evidence=[issue_file])
+ elif item["issue"] != "Schema validation could not execute":
+ category = ("CATEGORY_PROVENANCE" if item["issue"] == "Invalid category provenance" else
+ "JSON" if "JSON" in item["issue"] else "PARITY" if "record" in item["issue"].lower()
+ or "identit" in item["issue"].lower() else "HTML" if "HTML" in item["issue"] else "DATA")
+ ctx.add("ARTIFACT." + category, "BLOCKED" if item.get("blocked") else "FAIL",
+ item["issue"] + ": " + Path(item["file"]).name,
+ item.get("expected", "Consistent current-run report artifacts"),
+ item.get("actual", item.get("suite", "See evidence for the discrepancy")),
+ mode, suite=item.get("suite", ""), evidence=[issue_file])
+ schema_blocked = [item for item in issues if item["issue"]
+ == "Schema validation could not execute"]
+ blocked = schema_blocked + [item for item in issues if item.get("blocked")]
+ for item in schema_blocked:
+ ctx.add("ARTIFACT.SCHEMA", "BLOCKED", "Schema evaluator could not check " + Path(item["file"]).name,
+ "The registered schema loads and validation completes", item["actual"], mode, evidence=[issue_file])
+ counts = Counter(issue["issue"] for issue in issues)
+ omitted_files = [
+ Path(check["file"]).name for check in schema_checks if check["omitted_missing_info_paths"]]
+ if provenance["source"] == "unknown" and omitted_files:
+ ctx.add("ARTIFACT.CATEGORY_PROVENANCE", "WARN", "Missing Test_suite_info could not be attributed to a supplied category",
+ "Verified generating-run category provenance for this conditional requirement",
+ provenance["message"] + "; missing-info requirement not applied in " +
+ ", ".join(omitted_files)
+ + "; all other schema checks remain active", mode, evidence=[issue_file])
+ verdict = "FAIL" if len(issues) > len(blocked) else "BLOCKED" if blocked else "PASS"
+ ctx.add("ARTIFACT.CONSISTENCY", verdict,
+ "Supplied report package has correctness problems" if issues else "Supplied static report checks agree",
+ "Strict JSON, applicable Doctor schema checks, raw/merged identities, "
+ "HTML decisions/counts/rows, and local links/anchors",
+ f"{json_count} JSON files, {len(pages)} HTML pages; " + (
+ "; ".join(f"{name}: {count}" for name, count in counts.items()) or "no discrepancies"),
+ mode, evidence=[issue_file])
+ if coverage:
+ ctx.add("ARTIFACT.COVERAGE", "WARN", "Some artifact comparisons could not be safely evaluated",
+ "Explicit count units and a registered schema/display mapping",
+ "; ".join(sorted(set(coverage))[:5]) +
+ f"; {len(set(coverage))} coverage notes in evidence",
+ mode, evidence=[issue_file])
+
+
+# ---------------------------------------------------------------------------
+# Optionally check browser controls and PDF content using Doctor's sample reports.
+# ---------------------------------------------------------------------------
+
+FWTS_LOG = """Running tests: uefirtmisc
+====================
+uefirtmisc: Doctor interface checks
+Test 1 of 2: Doctor passing interface
+PASSED: Test 1, Doctor passed
+Test 2 of 2: Doctor failing interface
+FAILED [HIGH] Doctor failed
+"""
+OUTCOMES = {"pass": (2, 0, 0, "Compliant"),
+ "fail": (1, 1, 0, "Not Compliant"),
+ "waived": (1, 0, 1, "Compliant with waivers")}
+
+# Check what a report reader sees and clicks; do not call private renderer helpers.
+BROWSER_ASSERTIONS = r""""""
+
+
+def browser_result(output):
+ """Read the browser's check results; a missing result is not a passing check."""
+ match = re.search(r'
(.*?)
', output, re.DOTALL)
+ if not match:
+ raise ValueError("Browser exited without running the report assertions")
+ data = json.loads(html.unescape(match.group(1)))
+ if (not isinstance(data, dict) or type(data.get("checks")) is not int or
+ data["checks"] < 4 or not isinstance(data.get("failures"), list)):
+ raise ValueError("Incomplete browser assertions: " + str(data))
+ return data
+
+
+def pdf_problems(text, prefix, outcome):
+ """Check expected suite names, compliance and counters in extracted PDF text."""
+ passed, failed, waived, compliance = OUTCOMES[outcome]
+ text = " ".join(text.split())
+ issues = []
+ if not re.search(r"(?window.doctorErrors=[];window.addEventListener("error",function(e){'
+ 'window.doctorErrors.push(e.message);});window.addEventListener("unhandledrejection",'
+ 'function(e){window.doctorErrors.push(String(e.reason));});')
+ content = re.sub(r"]*>", lambda match: match.group(0) +
+ capture, content, count=1, flags=re.I)
+ content = re.sub(r"", lambda _: BROWSER_ASSERTIONS +
+ "