Something went wrong. Try again.
Exploring the idea of generated web rendering engine.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103#!/usr/bin/env python3"""After a job lands, says whether the web-features it declared moved.
bench/expected-features-check.py --result <result.json> --events <file> --snapshot <map.json>
--result the landed job's result.json (jobs/src/result.rs); its `expected_features` are the web-features ids the job's manifest says it implements.--events only the event lines this landing appended to docs/web-features-events.jsonl (bench/after-land.sh passes the same file as to bench/feature-announce.py).--snapshot docs/web-features-map.json as regenerated by that landing.
A feature moved when an event takes it forward to partial or complete (the same test asbench/feature-announce.py `read_events`); that one is announced and needs no word here.For the rest, by their status in the snapshot:
- partial or complete: the job added keys to a feature an earlier landing had already moved, so there is nothing to announce. One plain line names them. - anything else, or absent from the snapshot: no rule in docs/feature-map.json gave the job's keys a status, so the feature stays where it was and the announcement is silent about it. One line in capitals names every such feature, its status, and the fix.
Nothing declared, or every feature moved: prints nothing. All output is on stderr and theexit status is 0 whatever it finds; an unreadable input is one line and exit 0 as well, sothe check never changes a landing's outcome. Exit 2 is a usage error only."""import argparseimport jsonimport sys
RANK = {"partial": 1, "complete": 2}
def say(msg): print(f"expected features: {msg}", file=sys.stderr)
def moved_forward(path): out = set() with open(path) as f: for line in f: try: e = json.loads(line) except ValueError: continue if not isinstance(e, dict) or e.get("type") != "feature-status": continue if RANK.get(e.get("to"), 0) > RANK.get(e.get("from"), 0) and isinstance(e.get("feature"), str): out.add(e["feature"]) return out
def main(): p = argparse.ArgumentParser() p.add_argument("--result", required=True) p.add_argument("--events", required=True) p.add_argument("--snapshot", required=True) a = p.parse_args()
try: with open(a.result) as f: result = json.load(f) expected = result.get("expected_features") or [] job = result.get("name") or "the landed job" except (OSError, ValueError, AttributeError) as e: say(f"not checked: cannot read {a.result} ({e})") return 0 expected = [x for x in expected if isinstance(x, str)] if not expected: return 0 try: moved = moved_forward(a.events) with open(a.snapshot) as f: features = json.load(f).get("features") or {} except (OSError, ValueError, AttributeError) as e: say(f"not checked: cannot read the events or the snapshot ({e})") return 0
already, stuck = [], [] for fid in expected: if fid in moved: continue entry = features.get(fid) status = entry.get("status") if isinstance(entry, dict) else None if status in RANK: already.append(f"{fid} ({status})") elif status is None: stuck.append(f"{fid} (absent from the map)") else: stuck.append(f"{fid} (stays {status})")
if already: say(f"{job} extended {', '.join(already)}, already there before this landing; " "nothing to announce for them") if stuck: say(f"NOT ANNOUNCED: {job} declared {', '.join(stuck)} and no map rule moved it; " f"add the manifest's rules with `job-check feature-rules specs/{job}.job.json` " f"on the base branch, then `bench/after-land.sh --track spec-{job}` announces it") return 0
if __name__ == "__main__": sys.exit(main())