In this section
- Acid Live test · globalgrid2050 / automation/news/tests/acid_live.py lines 1–371
- Acid Report test · globalgrid2050 / automation/news/tests/acid_report.py lines 1–122
- Compare Legacy Collector test · globalgrid2050 / automation/news/tests/compare_legacy_collector.py lines 1–123
Acid Live
A Python command-line tool in the tests folder of GlobalGrid2050 that tests project signals, the Renewable Energy Planning Database (REPD) register and solar.
testglobalgrid2050 / automation/news/tests/acid_live.py · lines 1–371 of 371 · Entry point · pattern parse_day (shared by 2 files)
- What it does
- It tests project signals, the REPD register and solar. Defines 11 functions or classes, including parse_stamp, parse_day, is_v2, lists_of, shown. Uses libraries __future__, argparse, datetime, json, re. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. Domain terms in the code: the REPD register, solar.
- Inputs & outputs
- In: JSON file project_signals.json; command-line arguments.
- Downstream impact
- Used directly by 2 files: Test Signals Acid (globalgrid2050); GlobalGrid2050 Project Signals Acid Workflow (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 Agent1 Producer Strict Workflow (globalgrid2050); GlobalGrid2050 Pipeline Project Evidence Weekly Workflow (globalgrid2050).
- What it achieves
- It parses stamp (`parse_stamp`) and parses day (`parse_day`). Acid check of a published `dist/project_signals.json` (the real file, or one a test built). It accepts `--now`, `--summary` and `--source`.
- Why it matters
- Run by GlobalGrid2050 Project Signals Acid Workflow. Checked by Test Signals Acid.
- Application
- globalgrid2050 · automation/news/tests · Python CLI
- Uses
- __future__, argparse, datetime, json, re, sys, pathlib
- Used by
- imported by Test Signals Acid (import), run by GlobalGrid2050 Project Signals Acid Workflow (workflow run)
- Produces
- parse_stamp, parse_day, is_v2, lists_of, shown, tier_of, check, failures, report, main
- Defines here
- parse_stamp, parse_day, is_v2, lists_of, shown, tier_of, _schema, check, failures, report, main
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 automation/news/tests/acid_live.py:1-371 · blob 48759440eb4d4032d5af529d37d3e4751e07d6a2 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Acid check of a published dist/project_signals.json (the real file, or one a test built).
python automation/news/tests/acid_live.py dist/project_signals.json [--now 2026-11-14T12:00:00Z] [--summary FILE]
Rules (each is reported by name; the exit code is 1 when any fails):
schema the file is project-signals.v2 with the keys and value sets of the contract
nothing no project is left with neither an item nor a planning file, and the count says 0
repd-9050 no item on REPD 9050 whose title lacks "solar"
undated-order in every list an undated item is never above a dated one, and dates run newest first
tier-counts the counts by tier are what the items give when counted again, and sum to the 200
tier-purity recent_news holds only publisher items dated within the recent window; no list mixes tiers
dates every date is a real calendar date, not after the day following the run
generated-at generated_at is not older than two days, unless the file and its parts say stale;
and it is never later than the newest successful collection it reports
A version 1 file is read too (its one "signals" list is checked for order, dates and REPD 9050), and fails the
rules it cannot meet by construction (schema, tier-counts, tier-purity). No network; standard library only.
"""
from __future__ import annotations
import argparse
import datetime as dt
import json
import re
import sys
from pathlib import Path
V2 = "project-signals.v2"
LISTS = ("recent_news", "official", "archive")
TIERS = ("recent_news", "official", "archive_only", "planning_file_only", "nothing")
NEWS_FAMILIES = ("bbc", "trade", "national", "regional")
FAMILIES = ("official",) + NEWS_FAMILIES + ("developer",)
EVENTS = ("consent", "refusal", "appeal", "legal_challenge", "financial_close", "construction_start", "energisation",
"grid_connection", "sale", None)
LABELS = ("planning file (verified link)", "planning file (unverified link)", "planning register search",
"planning register finder")
PART_STATUS = ("ok", "stale", "failed", "absent")
LIVE_PARTS = ("official", "trade", "index")
MAX_AGE_DAYS = 2
RULES = ("schema", "nothing", "repd-9050", "undated-order", "tier-counts", "tier-purity", "dates", "generated-at")
def parse_stamp(value):
if not isinstance(value, str):
return None
try:
stamp = dt.datetime.fromisoformat(value.replace("Z", "+00:00"))
except ValueError:
return None
return stamp if stamp.tzinfo else stamp.replace(tzinfo=dt.timezone.utc)
def parse_day(value):
if not isinstance(value, str) or not re.fullmatch(r"\d{4}-\d{2}-\d{2}", value):
return None
try:
return dt.date.fromisoformat(value)
except ValueError:
return None
def is_v2(doc):
return isinstance(doc, dict) and doc.get("schema") == V2
def lists_of(project, v2=None):
"""{list name: [items]} for either version: the three tier lists, or version 1's single "signals"."""
if v2 is None:
v2 = any(name in project for name in LISTS)
names = LISTS if v2 else ("signals",)
return {name: [i for i in (project.get(name) or []) if isinstance(i, dict)] for name in names}
def shown(project):
"""Every item in the order a reader meets it."""
return [item for items in lists_of(project).values() for item in items]
def tier_of(project):
"""The exclusive bucket of the contract, counted from the items themselves."""
lists = lists_of(project, True)
if any(i.get("confidence") == "confirmed" for i in lists["recent_news"]):
return "recent_news"
if any(i.get("confidence") == "confirmed" for i in lists["official"]):
return "official"
if any(lists.values()):
return "archive_only"
file = project.get("planning_file")
return "planning_file_only" if isinstance(file, dict) and file.get("url") else "nothing"
def _schema(doc, fail):
if not is_v2(doc):
fail("schema is %r, not %r" % (doc.get("schema") if isinstance(doc, dict) else type(doc).__name__, V2))
return
for key, kind in (("generated_at", (str, type(None))), ("run_at", str), ("stale", bool), ("recent_days", int),
("parts", dict), ("counts", dict), ("projects", dict)):
if not isinstance(doc.get(key), kind):
fail("top level %r missing or of the wrong type" % key)
for name, part in (doc.get("parts") or {}).items():
if not isinstance(part, dict) or part.get("status") not in PART_STATUS:
fail("parts.%s.status is %r" % (name, part.get("status") if isinstance(part, dict) else part))
elif part.get("collected_at") is not None and parse_stamp(part.get("collected_at")) is None:
fail("parts.%s.collected_at is not a timestamp" % name)
counts = doc.get("counts") if isinstance(doc.get("counts"), dict) else {}
for key in ("with_signal", "with_confirmed_signal", "split", "with_signal_by_family"):
if key in counts:
fail("counts still has the mixed version 1 key %r" % key)
if not isinstance(counts.get("by_tier"), dict) or set(counts.get("by_tier") or {}) != set(TIERS):
fail("counts.by_tier must have exactly %s" % ", ".join(TIERS))
headline = counts.get("headline")
# This checker is the *new producer* publication gate, not an archival file
# viewer. Legacy published snapshots retain their bytes and historical
# checker pinned to their own source revision. A new project-signals.v2
# file must NEVER pass while claiming candidate matches are verified news.
expected_label = "projects with recent candidate news (independent evidence pending)"
if not isinstance(headline, dict) or headline.get("label") != expected_label:
fail("counts.headline.label must declare recent candidate news pending independent evidence")
for ref, project in (doc.get("projects") or {}).items():
if not isinstance(project, dict):
fail("project %s is not an object" % ref)
continue
for name in LISTS:
if not isinstance(project.get(name), list):
fail("project %s has no list %r" % (ref, name))
if project.get("tier") not in TIERS:
fail("project %s tier is %r" % (ref, project.get("tier")))
if project.get("alias_standing") not in ("confirmed", "possible"):
fail("project %s alias_standing is %r" % (ref, project.get("alias_standing")))
file = project.get("planning_file")
if not isinstance(file, dict) or file.get("label") not in LABELS or file.get("link_type") not in ("direct", "search") \
or not str(file.get("url") or "").startswith("https://"):
fail("project %s planning_file is missing, unlabelled or without an https link" % ref)
elif (file["link_type"] == "direct") != file["label"].startswith("planning file ("):
fail("project %s planning_file label %r does not agree with link_type %r" % (ref, file["label"], file["link_type"]))
elif (file["label"] == "planning file (verified link)") != (file.get("verified") is True):
fail("project %s planning_file label and 'verified' disagree" % ref)
for name, items in lists_of(project, True).items():
for item in items:
where = "project %s %s %r" % (ref, name, str(item.get("link"))[:80])
if not item.get("title") or not str(item.get("link") or "").startswith("https://"):
fail(where + ": no title or https link")
if item.get("tier") != name:
fail(where + ": tier %r in list %r" % (item.get("tier"), name))
if item.get("confidence") not in ("confirmed", "possible"):
fail(where + ": confidence %r" % item.get("confidence"))
if item.get("obtained") not in ("fetched", "reviewed"):
fail(where + ": obtained %r" % item.get("obtained"))
if item.get("source") not in LIVE_PARTS + ("reviewed",):
fail(where + ": source %r" % item.get("source"))
if item.get("family") not in FAMILIES:
fail(where + ": family %r" % item.get("family"))
if item.get("freshness") not in ("recent", "older", "undated"):
fail(where + ": freshness %r" % item.get("freshness"))
if item.get("event") not in EVENTS:
fail(where + ": event %r" % item.get("event"))
if parse_stamp(item.get("collected_at")) is None:
fail(where + ": collected_at missing")
if not item.get("basis"):
fail(where + ": no basis")
if item.get("confidence") == "confirmed" and project.get("alias_standing") != "confirmed":
fail(where + ": confirmed item under an alias that is only possible")
if len(items) > 5:
fail("project %s %s has %d items (cap 5)" % (ref, name, len(items)))
def check(doc, now=None):
"""[(rule, passed, [evidence lines])] in the order of RULES."""
found = {rule: [] for rule in RULES}
if not isinstance(doc, dict) or not isinstance(doc.get("projects"), dict):
return [(rule, False, ["the file is not a project signals file"]) for rule in RULES]
v2 = is_v2(doc)
projects = {ref: p for ref, p in doc["projects"].items() if isinstance(p, dict)}
counts = doc.get("counts") if isinstance(doc.get("counts"), dict) else {}
run_at = parse_stamp(doc.get("run_at")) or parse_stamp(now) or dt.datetime.now(dt.timezone.utc)
now_stamp = parse_stamp(now) or dt.datetime.now(dt.timezone.utc)
recent_days = doc.get("recent_days") if isinstance(doc.get("recent_days"), int) else 90
_schema(doc, found["schema"].append)
# nothing
for ref, project in projects.items():
file = project.get("planning_file")
if not shown(project) and not (isinstance(file, dict) and file.get("url")):
found["nothing"].append("project %s has neither an item nor a planning file" % ref)
said = (counts.get("by_tier") or {}).get("nothing") if v2 else counts.get("nothing")
if said != 0:
found["nothing"].append("the count of projects with nothing is %r, not 0" % said)
if not projects:
found["nothing"].append("the file has no project")
elif counts.get("projects") != len(projects):
found["nothing"].append("counts.projects is %r, the file has %d" % (counts.get("projects"), len(projects)))
# REPD 9050
for item in shown(projects.get("9050") or {}):
if "solar" not in str(item.get("title") or "").lower():
found["repd-9050"].append("REPD 9050: %r (%s)" % (item.get("title"), item.get("link")))
# order and dates
last_day = (run_at + dt.timedelta(days=1)).date()
for ref, project in projects.items():
for name, items in lists_of(project).items():
seen_undated, previous = None, None
for position, item in enumerate(items):
raw = item.get("date")
day = parse_day(raw)
if raw is not None and day is None:
found["dates"].append("project %s %s: %r is not a calendar date" % (ref, name, raw))
elif day and day > last_day:
found["dates"].append("project %s %s: %s is in the future" % (ref, name, raw))
if v2 and "year" in item:
year = item.get("year")
if day is not None and year != day.year:
found["dates"].append("project %s %s: year %r does not belong to date %r" %
(ref, name, year, raw))
elif day is None and year is not None:
# A reviewed page or URL may support a YEAR only. Do
# not upgrade it to a fabricated exact date or fresh
# news, and refuse impossible/future-year hints.
if name != "archive" or type(year) is not int or not 2005 <= year <= last_day.year:
found["dates"].append("project %s %s: invalid year-only archive hint %r" %
(ref, name, year))
if day is None:
seen_undated = seen_undated if seen_undated is not None else position
continue
if seen_undated is not None:
found["undated-order"].append("project %s %s: undated item at place %d is above %s at place %d" % (
ref, name, seen_undated + 1, raw, position + 1))
seen_undated = None # one line per run of undated items is enough
if previous and day > previous:
found["undated-order"].append("project %s %s: %s at place %d is below the older %s" % (
ref, name, raw, position + 1, previous.isoformat()))
previous = day
# tier counts, tier purity
if not v2:
found["tier-counts"].append("version 1 counts one mixed figure (with_signal %r, with_confirmed_signal %r): recent "
"news, old articles, official notices and reviewed research are not separated"
% (counts.get("with_signal"), counts.get("with_confirmed_signal")))
found["tier-purity"].append("version 1 has one list per project; items carry no tier and no freshness")
else:
by_tier = {tier: 0 for tier in TIERS}
with_ = {"with_recent_news": 0, "with_official": 0, "with_archive": 0, "with_possible_recent_news": 0}
item_counts = {name: 0 for name in LISTS}
possible_only = 0
cutoff = run_at.date() - dt.timedelta(days=recent_days)
for ref, project in projects.items():
lists = lists_of(project, True)
tier = tier_of(project)
by_tier[tier] += 1
if project.get("tier") != tier:
found["tier-counts"].append("project %s says tier %r, its items give %r" % (ref, project.get("tier"), tier))
confirmed_recent = any(i.get("confidence") == "confirmed" for i in lists["recent_news"])
with_["with_recent_news"] += confirmed_recent
with_["with_possible_recent_news"] += bool(lists["recent_news"]) and not confirmed_recent
with_["with_official"] += any(i.get("confidence") == "confirmed" for i in lists["official"])
with_["with_archive"] += bool(lists["archive"])
every = [i for items in lists.values() for i in items]
possible_only += tier == "archive_only" and all(i.get("confidence") == "possible" for i in every)
for name, items in lists.items():
item_counts[name] += len(items)
for item in items:
day, family = parse_day(item.get("date")), item.get("family")
fresh = "undated" if day is None else "recent" if day >= cutoff else "older"
where = "project %s %s %r" % (ref, name, str(item.get("link"))[:80])
if item.get("freshness") != fresh:
found["tier-purity"].append("%s: freshness %r, its date %r gives %r" % (where, item.get("freshness"), item.get("date"), fresh))
if name == "recent_news" and (fresh != "recent" or family not in NEWS_FAMILIES):
found["tier-purity"].append("%s: in recent_news but %s, family %r" % (where, fresh, family))
if name == "official" and (family != "official" or day is None):
found["tier-purity"].append("%s: in official but family %r, date %r" % (where, family, item.get("date")))
if name == "archive" and family in NEWS_FAMILIES and fresh == "recent":
found["tier-purity"].append("%s: a recent publisher item filed as archive" % where)
if name == "archive" and family == "official" and day is not None:
found["tier-purity"].append("%s: a dated official item filed as archive" % where)
links = [i.get("link") for i in every]
if len(links) != len(set(links)):
found["tier-purity"].append("project %s lists a link in more than one place" % ref)
said_tiers = counts.get("by_tier") if isinstance(counts.get("by_tier"), dict) else {}
for tier in TIERS:
if said_tiers.get(tier) != by_tier[tier]:
found["tier-counts"].append("counts.by_tier.%s is %r, the items give %d" % (tier, said_tiers.get(tier), by_tier[tier]))
if sum(v for v in said_tiers.values() if isinstance(v, int)) != len(projects):
found["tier-counts"].append("counts.by_tier does not sum to the %d projects" % len(projects))
headline = counts.get("headline") if isinstance(counts.get("headline"), dict) else {}
if headline.get("value") != by_tier["recent_news"]:
found["tier-counts"].append("counts.headline.value is %r, projects with confirmed recent news: %d" % (
headline.get("value"), by_tier["recent_news"]))
for key, value in with_.items():
if key in counts and counts.get(key) != value:
found["tier-counts"].append("counts.%s is %r, the items give %d" % (key, counts.get(key), value))
if "possible_only" in counts and counts.get("possible_only") != possible_only:
found["tier-counts"].append("counts.possible_only is %r, the items give %d" % (counts.get("possible_only"), possible_only))
said_items = counts.get("items") if isinstance(counts.get("items"), dict) else {}
for name in LISTS:
if name in said_items and said_items.get(name) != item_counts[name]:
found["tier-counts"].append("counts.items.%s is %r, the lists hold %d" % (name, said_items.get(name), item_counts[name]))
# generated_at
parts = doc.get("parts") if isinstance(doc.get("parts"), dict) else {}
generated = parse_stamp(doc.get("generated_at"))
live = {name: parts.get(name) for name in LIVE_PARTS if isinstance(parts.get(name), dict)}
says_stale = doc.get("stale") is True or any(p.get("status") in ("stale", "failed") for p in live.values())
if generated is None:
if not says_stale:
found["generated-at"].append("generated_at is %r and nothing says stale" % doc.get("generated_at"))
else:
age = now_stamp - generated
if age > dt.timedelta(days=MAX_AGE_DAYS) and not says_stale:
found["generated-at"].append("generated_at %s is %.1f days old and neither 'stale' nor a part says so" % (
doc.get("generated_at"), age.total_seconds() / 86400))
if age < dt.timedelta(minutes=-10):
found["generated-at"].append("generated_at %s is in the future" % doc.get("generated_at"))
if v2:
good = [parse_stamp(p.get("collected_at")) for p in live.values() if p.get("status") == "ok"]
good = [g for g in good if g]
if good and generated != max(good):
found["generated-at"].append("generated_at %s is not the newest successful live collection (%s)" % (
doc.get("generated_at"), max(good).isoformat()))
if doc.get("stale") is not True and any(p.get("status") != "ok" for p in live.values()):
found["generated-at"].append("a live part is not ok but 'stale' is not true")
return [(rule, not found[rule], found[rule]) for rule in RULES]
def failures(doc, now=None):
"""{rule: [evidence]} of the rules that fail."""
return {rule: evidence for rule, passed, evidence in check(doc, now) if not passed}
def report(results, doc, source=""):
lines = ["## Project signals: live acid check\n",
"File: %s. schema `%s`, generated_at `%s`%s.\n" % (
source or "dist/project_signals.json", doc.get("schema") if isinstance(doc, dict) else "?",
doc.get("generated_at") if isinstance(doc, dict) else "?",
", stale" if isinstance(doc, dict) and doc.get("stale") is True else ""),
"| rule | result | first evidence | more |", "|---|---|---|---|"]
for rule, passed, evidence in results:
lines.append("| %s | %s | %s | %s |" % (rule, "pass" if passed else "**FAIL**",
(evidence[0] if evidence else "").replace("|", "/")[:260],
("%d more" % (len(evidence) - 1)) if len(evidence) > 1 else ""))
failed = [rule for rule, passed, _ in results if not passed]
lines.append("\n**%s**\n" % ("Failed: " + ", ".join(failed) if failed else "All rules pass."))
return "\n".join(lines) + "\n"
def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("file")
ap.add_argument("--now", default=None)
ap.add_argument("--summary", default=None)
ap.add_argument("--source", default="")
args = ap.parse_args(argv)
try:
doc = json.loads(Path(args.file).read_text(encoding="utf-8"))
except (OSError, ValueError) as error:
doc = None
text = "## Project signals: live acid check\n\n**Failed: schema** (the published file could not be read: %s)\n" % type(error).__name__
results = [("schema", False, [])]
else:
results = check(doc, args.now)
text = report(results, doc, args.source)
print(text)
if args.summary:
with open(args.summary, "a", encoding="utf-8") as handle:
handle.write(text + "\n")
return 1 if any(not passed for _rule, passed, _e in results) else 0
if __name__ == "__main__":
sys.exit(main())Acid Report
A Python command-line tool in the tests folder of GlobalGrid2050 that reads suite (`read_suite`). It is built from the cell step (`cell`) and the table step (`table`).
testglobalgrid2050 / automation/news/tests/acid_report.py · lines 1–122 of 122 · Entry point · pattern table (shared by 65 files)
- What it does
- It tests its inputs. Defines read_suite, cell, table, main. Uses libraries __future__, argparse, json, sys, xml.etree.ElementTree. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage upstream_foresight (topic 'markets-data'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
- Inputs & outputs
- In: command-line arguments.
- Downstream impact
- Used directly by 2 files: Test Signals Acid (globalgrid2050); GlobalGrid2050 Project Signals Acid Workflow (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 Agent1 Producer Strict Workflow (globalgrid2050); GlobalGrid2050 Pipeline Project Evidence Weekly Workflow (globalgrid2050).
- What it achieves
- One table for all project-signals test suites, from the JUnit files pytest wrote. It accepts `--summary`, `--json` and `--commit`.
- Why it matters
- Run by GlobalGrid2050 Project Signals Acid Workflow. Checked by Test Signals Acid.
- Application
- globalgrid2050 · automation/news/tests · Python CLI
- Uses
- __future__, argparse, json, sys, xml.etree.ElementTree, pathlib
- Used by
- imported by Test Signals Acid (import), run by GlobalGrid2050 Project Signals Acid Workflow (workflow run)
- Produces
- read_suite, cell, table, main
- Defines here
- read_suite, cell, table, main
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 automation/news/tests/acid_report.py:1-122 · blob f71a9f994433aa8273a1cb40a2faf2a3f50e9f4a · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""One table for all project-signals test suites, from the JUnit files pytest wrote.
python automation/news/tests/acid_report.py <dir of *.xml> [--summary FILE] [--json FILE]
Columns: suite, tests, passed, failed, then "known failing until the fixer's PR" (a test marked xfail with the
review finding it covers; strict, so one that passes unexpectedly is counted as failed), "open recommendation"
(an xfail whose reason starts with OPEN: a tester's recommendation outside the contract, never a failure) and
skipped. A suite that wrote no report, or collected no test, counts as failed. Exit code 1 when any suite has
a failure.
"""
from __future__ import annotations
import argparse
import json
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
ORDER = ("official", "trade", "index", "planning_file", "combiner", "gate", "acid")
def read_suite(path):
"""{tests, passed, failed, known, skipped, failures: [(name, message)], known_list: [(name, reason)]}."""
out = {"tests": 0, "passed": 0, "failed": 0, "known": 0, "open": 0, "skipped": 0, "failures": [], "known_list": [],
"open_list": []}
try:
root = ET.parse(path).getroot()
except (ET.ParseError, OSError) as error:
out["failed"] = 1
out["failures"].append(("(report unreadable)", str(error)[:200]))
return out
for case in root.iter("testcase"):
out["tests"] += 1
name = "%s::%s" % ((case.get("classname") or "").rsplit(".", 1)[-1], case.get("name") or "")
bad = case.find("failure") if case.find("failure") is not None else case.find("error")
skipped = case.find("skipped")
if bad is not None:
out["failed"] += 1
out["failures"].append((name, (bad.get("message") or "").strip()[:300]))
elif skipped is not None and skipped.get("type") == "pytest.xfail":
reason = (skipped.get("message") or "").strip()[:300]
kind = "open" if reason.startswith("OPEN") else "known"
out[kind] += 1
out[kind + "_list"].append((name, reason))
elif skipped is not None:
out["skipped"] += 1
else:
out["passed"] += 1
if not out["tests"]:
out["failed"] = 1
out["failures"].append(("(no test collected)", "the suite did not run"))
return out
def cell(text):
return str(text).replace("|", "/").replace("\n", " ")
def table(suites, commit=""):
lines = ["## Project signals: all test suites together%s\n" % (" at `%s`" % commit[:12] if commit else ""),
"| suite | tests | passed | failed | known failing until the fixer's PR | open recommendation | skipped |",
"|---|---|---|---|---|---|---|"]
total = {"tests": 0, "passed": 0, "failed": 0, "known": 0, "open": 0, "skipped": 0}
for name, s in suites:
lines.append("| %s | %d | %d | %s | %d | %d | %d |" % (name, s["tests"], s["passed"],
("**%d**" % s["failed"]) if s["failed"] else "0", s["known"],
s["open"], s["skipped"]))
for key in total:
total[key] += s[key]
lines.append("| **all** | **%d** | **%d** | **%d** | **%d** | **%d** | **%d** |" % (
total["tests"], total["passed"], total["failed"], total["known"], total["open"], total["skipped"]))
failures = [(name, test, message) for name, s in suites for test, message in s["failures"]]
if failures:
lines += ["\n### Failed\n", "| suite | test | message |", "|---|---|---|"]
lines += ["| %s | `%s` | %s |" % (name, cell(test), cell(message)) for name, test, message in failures]
known = [(name, test, reason) for name, s in suites for test, reason in s["known_list"]]
if known:
lines += ["\n### Known failing until the fixer's PR (%d)\n" % len(known),
"Each is a rule the code at this commit does not meet. The marker is strict: a test listed here that "
"passes is reported as failed, and on code that declares the revised contract the marker is not applied "
"at all, so every one of these must pass there.\n",
"| suite | test | finding covered |", "|---|---|---|"]
lines += ["| %s | `%s` | %s |" % (name, cell(test), cell(reason)) for name, test, reason in known]
opened = [(name, test, reason) for name, s in suites for test, reason in s["open_list"]]
if opened:
lines += ["\n### Open recommendations (%d)\n" % len(opened),
"Reported by the acid testers, outside contract version 2. Not failures; listed so they are not lost.\n",
"| suite | test | recommendation |", "|---|---|---|"]
lines += ["| %s | `%s` | %s |" % (name, cell(test), cell(reason)) for name, test, reason in opened]
return "\n".join(lines) + "\n", total
def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("directory")
ap.add_argument("--summary", default=None)
ap.add_argument("--json", default=None)
ap.add_argument("--commit", default="")
ap.add_argument("--expect", default=",".join(ORDER), help="suites that must have a report")
args = ap.parse_args(argv)
found = {p.stem: p for p in Path(args.directory).glob("*.xml")}
names = [n for n in args.expect.split(",") if n] + sorted(n for n in found if n not in args.expect.split(","))
suites = [(name, read_suite(found[name]) if name in found else
{"tests": 0, "passed": 0, "failed": 1, "known": 0, "open": 0, "skipped": 0,
"failures": [("(no report)", "the suite did not run")], "known_list": [], "open_list": []}) for name in names]
text, total = table(suites, args.commit)
try:
print(text)
except BrokenPipeError:
pass
if args.summary:
with open(args.summary, "a", encoding="utf-8") as handle:
handle.write(text + "\n")
if args.json:
Path(args.json).write_text(json.dumps({"commit": args.commit, "total": total, "suites": dict(suites)}, indent=1) + "\n",
encoding="utf-8")
return 1 if total["failed"] else 0
if __name__ == "__main__":
sys.exit(main())Compare Legacy Collector
A Python command-line tool in the tests folder of GlobalGrid2050 that tests pipeline feeds, original feeds, Renewable Energy Planning Database (REPD) fixture and the REPD register.
testglobalgrid2050 / automation/news/tests/compare_legacy_collector.py · lines 1–123 of 123 · Entry point · pattern run_once (shared by 4 files)
- What it does
- It tests pipeline feeds, original feeds, REPD fixture and the REPD register. Defines git, ensure_scope, run_once, ensure_only_cop31_bbc_added, main. Uses libraries __future__, argparse, csv, json, pathlib. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'legacy'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: the REPD register.
- Inputs & outputs
- In: JSON file pipeline_feeds.json; JSON file feeds.json; CSV file repd-fixture.csv; JSON file original_feeds.json; JSON file old.json; JSON file new.json; command-line arguments. Out: JSON file original_feeds.json.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 Pipeline Headlines Workflow (globalgrid2050).
- What it achieves
- It runs once (`run_once`) and is built from the git step (`git`) and the ensure scope helper (`ensure_scope`). Fail-closed legacy replay and exact source guard for the BBC COP31 priority lane. It accepts `--base`.
- Why it matters
- Run by GlobalGrid2050 Pipeline Headlines Workflow.
- Application
- globalgrid2050 · automation/news/tests · Python CLI
- Uses
- Pipeline Headlines (script call), Test Pipeline Headlines (script call), Test Spp Excluded (script call), News Algorithm (script call), Test Cop31 Climate Priority (script call), __future__, argparse, csv, json, pathlib, subprocess, sys, tempfile
- Used by
- run by GlobalGrid2050 Pipeline Headlines Workflow (workflow run)
- Produces
- git, ensure_scope, run_once, ensure_only_cop31_bbc_added, main
- Defines here
- git, ensure_scope, run_once, ensure_only_cop31_bbc_added, main
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 automation/news/tests/compare_legacy_collector.py:1-123 · blob c040c9ffaf74602b610897ebe1298c5e0a5c6493 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: experimental · users: none · canonical: production_core
#!/usr/bin/env python3
"""Fail-closed legacy replay and exact source guard for the BBC COP31 priority lane.
Every pre-existing publisher, UK planning record, REPD match and output must
remain equivalent on the original fixture. No homepage or version edits.
"""
from __future__ import annotations
import argparse
import csv
import json
from pathlib import Path
import subprocess
import sys
import tempfile
ROOT = Path(__file__).resolve().parents[3]
MODULES = ("pipeline_headlines.py", "datacentre_feed.py", "names.py", "research_indexes.py")
ALLOWED = {
".github/workflows/pipeline-headlines.yml",
"automation/news/pipeline_headlines.py",
"automation/news/pipeline_feeds.json",
"automation/news/tests/test_pipeline_headlines.py",
"automation/news/tests/test_spp_verified_public_links.py",
"automation/news/tests/test_spp_excluded.py",
"automation/news/tests/compare_legacy_collector.py",
"automation/news/news_algorithm.py",
"automation/news/tests/test_cop31_climate_priority.py",
}
def git(*args: str) -> bytes:
return subprocess.check_output(["git", *args], cwd=ROOT)
def ensure_scope(base: str) -> None:
changed = {s for s in git("diff", "--name-only", f"{base}..HEAD").decode().splitlines() if s}
forbidden = changed - ALLOWED
if forbidden:
raise AssertionError("Unrelated change detected: " + ", ".join(sorted(forbidden)))
expected = {"automation/news/pipeline_headlines.py", "automation/news/pipeline_feeds.json",
"automation/news/news_algorithm.py", "automation/news/tests/test_cop31_climate_priority.py"}
if not expected <= changed:
raise AssertionError("Expected additive collector/config changes missing")
def run_once(script: Path, feeds: Path, fixtures: Path, repd: Path, dest: Path) -> dict:
subprocess.run(
[sys.executable, str(script), "--feeds", str(feeds),
"--fixtures", str(fixtures), "--repd", str(repd), "--out", str(dest),
"--now", "2026-11-14T12:00:00Z"],
cwd=ROOT, check=True, capture_output=True, text=True, timeout=60)
return json.loads(dest.read_text(encoding="utf-8"))
def ensure_only_cop31_bbc_added(base: str) -> None:
old = json.loads(git("show", f"{base}:automation/news/pipeline_feeds.json"))
new = json.loads((ROOT / "automation/news/pipeline_feeds.json").read_text(encoding="utf-8"))
legacy = old["feeds"]
feeds = new["feeds"]
assert len(feeds) == len(legacy) + 1, "Exactly one curated BBC link expected"
assert feeds[:len(legacy)] == legacy, "Prior feeds, source order and flags must not change"
addition = feeds[-1]
assert addition.get("url") == "https://www.bbc.co.uk/news/articles/c6ly5w40eg07o"
assert addition.get("source") == "BBC News"
assert addition.get("kind") == "curated"
assert addition.get("uk_only") is False
assert addition.get("title") == "COP31 fossil-fuel negotiations reach a deadlock"
assert addition.get("date") == "2026-11-21T07:31:05Z"
assert new.get("climate_policy_patch_id") == "20261122-cop31-priority-v1"
assert new.get("source_patch_id") == old.get("source_patch_id")
assert new.get("excluded_sources") == old.get("excluded_sources") == ["Solar Power Portal"]
assert new.get("source_release_id") == old.get("source_release_id")
assert len({f["url"] for f in feeds}) == len(feeds), "Duplicate URLs forbidden"
print(f"PASS: {len(legacy)} prior feeds byte-equivalent, exactly one BBC COP31 link")
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--base", required=True, help="PR Git base, e.g. HEAD^1")
args = ap.parse_args()
base = args.base
ensure_scope(base)
ensure_only_cop31_bbc_added(base)
fixtures = ROOT / "automation/news/tests/fixtures/pipeline"
with tempfile.TemporaryDirectory(prefix="pn-legacy-comparison-") as tmp:
tmp = Path(tmp)
baseline = tmp / "baseline" / "automation" / "news"
baseline.mkdir(parents=True)
for file in MODULES:
(baseline / file).write_bytes(git("show", f"{base}:automation/news/{file}"))
# Exclude Solar Power Portal from BOTH runs. Every other fixture item
# must match the unchanged baseline byte-for-byte.
fixture = json.loads(git("show", f"{base}:automation/news/tests/fixtures/pipeline/feeds.json"))
fixture["feeds"] = [f for f in fixture["feeds"]
if f.get("source") != "Solar Power Portal"]
(tmp / "original_feeds.json").write_text(json.dumps(fixture), encoding="utf-8")
repd = tmp / "repd-fixture.csv"
with repd.open("w", encoding="utf-8", newline="") as fp:
writer = csv.DictWriter(fp, fieldnames=[
"Ref ID", "Site Name", "Technology Type", "Operator (or Applicant)",
"County", "Planning Authority", "Region"])
writer.writeheader()
writer.writerow({
"Ref ID": "12588", "Site Name": "Botley West Solar Project",
"Technology Type": "Solar Photovoltaics", "Operator (or Applicant)": "SolarFive",
"County": "Oxfordshire", "Planning Authority": "West Oxfordshire",
"Region": "South East"})
old = run_once(baseline / MODULES[0], tmp / "original_feeds.json",
fixtures, repd, tmp / "old.json")
new = run_once(ROOT / "automation/news/pipeline_headlines.py",
tmp / "original_feeds.json", fixtures, repd, tmp / "new.json")
# Except the explicitly removed publisher, existing article metadata, dates,
# REPD association, counts and feed health must remain unchanged.
for key in ("items", "counts", "feeds", "status", "schema", "generated_at", "limits"):
if old[key] != new[key]:
raise AssertionError(f"Legacy output regression: {key}")
print(f"PASS: {len(old['items'])} remaining-publisher headlines unchanged; "
f"no unrelated release or UI edits")
if __name__ == "__main__":
main()