Skip to content

A Validator Looser Than Its Consumer: Three Instances, and Why a Whitespace Test Cannot Close the Class #1503

Closed

Description

@ptr727

A validator is only as strict as the comparison its value eventually meets. Three defects of this shape have been found in the last day, in three different files, by three different mechanisms, and none of them is findable by testing the validator alone, because in every case the validator behaved exactly as written.

The three instances

  • spec/validate.py, environment_errors_for_repo. A declared deployment environment name and each custom branch name were tested for emptiness by .strip() truthiness, so "pypi " passed. repo-config/configure.sh resolves the environment with select(.name == $n), and compares each declared branch to the live policy names directly. Fixed for whitespace in Reject a Deployment Environment Name or Branch That Carries Surrounding Whitespace #1504, and see the open half below.
  • scripts/handoff.py, --track. Validated with TRACK.match(...) rather than fullmatch, so --track $'sess\n' passed and the metadata block parsed the value back without the newline. Two commands on what the operator believed was one lane, compared with a plain ==. Fixed during Move the Session Handoff to a Chain of Labeled Issues #1501.
  • registry/repos.schema.json, the description pattern at line 55. ^\S(?:[^\n\r]*\S)?$, carrying a $comment that says it is kept in sync with spec/validate.py's description_errors(). It is not, in two directions at once, for reasons below.

Why a whitespace test cannot close it

Every test written in terms of whitespace encodes somebody's definition of whitespace, and the consumer has its own.

str.strip() removes the 29 characters Python calls whitespace, 19 of them non-ASCII. It does not remove U+200B, U+200C, U+200D, U+2060, U+FEFF, U+00AD or U+180E. Those are invisible, are trimmed or normalised by other layers routinely, and are just as unmatchable by an exact comparison as a trailing space. So the fix in #1504 rejects a padded name and accepts a name with a zero-width space appended, which fails at exactly the same place for exactly the same reason.

The schema is worse, not better, because it is a second definition rather than the same one. Its regex engine is whichever the reader's editor uses, ECMA-262 in practice, and ECMA-262 \s includes U+FEFF where Python's does not. Under check-jsonschema, which uses Python re, $ matches before a trailing newline, so "pypi\n" satisfies the pattern and fails the validator. A pattern and a Python function asserting "the same" constraint in two languages that disagree about what whitespace is will disagree, and the $comment claiming they are in sync is the part that misleads.

An attempt to close this by adding that same idiom to the environment name and branch fields was made and reverted inside #1504, on measurement: it turned a one-directional gap, where the schema admits what the validator refuses, into a two-directional one, where the editor also refuses a value the gate allows. The safe direction for an advisory schema to be wrong is the loose one.

What the fix has to be

A positive grammar per field, not a wider negative test. Stated positively it admits nothing invisible in either direction, needs no notion of whitespace, and cannot drift when a Python release changes isspace().

Two constraints on designing it, both measured rather than predicted:

  • The grammar must be written so both regex engines agree on it. $ is not end-of-string in Python re; (?![\s\S]) is end-of-string in both. \s and \S mean different sets in the two engines and cannot appear in a shared grammar at all.
  • The two fields need two grammars. A GitHub deployment branch policy name is a pattern and legitimately carries / and *, so releases/* must pass. A grammar tight enough to look right on the three names the registry declares today (pypi, production, staging) will refuse the first adopter that declares a release-line pattern, and it will pass every test and every live value on the way.

Scope

The sweep this argues for is not "where else is a value tested by truthiness". It is: which declared fields are consumed by exact comparison, or concatenated into a URL or a path, and is each validated to the strictness that consumer requires. Truthiness is one way to be looser than the consumer. An unanchored match, a case-insensitive check feeding a case-sensitive lookup, and a check permitting interior whitespace where the consumer splits on it are the same defect in different clothes. The name-into-path shape is the highest-consequence one, because a wrong answer and a request to somewhere else are not the same kind of wrong.

#1372 is the nearest existing issue, the label payload validator admitting duplicate names and uppercase hex. Same family, different file, and not folded into this one because its fix is local to configure.sh while this one spans the schema, the validator, and whatever the sweep turns up.

Also found while measuring, unfixed and out of scope here

environment_errors_for_repo accepts a duplicate branch name inside one custom set. ["main", "main"] returns no error, and configure.sh sorts and joins both sides before comparing, so it reads as drift.

Activity

  1. ptr727 commented on Sep 10, 2026

    @ptr727
    OwnerAuthor

    Two more instances, both measured while fixing the first one in #1506, and one of them was introduced by that fix before a review pass caught it.

    A fourth instance: two engines asserting one constraint

    registry/repos.schema.json's description pattern ^\S(?:[^\n\r]*\S)?$ carries a $comment saying it is kept in sync with spec/validate.py's description_errors(). It is not, in two directions at once, and neither is a bug in either file.

    registry/repos.json names that schema and no CI job validates against it, so the only reader that ever applies the pattern is the author's editor, whose engine is ECMA-262. ECMA-262 \s includes U+FEFF where Python's does not, so the pattern rejects a description Python accepts. Under Python re, which a command-line schema checker uses, $ matches before a trailing newline, so a value ending in one satisfies the pattern and fails the function.

    Adding that same idiom to the environment name and branch fields was tried in #1506 and reverted on measurement: it turned a one-directional gap, where an advisory schema admits what the gate refuses, into a two-directional one where the editor also refuses a value the gate allows. A false rejection in an editor is the worse half.

    So a grammar for these fields has to be written so both engines agree on it. $ is not end-of-string in Python re; (?![\s\S]) is end-of-string in both. \s and \S name different sets in the two engines and cannot appear in a shared grammar at all.

    A fifth instance, self-inflicted, and the shape worth remembering

    #1506 casefolded spec/validate.py's duplicate-name check because spec/audit.py narrows on name.lower(). That fixed one divergence and created another: the validator now normalized with casefold and the consumer still with lower, which differ on a name carrying a sharp s. An entry declared with the character and selected without it matched under neither. CodeRabbit caught it; both sides use casefold now, and each of the six call sites is pinned by a test that fails when it alone reverts.

    The general shape: fixing one side of a normalizer disagreement is how the next one gets made. The unit that has to agree is every site that normalizes the value, found and changed together, not the one the finding names.

    A third normalizer, still in play

    repo-config/configure.sh resolves a registry entry with an exact select(.name == $n) against ${repo##*/}, the repository argument's last path segment. That is neither lower nor casefold. An entry named Blog for github.com/owner/blog resolves under spec/audit.py --repo blog and passes spec/validate.py, while this lookup misses and falls through to .defaults.workflowModel // "release", choosing a ruleset from a default rather than from the entry. The run does abort later, because spec/resolve_description.py raises on a case-only near-miss, but that is an ordering coincidence rather than a check on this lookup, and the model is already resolved by then.

    Not reachable through any name the fleet can configure: GitHub restricts a repository name to [A-Za-z0-9._-], where all three normalizers agree. It is reachable in the JSON only because nothing enforces name against the url's repo segment, which may itself be the thing worth fixing instead.

    Scope, restated

    The sweep is not "where else is a value tested by truthiness". It is: which declared fields are consumed by exact comparison, by a normalized comparison, or by concatenation into a URL or a path, and does every site that touches one agree on the rule. Truthiness, an unanchored match, two regex engines, and two case normalizers are the same defect in four sets of clothes.

  2. ptr727 commented on Sep 10, 2026

    @ptr727
    OwnerAuthor

    One more surface, found while triaging a suppressed finding on #1489, and it is the same shape as the schema's description pattern already recorded above.

    registry/repos.schema.json declares "additionalProperties": false on an environment object. spec/validate.py's environment_errors_for_repo does not enforce it, and no CI job runs the schema, so the contract is stated on two surfaces and only the surface that is never run states this half of it.

    The failure a reviewer predicted for it does not occur, and measuring that is what makes the residue clear rather than alarming:

    typo of branchPolicy   {"name": "e", "branchPolciy": "none"}
      -> ["Fixture: environments[0] missing 'branchPolicy' (expected custom, none)"]
    typo of branches       {"name": "e", "branchPolicy": "custom", "branchs": ["main"]}
      -> ["Fixture: environments[0] branchPolicy custom must declare 'branches'"]
    stray extra key        {"name": "e", "branchPolicy": "none", "description": "x"}
      -> []
    

    Every key carrying meaning is required, or forbidden under the policy that excludes it, so a misspelling is reported as the absence of the real key rather than as an unknown one. What passes is a stray key that is not a typo of anything, and configure.sh reads named keys rather than iterating, so it produces no downstream report at all.

    So this is not a defect with a victim. It is the class: a rule written twice, once where it runs and once where it does not, with no mechanism keeping the two in agreement. Closing it means deciding what the schema owns and what the validator owns, which is the same decision the description pattern needs, rather than adding one more check to whichever file the next finding happens to name.

  3. added 3 commits that reference this issue on Sep 10, 2026
    80d0f6d
    b21059f
    f4e3f31
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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions