Skip to content

refactor(core): one canonical parser for boolean env flags - #1804

Merged
zackees merged 2 commits into
mainfrom
agent/env-flag-unify
Oct 31, 2026
Merged

zackees merged 2 commits into
mainfrom
agent/env-flag-unify

Conversation

@zackees

@zackees zackees commented Oct 31, 2026

Copy link
Copy Markdown
Member

Closes #1798 as "unify", with one documented truth table.

The conflict, and the fix

site before: =no before: =true after
fbuild-cli/update_check.rs::is_truthy_env on (bug) on off / on
fbuild-paths/running_process.rs::env_flag_is_one off off (footgun) off / on
fbuild-daemon/…/avr8js_npm.rs::refresh_emu_cache_requested off on (True: off) off / on
fbuild-packages-fetch/…/downloader_mirrors.rs::mirror_first_requested on (bug) on off / on

New fbuild_core::env_flag (all four crates already depend on it):

  • parse(&str) -> Option<bool> — pure, tested without touching the process env.
  • is_set(name) -> bool — the one call every flag uses.

Truth table (value trimmed, ASCII case-insensitive): on = 1, true,
yes, on; off = unset, "", 0, false, no, off; anything else =
off
. The last rule is the important one: a typo (ture, -1, 2) must never
silently enable a feature. =no/=off are now genuinely off everywhere, and
=true/=yes are now genuinely on everywhere.

Deliberately not migrated

  • FBUILD_DEV_MODE (4 copies in fbuild-paths, fbuild-core::response_file,
    fbuild-cli::dispatch). Its literal-1-only contract is deliberate
    (dylint: ban raw .fbuild path literals outside fbuild-paths; ratchet to zero #1349: var_os(..).is_some() made =0 select the dev tree). Widening it
    would relocate the cache root for anyone with FBUILD_DEV_MODE=true in the
    environment — an owner decision, tracked on the issue, not a mechanical move.
  • windows_long_paths.rs's CI-marker check (same broad rule as the old
    is_truthy_env) — separate cleanup.
  • port_doctor's sysfs control parser and cdc.rs's -DARDUINO_USB_CDC_ON_BOOT
    parser: those read kernel/compiler values, not env vars, and their current
    comments document why unknown input is "no data", not false.

Tests (real output)

  • soldr cargo test -p fbuild-core --lib env_flag → 5 passed, 0 failed
    (truthy set, falsy set, padding, malformed-never-on, is_set through a
    dedicated env name).
  • soldr cargo test -p fbuild-cli --bin fbuild canonical_env_flag → 1 passed
    (suppress_from_env over 1/true/on/Yes/0/no/off/ture/"").
  • soldr cargo test -p fbuild-paths --lib → 92 passed, 0 failed, 1 ignored.
  • soldr cargo test -p fbuild-daemon --lib npm_cache → 10 passed, 0 failed.
  • soldr cargo test -p fbuild-packages-fetch --lib mirror_first_env → 1 passed.
  • bash test (TMPDIR=/home/niteris/t) → 4044 passed / 0 failed / 109 ignored, rc 0.
  • soldr cargo fmt --check rc 0; SOLDR_VERDICTS=off soldr cargo clippy --workspace --all-targets -- -D warnings rc 0;
    boundary 44/43 rc 0; ci/check_test_layout.py ok.

Note: the new update_check test and the existing ci_detection_via_ci_env test both
mutate CI markers, so they now share a Mutex guard; previously they raced on
separate test threads.

Local ci.run_dylint is not usable on this host (nightly driver/rustc drift); the
hosted Dylint lanes on this PR are the evidence.

fbuild answered "is this FBUILD_* flag on?" three different ways with
observably different results for the same value:

- fbuild-cli `is_truthy_env` treated everything but "", "0" and "false"
  as true, so `=no`, `=off` and `=-1` *enabled* features.
- fbuild-paths `env_flag_is_one` accepted only "1", so `=true` and
  `=yes` were off.
- daemon `refresh_emu_cache_requested` accepted 1/true/TRUE/yes/YES but
  not `True` or `on`.

Add `fbuild_core::env_flag` with one documented truth table -- on:
1/true/yes/on, off: unset/""/0/false/no/off, unrecognised: off -- and
route the four copies through it. Unrecognised input is deliberately
off so a typo can never silently enable a feature.

Not migrated, by design: FBUILD_DEV_MODE keeps its literal-`1` contract
(#1349: a stray `=0` used to select the dev tree), and the CI-marker
helper in windows_long_paths.rs is untouched. Widening those is a
separate decision, not a mechanical move.
@coderabbitai

coderabbitai Bot commented Oct 31, 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

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 64dcaf2 Oct 31, 2026
28 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Oct 31, 2026
@zackees
zackees deleted the agent/env-flag-unify branch November 5, 2026 05:51
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.

research: 3 conflicting implementations of truthy env-var parsing -- which is canonical?

1 participant