Skip to content

Commit a9a58b2

Browse files
luisleo526claude
andcommitted
Merge engine main 7a7d099 into the #504 branch: drop TIMEOUT 180 from the six ownership manifest tests
Brings in the release-reset test fix (#509) so this branch's preflight is no longer red on the tag's catalog-diff test. Merge, no rebase, no force. The diff against main stays the one-line tests/CMakeLists.txt change. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2 parents 7504cf2 + 7a7d099 commit a9a58b2

2 files changed

Lines changed: 132 additions & 9 deletions

File tree

‎scripts/test_gen_run_failure_catalog_diff.py‎

Lines changed: 127 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
tags (a diff whose from tag published no catalog is recomputed offline; one
1313
whose from tag published a catalog is rebuilt by running the diff backwards;
1414
a hidden removal, a forged null from and required tags fail), the flags a
15-
sibling catalog uses, and this tree's own checked-in diff.
15+
sibling catalog uses, and this tree's own checked-in diff. What a diff says of
16+
a code follows the diff's own start (from.version against the code's since),
17+
so those tests hold before and after the reset a release brings.
1618
1719
The documentation page lists every class, code and argument kind of
1820
docker/run_failure_codes.json between two markers; test_docs_tables holds
@@ -111,6 +113,17 @@ def catalog_bytes(codes: dict) -> bytes:
111113
return (json.dumps(catalog, indent=1, sort_keys=True) + "\n").encode()
112114

113115

116+
def field_at(entry: dict, path: str) -> tuple:
117+
"""Whether `path` (object keys joined by '.', as a diff change spells a
118+
field) names a member of `entry`, and that member (None when it does not)."""
119+
value = entry
120+
for key in path.split("."):
121+
if not isinstance(value, dict) or key not in value:
122+
return False, None
123+
value = value[key]
124+
return True, value
125+
126+
114127
class Repo:
115128
def __init__(self, path: Path):
116129
self.path = path
@@ -187,6 +200,57 @@ def release(self, tag: str) -> None:
187200
self.repo.tag(tag)
188201
self.ok(self.repo.run("--check"))
189202

203+
def assert_diff_states_code(self, diff: dict, name: str, entry: dict) -> None:
204+
"""What `diff` must say of the code `name`, whose catalog entry is `entry`.
205+
206+
The diff's own start decides, so one expectation holds before and after
207+
the reset a release brings (--reset: from that release, nothing added).
208+
`since` is the release that first ships the code, from.version the
209+
release whose catalog the diff is against; the generator's version_key
210+
compares them as numbers, a candidate X.Y.Z-rc.N below its release X.Y.Z.
211+
"""
212+
start, since = diff["from"]["version"], entry["since"]
213+
start_key, since_key = generator.version_key(start), generator.version_key(since)
214+
self.assertIsNotNone(start_key, f"from.version {start!r} is no release version")
215+
self.assertIsNotNone(since_key, f"{name}: since {since!r} is no release version")
216+
added = [item for item in diff["added"] if item["code"] == name]
217+
self.assertNotIn(name, [item["code"] for item in diff["removed"]],
218+
f"{name} is removed: a published code is deprecated, never removed")
219+
# since is X.Y.Z, which a release shares with its candidates: from a candidate of
220+
# its own release (since X.Y.Z, the diff from X.Y.Z-rc.N) it cannot tell whether
221+
# the candidate shipped the code, so the diff says, and is held to what it says.
222+
after_start = bool(added) if start.startswith(since + "-rc.") else since_key > start_key
223+
if after_start:
224+
# It has not shipped in the diff's published base: corrections to its
225+
# class/args are part of the whole addition, not a breaking change.
226+
self.assertEqual(added, [{"code": name, "collection": "codes", "entry": entry}],
227+
f"{name} first ships in {since}, after {start} where the diff "
228+
"starts: the diff must add it, whole")
229+
self.assertNotIn(name, [item["code"] for item in diff["changed"]],
230+
f"{name} first ships in {since}, after {start} where the diff "
231+
"starts: it is an addition, not a change")
232+
return
233+
# The start's catalog carries it: the diff does not add it. It may list it as
234+
# changed -- a correction made since the release -- but for real changes only,
235+
# and as this tree's catalog holds them.
236+
self.assertEqual(added, [],
237+
f"{name} first ships in {since}, not after {start} where the diff "
238+
"starts: it is no addition")
239+
changed = [item for item in diff["changed"] if item["code"] == name]
240+
self.assertLessEqual(len(changed), 1, f"{name} is changed twice")
241+
for item in changed:
242+
self.assertEqual(item["collection"], "codes")
243+
self.assertTrue(item["fields"], f"{name} is changed in no field")
244+
for change in item["fields"]:
245+
sides = [(change[f"{side}Present"], json.dumps(change[side], sort_keys=True))
246+
for side in ("before", "after")]
247+
where = f"{name} {change['path']}"
248+
self.assertNotEqual(sides[0], sides[1],
249+
f"{where} is listed as changed, and did not change")
250+
held, value = field_at(entry, change["path"])
251+
self.assertEqual(sides[1], (held, json.dumps(value, sort_keys=True)),
252+
f"{where}: the after side is not this tree's catalog")
253+
190254
def test_self_test(self) -> None:
191255
result = subprocess.run([sys.executable, str(SCRIPT), "--self-test"],
192256
capture_output=True, text=True)
@@ -455,14 +519,69 @@ def test_report_sink_failed_is_engine_fault(self) -> None:
455519
"report sink write failed",
456520
"report sink write made no progress",
457521
])
458-
# It has not shipped in the diff's published base: corrections to its
459-
# class/args are part of the whole addition, not a breaking change.
522+
# What the diff says of the code follows the diff's own start: an addition
523+
# while its release is in progress (the diff starts at an older release),
524+
# part of the base once a release reset has moved the start to its release.
460525
diff = json.loads((ROOT / DIFF).read_text(encoding="utf-8"))
461-
additions = [item for item in diff["added"] if item["code"] == "report_sink_failed"]
462-
self.assertEqual(additions, [
463-
{"code": "report_sink_failed", "collection": "codes", "entry": entry},
464-
])
465-
self.assertNotIn("report_sink_failed", [item["code"] for item in diff["changed"]])
526+
self.assert_diff_states_code(diff, "report_sink_failed", entry)
527+
528+
def test_a_codes_diff_holds_before_and_after_its_release_reset(self) -> None:
529+
# alpha ships in 1.1.0. While that release is in progress the diff, from
530+
# v1.0.0, adds it; after the reset the release brings it is in the diff's
531+
# base and the diff adds nothing. One expectation holds on both sides.
532+
alpha = code("1.1.0")
533+
self.start({"alpha": alpha})
534+
before = self.repo.diff()
535+
self.assertEqual([item["code"] for item in before["added"]], ["alpha"])
536+
self.assert_diff_states_code(before, "alpha", alpha)
537+
self.release("v1.1.0")
538+
after = self.repo.diff()
539+
self.assertEqual(after["added"], [])
540+
self.assert_diff_states_code(after, "alpha", alpha)
541+
542+
def refused(diff: dict, needle: str) -> None:
543+
with self.assertRaises(AssertionError) as raised:
544+
self.assert_diff_states_code(diff, "alpha", alpha)
545+
self.assertIn(needle, str(raised.exception))
546+
547+
def starting_at(diff: dict, version: str) -> dict:
548+
moved = json.loads(json.dumps(diff))
549+
moved["from"]["version"] = version
550+
return moved
551+
552+
# The expectation can fail: each diff below says the other side's thing.
553+
refused(starting_at(before, "1.1.0"), "is no addition")
554+
refused(starting_at(after, "1.0.0"), "the diff must add it")
555+
# A candidate sorts below its release: 1.0.9-rc.2 starts before 1.1.0,
556+
# 1.2.0-rc.1 after it.
557+
for version, state in (("1.0.9-rc.2", before), ("1.2.0-rc.1", after)):
558+
self.assert_diff_states_code(starting_at(state, version), "alpha", alpha)
559+
refused(starting_at(after, "1.0.9-rc.2"), "the diff must add it")
560+
refused(starting_at(before, "1.2.0-rc.1"), "is no addition")
561+
# 1.1.0-rc.1 shares alpha's since: the diff says whether the candidate
562+
# shipped alpha, and either way is held to its rules.
563+
for state in (before, after):
564+
self.assert_diff_states_code(starting_at(state, "1.1.0-rc.1"), "alpha", alpha)
565+
# A correction made after the release is a change of a published code: the
566+
# diff may say so, truthfully, and nothing else.
567+
said = {"path": "description", "beforePresent": True, "afterPresent": True,
568+
"before": "older", "after": "d"}
569+
corrected = starting_at(after, "1.1.0")
570+
corrected["changed"] = [{"code": "alpha", "collection": "codes", "fields": [said]}]
571+
self.assert_diff_states_code(corrected, "alpha", alpha)
572+
for lie, needle in ((dict(said, before="d"), "did not change"),
573+
(dict(said, after="e"), "not this tree's catalog")):
574+
lying = starting_at(corrected, "1.1.0")
575+
lying["changed"][0]["fields"] = [lie]
576+
refused(lying, needle)
577+
# Before its release the code is an addition, whole: no change beside it.
578+
unreleased = starting_at(before, "1.0.0")
579+
unreleased["changed"] = corrected["changed"]
580+
refused(unreleased, "not a change")
581+
# A published code is never removed.
582+
removed = starting_at(after, "1.1.0")
583+
removed["removed"] = [{"code": "alpha", "collection": "codes", "entry": alpha}]
584+
refused(removed, "is removed")
466585

467586
def test_docs_tables(self) -> None:
468587
catalog = json.loads((ROOT / CATALOG).read_text(encoding="utf-8"))

‎tests/test_s4e_misc_contracts.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def test_upcoming_failure_codes_are_announced():
9191
releases = {row["entry"]["since"] for row in diff["added"]
9292
if row["collection"] == "codes"}
9393
upcoming = {name for name, entry in codes.items() if entry["since"] in releases}
94-
assert upcoming, "the release diff must identify the upcoming code population"
94+
# Right after a release the diff is reset (from that release, nothing added): no
95+
# release is upcoming and the page has nothing to announce, so the population is
96+
# empty by construction and the comparison below holds for it. (The former
97+
# "assert upcoming" failed exactly there; an assertion that every added code is
98+
# in `upcoming` would be true by construction, so none is made.)
9599
announced = set(re.findall(r"`([a-z][a-z0-9_]+)`", failure_code_preamble()))
96100
assert upcoming <= announced, f"unannounced failure codes: {sorted(upcoming - announced)}"

0 commit comments

Comments
 (0)