test(wac): pin the failure record with one corpus both SDKs read

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-07-28 11:25:26 +00:00
co-authored by Claude Opus 5
parent aeaea57ca1
commit a558d876d8
4 changed files with 192 additions and 15 deletions
@@ -2,6 +2,7 @@
import asyncio
import json
import pathlib
import pytest
from datetime import datetime, timezone
@@ -968,6 +969,64 @@ class TestErrorPropagation:
assert "step failed" in r["result"]["caught"]
class TestFailureRecordCorpus:
"""The cases both SDKs must agree on, read from one shared file.
`name` and `stack` drifted between the two clients twice while the record
was being unified, and each time only a reviewer noticed: a suite that only
knows its own language cannot see a divergence. The corpus is the same file
the typescript suite reads.
"""
CORPUS = json.loads(
(
pathlib.Path(__file__).resolve().parents[3]
/ "backend/windmill-common/src/wac_failure_corpus.json"
).read_text()
)
@staticmethod
def _construct(spec: dict) -> BaseException:
exc = type(spec["name"], (Exception,), {})(spec["message"])
for key, value in (spec.get("props") or {}).items():
setattr(exc, key, value)
if spec.get("circular_prop"):
cyclic: dict = {}
cyclic["self"] = cyclic
setattr(exc, spec["circular_prop"], cyclic)
return exc
@pytest.mark.parametrize("case", CORPUS["cases"], ids=lambda c: c["case"])
def test_marker_matches_the_shared_contract(self, case):
exc = self._construct(case["thrown"])
def raiser():
raise exc
# through the real step path, so the stack is the one a failure actually
# records rather than one this test happens to construct
async def run():
ctx = WorkflowCtx({})
try:
await ctx._run_inline_step("k", raiser)
except _StepSuspend as suspended:
return suspended.dispatch_info["result"]
raise AssertionError("a raising step did not suspend")
error = asyncio.run(run())["result"]["error"]
expect = case["expect"]
assert error["name"] == expect["name"]
assert error["message"] == expect["message"]
assert ("stack" in error) == (expect["stack"] == "present")
if "extra" in expect:
assert error["extra"] == expect["extra"]
for absent in expect.get("absent", []):
assert absent not in error
# whatever it kept has to survive the trip to the checkpoint
json.dumps(error, allow_nan=False)
class TestRaisingInlineStepIsCheckpointed:
"""A ``step()`` whose body raises must still land in ``completed_steps``.
+21 -15
View File
@@ -2784,21 +2784,27 @@ def _step_error_marker(key: str, exc: BaseException) -> dict:
# connection raises in turn. This runs inside the ``except`` that is
# reporting the user's failure, so an escape here would replace their
# error with an unrelated one and skip the checkpoint entirely.
# Narrow: what json raises for something it cannot represent. A broader
# catch would hide a mistake in this function as a silently missing
# field, which is how it read before.
try:
# ``parse_constant`` catches the one thing ``default`` cannot: a
# float is serializable, so ``NaN``/``Infinity`` pass through as
# bare literals that are not JSON and that the backend's extractor
# rejects — taking the whole checkpoint down with them. Kept as
# their text rather than dropped, so the attribute still says
# something.
error["extra"] = json.loads(
json.dumps(extra, default=_safe_str), parse_constant=lambda c: c
)
except (TypeError, ValueError, RecursionError):
pass
#
# Per attribute, so one that cannot be represented does not take the
# rest with it — an ``AxiosError``-shaped exception carrying both a
# ``code`` and a cyclic ``request`` keeps the ``code``. The typescript
# client admits properties one at a time for the same reason.
safe_extra = {}
for _k, _v in extra.items():
# Narrow: what json raises for something it cannot represent. A
# broader catch would hide a mistake here as a silently missing
# field, which is how it read before. ``parse_constant`` catches the
# one thing ``default`` cannot: a float is serializable, so
# ``NaN``/``Infinity`` pass through as bare literals that are not
# JSON and that the backend's extractor rejects.
try:
safe_extra[_k] = json.loads(
json.dumps(_v, default=_safe_str), parse_constant=lambda c: c
)
except (TypeError, ValueError, RecursionError):
pass
if safe_extra:
error["extra"] = safe_extra
return {
"__wmill_error": True,
"message": _safe_str(exc),