test: make cancelStream harnesses tolerate the new reason param + stdout provenance log

Codex gate on #5346 flagged two brittle static extractors that broke on the
cancelStream(reason) signature change + the new '[stream] cancel requested'
stdout log:

- test_cancel_stream_owner_guard.py: the Node harness parsed ALL of stdout as
  JSON; the provenance console.info line (fires during runAll) polluted it.
  Parse the LAST non-empty stdout line (the result JSON is always emitted last,
  after runAll resolves).
- test_sprint36.py: two extractors did src.find('async function cancelStream()')
  (exact, no params). Switched to a signature-tolerant regex and widened the
  catch-block window (the provenance log/comments now precede the try/catch).

Both pre-existing tests, updated to match the intentional #5345 change (not the
code bent to fit the test).
This commit is contained in:
nesquena-hermes
2026-07-01 15:34:35 +00:00
parent 051b01fff1
commit 457ee01987
2 changed files with 22 additions and 5 deletions
+10 -1
View File
@@ -329,7 +329,16 @@ def _run_cancel_stream_scenarios() -> dict:
f"--- stderr ---\n{completed.stderr}"
)
try:
return json.loads(completed.stdout)
# The function under test legitimately emits diagnostic lines on stdout
# (e.g. cancelStream's '[stream] cancel requested' provenance log, added
# for #5345). Those fire DURING runAll(); the result JSON is written by
# `console.log(JSON.stringify(r))` only after runAll() resolves, so it is
# always the LAST non-empty stdout line. Parse that rather than assuming
# stdout is pure JSON.
lines = [ln for ln in completed.stdout.splitlines() if ln.strip()]
if not lines:
raise json.JSONDecodeError("empty stdout", completed.stdout or "", 0)
return json.loads(lines[-1])
except json.JSONDecodeError as e:
raise AssertionError(
f"node subprocess returned non-JSON output:\n"
+12 -4
View File
@@ -46,8 +46,11 @@ class TestCancelStreamCleanup:
def _get_cancel_block(self):
"""Extract the cancelStream function body from boot.js."""
src = read("static/boot.js")
idx = src.find("async function cancelStream()")
assert idx != -1, "cancelStream not found in boot.js"
# Signature-tolerant: cancelStream now takes a `reason` param (#5345), so
# match the declaration regardless of its parameter list.
m = re.search(r"async function cancelStream\s*\(", src)
assert m is not None, "cancelStream not found in boot.js"
idx = m.start()
# Find the closing brace — scan for the matching }
depth = 0
end = idx
@@ -122,8 +125,13 @@ class TestCancelStreamErrorPath:
The status is cleared by setStatus('') unconditionally.
"""
src = read("static/boot.js")
idx = src.find("async function cancelStream()")
block = src[idx:idx + 400]
# Signature-tolerant match (cancelStream now takes a `reason` param, #5345).
m = re.search(r"async function cancelStream\s*\(", src)
assert m is not None, "cancelStream not found in boot.js"
idx = m.start()
# Widen the window: the provenance log + comments added for #5345 sit
# before the try/catch, so 400 chars no longer reaches the catch block.
block = src[idx:idx + 1200]
# The old pattern was setStatus inside catch; new pattern has it outside
# Look for the catch block specifically
catch_idx = block.find("}catch(")