fix(698): review round 2 — close a PRE-EXISTING SIGPIPE inversion, narrow the bot allow-list, correct two overclaims
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / Docs update reminder (pull_request) Successful in 24s
PR Gates / decisions lifecycle (pull_request) Successful in 33s
review-verdict/h10 Awaiting review verdict for bafb487
PR Gates / Script tests (pytest) (pull_request) Successful in 59s
Review verdict / Set review-verdict status (pull_request_target) Successful in 34s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m30s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m36s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m9s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 21m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 22m6s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / Docs update reminder (pull_request) Successful in 24s
PR Gates / decisions lifecycle (pull_request) Successful in 33s
review-verdict/h10 Awaiting review verdict for bafb487
PR Gates / Script tests (pytest) (pull_request) Successful in 59s
Review verdict / Set review-verdict status (pull_request_target) Successful in 34s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m30s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m36s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m9s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 21m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 22m6s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Cross-family adversarial review returned BLOCKED with 3 Blockers + 2 Highs. Two were verified independently before acting on them. BLOCKER 1 (pre-existing on main, not introduced here). `producer | grep -q…` inverts under `set -o pipefail`: grep exits at its first match, the producer takes SIGPIPE and exits 141 once the list exceeds the pipe buffer, so a MATCH is reported as a FAILED pipeline. Reproduced at 1901 paths / ~171KB, inside the enumerator's 2000-file cap: * `A.cs` + 1900 docs paths -> docs_only=yes, status 141 (a C# PR exempted) * `.gitea/…` + 1900 docs -> the PROTECTED guard MISSES entirely The second reaches a green required status on a PR rewriting the gate, with no retarget, no bot account and no forged status. This construct shipped with the original docs-only check (review-verdict.yml:257 on main), so it was live. Fixed in both the enforced gate and the advisory hook by using here-strings, which have no writer to signal. New record `ci.grep-q-pipefail-inversion`. BLOCKER 2 (mine). `web/package.json` / `web/package-lock.json` are removed from BOT_MANIFESTS. renovate.json enables only nuget/github-actions/dockerfile, so npm is unmanaged here and the entry bought nothing — while package.json `scripts` are EXECUTED by CI (npm ci, npm run build). It widened an exemption onto a code-execution path for no benefit. BLOCKER 3 + HIGH (documentation was wrong, code unchanged). The claim that `edited` made the retarget residual "non-durable" is retracted: runs are not serialized, so a stale run can post `success` after the reclassifying run posts `pending`. The ABA transition is narrowed and observable, NOT closed. Likewise the provenance check asks "posted by a user credential", not "posted by a reviewer" — ETV_STATUS_AUTH is basic auth, so a #697 forgery gets a non-null creator AND an attacker-chosen description and is preserved as human. Both now stated at full strength. TESTS. 4 large-input cases crossing the pipe buffer, each paired with a large-input POSITIVE control so "large lists now fail closed" (a deadlock) cannot pass as a fix. Verified by mutation: reverting the here-strings turns all three negatives red while the control stays green. Two of my own weak tests fixed — the "base advances" case called head_moves_to(SHA) with the already-current sha (a duplicate positive control, now a structural assertion that the comparator is .base.ref and never .base.sha), and the arity test counted five arguments without checking the fifth was the base. The whole class was invisible because every previous test used a handful of short paths: a guard whose behaviour depends on a buffer threshold needs a test that crosses it. Refs: #698 Decisions-Edit: yes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -343,16 +343,26 @@ def test_positive_control_an_unmoved_base_still_enumerates(enumerate_files):
|
||||
assert enumerate_files.paths() == ["docs/a.md", "ErsatzTV/Program.cs"]
|
||||
|
||||
|
||||
def test_a_base_that_merely_ADVANCES_is_not_a_retarget(enumerate_files):
|
||||
def test_the_base_comparator_is_the_BRANCH_NAME_never_the_TIP_SHA():
|
||||
"""`.base.ref` is compared, never `.base.sha` — matching `post-review-verdict.sh` (ersatztv#632).
|
||||
|
||||
Comparing tips would fail every enumeration on every unrelated merge to `main`: a self-inflicted
|
||||
deadlock dressed as a security control. The stub always serves branch NAMES, so this passes only
|
||||
because the script never looks at a tip sha.
|
||||
deadlock dressed as a security control.
|
||||
|
||||
This is a STRUCTURAL assertion on purpose, and the previous version of this test is why. It was
|
||||
written behaviourally as `head_moves_to(SHA)` — the sha that was ALREADY current — so it modelled
|
||||
no movement at all and was simply a duplicate positive control. It would have passed just as
|
||||
happily against a script comparing tip shas. The stub serves only branch names, so no behavioural
|
||||
test in this harness can distinguish the two comparators; say so and assert the source instead.
|
||||
"""
|
||||
enumerate_files.set_pages(_rows(["docs/a.md"]))
|
||||
enumerate_files.head_moves_to(SHA) # head unchanged; base branch unchanged
|
||||
assert enumerate_files.paths() == ["docs/a.md"]
|
||||
src = SCRIPT.read_text()
|
||||
assert ".base.ref" in src, "the enumeration no longer reads .base.ref"
|
||||
binding = [ln for ln in src.splitlines()
|
||||
if "base_before=" in ln or "base_after=" in ln]
|
||||
assert binding, "no base binding assignments found"
|
||||
for ln in binding:
|
||||
assert ".base.ref" in ln and ".base.sha" not in ln, (
|
||||
f"the base binding compares a tip sha, which deadlocks on ordinary churn: {ln.strip()!r}")
|
||||
|
||||
|
||||
def test_a_SHORT_page_does_not_end_the_enumeration(enumerate_files):
|
||||
@@ -579,6 +589,11 @@ def test_the_caller_passes_the_BASE_REF_argument(caller):
|
||||
assert len(args) >= 5, (
|
||||
f"{caller.relative_to(REPO_ROOT)} calls the enumeration with {len(args)} quoted "
|
||||
f"arguments, expected 5 including the expected base ref: {ln.strip()!r}")
|
||||
# Counting five arguments is not enough — cold review caught that passing `"$SHA"` twice
|
||||
# satisfied the count while stalling every real exemption. Name the fifth.
|
||||
assert re.search(r'(?i)base', args[4]), (
|
||||
f"{caller.relative_to(REPO_ROOT)} passes {args[4]} as the 5th argument; it must be the "
|
||||
f"expected BASE ref: {ln.strip()!r}")
|
||||
|
||||
|
||||
@CALLERS
|
||||
@@ -1130,8 +1145,7 @@ def test_bot_positive_control_a_REAL_dependency_bump_IS_still_exempt(tmp_path):
|
||||
"would now stall waiting on a human verdict")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["Directory.Packages.props", ".config/dotnet-tools.json",
|
||||
"web/package.json", "web/package-lock.json"])
|
||||
@pytest.mark.parametrize("path", ["Directory.Packages.props", ".config/dotnet-tools.json"])
|
||||
def test_every_manifest_in_the_allow_list_is_actually_exempt(tmp_path, path):
|
||||
"""Pin the SET, not one example of it. A test that only ever exercises Directory.Packages.props
|
||||
cannot see a typo in any of the other three alternations."""
|
||||
@@ -1260,3 +1274,71 @@ def test_a_PENDING_status_from_a_previous_run_is_replaced_normally(tmp_path):
|
||||
status_creator=None, status_desc="Awaiting review verdict for a9e3e23")
|
||||
assert posted is not None
|
||||
assert posted["state"] == "success"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["web/package.json", "web/package-lock.json"])
|
||||
def test_the_npm_manifests_are_NOT_exempt(tmp_path, path):
|
||||
"""Cross-family review called an earlier draft's inclusion of these a Blocker, correctly.
|
||||
|
||||
`renovate.json` sets `enabledManagers: ["nuget", "github-actions", "dockerfile"]`, so Renovate does
|
||||
not manage npm here at all — the entry bought nothing. Meanwhile `package.json` carries `scripts`
|
||||
that CI EXECUTES (`npm ci`, `npm run build`), so exempting it lets a hijacked bot branch run
|
||||
arbitrary shell in CI while every path still matches a "manifest" allow-list. Widening an exemption
|
||||
to a code-execution vector for no operational benefit is strictly worse than the hole being closed.
|
||||
"""
|
||||
posted, _ = _run_classify(tmp_path, _emitting(path), author="renovate")
|
||||
assert posted is not None
|
||||
assert posted["state"] == "pending", (
|
||||
f"{path} was exempted; package.json scripts execute in CI, and npm is not a managed ecosystem "
|
||||
"in this repo")
|
||||
|
||||
|
||||
# --- The `grep -q` + `pipefail` inversion (found by cross-family review of this PR) ---------------
|
||||
#
|
||||
# `grep -q` exits at its FIRST match, so the upstream writer takes SIGPIPE (141) once the path list
|
||||
# exceeds the pipe buffer. Under `set -o pipefail` the pipeline is then a FAILURE even though grep
|
||||
# MATCHED, inverting every guard built on `printf … | grep -q`. Reproduced at 171KB / 1901 paths,
|
||||
# comfortably inside the enumerator's 2000-file cap.
|
||||
#
|
||||
# These are the regression guards, and they are the tests the original round did not have: every
|
||||
# earlier case used a handful of short paths, far below the buffer, so the whole class was invisible.
|
||||
# The construct PREDATES #698, so `main` carried this hole with no retarget or bot account required.
|
||||
|
||||
def _many_docs(n=1900):
|
||||
return [f"docs/{'d' * 40}-{i:040d}.md" for i in range(n)]
|
||||
|
||||
|
||||
def test_a_LARGE_pr_with_a_code_file_is_not_classified_docs_only(tmp_path):
|
||||
"""The code file goes FIRST so `grep -qv` matches immediately and the writer is left with ~171KB
|
||||
still to push — the exact shape that produced exit 141 and `docs_only=yes`."""
|
||||
posted, r = _run_classify(tmp_path, _emitting("A.cs", *_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending", (
|
||||
"a PR containing A.cs was exempted as docs-only because the classification pipeline was "
|
||||
f"inverted by SIGPIPE on a large file list (desc={posted['description']!r})")
|
||||
|
||||
|
||||
def test_a_LARGE_pr_touching_a_PROTECTED_path_still_voids_the_exemptions(tmp_path):
|
||||
"""The worse direction: here the inversion makes the PROTECTED guard MISS, so a PR editing the
|
||||
gate's own workflow falls through to the docs-only exemption and self-exempts."""
|
||||
posted, r = _run_classify(tmp_path, _emitting(".gitea/workflows/review-verdict.yml", *_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending", (
|
||||
"a PR editing .gitea/workflows/ was exempted — the protected-path guard was skipped on a "
|
||||
f"large file list (desc={posted['description']!r})")
|
||||
|
||||
|
||||
def test_a_LARGE_bot_pr_with_a_code_file_is_not_manifest_exempt(tmp_path):
|
||||
"""The same inversion reached through the third guard added by this change."""
|
||||
posted, r = _run_classify(tmp_path, _emitting("A.cs", *_many_docs()), author="renovate")
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "pending"
|
||||
|
||||
|
||||
def test_positive_control_a_LARGE_genuinely_docs_only_pr_IS_still_exempt(tmp_path):
|
||||
"""Without this the three tests above could pass because large lists now fail outright, which
|
||||
would be a merge deadlock rather than a fix."""
|
||||
posted, r = _run_classify(tmp_path, _emitting(*_many_docs()))
|
||||
assert posted is not None, f"the job posted nothing: {r.stderr[-2000:]}"
|
||||
assert posted["state"] == "success", (
|
||||
f"a large but genuinely docs-only PR lost its exemption (desc={posted['description']!r})")
|
||||
|
||||
Reference in New Issue
Block a user