Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8eb11a23f6 | ||
|
|
3cffd5ea14 | ||
|
|
29a93aaedc | ||
|
|
4c472a6a64 | ||
|
|
32937487d1 |
No files matched your search
@@ -28,3 +28,9 @@ ci/py-lock/** text eol=lf
|
||||
# The vendored bundles are third-party bytes whose sha256 is pinned in tests/vendor/README.md: no checkout converts their line endings
|
||||
# (a Windows runner with core.autocrlf=true would hand them over with CRLF and the hash would no longer match).
|
||||
tests/vendor/*.js -text
|
||||
|
||||
# The list of required suites and its fragments are compared as the exact dump of their content
|
||||
# (one value per line, LF): a Windows checkout with core.autocrlf=true would hand the judge
|
||||
# and the tests CRLF text that is not that dump.
|
||||
ci/required-suites.json text eol=lf
|
||||
ci/required-suites.d/*.json text eol=lf
|
||||
@@ -327,7 +327,7 @@ jobs:
|
||||
|
||||
# The judge of the engine series' gate on the junit of the step above: the exact count of the row (not one test more, not one less), no skip, every
|
||||
# file of the row passed, and the list only grows against main. The judge and the list it compares with are read from main, never from the branch under
|
||||
# judgment (a branch that edits its own judge or its own list cannot pass itself): a PR that adds a test and does not raise min_tests is red here.
|
||||
# judgment (a branch that edits its own judge or its own list cannot pass itself): a PR that adds a test and does not add its fragment is red here.
|
||||
# The suite launches no browser, so --binary names the interpreter that ran it (the judge wants a file to hash; nothing reads that hash: no --out).
|
||||
- name: Judge the suite wrapper.unit.all (the exact count, with the judge and the list of main)
|
||||
if: always() && matrix.python == '3.11'
|
||||
@@ -339,6 +339,13 @@ jobs:
|
||||
git show origin/main:scripts/ci_verdict.py > "$RUNNER_TEMP/main/ci_verdict.py"
|
||||
git show origin/main:ci/required-suites.json > "$RUNNER_TEMP/main/required-suites.json"
|
||||
if git cat-file -e origin/main:ci/retired-tests.json; then git show origin/main:ci/retired-tests.json > "$RUNNER_TEMP/main/retired-tests.json"; fi
|
||||
# The floor of a row is the list plus the fragments of the folder next to it, so main's folder goes next to main's list. While main has no
|
||||
# folder nothing is copied: the judge of main does not know it yet (and once it does, a list with no folder is red there).
|
||||
if git cat-file -e origin/main:ci/required-suites.d; then
|
||||
mkdir -p "$RUNNER_TEMP/main-fragments"
|
||||
git archive origin/main ci/required-suites.d | tar -x -C "$RUNNER_TEMP/main-fragments"
|
||||
mv "$RUNNER_TEMP/main-fragments/ci/required-suites.d" "$RUNNER_TEMP/main/required-suites.d"
|
||||
fi
|
||||
python "$RUNNER_TEMP/main/ci_verdict.py" judge --required ci/required-suites.json --suite "wrapper.unit.all.$SUITE_OS" --os "$SUITE_OS" --junit "$RUNNER_TEMP/unit-junit.xml" --binary "$(python -c 'import sys; print(sys.executable)')" --main-required "$RUNNER_TEMP/main/required-suites.json"
|
||||
|
||||
# ONE SINGLE CONTEXT FOR BRANCH PROTECTION. Measured 2026-08-13: this
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"tests/test_detectors_e2e.py::test_the_headless_detector_sees_no_headless_and_no_proxy_tell",
|
||||
"tests/test_realness_behind_a_declared_exit_e2e.py::test_the_vendored_detection_page_finds_nothing_behind_the_gateway"
|
||||
]
|
||||
+1556
-30
File diff suppressed because it is too large.
Load diff
+342
-55
@@ -16,23 +16,30 @@ pytest wrote and fails on every one of them.
|
||||
reads the junit, writes the result json (with `verdict`: "green" or "red") and exits 1, printing EVERY problem
|
||||
with its reason, one per line, when: the junit or the row is missing; the junit is not xunit2 (a testcase with
|
||||
no `classname`); a test failed, errored or was skipped; fewer tests were collected than `min_tests`, or, when
|
||||
the row is `exact`, any number other than `min_tests` (a deselected test is not in the junit: `min_tests` goes
|
||||
up by hand when a test is added, never silently); a required file or node id did not pass; the binary is
|
||||
the row is `exact`, any number other than `min_tests` (a deselected test is not in the junit: a fragment is
|
||||
added when a test is added, never silently); a required file or node id did not pass; the binary is
|
||||
missing (--binary is mandatory: without it exit 2) or the commit cannot be known; the --seal is unreadable.
|
||||
With --main-required (the list of main) the list only grows: a suite of main is gone, its minimum went down,
|
||||
its `exact` went from true to false, its os or tests lost an element, or its marker changed is red.
|
||||
With --main-required (the list of main) the list only grows, on EFFECTIVE rows on both sides (see the fragments, below): a suite of
|
||||
main is gone, its minimum went down, its `exact` went from true to false, its os or tests lost an element, or its marker changed is red.
|
||||
Main's fragments are read from the folder `required-suites.d` NEXT TO main's list; main's list without that folder is red ("main's
|
||||
fragments are not known"). A fragment of main that is missing or changed in the judged tree is allowed only as a FOLD: every effective row
|
||||
identical to main's, consumed.json gaining exactly the `consumes` of the removed fragments, and no fragment that main lacks.
|
||||
The one exception is `retired-tests.json` NEXT TO main's list (read from main, never from the judged branch): a file it names that
|
||||
no longer exists in the checkout may leave the rows, and the minimum of a row may go down by the tests main counted for it in that
|
||||
row (`tests: {row id: n}`), and by no more. A retired file still on disk, or any other lost test, stays red.
|
||||
The same file may also retire single tests whose file stays: {"nodeid": "<file>::<test>", "suite": <row id>, "count": n, "reason",
|
||||
"decided_by", "date", "from_min_tests"}. The minimum of that row may go down by the sum of the `count` of its entries and by no more, and
|
||||
only for a nodeid whose file the row of main lists, and only while main's minimum of that row still equals `from_min_tests` (once the removal
|
||||
is on main and its floor is lower, the entry is inert); a declared nodeid that the judged leg still collects is red, and so is any test that
|
||||
goes without an entry.
|
||||
"decided_by", "date"} (`from_min_tests` is optional and ignored). A single test leaves a row by a fragment of the branch that carries a
|
||||
NEGATIVE value for the row and `consumes` the nodeid: each consumed nodeid is a nodeid entry of main's list for that row, is not in main's
|
||||
consumed.json nor in a fragment of main, and the judged leg no longer collects it; |value| is at most the sum of the `count` of the
|
||||
consumed entries for that row, and only for a nodeid whose file the row of main lists. A retirement is consumed once, by name; a declared
|
||||
nodeid that the judged leg still collects is red, and so is any test that goes without an entry.
|
||||
What the file of main is can be said only by the gate, which checks main out (a failed download is not
|
||||
"main has no list"): the file exists -> it is compared; it does not exist and the gate passed
|
||||
--main-has-no-list (main was checked out and has no such file) -> passed, declared; it does not exist
|
||||
without --main-has-no-list -> RED, "it is not known what main has".
|
||||
The same for main's folder of fragments: the caller passes --main-has-no-fragments only when git says the ref main's list was read from
|
||||
(e.g. the previous wrapper release, for the core's proof on a tag) has no ci/required-suites.d; main is then its base list, with no
|
||||
fragment and nothing consumed, and the run says so. The flag while the folder exists is red; no flag and no folder is red too.
|
||||
The commit is --commit SHA or `git rev-parse HEAD` in the current directory (the checkout of the wrapper),
|
||||
NEVER GITHUB_SHA (in a called workflow it is the commit of the engine's repository). --seal reads the seal of
|
||||
the gate: the seal that `python -m invisible_core seal` writes, and the release seal, carry NO sha256 of the
|
||||
@@ -45,6 +52,18 @@ pytest wrote and fails on every one of them.
|
||||
is of a (suite, os) that is not in the list, or twice; the commit is not the same in every result, or the
|
||||
binary sha256 is not the same in every result of one OS (or missing).
|
||||
|
||||
ci_verdict.py fragment --required ci/required-suites.json --name <slug> --set ROW=N [--set ROW=N ...] [--consumes NODEID ...]
|
||||
[--main-ref origin/main]
|
||||
writes ci/required-suites.d/<slug>.json ({row id: N}, plus `consumes` when given) and prints its path. If the name already exists in
|
||||
the working tree or on the main ref (`git ls-tree`), it takes -2, -3, ...; it NEVER edits an existing fragment.
|
||||
|
||||
THE FLOOR IS A SUM OF PARTS. The effective `min_tests` of a row is the `min_tests` of `ci/required-suites.json` plus the sum of the values of the
|
||||
fragments in the folder `required-suites.d` next to the list (one loader, `effective_rows`; `args`, `judge` and `complete` read effective rows). The
|
||||
folder always exists: it holds `consumed.json` (a JSON list of the retired nodeids already consumed) and one file `<slug>.json` per change
|
||||
(the name starts with a lower-case letter or a digit, then only a-z 0-9 . _ -, and ends in .json; consumed.json is not a fragment), whose content is {"<row id>": integer, ..., optional "consumes": [nodeid, ...]}. A value is an
|
||||
integer other than 0; a negative one is allowed only with `consumes`. A missing folder, a bad name, an unknown row id, a value that is not an
|
||||
integer, 0, or a negative value without `consumes` is a malformed list (exit 2, with the reason).
|
||||
|
||||
The list is validated by all three commands (a malformed one is exit 2, with the reason, never green): ids unique; per
|
||||
row `os` a non-empty subset of {linux, windows}, `tests` a non-empty list of unique strings, `min_tests` an integer > 0,
|
||||
`exact` a bool, `marker` a string, `needs_root` a bool or a list of the row's OSes.
|
||||
@@ -85,6 +104,7 @@ import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
@@ -221,12 +241,153 @@ def _read_json_list(path):
|
||||
raise Usage("cannot read the required list %s: %s" % (path, exc))
|
||||
|
||||
|
||||
def load_required(path):
|
||||
data = _read_json_list(path)
|
||||
problems = validate_list(data)
|
||||
# ------------------------------------------------------------------------------------------------ the fragments
|
||||
FRAGMENTS_DIR = "required-suites.d"
|
||||
CONSUMED_NAME = "consumed.json"
|
||||
CONSUMES = "consumes"
|
||||
FRAGMENT_NAME = re.compile(r"^[a-z0-9][a-z0-9._-]*\.json$")
|
||||
|
||||
|
||||
class Required:
|
||||
"""A required list read with its fragments. `rows` are the EFFECTIVE rows (`min_tests` = the base + the sum of the fragments), `base` the
|
||||
rows as the list has them, `fragments` {slug: {"values": {row id: int}, "consumes": [nodeid]}}, `consumed` the list of consumed.json."""
|
||||
|
||||
def __init__(self, base, rows, fragments, consumed):
|
||||
self.base, self.rows, self.fragments, self.consumed = base, rows, fragments, consumed
|
||||
|
||||
|
||||
def fragments_dir(required_path):
|
||||
"""The folder of the fragments of a list: `required-suites.d` next to it."""
|
||||
return Path(required_path).with_name(FRAGMENTS_DIR)
|
||||
|
||||
|
||||
def _read_fragments(folder, row_ids):
|
||||
"""-> (fragments, consumed, problems) of the folder. Every reason it is malformed is in `problems`."""
|
||||
folder = Path(folder)
|
||||
if not folder.is_dir():
|
||||
return {}, [], ["the folder %s does not exist (it always holds %s)" % (folder, CONSUMED_NAME)]
|
||||
problems, fragments, consumed = [], {}, []
|
||||
names = sorted(os.listdir(folder))
|
||||
if CONSUMED_NAME not in names:
|
||||
problems.append("%s has no %s" % (folder, CONSUMED_NAME))
|
||||
for name in names:
|
||||
path = folder / name
|
||||
if name == CONSUMED_NAME:
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as exc:
|
||||
problems.append("%s cannot be read: %s" % (path, exc))
|
||||
continue
|
||||
if not (isinstance(data, list) and all(isinstance(n, str) and n.strip() for n in data) and len(set(data)) == len(data)):
|
||||
problems.append("%s must be a list of distinct non-empty nodeids" % path)
|
||||
else:
|
||||
consumed = data
|
||||
continue
|
||||
if not path.is_file() or not FRAGMENT_NAME.match(name):
|
||||
problems.append("%s: the name of a fragment is <slug>.json (lower-case letters, digits, '.', '_' and '-', starting with a letter or "
|
||||
"a digit), and %s is not a fragment" % (path, CONSUMED_NAME))
|
||||
continue
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as exc:
|
||||
problems.append("%s cannot be read: %s" % (path, exc))
|
||||
continue
|
||||
fragment, bad = _parse_fragment(data, row_ids)
|
||||
problems += ["fragment %s: %s" % (name, why) for why in bad]
|
||||
if not bad:
|
||||
fragments[name[:-len(".json")]] = fragment
|
||||
return fragments, consumed, problems
|
||||
|
||||
|
||||
def _parse_fragment(data, row_ids):
|
||||
if not isinstance(data, dict):
|
||||
return None, ["a fragment is a JSON object {row id: integer}"]
|
||||
problems, values, consumes = [], {}, []
|
||||
for key, value in data.items():
|
||||
if key == CONSUMES:
|
||||
if not (isinstance(value, list) and all(isinstance(n, str) and n.strip() for n in value) and len(set(value)) == len(value)):
|
||||
problems.append("%s must be a list of distinct non-empty nodeids, not %r" % (CONSUMES, value))
|
||||
else:
|
||||
consumes = list(value)
|
||||
elif key not in row_ids:
|
||||
problems.append("%r is not a row of the list" % key)
|
||||
elif not _is_int(value):
|
||||
problems.append("the value of %s must be an integer, not %r" % (key, value))
|
||||
elif value == 0:
|
||||
problems.append("the value of %s is 0: a fragment that changes nothing" % key)
|
||||
else:
|
||||
values[key] = value
|
||||
if not values and not problems:
|
||||
problems.append("no row: a fragment names at least one row")
|
||||
for key, value in sorted(values.items()):
|
||||
if value < 0 and not consumes:
|
||||
problems.append("the value of %s is negative (%d) and the fragment has no `%s`: a test leaves a row only by a retirement it consumes"
|
||||
% (key, value, CONSUMES))
|
||||
return {"values": values, "consumes": consumes}, problems
|
||||
|
||||
|
||||
def _effective(base, fragments):
|
||||
rows = []
|
||||
for row in base:
|
||||
if isinstance(row, dict):
|
||||
row = dict(row)
|
||||
row["min_tests"] = _int(row.get("min_tests")) + sum(f["values"].get(row.get("id"), 0) for f in fragments.values())
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
|
||||
def _bad_list(head, reasons):
|
||||
"""A BadList whose message is `head` and then one reason per line."""
|
||||
return BadList(head + "".join("\n " + reason for reason in reasons))
|
||||
|
||||
|
||||
def read_required(path):
|
||||
"""The list and its fragments, strictly: a list or a folder that is malformed is a BadList (exit 2), naming every reason."""
|
||||
base = _read_json_list(path)
|
||||
problems = validate_list(base)
|
||||
if problems:
|
||||
raise BadList("the required list %s is malformed:\n %s" % (path, "\n ".join(problems)))
|
||||
return data
|
||||
raise _bad_list("the required list %s is malformed:" % path, problems)
|
||||
fragments, consumed, bad = _read_fragments(fragments_dir(path), {r["id"] for r in base})
|
||||
if bad:
|
||||
raise _bad_list("the fragments of the required list %s are malformed:" % path, bad)
|
||||
rows = _effective(base, fragments)
|
||||
low = ["%s: the effective min_tests is %d (> 0 needed)" % (r["id"], r["min_tests"]) for r in rows if r["min_tests"] <= 0]
|
||||
if low:
|
||||
raise _bad_list("the fragments of the required list %s leave a row with no test:" % path, low)
|
||||
return Required(base, rows, fragments, consumed)
|
||||
|
||||
|
||||
def effective_rows(required_path):
|
||||
"""THE loader: the rows of the list with `min_tests` = the base + the sum of the fragments of the folder next to it."""
|
||||
return read_required(required_path).rows
|
||||
|
||||
|
||||
def read_main_required(path, no_fragments=False):
|
||||
"""The list of main and its fragments, leniently (main may be older than the format): -> (Required or None, problems). Main's list without
|
||||
its folder is a problem ("main's fragments are not known"), never an empty folder. `no_fragments` is the declaration of the caller that git
|
||||
says the ref the list was read from has no folder (a release older than the format): main's rows are then its base rows, no fragment, nothing
|
||||
consumed. The declaration while the folder is there is a problem."""
|
||||
base = _read_json_list(path)
|
||||
if not isinstance(base, list):
|
||||
return None, ["the list of main is not a JSON list: it cannot be compared"]
|
||||
folder = fragments_dir(path)
|
||||
if no_fragments:
|
||||
if folder.exists():
|
||||
return None, ["the folder %s of main exists, but --main-has-no-fragments says the ref of main has none" % folder]
|
||||
print("NOTE: --main-has-no-fragments: the ref main's list was read from has no %s; main is compared on its base list, with no fragment "
|
||||
"and nothing consumed" % FRAGMENTS_DIR)
|
||||
return Required(base, _effective(base, {}), {}, []), []
|
||||
if not folder.is_dir():
|
||||
return None, ["main's fragments are not known: the list of main %s has no folder %s next to it" % (path, FRAGMENTS_DIR)]
|
||||
ids = {r.get("id") for r in base if isinstance(r, dict)}
|
||||
fragments, consumed, bad = _read_fragments(folder, ids)
|
||||
if bad:
|
||||
return None, ["main's fragments are not readable: %s" % "; ".join(bad)]
|
||||
return Required(base, _effective(base, fragments), fragments, consumed), []
|
||||
|
||||
|
||||
def load_required(path):
|
||||
return effective_rows(path)
|
||||
|
||||
|
||||
def find_suite(suites, suite_id, os_name):
|
||||
@@ -341,8 +502,8 @@ RETIRED_NAME = "retired-tests.json"
|
||||
def validate_retired(data, suite_ids=None):
|
||||
"""-> the reasons why `data` is not a well-formed list of retired tests (empty if it is). Two kinds of entry, in one list:
|
||||
a FILE that is gone ({file, reason, date, tests: {row id: number of tests the file had in that row on main, counted with the row's marker}}), and
|
||||
a single TEST whose file stays ({nodeid: "<file>::<test>", suite: row id, count > 0, reason, decided_by, date, from_min_tests: the minimum of
|
||||
the row on main when the entry was written, an integer >= count, the same for every entry of a suite}). `suite_ids`, when given, are the row
|
||||
a single TEST whose file stays ({nodeid: "<file>::<test>", suite: row id, count > 0, reason, decided_by, date; optional and ignored, from_min_tests: the minimum of
|
||||
the row on main when the entry was written, an integer >= count, the same for every entry of a suite that has one}). `suite_ids`, when given, are the row
|
||||
ids of main's list: the suite of a nodeid entry must be one of them."""
|
||||
if not isinstance(data, list):
|
||||
return ["the retired list must be a JSON list"]
|
||||
@@ -400,9 +561,10 @@ def _validate_retired_node(e, where, suite_ids, seen):
|
||||
for key in ("reason", "decided_by", "date"):
|
||||
if not isinstance(e.get(key), str) or not e.get(key).strip():
|
||||
problems.append("%s: %s must be a non-empty string" % (where, key))
|
||||
frm = e.get("from_min_tests")
|
||||
if not _is_int(frm) or frm < 1 or (_is_int(e.get("count")) and frm < e["count"]):
|
||||
problems.append("%s: from_min_tests must be an integer >= count (the minimum of the suite on main when the entry was written)" % where)
|
||||
if "from_min_tests" in e: # optional and ignored: the retirement is consumed by name now (see against_main); an old entry keeps it
|
||||
frm = e["from_min_tests"]
|
||||
if not _is_int(frm) or frm < 1 or (_is_int(e.get("count")) and frm < e["count"]):
|
||||
problems.append("%s: from_min_tests must be an integer >= count (the minimum of the suite on main when the entry was written)" % where)
|
||||
return problems
|
||||
|
||||
|
||||
@@ -427,48 +589,102 @@ def retired_of_main(main_required):
|
||||
return data, []
|
||||
|
||||
|
||||
def _retired_tests_of(row, retired, collected, judged):
|
||||
"""-> (the number of tests the row may lose because main retired them one by one, problems). An entry counts only if the file of its nodeid is
|
||||
in the row of main (a nodeid that the row does not run is not a test the row loses). The judge has the junit of the leg it judges and only
|
||||
counts of main, so a declared nodeid that the judged leg still collects is red (and counts for nothing), and the nodeid of another row is taken
|
||||
on its count, the leg of that row checking it. An entry counts only while the minimum of the row on main is still its `from_min_tests`: once
|
||||
the removal is on main the floor is lower and the entry is inert (it allows nothing and asks nothing)."""
|
||||
allowed, problems = 0, []
|
||||
listed = row.get("tests", [])
|
||||
for e in retired:
|
||||
if not (isinstance(e, dict) and isinstance(e.get("nodeid"), str) and e.get("suite") == row.get("id")):
|
||||
continue
|
||||
nid = e["nodeid"]
|
||||
if _int(row.get("min_tests")) != e.get("from_min_tests"):
|
||||
continue
|
||||
if nid not in listed and nid.split("::", 1)[0] not in listed:
|
||||
continue
|
||||
if collected is not None and judged == row.get("id") and any(n == nid or _base(n) == nid for n in collected):
|
||||
problems.append("the test %s is declared retired for %s, but the suite still collects it: it did not leave" % (nid, row.get("id")))
|
||||
continue
|
||||
allowed += _int(e.get("count"))
|
||||
def _retirement_allowance(current, main, retired, collected, judged):
|
||||
"""-> ({row id: how many tests the rows may lose by single-test retirements}, problems). Only the fragments the branch ADDS count (a fragment of
|
||||
main is already in main's effective rows). A fragment may carry a negative value for a row only with `consumes`, and only if: each consumed nodeid
|
||||
is a nodeid entry of main's retired-tests.json for one of its negative rows; it is not in main's consumed.json nor in a fragment of main (a
|
||||
retirement is used once, whatever merges in between), nor in another fragment of the branch; the judged leg no longer collects it; and |value|
|
||||
is at most the sum of the `count` of the consumed entries of that row whose file or node id the row of main lists."""
|
||||
allowed, problems = {}, []
|
||||
entries = [e for e in retired if isinstance(e, dict) and isinstance(e.get("nodeid"), str) and isinstance(e.get("suite"), str)]
|
||||
taken = {n: "main's %s" % CONSUMED_NAME for n in main.consumed}
|
||||
for name, frag in main.fragments.items():
|
||||
for n in frag["consumes"]:
|
||||
taken.setdefault(n, "the fragment %s of main" % name)
|
||||
main_rows = {r.get("id"): r for r in main.base if isinstance(r, dict)}
|
||||
for name in sorted(set(current.fragments) - set(main.fragments)):
|
||||
frag = current.fragments[name]
|
||||
negative = {row: v for row, v in frag["values"].items() if v < 0}
|
||||
usable = {row: 0 for row in negative}
|
||||
for nid in frag["consumes"]:
|
||||
if nid in taken:
|
||||
problems.append("the fragment %s consumes the retirement of %s, which %s has already consumed: a retirement is used once"
|
||||
% (name, nid, taken[nid]))
|
||||
continue
|
||||
taken[nid] = "the fragment %s" % name
|
||||
mine = [e for e in entries if e["nodeid"] == nid and e["suite"] in negative]
|
||||
if not mine:
|
||||
problems.append("the fragment %s consumes %s, which is not a retired test of main's %s for any row it lowers (%s)"
|
||||
% (name, nid, RETIRED_NAME, ", ".join(sorted(negative)) or "none"))
|
||||
for e in mine:
|
||||
row = main_rows.get(e["suite"])
|
||||
listed = row.get("tests", []) if isinstance(row, dict) else []
|
||||
if nid not in listed and nid.split("::", 1)[0] not in listed:
|
||||
continue # a nodeid the row of main does not run is not a test the row loses
|
||||
if collected is not None and judged == e["suite"] and any(n == nid or _base(n) == nid for n in collected):
|
||||
problems.append("the test %s is declared retired for %s, but the suite still collects it: it did not leave" % (nid, e["suite"]))
|
||||
continue
|
||||
usable[e["suite"]] += _int(e.get("count"))
|
||||
for row, value in sorted(negative.items()):
|
||||
if -value > usable[row]:
|
||||
problems.append("the fragment %s lowers %s by %d, but the retired tests it consumes account for %d of it"
|
||||
% (name, row, -value, usable[row]))
|
||||
else:
|
||||
allowed[row] = allowed.get(row, 0) - value
|
||||
return allowed, problems
|
||||
|
||||
|
||||
def _fold_problems(current, main, removed):
|
||||
"""The only way a fragment of main leaves: the fold. Every effective row is identical to main's, consumed.json gains exactly the `consumes` of the
|
||||
removed fragments, and the branch has no fragment that main lacks."""
|
||||
problems = []
|
||||
cur = {r.get("id"): r for r in current.rows if isinstance(r, dict)}
|
||||
old = {r.get("id"): r for r in main.rows if isinstance(r, dict)}
|
||||
for sid in sorted(set(cur) | set(old), key=str):
|
||||
if cur.get(sid) != old.get(sid):
|
||||
problems.append("fragments of main were removed outside a fold: the effective row %s is not the one of main (%s on main, %s here)"
|
||||
% (sid, old[sid].get("min_tests") if sid in old else "absent", cur[sid].get("min_tests") if sid in cur else "absent"))
|
||||
expected = set(main.consumed) | {n for name in removed for n in main.fragments[name]["consumes"]}
|
||||
if set(current.consumed) != expected:
|
||||
problems.append("a fold moves the `%s` of the removed fragments into %s and nothing else: expected %d nodeid(s), found %d (missing: %s; extra: %s)"
|
||||
% (CONSUMES, CONSUMED_NAME, len(expected), len(current.consumed), ", ".join(sorted(expected - set(current.consumed))) or "none",
|
||||
", ".join(sorted(set(current.consumed) - expected)) or "none"))
|
||||
added = sorted(set(current.fragments) - set(main.fragments))
|
||||
if added:
|
||||
problems.append("a fold carries no new fragment, and the branch adds: %s" % ", ".join(added))
|
||||
return problems
|
||||
|
||||
|
||||
def against_main(current, main, retired=(), exists=os.path.exists, collected=None, judged=None):
|
||||
"""The list only grows: every suite of main is still here, with no lower minimum, no exact turned off, no lost
|
||||
test or OS and the same marker. `main` is read leniently (it may be older than the current format).
|
||||
"""The list only grows, on EFFECTIVE rows (the base + the fragments) on both sides: every suite of main is still here, with no lower minimum, no
|
||||
exact turned off, no lost test or OS and the same marker. `current` and `main` are `Required`; main is read leniently (it may be older than the
|
||||
current format).
|
||||
|
||||
A fragment of main is never edited. It may leave (be missing here) only in a fold (`_fold_problems`); outside a fold consumed.json is main's.
|
||||
|
||||
The one way a test leaves a row is `retired` (the list of MAIN, never of the branch): a file that main retired and that no longer exists
|
||||
(`exists`, in the checkout judged) is not a lost test, and the minimum of the row may go down by exactly the tests main counted for that file
|
||||
in that row (``tests[row id]``), and by no more. A retired file that is still on disk is not excused: it must stay in its rows.
|
||||
|
||||
The other way is a single retired test (``nodeid``, ``suite``, ``count``) whose file stays in the row: the minimum of the suite may go down by
|
||||
the ``count`` of its entries, and by no more. ``collected`` (the node ids of the junit of the judged leg) and ``judged`` (that leg's suite) let
|
||||
The other way is a single retired test (``nodeid``, ``suite``, ``count``) whose file stays in the row, consumed by a fragment of the branch with a
|
||||
negative value (`_retirement_allowance`). ``collected`` (the node ids of the junit of the judged leg) and ``judged`` (that leg's suite) let
|
||||
the judge see that a declared nodeid is gone from the leg; of the collection of main it has only the count."""
|
||||
problems = []
|
||||
if not isinstance(main, list):
|
||||
return ["the list of main is not a JSON list: it cannot be compared"]
|
||||
retired = list(retired)
|
||||
changed = sorted(n for n in main.fragments if n in current.fragments and current.fragments[n] != main.fragments[n])
|
||||
removed = sorted(n for n in main.fragments if n not in current.fragments)
|
||||
for name in changed:
|
||||
problems.append("the fragment %s of main was changed here: a fragment is never edited" % name)
|
||||
if removed:
|
||||
problems += _fold_problems(current, main, removed)
|
||||
elif set(current.consumed) != set(main.consumed):
|
||||
problems.append("%s differs from main's outside a fold (a retirement is consumed by a fragment, and only a fold moves it)" % CONSUMED_NAME)
|
||||
gone = {e["file"]: e["tests"] for e in retired if isinstance(e, dict) and isinstance(e.get("file"), str)
|
||||
and isinstance(e.get("tests"), dict) and not exists(e["file"])}
|
||||
by_id = {s.get("id"): s for s in current if isinstance(s, dict)}
|
||||
for old in main:
|
||||
by_test, why = _retirement_allowance(current, main, retired, collected, judged)
|
||||
problems += why
|
||||
by_id = {s.get("id"): s for s in current.rows if isinstance(s, dict)}
|
||||
for old in main.rows:
|
||||
if not isinstance(old, dict):
|
||||
continue
|
||||
sid = old.get("id")
|
||||
@@ -479,10 +695,7 @@ def against_main(current, main, retired=(), exists=os.path.exists, collected=Non
|
||||
lost = [t for t in old.get("tests", []) if t not in new.get("tests", [])]
|
||||
excused = [t for t in lost if t in gone]
|
||||
lost = [t for t in lost if t not in gone]
|
||||
allowed = sum(_int(gone[t].get(sid)) for t in excused)
|
||||
by_test, why = _retired_tests_of(old, retired, collected, judged)
|
||||
allowed += by_test
|
||||
problems += why
|
||||
allowed = sum(_int(gone[t].get(sid)) for t in excused) + by_test.get(sid, 0)
|
||||
if _int(new.get("min_tests")) < _int(old.get("min_tests")) - allowed:
|
||||
problems.append("the minimum of %s went down: %s on main, %s here%s"
|
||||
% (sid, old.get("min_tests"), new.get("min_tests"),
|
||||
@@ -565,7 +778,8 @@ def cmd_judge(ns):
|
||||
"problems": problems}
|
||||
code_on_red = 1
|
||||
try:
|
||||
suites = load_required(ns.required)
|
||||
required = read_required(ns.required)
|
||||
suites = required.rows
|
||||
row = find_suite(suites, ns.suite, ns.os)
|
||||
except BadList as exc:
|
||||
problems.append(str(exc))
|
||||
@@ -609,8 +823,8 @@ def cmd_judge(ns):
|
||||
if collected < minimum:
|
||||
problems.append("collected %d test(s), fewer than the minimum %s" % (collected, minimum))
|
||||
elif row.get("exact") and collected != minimum:
|
||||
problems.append("collected %d test(s), but the suite is exact: %s, not more (a test was added: raise min_tests "
|
||||
"by hand)" % (collected, minimum))
|
||||
problems.append("collected %d test(s), but the suite is exact: %s, not more (a test was added: add a fragment, "
|
||||
"`ci_verdict.py fragment --name <slug> --set %s=N`)" % (collected, minimum, ns.suite))
|
||||
missing = []
|
||||
for entry in row.get("tests", []):
|
||||
why = required_status(entry, cases)
|
||||
@@ -618,6 +832,8 @@ def cmd_judge(ns):
|
||||
missing.append(entry)
|
||||
problems.append(why)
|
||||
|
||||
if ns.main_has_no_fragments and not ns.main_required:
|
||||
problems.append("--main-has-no-fragments without --main-required: it says nothing")
|
||||
if ns.main_has_no_list and not ns.main_required:
|
||||
problems.append("--main-has-no-list without --main-required: it says nothing")
|
||||
elif ns.main_required:
|
||||
@@ -628,8 +844,10 @@ def cmd_judge(ns):
|
||||
try:
|
||||
retired, retired_problems = retired_of_main(ns.main_required)
|
||||
problems += retired_problems
|
||||
problems += against_main(suites, _read_json_list(ns.main_required), retired,
|
||||
collected={n for n, _o in cases}, judged=ns.suite)
|
||||
main_required, main_problems = read_main_required(ns.main_required, ns.main_has_no_fragments)
|
||||
problems += main_problems
|
||||
if main_required is not None:
|
||||
problems += against_main(required, main_required, retired, collected={n for n, _o in cases}, judged=ns.suite)
|
||||
except Usage as exc:
|
||||
problems.append(str(exc))
|
||||
elif ns.main_has_no_list:
|
||||
@@ -659,6 +877,64 @@ def _finish(ns, result, code_on_red):
|
||||
return 0
|
||||
|
||||
|
||||
def _names_on_ref(folder, ref):
|
||||
"""-> the file names of `folder` on the git ref `ref` (empty when the folder is not there on that ref). A ref git cannot read is a usage error:
|
||||
a name that main may already have must never be guessed."""
|
||||
try:
|
||||
done = subprocess.run(["git", "-C", str(folder.parent), "ls-tree", "--name-only", ref, "--", folder.name + "/"],
|
||||
capture_output=True, text=True, timeout=60)
|
||||
except (OSError, subprocess.SubprocessError) as exc:
|
||||
raise Usage("cannot ask git for %s: %s" % (ref, exc))
|
||||
if done.returncode != 0:
|
||||
raise Usage("git cannot list %s/ on %s (%s): fetch it, or name another ref with --main-ref"
|
||||
% (folder.name, ref, done.stderr.strip() or "exit %d" % done.returncode))
|
||||
return {Path(line.strip()).name for line in done.stdout.splitlines() if line.strip()}
|
||||
|
||||
|
||||
def cmd_fragment(ns):
|
||||
"""Write the fragment of this change: a NEW file, never an edit of one that exists (here or on main)."""
|
||||
slug = ns.name
|
||||
if not re.match(r"^[a-z0-9][a-z0-9._-]*$", slug or "") or (slug + ".json") == CONSUMED_NAME:
|
||||
raise Usage("--name %r is not a slug: lower-case letters, digits, '.', '_' and '-', starting with a letter or a digit (and not 'consumed')" % slug)
|
||||
base = _read_json_list(ns.required)
|
||||
problems = validate_list(base)
|
||||
if problems:
|
||||
raise _bad_list("the required list %s is malformed:" % ns.required, problems)
|
||||
folder = fragments_dir(ns.required)
|
||||
if not folder.is_dir():
|
||||
raise Usage("the folder %s does not exist" % folder)
|
||||
ids = {row["id"] for row in base}
|
||||
content = {}
|
||||
for item in ns.set or []:
|
||||
row, _eq, number = item.rpartition("=")
|
||||
if not _eq or row not in ids:
|
||||
raise Usage("--set %r is not ROW=N with a row of the list" % item)
|
||||
try:
|
||||
value = int(number)
|
||||
except ValueError:
|
||||
raise Usage("--set %r: N must be an integer" % item)
|
||||
if row in content:
|
||||
raise Usage("--set names %s twice" % row)
|
||||
content[row] = value
|
||||
consumes = list(ns.consumes or [])
|
||||
fragment, bad = _parse_fragment(dict(content, **({CONSUMES: consumes} if consumes else {})), ids)
|
||||
if bad:
|
||||
raise Usage("the fragment would be malformed: %s" % "; ".join(bad))
|
||||
taken = {name for name in os.listdir(folder)} | _names_on_ref(folder, ns.main_ref)
|
||||
name, n = slug, 1
|
||||
while name + ".json" in taken:
|
||||
n += 1
|
||||
name = "%s-%d" % (slug, n)
|
||||
path = folder / (name + ".json")
|
||||
out = dict(content)
|
||||
if consumes:
|
||||
out[CONSUMES] = consumes
|
||||
with open(path, "xb") as fh: # "x": never over a file that is there
|
||||
fh.write((json.dumps(out, indent=1, ensure_ascii=False) + "\n").encode("utf-8"))
|
||||
print(path)
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_complete(ns):
|
||||
suites = load_required(ns.required)
|
||||
expected = {(s["id"], o) for s in suites for o in s["os"]}
|
||||
@@ -738,15 +1014,26 @@ def main(argv=None):
|
||||
j.add_argument("--main-required")
|
||||
j.add_argument("--main-has-no-list", action="store_true",
|
||||
help="the gate checked main out and the list is not there (a failed checkout is not this)")
|
||||
j.add_argument("--main-has-no-fragments", action="store_true",
|
||||
help="git says the ref main's list was read from has no ci/required-suites.d (a release older than the fragments): "
|
||||
"main is compared on its base list. Red while the folder is there; without it and without the folder: red")
|
||||
c = sub.add_parser("complete", help="check that every (suite, os) reported green at one commit")
|
||||
c.add_argument("--required", required=True)
|
||||
c.add_argument("--results", required=True)
|
||||
f = sub.add_parser("fragment", help="write the fragment of a change (a new file in required-suites.d)")
|
||||
f.add_argument("--required", required=True)
|
||||
f.add_argument("--name", required=True, help="the slug of the branch; -2, -3, ... is added if the name exists here or on main")
|
||||
f.add_argument("--set", action="append", metavar="ROW=N", help="the tests this change adds (N > 0) to a row; repeat for more rows")
|
||||
f.add_argument("--consumes", action="append", metavar="NODEID", help="the retired test a negative N consumes; repeat")
|
||||
f.add_argument("--main-ref", default="origin/main", help="the ref whose fragments the name must not collide with (default origin/main)")
|
||||
ns = ap.parse_args(argv)
|
||||
try:
|
||||
if ns.cmd == "judge":
|
||||
if not ns.binary:
|
||||
raise Usage("judge needs --binary (the engine the suite ran against: its hash goes in the result)")
|
||||
return cmd_judge(ns)
|
||||
if ns.cmd == "fragment":
|
||||
return cmd_fragment(ns)
|
||||
if ns.cmd == "complete":
|
||||
return cmd_complete(ns)
|
||||
return cmd_args(ns)
|
||||
|
||||
@@ -16,6 +16,7 @@ import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
||||
import ci_ab_oracle as ab # noqa: E402
|
||||
import ci_verdict # noqa: E402 (the loader of the rows: min_tests is the list plus its fragments)
|
||||
import ci_crash_evidence as crash # noqa: E402
|
||||
import ci_host_gate as gate # noqa: E402
|
||||
|
||||
@@ -762,7 +763,7 @@ def test_the_recorders_own_test_runs_in_the_host_job_after_the_a_a_and_is_left_o
|
||||
assert "host-crash-e2e.xml" in host_job.split("Upload what the test saved")[1]
|
||||
shared = _job(text, "e2e-linux")
|
||||
assert crash_file not in _job(text, "e2e-host-windows") and crash_file not in shared and 'wrapper.e2e.suite.linux.${{ matrix.part }}' in shared
|
||||
rows = {r["id"]: r for r in json.loads((root / "ci" / "required-suites.json").read_text(encoding="utf-8"))}
|
||||
rows = {r["id"]: r for r in ci_verdict.effective_rows(root / "ci" / "required-suites.json")}
|
||||
row = rows["wrapper.e2e.ab_host_crash"]
|
||||
assert row["os"] == ["linux"] and row["linux_only"].strip() and row["tests"] == [crash_file] and row["min_tests"] == 1 and row["exact"] is True and row["marker"] == "e2e"
|
||||
assert rows["wrapper.e2e.ab_host"]["min_tests"] == 1 and rows["wrapper.e2e.ab_host"]["tests"] == ["tests/test_ab_host_e2e.py"], "the A/A is still the one test of its row"
|
||||
|
||||
@@ -41,6 +41,9 @@ def _required(tmp_path, **over):
|
||||
row.update(over)
|
||||
path = tmp_path / "required.json"
|
||||
path.write_text(json.dumps([row]), encoding="utf-8")
|
||||
folder = tmp_path / "required-suites.d" # the list is read with the folder of its fragments next to it
|
||||
folder.mkdir(exist_ok=True)
|
||||
(folder / "consumed.json").write_text("[]", encoding="utf-8")
|
||||
return str(path)
|
||||
|
||||
|
||||
|
||||
+366
-39
@@ -36,8 +36,15 @@ def _suite(**over):
|
||||
return row
|
||||
|
||||
|
||||
def _write_required(path, rows):
|
||||
def _write_required(path, rows, fragments=None, consumed=None):
|
||||
"""The list, and the folder of its fragments next to it (it always exists: it holds consumed.json). `fragments` is {slug: content}."""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text("[\n" + ",\n".join(" " + json.dumps(r) for r in rows) + "\n]\n", encoding="utf-8")
|
||||
folder = path.with_name("required-suites.d")
|
||||
folder.mkdir(exist_ok=True)
|
||||
(folder / "consumed.json").write_text(json.dumps(consumed or []), encoding="utf-8")
|
||||
for slug, content in (fragments or {}).items():
|
||||
(folder / (slug + ".json")).write_text(json.dumps(content), encoding="utf-8")
|
||||
return path
|
||||
|
||||
|
||||
@@ -60,8 +67,8 @@ GREEN = [_case(FILE_A, "test_x"), _case(FILE_A, "test_y[p1]"), _case(FILE_B, "te
|
||||
SHA = "a" * 40
|
||||
|
||||
|
||||
def _judge(tmp_path, cases, rows=None, extra=(), suite="s.one", os_name="linux", with_binary=True, commit=SHA):
|
||||
required = _write_required(tmp_path / "required.json", rows or [_suite()])
|
||||
def _judge(tmp_path, cases, rows=None, extra=(), suite="s.one", os_name="linux", with_binary=True, commit=SHA, fragments=None, consumed=None):
|
||||
required = _write_required(tmp_path / "required.json", rows or [_suite()], fragments, consumed)
|
||||
junit = _junit(tmp_path / "junit.xml", cases) if cases is not None else tmp_path / "absent.xml"
|
||||
binary = tmp_path / "firefox.bin"
|
||||
binary.write_bytes(b"engine")
|
||||
@@ -181,8 +188,9 @@ def test_a_class_in_the_junit_is_part_of_the_node_id():
|
||||
|
||||
|
||||
# --- against main ------------------------------------------------------------------------------------------------
|
||||
def _main_file(tmp_path, rows):
|
||||
return _write_required(tmp_path / "main.json", rows)
|
||||
def _main_file(tmp_path, rows, fragments=None, consumed=None):
|
||||
"""main's list in a folder of its own: its fragments are the folder next to IT."""
|
||||
return _write_required(tmp_path / "mainside" / "main.json", rows, fragments, consumed)
|
||||
|
||||
|
||||
def test_a_list_that_only_grew_is_green(tmp_path):
|
||||
@@ -260,11 +268,11 @@ def test_a_main_list_older_than_the_format_is_still_compared(tmp_path):
|
||||
GONE = "tests/test_d.py"
|
||||
|
||||
|
||||
def _main_with(tmp_path, rows, retired=None):
|
||||
def _main_with(tmp_path, rows, retired=None, fragments=None, consumed=None):
|
||||
"""main's list in its own folder, and the retired list of main next to it."""
|
||||
folder = tmp_path / "main"
|
||||
folder.mkdir()
|
||||
required = _write_required(folder / "required.json", rows)
|
||||
folder.mkdir(parents=True)
|
||||
required = _write_required(folder / "required.json", rows, fragments, consumed)
|
||||
if retired is not None:
|
||||
(folder / verdict.RETIRED_NAME).write_text(json.dumps(retired), encoding="utf-8")
|
||||
return required
|
||||
@@ -349,36 +357,51 @@ def test_a_retired_file_does_not_excuse_another_loss_in_the_same_row(tmp_path, m
|
||||
GONE_NODE = FILE_A + "::test_gone"
|
||||
|
||||
|
||||
def _retired_test(nodeid=GONE_NODE, suite="s.one", count=1, from_min_tests=5, **over):
|
||||
entry = {"nodeid": nodeid, "suite": suite, "count": count, "from_min_tests": from_min_tests, "reason": "removed with its bundle", "decided_by": "pm", "date": "2026-11-27"}
|
||||
_OMIT = object()
|
||||
|
||||
|
||||
def _retired_test(nodeid=GONE_NODE, suite="s.one", count=1, from_min_tests=_OMIT, **over):
|
||||
"""An entry of main's retired-tests.json for a single test. `from_min_tests` is optional (and ignored): left out unless a test passes it."""
|
||||
entry = {"nodeid": nodeid, "suite": suite, "count": count, "reason": "removed with its bundle", "decided_by": "pm", "date": "2026-11-27"}
|
||||
if from_min_tests is not _OMIT:
|
||||
entry["from_min_tests"] = from_min_tests
|
||||
entry.update(over)
|
||||
return entry
|
||||
|
||||
|
||||
def _main_that_had_the_test(tmp_path, retired, min_tests=5):
|
||||
def _main_that_had_the_test(tmp_path, retired, min_tests=5, fragments=None, consumed=None):
|
||||
"""main's row of FILE_A, FILE_B, NODE with one more test (the one that is retired) in the floor."""
|
||||
return _main_with(tmp_path, [_suite(min_tests=min_tests)], retired)
|
||||
return _main_with(tmp_path, [_suite(min_tests=min_tests)], retired, fragments, consumed)
|
||||
|
||||
|
||||
def _retiring(*nodeids, row="s.one", value=-1):
|
||||
"""The fragment of the PR that retires tests: a negative value for the row, and the retirements it consumes."""
|
||||
return {"retire-it": {row: value, "consumes": list(nodeids)}}
|
||||
|
||||
|
||||
def test_a_declared_test_lets_the_floor_drop_by_exactly_its_count_is_green(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()])
|
||||
assert _judge(tmp_path, GREEN, extra=["--main-required", str(main)])[0] == 0 # 5 on main, 4 here, 1 declared
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
assert code == 0 # 5 on main, 5 in the list, -1 of the fragment: 4 here
|
||||
|
||||
|
||||
def test_the_counts_of_the_entries_of_a_suite_are_summed(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
other = FILE_B + "::test_also_gone"
|
||||
other, third = FILE_B + "::test_also_gone", FILE_A + "::t3"
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(from_min_tests=7), _retired_test(other, from_min_tests=7),
|
||||
_retired_test(nodeid=FILE_A + "::t3", from_min_tests=7)], min_tests=7)
|
||||
assert _judge(tmp_path, GREEN, extra=["--main-required", str(main)])[0] == 0 # 7 -> 4: three declared
|
||||
_retired_test(nodeid=third, from_min_tests=7)], min_tests=7)
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=7)], fragments=_retiring(GONE_NODE, other, third, value=-3),
|
||||
extra=["--main-required", str(main)])
|
||||
assert code == 0 # 7 -> 4: three declared
|
||||
|
||||
|
||||
def test_a_floor_that_drops_by_more_than_the_declared_count_is_red(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(count=1, from_min_tests=6)], min_tests=6) # 6 -> 4 here: one declared, two lost
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", str(main)])
|
||||
assert code == 1 and "went down" in capsys.readouterr().out
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(count=1)], min_tests=6) # 6 -> 4 here: one declared, two lost
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=6)], fragments=_retiring(GONE_NODE, value=-2), extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "went down" in out and "account for 1" in out
|
||||
|
||||
|
||||
def test_a_test_that_goes_with_no_entry_is_red(tmp_path, monkeypatch, capsys):
|
||||
@@ -396,7 +419,7 @@ def test_an_entry_of_another_suite_or_of_a_file_the_row_does_not_run_excuses_not
|
||||
main = _main_that_had_the_test(folder, [entry])
|
||||
sub = tmp_path / ("run%d" % i)
|
||||
sub.mkdir()
|
||||
code, _r = _judge(sub, GREEN, extra=["--main-required", str(main)])
|
||||
code, _r = _judge(sub, GREEN, rows=[_suite(min_tests=5)], fragments=_retiring(entry["nodeid"]), extra=["--main-required", str(main)])
|
||||
assert code == 1 and "went down" in capsys.readouterr().out, entry
|
||||
|
||||
|
||||
@@ -404,7 +427,7 @@ def test_a_declared_test_that_the_suite_still_collects_is_red(tmp_path, monkeypa
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()])
|
||||
still = GREEN + [_case(FILE_A, "test_gone")]
|
||||
code, _r = _judge(tmp_path, still, rows=[_suite(min_tests=5)], extra=["--main-required", str(main)])
|
||||
code, _r = _judge(tmp_path, still, rows=[_suite(min_tests=6)], fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and GONE_NODE in out and "still collects it" in out
|
||||
|
||||
@@ -413,7 +436,7 @@ def test_a_declared_test_still_collected_with_a_parameter_is_red_and_excuses_not
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()])
|
||||
still = GREEN[:3] + [_case(FILE_A, "test_gone[p1]")] # 4 tests, the floor of 4 lowered by the entry
|
||||
code, _r = _judge(tmp_path, still, extra=["--main-required", str(main)])
|
||||
code, _r = _judge(tmp_path, still, rows=[_suite(min_tests=5)], fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "still collects it" in out and "went down" in out
|
||||
|
||||
@@ -422,8 +445,9 @@ def test_the_retired_tests_of_the_branch_excuse_nothing(tmp_path, monkeypatch, c
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, None)
|
||||
(tmp_path / verdict.RETIRED_NAME).write_text(json.dumps([_retired_test()]), encoding="utf-8")
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", str(main)])
|
||||
assert code == 1 and "went down" in capsys.readouterr().out
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "not a retired test of main" in out and "went down" in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad, why", [
|
||||
@@ -464,24 +488,26 @@ def test_files_and_tests_may_share_the_list():
|
||||
assert verdict.validate_retired([_retired(), _retired_test()], {"s.one"}) == []
|
||||
|
||||
|
||||
def test_an_entry_allows_the_drop_only_while_main_still_has_the_floor_it_was_written_at(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(from_min_tests=5)], min_tests=5)
|
||||
assert _judge(tmp_path, GREEN, extra=["--main-required", str(main)])[0] == 0
|
||||
capsys.readouterr()
|
||||
# the removal is on main: its floor is 4, the entry was written at 5 and is inert, so a further drop is red
|
||||
sub = tmp_path / "later"
|
||||
sub.mkdir()
|
||||
main = _main_that_had_the_test(sub, [_retired_test(from_min_tests=5)], min_tests=4)
|
||||
code, _r = _judge(sub, GREEN, rows=[_suite(min_tests=3)], extra=["--main-required", str(main)])
|
||||
assert code == 1 and "went down" in capsys.readouterr().out
|
||||
def test_an_old_entry_with_from_min_tests_and_a_new_one_without_it_are_both_valid_and_the_number_is_ignored():
|
||||
assert verdict.validate_retired([_retired_test(from_min_tests=5), _retired_test(FILE_B + "::t")], {"s.one"}) == []
|
||||
assert verdict.validate_retired([_retired_test(from_min_tests=5, nodeid=FILE_B + "::t", suite="s.two")], {"s.one", "s.two"}) == []
|
||||
|
||||
|
||||
def test_an_inert_entry_asks_nothing_of_a_suite_that_collects_the_test_again(tmp_path, monkeypatch):
|
||||
def test_a_retirement_is_used_whatever_the_floor_of_main_is_now(tmp_path, monkeypatch):
|
||||
"""The old entry counted only while main's floor was still `from_min_tests`; any merge in between made it inert and the retiring PR went red.
|
||||
Now it is used by name: main's floor is 7 (others merged), the entry says 5, and the fragment of the retirement is green."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(from_min_tests=5)], min_tests=4)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test(from_min_tests=5)], min_tests=7)
|
||||
code, _r = _judge(tmp_path, GREEN + [_case(FILE_A, "test_a"), _case(FILE_A, "test_b")], rows=[_suite(min_tests=7)],
|
||||
fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
assert code == 0 # 7 on main, -1 of the fragment, 6 collected
|
||||
|
||||
|
||||
def test_an_entry_already_consumed_asks_nothing_of_a_suite_that_collects_the_test_again(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()], min_tests=4, consumed=[GONE_NODE])
|
||||
again = GREEN + [_case(FILE_A, "test_gone")]
|
||||
assert _judge(tmp_path, again, rows=[_suite(min_tests=5)], extra=["--main-required", str(main)])[0] == 0
|
||||
assert _judge(tmp_path, again, rows=[_suite(min_tests=5)], consumed=[GONE_NODE], extra=["--main-required", str(main)])[0] == 0
|
||||
|
||||
|
||||
def test_the_entries_of_one_suite_must_share_one_from_min_tests():
|
||||
@@ -805,7 +831,8 @@ def test_complete_fails_on_an_unreadable_json_and_on_a_json_that_is_not_a_result
|
||||
|
||||
# --- the real list-----------------------------------------------------------------------------------------------
|
||||
def _real():
|
||||
return json.loads(REQUIRED.read_text(encoding="utf-8"))
|
||||
"""The rows of the real list as the judge reads them: the base plus the fragments (`min_tests` is the effective floor)."""
|
||||
return verdict.effective_rows(REQUIRED)
|
||||
|
||||
|
||||
def test_the_real_list_is_well_formed_for_the_judge_and_every_row_is_exact():
|
||||
@@ -1000,3 +1027,303 @@ def test_the_real_whole_suite_rows_name_files_only_and_hold_what_the_unit_job_of
|
||||
def test_a_suite_that_needs_root_only_on_linux_still_runs_on_windows():
|
||||
doh = [r for r in _real() if r["id"] == "wrapper.e2e.doh"][0]
|
||||
assert doh["os"] == ["linux", "windows"] and doh["needs_root"] == ["linux"]
|
||||
|
||||
|
||||
# --- the floor is the list plus the fragments of the folder next to it ----------------------------------------------
|
||||
def _cases(n):
|
||||
"""A junit of n passing tests (the four of GREEN and more of FILE_A)."""
|
||||
return GREEN + [_case(FILE_A, "test_more_%d" % i) for i in range(n - len(GREEN))]
|
||||
|
||||
|
||||
def _main_args(tmp_path, rows, fragments=None, consumed=None):
|
||||
return ["--main-required", str(_main_file(tmp_path, rows, fragments, consumed))]
|
||||
|
||||
|
||||
def test_two_fragments_on_one_row_add_up(tmp_path):
|
||||
both = {"pr-a": {"s.one": 2}, "pr-b": {"s.one": 3}}
|
||||
assert _judge(tmp_path, _cases(9), fragments=both)[0] == 0 # 4 in the list, 2 + 3 in the fragments
|
||||
assert verdict.effective_rows(tmp_path / "required.json")[0]["min_tests"] == 9
|
||||
assert _judge(tmp_path, _cases(8), fragments=both)[0] == 1
|
||||
|
||||
|
||||
def test_main_plus_two_open_prs_is_green_and_exact_holds_on_the_sum(tmp_path, capsys):
|
||||
both = {"pr-a": {"s.one": 2}, "pr-b": {"s.one": 3}}
|
||||
assert _judge(tmp_path, _cases(9), fragments=both, extra=_main_args(tmp_path, [_suite()]))[0] == 0
|
||||
capsys.readouterr()
|
||||
code, _r = _judge(tmp_path, _cases(10), fragments=both, extra=_main_args(tmp_path, [_suite()]))
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "exact: 9" in out and "add a fragment" in out
|
||||
# the same when main already has A and the branch adds B on top of it
|
||||
later = tmp_path / "later"
|
||||
assert _judge(later, _cases(9), fragments=both, extra=_main_args(later, [_suite()], {"pr-a": {"s.one": 2}}))[0] == 0
|
||||
|
||||
|
||||
def test_a_fragment_of_main_that_is_missing_outside_a_fold_is_red(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()], {"pr-a": {"s.one": 2}}) # main collects 6
|
||||
code, _r = _judge(tmp_path, _cases(4), extra=main) # the branch deleted the fragment: its own count is exact at 4
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "fragments of main were removed outside a fold" in out and "went down" in out
|
||||
|
||||
|
||||
def test_a_fold_with_equal_sums_is_green(tmp_path):
|
||||
main = _main_args(tmp_path, [_suite()], {"pr-a": {"s.one": 2}}) # 4 + 2
|
||||
assert _judge(tmp_path, _cases(6), rows=[_suite(min_tests=6)], extra=main)[0] == 0 # the list now says 6, the fragment is gone
|
||||
|
||||
|
||||
def test_a_fold_that_loses_one_is_red(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()], {"pr-a": {"s.one": 2}})
|
||||
code, _r = _judge(tmp_path, _cases(5), rows=[_suite(min_tests=5)], extra=main)
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "is not the one of main (6 on main, 5 here)" in out
|
||||
|
||||
|
||||
def test_a_fold_moves_the_consumes_of_the_removed_fragments_into_consumed_json(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
retire = {"retire-it": {"s.one": -1, "consumes": [GONE_NODE]}}
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()], min_tests=5, fragments=retire) # 5 - 1 = 4
|
||||
assert _judge(tmp_path, GREEN, rows=[_suite(min_tests=4)], consumed=[GONE_NODE], extra=["--main-required", str(main)])[0] == 0
|
||||
capsys.readouterr()
|
||||
sub = tmp_path / "forgot"
|
||||
main = _main_that_had_the_test(sub, [_retired_test()], min_tests=5, fragments=retire)
|
||||
code, _r = _judge(sub, GREEN, rows=[_suite(min_tests=4)], extra=["--main-required", str(main)]) # consumed.json did not gain the nodeid
|
||||
assert code == 1 and "a fold moves the `consumes`" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_fold_carries_no_new_fragment(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()], {"pr-a": {"s.one": 2}})
|
||||
code, _r = _judge(tmp_path, _cases(6), rows=[_suite(min_tests=5)], fragments={"pr-c": {"s.one": 1}}, extra=main) # 5 + 1 = 6 as on main
|
||||
assert code == 1 and "a fold carries no new fragment" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_fragment_of_main_that_is_edited_is_red(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()], {"pr-a": {"s.one": 2}})
|
||||
code, _r = _judge(tmp_path, _cases(7), fragments={"pr-a": {"s.one": 3}}, extra=main)
|
||||
assert code == 1 and "the fragment pr-a of main was changed here" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_consumed_json_that_differs_from_main_outside_a_fold_is_red(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()])
|
||||
code, _r = _judge(tmp_path, GREEN, consumed=[GONE_NODE], extra=main)
|
||||
assert code == 1 and "consumed.json differs from main's outside a fold" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_negative_value_with_no_consumes_is_a_malformed_list(tmp_path, capsys):
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], fragments={"retire-it": {"s.one": -1}})
|
||||
assert code == 2 and "negative" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_negative_value_that_consumes_a_test_main_never_retired_is_red(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, None)
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], fragments=_retiring(GONE_NODE), extra=["--main-required", str(main)])
|
||||
assert code == 1 and "not a retired test of main" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_retirement_that_main_consumed_in_its_consumed_json_cannot_be_consumed_again(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()], consumed=[GONE_NODE])
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], consumed=[GONE_NODE], fragments=_retiring(GONE_NODE),
|
||||
extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "already consumed" in out and "main's consumed.json" in out
|
||||
|
||||
|
||||
def test_a_retirement_that_a_fragment_of_main_consumed_cannot_be_consumed_again(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
first = {"first-retire": {"s.one": -1, "consumes": [GONE_NODE]}}
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()], fragments=first)
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=5)], fragments=dict(first, **{"second-retire": {"s.one": -1, "consumes": [GONE_NODE]}}),
|
||||
extra=["--main-required", str(main)])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 1 and "already consumed" in out and "the fragment first-retire of main" in out
|
||||
|
||||
|
||||
def test_the_same_retirement_in_two_fragments_of_the_branch_is_consumed_twice_and_red(tmp_path, monkeypatch, capsys):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
main = _main_that_had_the_test(tmp_path, [_retired_test()], min_tests=6)
|
||||
two = {"retire-a": {"s.one": -1, "consumes": [GONE_NODE]}, "retire-b": {"s.one": -1, "consumes": [GONE_NODE]}}
|
||||
code, _r = _judge(tmp_path, GREEN, rows=[_suite(min_tests=6)], fragments=two, extra=["--main-required", str(main)])
|
||||
assert code == 1 and "already consumed" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_main_s_list_without_its_folder_is_red(tmp_path, capsys):
|
||||
(tmp_path / "mainside").mkdir()
|
||||
(tmp_path / "mainside" / "main.json").write_text(json.dumps([_suite()]), encoding="utf-8")
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", str(tmp_path / "mainside" / "main.json")])
|
||||
assert code == 1 and "main's fragments are not known" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_a_malformed_fragment_of_main_is_red_never_ignored(tmp_path, capsys):
|
||||
main = _main_args(tmp_path, [_suite()], {"Not-A-Slug": {"s.one": 1}})
|
||||
code, _r = _judge(tmp_path, GREEN, extra=main)
|
||||
assert code == 1 and "main's fragments are not readable" in capsys.readouterr().out
|
||||
|
||||
|
||||
def _bad_fragment(tmp_path, name, content):
|
||||
required = _write_required(tmp_path / "required.json", [_suite()])
|
||||
folder = required.with_name("required-suites.d")
|
||||
if name is None:
|
||||
(folder / "consumed.json").unlink()
|
||||
folder.rmdir()
|
||||
else:
|
||||
(folder / name).write_text(content, encoding="utf-8")
|
||||
return required
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name, content, why", [
|
||||
("Upper.json", '{"s.one": 1}', "the name of a fragment"),
|
||||
("notes.txt", "1", "the name of a fragment"),
|
||||
("a.json", '{"s.unknown": 1}', "not a row of the list"),
|
||||
("a.json", '{"s.one": 0}', "is 0"),
|
||||
("a.json", '{"s.one": "2"}', "must be an integer"),
|
||||
("a.json", '{"s.one": true}', "must be an integer"),
|
||||
("a.json", '{"s.one": -1}', "has no `consumes`"),
|
||||
("a.json", '[1]', "JSON object"),
|
||||
("a.json", '{"s.one": 1', "cannot be read"),
|
||||
(None, "", "does not exist"),
|
||||
])
|
||||
def test_a_malformed_fragment_is_a_malformed_list_exit_2_with_the_reason(tmp_path, capsys, name, content, why):
|
||||
required = _bad_fragment(tmp_path, name, content)
|
||||
assert verdict.main(["args", "--required", str(required), "--suite", "s.one", "--os", "linux"]) == 2
|
||||
assert why in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_a_malformed_fragment_is_exit_2_for_judge_and_complete_too(tmp_path, capsys):
|
||||
required = _bad_fragment(tmp_path, "a.json", '{"s.one": 0}')
|
||||
junit = _junit(tmp_path / "junit.xml", GREEN)
|
||||
binary = tmp_path / "bin"
|
||||
binary.write_bytes(b"x")
|
||||
assert verdict.main(["judge", "--required", str(required), "--suite", "s.one", "--os", "linux", "--junit", str(junit),
|
||||
"--binary", str(binary), "--commit", SHA]) == 2
|
||||
assert "is 0" in capsys.readouterr().out
|
||||
(tmp_path / "results").mkdir()
|
||||
assert verdict.main(["complete", "--required", str(required), "--results", str(tmp_path / "results")]) == 2
|
||||
assert "is 0" in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_the_rewritten_base_list_has_one_value_per_line_and_is_the_dump_of_its_content():
|
||||
text = REQUIRED.read_bytes().decode("utf-8")
|
||||
assert "\r" not in text and text.endswith("]\n")
|
||||
assert text == json.dumps(json.loads(text), indent=1, ensure_ascii=False) + "\n"
|
||||
for number, line in enumerate(text.splitlines(), 1):
|
||||
stripped = line.strip().rstrip(",")
|
||||
# a line holds one thing: a bracket, a key with a scalar, a key opening a container, or one array item
|
||||
assert stripped in ("[", "]", "{", "}") or stripped.startswith('"') or stripped.lstrip("-").isdigit() or stripped in ("true", "false"), (number, line)
|
||||
|
||||
|
||||
def test_the_real_folder_of_fragments_exists_holds_consumed_json_and_every_fragment_loads():
|
||||
folder = verdict.fragments_dir(REQUIRED)
|
||||
assert folder.is_dir() and (folder / "consumed.json").is_file()
|
||||
assert [r["id"] for r in verdict.effective_rows(REQUIRED)] == [r["id"] for r in json.loads(REQUIRED.read_text(encoding="utf-8"))]
|
||||
|
||||
|
||||
def _git(cwd, *args):
|
||||
import subprocess
|
||||
return subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", *args],
|
||||
cwd=str(cwd), check=True, capture_output=True, text=True)
|
||||
|
||||
|
||||
def _repo_with_main(tmp_path, fragments=None):
|
||||
"""A repository whose branch `main` has ci/required-suites.json and its folder (with `fragments`)."""
|
||||
repo = tmp_path / "repo"
|
||||
(repo / "ci").mkdir(parents=True)
|
||||
required = _write_required(repo / "ci" / "required-suites.json", [_suite()], fragments)
|
||||
_git(repo, "init", "-q")
|
||||
_git(repo, "symbolic-ref", "HEAD", "refs/heads/main")
|
||||
_git(repo, "add", "-A")
|
||||
_git(repo, "commit", "-q", "-m", "main")
|
||||
return required
|
||||
|
||||
|
||||
def test_the_fragment_helper_adds_a_suffix_when_the_name_exists_and_never_overwrites(tmp_path, capsys):
|
||||
required = _repo_with_main(tmp_path, {"taken-on-main": {"s.one": 1}})
|
||||
folder = required.with_name("required-suites.d")
|
||||
|
||||
def run(*args):
|
||||
code = verdict.main(["fragment", "--required", str(required), "--main-ref", "main", *args])
|
||||
return code, capsys.readouterr().out.strip()
|
||||
|
||||
code, out = run("--name", "feature-x", "--set", "s.one=2")
|
||||
assert code == 0 and Path(out) == folder / "feature-x.json" and json.loads(Path(out).read_text(encoding="utf-8")) == {"s.one": 2}
|
||||
first = (folder / "feature-x.json").read_bytes()
|
||||
code, out = run("--name", "feature-x", "--set", "s.one=5")
|
||||
assert code == 0 and Path(out).name == "feature-x-2.json" and (folder / "feature-x.json").read_bytes() == first
|
||||
code, out = run("--name", "feature-x", "--set", "s.one=7")
|
||||
assert code == 0 and Path(out).name == "feature-x-3.json" and (folder / "feature-x-2.json").read_bytes() != first
|
||||
# a name only main has (it is not in the working tree) is taken too
|
||||
(folder / "taken-on-main.json").unlink()
|
||||
code, out = run("--name", "taken-on-main", "--set", "s.one=1")
|
||||
assert code == 0 and Path(out).name == "taken-on-main-2.json" and not (folder / "taken-on-main.json").exists()
|
||||
# the effective list reads what the helper wrote
|
||||
assert verdict.effective_rows(required)[0]["min_tests"] == 4 + 2 + 5 + 7 + 1
|
||||
|
||||
|
||||
def test_the_fragment_helper_refuses_what_the_loader_would_refuse(tmp_path, capsys):
|
||||
required = _repo_with_main(tmp_path)
|
||||
base = ["fragment", "--required", str(required), "--main-ref", "main"]
|
||||
assert verdict.main(base + ["--name", "x", "--set", "s.unknown=1"]) == 2
|
||||
assert verdict.main(base + ["--name", "x", "--set", "s.one=0"]) == 2
|
||||
assert verdict.main(base + ["--name", "x", "--set", "s.one=-1"]) == 2 # a negative value needs --consumes
|
||||
assert verdict.main(base + ["--name", "consumed", "--set", "s.one=1"]) == 2
|
||||
assert verdict.main(base + ["--name", "Bad Name", "--set", "s.one=1"]) == 2
|
||||
assert verdict.main(["fragment", "--required", str(required), "--main-ref", "no-such-ref", "--name", "x", "--set", "s.one=1"]) == 2
|
||||
assert sorted(p.name for p in required.with_name("required-suites.d").iterdir()) == ["consumed.json"]
|
||||
assert verdict.main(base + ["--name", "x", "--set", "s.one=-1", "--consumes", GONE_NODE]) == 0
|
||||
assert json.loads(next(required.with_name("required-suites.d").glob("x.json")).read_text(encoding="utf-8")) == {"s.one": -1, "consumes": [GONE_NODE]}
|
||||
|
||||
|
||||
def _defines(path, name):
|
||||
"""True if the file defines a function or a method called `name` (a static look: nothing is imported or collected)."""
|
||||
import ast
|
||||
try:
|
||||
tree = ast.parse(path.read_text(encoding="utf-8"))
|
||||
except (OSError, SyntaxError):
|
||||
return False
|
||||
return any(isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)) and n.name == name for n in ast.walk(tree))
|
||||
|
||||
|
||||
def test_every_retired_test_that_is_gone_from_its_file_is_consumed_or_in_a_fragment():
|
||||
"""A retirement whose test no longer exists was applied on main: it must be in consumed.json or in the `consumes` of a fragment, or a later
|
||||
PR could use it again to excuse an unrelated loss. A retirement whose test still exists is pending, and allowed."""
|
||||
required = verdict.read_required(REQUIRED)
|
||||
used = set(required.consumed) | {n for f in required.fragments.values() for n in f["consumes"]}
|
||||
unconsumed = []
|
||||
for entry in json.loads(RETIRED.read_text(encoding="utf-8")):
|
||||
if "nodeid" not in entry:
|
||||
continue
|
||||
file, test = entry["nodeid"].split("::", 1)
|
||||
if not _defines(ROOT / file, test.split("[", 1)[0].split("::")[-1]) and entry["nodeid"] not in used:
|
||||
unconsumed.append(entry["nodeid"])
|
||||
assert not unconsumed, "retired and gone, but not consumed: %s" % sorted(set(unconsumed))
|
||||
|
||||
|
||||
def _main_list_only(tmp_path, rows):
|
||||
"""main's list with NO folder next to it (a release older than the fragments)."""
|
||||
folder = tmp_path / "mainside"
|
||||
folder.mkdir()
|
||||
(folder / "main.json").write_text(json.dumps(rows), encoding="utf-8")
|
||||
return str(folder / "main.json")
|
||||
|
||||
|
||||
def test_a_main_with_no_fragments_declared_is_compared_on_its_base_list_and_the_run_says_so(tmp_path, capsys):
|
||||
main = _main_list_only(tmp_path, [_suite(min_tests=3, tests=[FILE_A])])
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", main, "--main-has-no-fragments"])
|
||||
out = capsys.readouterr().out
|
||||
assert code == 0 and "--main-has-no-fragments" in out and "compared on its base list" in out
|
||||
# compared for real: a base list that lost a suite of main is red
|
||||
sub = tmp_path / "lost"
|
||||
sub.mkdir()
|
||||
main = _main_list_only(sub, [_suite(), _suite(id="s.gone")])
|
||||
code, _r = _judge(sub, GREEN, extra=["--main-required", main, "--main-has-no-fragments"])
|
||||
assert code == 1 and "s.gone" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_the_declaration_that_main_has_no_fragments_while_its_folder_exists_is_red(tmp_path, capsys):
|
||||
main = _main_file(tmp_path, [_suite()])
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", str(main), "--main-has-no-fragments"])
|
||||
assert code == 1 and "says the ref of main has none" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_main_s_list_without_its_folder_and_without_the_declaration_stays_red(tmp_path, capsys):
|
||||
code, _r = _judge(tmp_path, GREEN, extra=["--main-required", _main_list_only(tmp_path, [_suite()])])
|
||||
assert code == 1 and "main's fragments are not known" in capsys.readouterr().out
|
||||
@@ -23,7 +23,6 @@ a minimum that is not the count, a Control+A row that is not that file. The gree
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -34,6 +33,8 @@ pytestmark = pytest.mark.unit
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
REQUIRED = ROOT / "ci" / "required-suites.json"
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
import ci_verdict # noqa: E402 (the loader of the rows: min_tests is the list plus its fragments)
|
||||
MARKER = "e2e"
|
||||
|
||||
PARTITION = {
|
||||
@@ -104,7 +105,7 @@ def _collected():
|
||||
|
||||
|
||||
def _rows():
|
||||
by_id = {r["id"]: r for r in json.loads(REQUIRED.read_text(encoding="utf-8"))}
|
||||
by_id = {r["id"]: r for r in ci_verdict.effective_rows(REQUIRED)}
|
||||
ids = [i for ids in PARTITION.values() for i in ids] + [CONTROL_A_ROW]
|
||||
missing = [i for i in ids if i not in by_id]
|
||||
assert not missing, "rows missing from ci/required-suites.json: %s" % missing
|
||||
|
||||
@@ -21,6 +21,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -28,6 +29,9 @@ import pytest
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
import ci_verdict # noqa: E402 (the loader of the rows: min_tests is the list plus its fragments)
|
||||
|
||||
WORKFLOW = ROOT / ".github" / "workflows" / "e2e.yml"
|
||||
SUITE = "wrapper.e2e.udp.exit"
|
||||
#: The job of the Linux parts and the prefix of the rows its matrix runs, one per part.
|
||||
@@ -38,7 +42,7 @@ ROW_ARGS = 'python scripts/ci_verdict.py args --required ci/required-suites.json
|
||||
|
||||
|
||||
def _suite(name: str = SUITE) -> dict:
|
||||
return next(s for s in json.loads((ROOT / "ci" / "required-suites.json").read_text(encoding="utf-8")) if s["id"] == name)
|
||||
return next(s for s in ci_verdict.effective_rows(ROOT / "ci" / "required-suites.json") if s["id"] == name)
|
||||
|
||||
|
||||
def _rows() -> dict:
|
||||
|
||||
@@ -13,13 +13,12 @@ This test reads the workflow as text (PyYAML is not a dependency of this package
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from test_the_root_e2e_run_in_the_root_step_and_nowhere_else import _matrix_parts, _rows, _steps, row_problems, step_if, step_part
|
||||
from test_the_root_e2e_run_in_the_root_step_and_nowhere_else import ci_verdict, _matrix_parts, _rows, _steps, row_problems, step_if, step_part
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
@@ -31,7 +30,7 @@ SUITE = "wrapper.e2e.udp.sandbox"
|
||||
|
||||
|
||||
def _suite() -> dict:
|
||||
return next(s for s in json.loads((ROOT / "ci" / "required-suites.json").read_text(encoding="utf-8")) if s["id"] == SUITE)
|
||||
return next(s for s in ci_verdict.effective_rows(ROOT / "ci" / "required-suites.json") if s["id"] == SUITE)
|
||||
|
||||
|
||||
def _env(body: str, key: str) -> list:
|
||||
|
||||
@@ -104,6 +104,10 @@ def _problems(text):
|
||||
problems.append("the judge that runs is the one of the branch under judgment, not the one of main")
|
||||
if "git show origin/main:ci/required-suites.json" not in run or "--main-required" not in run:
|
||||
problems.append("the list is not compared with the list of main (--main-required of `git show origin/main:ci/required-suites.json`)")
|
||||
if ("git cat-file -e origin/main:ci/required-suites.d" not in run or "git archive origin/main ci/required-suites.d" not in run
|
||||
or '"$RUNNER_TEMP/main/required-suites.d"' not in run):
|
||||
problems.append("main's folder of fragments is not copied next to main's list when main has it (git cat-file -e, then git archive origin/main ci/required-suites.d "
|
||||
"moved to $RUNNER_TEMP/main/required-suites.d): the floor of main would be its list without its fragments")
|
||||
if len(runs) != 1:
|
||||
problems.append("%d step(s) of the legs of Python 3.11 write a junit, one is needed" % len(runs))
|
||||
else:
|
||||
@@ -128,6 +132,13 @@ def test_the_unit_job_judges_the_exact_count_of_the_row_with_the_judge_of_main()
|
||||
assert not problems, "tests.yml, job unit: " + "; ".join(problems)
|
||||
|
||||
|
||||
def test_the_unit_job_copies_the_folder_of_the_fragments_of_main_next_to_its_list():
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
assert not _problems(text)
|
||||
assert any("folder of fragments" in p for p in _problems(text.replace("git archive origin/main ci/required-suites.d", "true"))), "no copy of the folder"
|
||||
assert any("folder of fragments" in p for p in _problems(text.replace("git cat-file -e origin/main:ci/required-suites.d", "true"))), "copied even when main has none"
|
||||
|
||||
|
||||
def test_the_unit_job_of_the_old_workflow_is_refused():
|
||||
problems = _problems(OLD_UNIT_JOB)
|
||||
assert any("judge with ci_verdict.py" in p for p in problems), problems
|
||||
|
||||
Reference in new issue
Block a user