Skip to content

chore(test-infra): lint bare boolean operators inside drogon CHECK/REQUIRE - #77

Merged
voidvec merged 1 commit into
masterfrom
chore/drogon-check-macro-lint
Aug 22, 2026
Merged

voidvec merged 1 commit into
masterfrom
chore/drogon-check-macro-lint

Conversation

@voidvec

@voidvec voidvec commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Fixes #76 (registered from the PR #68 review round).

Why

drogon's CHECK/REQUIRE are macros, not functions: CHECK_INTERNAL__ expands the argument via (internal::Decomposer() <= expr), and macro substitution does not parenthesize — a bare a || b re-associates to (Decomposer() <= a) || b and silently mis-evaluates, presenting as a flaky assertion. Real instance while debugging PR #68: CHECK(body.isMember("error") || body.isMember("code")) failed although the logged raw body contained the key.

What

  • tools/test/scripts/drogon_macro_bool_check.py — flags top-level bare ||/&& in CHECK(...)/REQUIRE(...) arguments; safe forms ((bool)(...), outer parens, operators nested in call/sub-expression brackets, *_THROWS variants, string/comment contents) are recognized. Ships with --selftest (14 embedded cases, mirroring the spec-governance tool's pattern).
  • CI: new static-checks step next to the naming validator (--selftest + scan of tests/).
  • Docs: docs/backend/testing-guide.md §2 gains a [MUST] subsection with the rule, the safe/forbidden forms, and the existing FunctionalTest.cc precedent.

Current tests/ tree scans clean (109 files) — the lint is purely preventive.

Verification

  • --selftest OK (14/14), full tests/ scan OK locally.
  • Workflow YAML validated; the new step mirrors the naming-validator step's shape.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@voidvec

voidvec commented Aug 22, 2026

Copy link
Copy Markdown
Owner Author

Independent review round — 3-perspective verification (completeness / correctness / impact)

Cross-verified the PR claims against the commit (36872e8, 3 files, +239). Verdict on the PR's own claims:

PR claims — verified TRUE ✅

  • The macro-expansion premise is real: drogon 1.9.13 drogon_test.h expands CHECK/REQUIRE → CHECK_INTERNAL__ → EVAL_AND_CHECK_TRUE__ → (Decomposer() <= expr) with no parenthesization; <= binds tighter than ||/&&, and Lhs::operator|| returns an always-empty ComparsionResult. Reproduced the mis-evaluation class described.
  • --selftest passes (14/14) and the tests/ scan reproduces OK: 109 file(s) scanned, exit 0.
  • CI step is well-placed (after the naming validator in static-checks), YAML valid, job name/dependencies unchanged so required-status-check wiring is unaffected; python3 available on ubuntu-22.04.
  • Docs subsection exists with the promised rule, safe/forbidden forms, and real FunctionalTest.cc precedents.
  • Zero runtime-behavior impact; no interaction with other static checks.

New findings this round:

Warnings (SHOULD FIX)

W1. CO_REQUIRE / MANDATE share the exact same Decomposer expansion but are not linted (verified false negative)
tools/test/scripts/drogon_macro_bool_check.py MACRO_START regex \b(CHECK|REQUIRE)\s*\(
_ is a word character, so \bREQUIRE never matches inside CO_REQUIRE(; MANDATE is absent entirely. Probe file with CO_REQUIRE(a || b); and MANDATE(x && y); → both reported clean (exit 0), while drogon_test.h L641/L653 show both expand through the same CHECK_INTERNAL__ path. No usage exists in tests/ today (grep-confirmed 0), so this is latent, but coroutine tests will reach for CO_REQUIRE and silently bypass the guard.
Fix: MACRO_START = re.compile(r"\b(CO_REQUIRE|MANDATE|CHECK|REQUIRE)\s*\(") + one selftest case each (keep the \s*\( suffix so *_THROWS/*_NOTHROW EVAL__ variants stay excluded).

W2. C++14 digit separators swallow code as a char literal (verified false negative)
Same file, char-literal state machine (~L84-113)
Probe CHECK(0b0101'1100 && ok); → reported clean: the lone ' inside a numeric literal enters chr state and blanks everything until the next ' (no newline reset), masking operators and disturbing paren-depth tracking for later macros.
Fix: treat ' as a char-literal start only when the preceding char is not alphanumeric/_.

W3. Empty scan silently passes — the gate degrades to a no-op if the target dir vanishes
Same file, iter_sources / main (~L146-193)
Path("nonexistent").rglob(...) raises nothing → prints OK: 0 file(s) scanned, exit 0 (verified: iter_sources(['no_such_dir']) → []). A renamed/moved tests/ or wrong cwd would leave the pipeline green while checking nothing — diverging from the sibling check_spec_governance.py convention (exit 2 for environment errors).
Fix: fail with a non-zero exit when scanned == 0 (or root.exists() is false).

Suggestions (CONSIDER)

  • Raw strings R"(...)": the blanker exits str state at the first embedded " — CHECK(msg == R"(a " || " b)") is a false positive (probe-verified). Rare today; document the limitation or parse the )<delim>" terminator.
  • {}/[] are not depth-tracked: CHECK([]{ return a || b; }()) is a conservative false positive. Adding brace/bracket depth fixes it.
  • Line-continuation comments (// ... \ + next line) aren't handled — corner-case false positive.
  • chmod +x in the CI step is a no-op for a python3-invoked script; harmless, kept or drop.

Summary of changes

  • The lint's premise is technically correct and the delivered pieces (script + selftest + CI step + docs) all exist and work as advertised.
  • Tool is genuinely preventive: current tests/ tree is clean and the gate cannot break existing pipelines.
  • Three verified gaps worth a follow-up commit: W1 (macro coverage), W2 (digit separators), W3 (silent empty scan). None blocks merge of the guard itself.

Fixes #76. drogon's CHECK/REQUIRE expand their argument via
(Decomposer() <= expr); an unparenthesized boolean chain re-associates to
(Decomposer() <= a) || b and silently mis-evaluates (bit PR #68 as a
seemingly-flaky assertion). New static check
tools/test/scripts/drogon_macro_bool_check.py (with --selftest) flags
top-level bare operators; wired into CI static checks next to the naming
validator. Convention documented in docs/backend/testing-guide.md §2
with the safe forms ((bool)(...), outer parens, split assertions) and
the repo's existing FunctionalTest.cc precedent. Current tree scans
clean (109 files).
@voidvec
voidvec force-pushed the chore/drogon-check-macro-lint branch from 36872e8 to 4381ef3 Compare August 22, 2026 12:03
@voidvec
voidvec merged commit 7d7110d into master Aug 22, 2026
8 checks passed
@voidvec
voidvec deleted the chore/drogon-check-macro-lint branch August 22, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test-infra footgun: bare boolean operators inside drogon CHECK/REQUIRE macros silently mis-evaluate

2 participants