test_an_undeliverable_payload_is_dropped_silently

Tests › tests/test_hook.py

passed Passed in the packaged run.

What this test is for

Why it exists

FOUND BY AN ADVERSARIAL AUDIT OF 1.0.10, AND IT FALSIFIED THIS COMPONENT'S CENTRAL CLAIM. `sys.stdout` is a BUFFERED TextIOWrapper, so `write()` alone lands in the buffer and the real I/O is deferred to interpreter shutdown — after `main()` has returned 0, and outside every `try` in the module. When that deferred flush failed, CPython printed "Exception ignored in: <stdout>" to stderr and exited 120.

Verifies REQ-DDB-WIKI-054

Given

  1. marker = tmp_path / f"clew-hook-seen-flush{hook._MISS_SUFFIX}"
  2. marker.write_bytes(b"." * (hook._QUIET_BELOW - 1))
3 more
  1. event = json.dumps({"tool_input": {"file_path": "/x/a.py"}})
  2. if not Path("/dev/full").exists(): # pragma: no cover - platform guard pytest.skip("/dev/full is Linux-specific")
  3. with Path("/dev/full").open("w") as full: result = subprocess.run( [sys.executable, "-m", "clew_hook", hook.READ_FLAG], input=event, stdout=full, stderr=subprocess.PIPE, text=True, cwd=str(REPO), env={**os.environ, "TMPDIR": str(tmp_path), "CLAUDE_CODE_SESSION_ID": "flush"}, check=False, )
→

When

  1. —
→

Then

  1. ✓ result.returncode equals 0
  2. ✓ result.stderr equals ""

tests/test_hook.py:1290 · its file's page

What it checks (2)

  1. assert result.returncode == 0, ( f"exit {result.returncode} when stdout could not be written. A non-zero exit on " f"PostToolUse surfaces stderr to the model, which is the channel this component exists " f"to keep shut." ) not attributed
  2. assert result.stderr == "", ( f"stderr must be EMPTY, not merely traceback-free — the shutdown-flush message says " f"'Exception ignored in:' and contains no 'Traceback', which is why the existing scans " f"missed it. Got: {result.stderr[:300]}" ) not attributed

What it reaches

Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.

Requirements it verifies (1)

requirementlinked byimplementers exercised
REQ-DDB-WIKI-054catalogunknown