Skip to content

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

Closed

Description

@zackees

Noticed while adding FBUILD_DOWNLOAD_MIRROR_FIRST in #1797: fbuild parses
"is this boolean env var on?" three different ways, with observably different
results for the same value, and there is no shared helper to reuse.

Copy Accepts as true
crates/fbuild-cli/src/update_check.rs:253 — is_truthy_env (private) anything except unset, empty, 0, case-fold false (so no, off, -1 are true)
crates/fbuild-paths/src/running_process.rs:115 — env_flag_is_one (private) exactly 1 (so true, yes, 1 are false)
crates/fbuild-daemon/src/handlers/emulator/avr8js_npm.rs:45 — refresh_emu_cache_requested 1, true, TRUE, yes, YES after trim (so True, on are false)

What it does to real input: FOO=true turns a feature on under the fbuild-cli
and daemon rules and off under the fbuild-paths rule; FOO=no turns it on
under the fbuild-cli rule and off under the other two; FOO=0 (trailing
space) is false everywhere except fbuild-paths, where it is also false but only
because nothing but 1 is true. An operator who learns one fbuild flag's
spelling cannot assume the next one behaves the same.

Deciding which is canonical is a design call (how permissive should a flag be?
should off/no be falsy? should a malformed value fail fast per the "reject
invalid input at the boundary" principle instead of silently meaning false?),
and unifying them is a cross-crate refactor touching fbuild-cli,
fbuild-paths, fbuild-daemon and now fbuild-packages-fetch — hence a
research issue rather than an inline winner, per the "conflicting
implementations get a research issue" directive in CLAUDE.md.

New in #1797: mirror_first_requested in
crates/fbuild-packages-fetch/src/downloader_mirrors.rs, which follows the
is_truthy_env rule (the broadest of the three) and documents that choice at
the function. It should move to whatever this issue picks.

Suggested shape if the answer is "unify": one pub fn env_flag(name: &str) -> bool
in fbuild-core (every crate above already depends on it), one documented truth
table, and a behaviour-preserving-where-possible migration in its own PR,
separate from any feature change.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions