test_every_renderer_is_vetted

Tests › tests/test_hook.py

passed Passed in the packaged run.

What this test is for

Why it exists

2.1 COMMENT NOTE (owner Q/A 2026-11-24). A second renderer is a second way for a value to become TEXT, and `test_no_run_time_value_can_reach_the_output` scans `_payload_for` alone, so a renderer it does not name would sit outside the security argument. Every function that calls `json.dumps` must be named here; the comment renderer interpolates exactly one value, bound from `int()`, and serialises once with no keywords.

Verifies REQ-DDB-WIKI-054

Given

  1. tree = ast.parse(HOOK_SOURCE.read_text(encoding="utf-8"))
  2. functions = [n for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)]
6 more
  1. def dumps_in(fn: ast.FunctionDef) -> list[ast.Call]: return [ n for n in ast.walk(fn) if isinstance(n, ast.Call) and isinstance(n.func, ast.Attribute) and n.func.attr == "dumps" ]
  2. renderers = {fn.name for fn in functions if dumps_in(fn)}
  3. fn = next(f for f in functions if f.name == "_comments_payload")
  4. subs = [n for n in ast.walk(fn) if isinstance(n, ast.BinOp) and isinstance(n.op, ast.Mod)]
  5. operand = subs[0].right.id
  6. binds = [ n.value.func.id for n in ast.walk(fn) if isinstance(n, ast.Assign) and isinstance(n.value, ast.Call) and isinstance(n.value.func, ast.Name) and any(isinstance(t, ast.Name) and t.id == operand for t in n.targets) ]
→

When

  1. —
→

Then

  1. ✓ renderers equals {"_payload_for", "_comments_payload"}
  2. ✓ len(subs) equals 1
  3. ✓ isinstance(subs[0].right, ast.Name) holds
  4. ✓ binds equals ["int"]
  5. ✓ len(dumps_in(fn)) equals 1
  6. ✓ dumps_in(fn)[0].keywords is false

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

What it checks (4)

  1. assert renderers == {"_payload_for", "_comments_payload"}, renderers not attributed
  2. assert len(subs) == 1 and isinstance(subs[0].right, ast.Name) not attributed
  3. assert binds == ["int"], f"{operand!r} must be bound from int() alone; bound from {binds}" not attributed
  4. assert len(dumps_in(fn)) == 1 and not dumps_in(fn)[0].keywords 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