Both languages read the same words as a boolean flag - #1344
Merged
Conversation
There are two canonical boolean parsers, one per language - crate::env_flag::parse_bool and matrixark_mcp_env.env_bool - and nothing compared them. They agree today on the words, on the trim-and-lowercase, and on answering the caller default for a word neither knows. That last part is the one mx#1308 was: nine rust readers matched "1"|"true"|"TRUE"|"yes"|"YES" with no trim and no lowercasing, and mapped anything else to false rather than to the default, so writing "on" to keep a default-on flag on turned it off. The python guard for the same class could not see the rust half, which is why it survived there. Deliberately about the canonical parsers only: raft.rs also accepts y/n and control.rs also accepts enabled, both intentional supersets that normalise correctly. Verified to fail on a word removed from one side, on the trim being dropped, and on an unknown word answering false instead of the default. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…he-same-boolean-words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are two canonical boolean parsers, one per language:
They agree — on the words, on trimming and lowercasing first, and on answering the caller's
default for a word neither knows. Nothing compared them.
Why the third of those matters most
tools/test_env_flag_vocabulary.pysettled this for python and wrote down why: "Boolean flagswere parsed in six different vocabularies. They disagreed on the two words an operator is most
likely to reach for." Its scan reads
os.environ.getshapes undertools/, so it could not seethe rust half of the same codebase — which kept the defect until #1308. Nine readers matched
"1" | "true" | "TRUE" | "yes" | "YES"with no trim and no lowercasing, and.map(...)ranbefore
.unwrap_or(default), so an unrecognised value came backfalserather than the default.Against a default-on flag:
Every default-on flag in the tree reached one of them, so writing
onto keep one on turned itoff, and so did a typo.
Both halves of that are pinned here: the word lists, and
_ => None— the shape that makes anunknown word fall back to the caller's default instead of to
false.What it checks
(it cannot be imported from
tools/), by matching the=> Some(true)/=> Some(false)arms.raw.trim().to_ascii_lowercase(); thepython side is driven, not read —
env_boolis called with" on ","ON","\tTrue\n"," 1"and their false counterparts, which are the spellings a unit file, an export and aheredoc actually leave.
_ => Nonein rust,and
env_bool("wat", True)/env_bool("wat", False)driven in python, so a single assertioncannot pass by the function simply answering one way.
Scoped to the canonical parsers on purpose.
raft.rsalso acceptsy/nandcontrol.rsalsoaccepts
enabled; both are intentional supersets that normalise correctly, and this does nottouch them.
It discriminates
Checked by perturbing the rust side three ways and watching it fail, then restoring:
"on"dropped from the TRUE arm.trim().to_ascii_lowercase()dropped_ => Nonechanged to_ => Some(false)The readability of the arms is asserted first, since both set comparisons would otherwise pass on
an empty scan.
No production code changes.
🤖 Generated with Claude Code