Skip to content

fix(ci): enforce and test the subprocess gate's documented contract - #1913

Merged
zackees merged 1 commit into
mainfrom
agent/subprocess-gate-tests
Nov 5, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/subprocess-gate-tests

Conversation

@zackees

@zackees zackees commented Nov 5, 2026

Copy link
Copy Markdown
Member

What

ci/find_direct_subprocess.py is the gate that forbids direct
std::process::Command::new / tokio::process::Command::new outside the
fbuild-core::subprocess wrappers (#141). It runs with --fail from
check-ubuntu.yml and lint-subprocess.yml — but it had no test at all,
and its docstring promised two behaviours the code did not implement.

1. The allowlist accepted an unexplained marker

The docstring says a site is allowlisted by

// allow-direct-spawn: <one-line reason>

A bare marker (// allow-direct-spawn, or with a colon and nothing after
it) was accepted as an allowlist entry whose reason was literally
<no reason given>. An unexplained hold-out then looks exactly like a
forgotten migration, and the site is pre-authorised forever. A reason after
the colon is now mandatory; without one the site is reported as unmigrated.

2. Commentary and fixtures failed the build — and a char literal hid a real spawn

The skip predicate only looked at how a line starts:

  • let x = 1; // e.g. Command::new("git") — trailing comment: false red.
  • /* ... Command::new("git") ... */ block, including nested: false red.
  • let s = "Command::new(x)"; in a test fixture: false red.
  • let q = '"'; let c = Command::new("git"); — the quote inside the char
    literal opened a phantom string that blanked the rest of the line, so the
    real spawn was invisible to the gate.

The line-start heuristic is replaced with a small Rust-aware lexer that blanks
// comments, nested /* ... */ comments, escaped strings, raw strings
(r#"..."#) and char literals, while preserving column positions (the marker
lookup still reads the raw line, so markers remain comment-based).

Reasoning moves into unmigrated() / exit_code(), and the pending list now
says why a reason-less marker did not take effect.

Verdict on the current tree is unchanged

Compared old vs new in JSON mode over the real workspace: identical — 36
sites, all allowlisted with the same reasons, 0 to migrate. This PR is
therefore safe to merge without touching any source file under crates/.

Tests

ci/test_find_direct_subprocess.py — 17 cases, registered in
ci/local_suites.py and .github/workflows/ci-workflow-drift.yml (the two
entry points that ci/test_local_suites.py keeps in parity):

  • unmarked spawn is a violation; all three spawn spellings matched;
  • same-line marker and previous-line marker allowlist, reason preserved;
  • bare / colon-only / whitespace-only markers do not allowlist (3 sub-cases);
  • trailing //, whole-line ///+//!, nested /* */, string, raw string,
    char-literal and lifetime cases;
  • a real spawn beside a documented mention is the only hit;
  • --fail decides the exit code;
  • the live workspace scan has zero unmigrated sites and every marker has a reason.

RED proof (old behaviour restored on top of the new file): 12 of 17 fail,
including test_marker_without_a_reason_does_not_allowlist, the nested-block
case and the workspace scan. Removing only the char-literal branch fails
test_char_literal_does_not_open_a_phantom_string — the escape hatch was real.

Gates run locally: ruff check clean, ci/check_python_complexity.py
All checks passed!, hosted self-test set 127 tests OK (110 before + 17),
ci.find_direct_subprocess on the workspace 0 to migrate.

Closes nothing; #141 stays open until the remaining hold-outs migrate.

`ci/find_direct_subprocess.py` runs with `--fail` in `check-ubuntu.yml` and
`lint-subprocess.yml`, but it had no test and its docstring promised two
things the code did not do (#141):

1. "allow a site with `allow-direct-spawn: <one-line reason>`" -- a BARE
   marker was accepted as an allowlist entry with the reason
   `<no reason given>`, so an unexplained hold-out was indistinguishable
   from a forgotten migration and silently pre-authorised every future
   `Command::new` at that site. A reason is now mandatory.
2. "skip occurrences inside doc comments or string literals" -- only lines
   *starting* with `//`, `///`, `//!` or `*` were skipped. A trailing
   `// Command::new(` comment, a `/* ... */` block, or a fixture string
   failed the build; worse, the quote in a char literal (`let q = '"';`)
   opened a phantom string that blanked the rest of the line and HID a
   real spawn after it.

Replace the line-start heuristic with a small Rust-aware line lexer that
blanks `//` comments, nested `/* ... */` comments, escaped strings, raw
strings (`r#"..."#`) and char literals while preserving columns. Reasoning
moves into `unmigrated()`/`exit_code()`, and the pending list now explains
why a reason-less marker did not work.

The verdict on the current workspace is unchanged and was verified
byte-for-byte: 36 sites, all allowlisted, 0 to migrate.

Tests: new `ci/test_find_direct_subprocess.py` (17 cases: both allowlist
directions, bare/colon/whitespace-only markers, trailing + nested block
comments, string/raw-string/char literals, lifetimes, CRLF, `--fail`
exit codes, and the live workspace scan). Registered in
`ci/local_suites.py` and the drift workflow; documented in `ci/README.md`.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 4b0eac0 Nov 5, 2026
31 checks passed
@zackees
zackees deleted the agent/subprocess-gate-tests branch November 5, 2026 11:09
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant