8000 Tests: property-based round trips for stores.py · Issue #47 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Tests: property-based round trips for stores.py #47

Closed

Description

@Lillecarl

tests/nanopynix/test_stores.py covers the store models by hand, case by
case. A property covers the same ground with less text and more reach.

Scope

  • parse(uri) -> model -> uri() must be stable for every model.
  • model -> uri() -> parse() must return an equal model.

Build the Hypothesis strategies from model_fields, so that the 49 settings
are covered without 49 hand-written cases.

Caution

The S3 and SSH stores cannot be opened on a test machine. State plainly in the
test module that they are round-trip tested and not opened. Do not claim
coverage that does not exist.

Section 5, item 3.2 of CODE_IMPROVEMENT_PLAN.md.

Activity

  1. Lillecarl commented on Aug 2, 2026

    @Lillecarl
    ContributorAuthor

    Done. The property found a real escaping bug in the authority.

    The gap the hand-written cases left

    test_stores.py has 16 cases across the 11 models. Between them they set 29
    of the 171 supported (model, field) pairs
    -- 83% of the fields in this
    library were rendered by nothing. The worst were the widest:
    S3BinaryCache 4/29, HttpBinaryCache 3/21, LocalOverlay 4/19.

    Counted a second way, by distinct field name rather than by pair: 29 of the
    54 names are set by no case at all -- secret_key, tls_certificate,
    read_only, remount_hook, endpoint and 24 more. Two of them,
    path_info_cache_size and store_dir, belong to StoreConfig and so exist on
    every one of the eleven models.

    tests/nanopynix/test_stores_properties.py builds the strategies from
    model_fields, so all 171 are covered and a field added tomorrow is covered
    the day it appears. A guard asserts the strategy set equals the supported-field
    set per model, because a builder that quietly skipped a field would leave both
    properties passing while testing less.

    The bug: the authority was never escaped

    _base() interpolated the authority straight into the URI while the query
    parameters went through quote. A FileBinaryCache's authority is a
    directory path, and a directory may hold any of these. Each broke
    differently, and three broke silently:

    path before after
    /var/cache/a&b authority ends at &; the rest becomes a query parameter Nix warns about and drops round-trips
    /var/cache/a?b truncated to /var/cache/a round-trips
    /var/cache/a#b truncated to /var/cache/a round-trips
    /var/cache/a b Nix refuses the whole URI round-trips
    /var/cache/a%b Nix refuses the whole URI round-trips

    The fix is quote on render and unquote on parse. Both are needed, and
    that is the part worth recording: Nix decodes a query parameter for you and
    does not decode the authority -- parse_store_reference hands back
    whatever percent-encoding the URI carried. Escaping alone would therefore have
    turned a silent truncation into a silen 10767 t %26 in a caller's path.

    Verified red-before-green by reverting the two lines: every model that has an
    authority fails, and no other does.

    What is not escaped, and why that is right

    :@[] reach Nix unescaped, because Nix reads them -- user@host:22 and
    [::1]. Escaping them would give a URI that nanopynix reads back perfectly and
    Nix reads as a host literally named user%40host. That is the worse failure of
    the two, because nothing reports it.

    The cost is that the authority must be authority syntax. file://relative and
    https://[ are refused by Nix; ssh://: is accepted and normalised to
    nothing. All three have their own test, so the narrower alphabet the strategies
    use is a written-down limit rather than a strategy quietly dodging a red.

    Three more limits, each now pinned

    • A list setting cannot hold whitespace. Nix joins with spaces and has no
      escape, so ["a b"] comes back ["a", "b"].
    • An empty list renders to nothing and comes back unset. An empty string
      renders and comes back. The asymmetry is deliberate and is now asserted.
    • HttpBinaryCache(url_scheme="https") and leaving it unset render the same
      URI, so the parser returns the unset spelling. Normalisation, like the
      parameter order Nix imposes.

    Everything else goes in unescaped and comes back whole -- a newline, a NUL, an
    emoji, Cyrillic. Measured, so the alphabets exclude nothing for being unusual.
    The one exception is a lone surrogate, which is not text: quote raises
    UnicodeEncodeError rather than encoding it.

    On the issue's caution

    Kept, and widened. No store is opened in this module at all -- not S3, not
    SSH, and not the two local ones either. Neither property needs one, and most
    generated configurations name a machine or a bucket that does not exist.
    test_stores.py opens Local and Dummy for real; that remains the whole of
    the opening coverage.

    Hypothesis is a new test dependency, in nanopynix's test extra. The profile
    sets database=None, because the packaged CI runner cds into a read-only
    store copy and has nowhere to write an example database, and deadline=None,
    because the TSan jobs run this suite instrumented, where a per-example deadline
    measures the sanitiser. 200 examples per model per property adds 25s.

  2. Lillecarl commented on Aug 2, 2026

    @Lillecarl
    ContributorAuthor

    Reopening: the commit that closed this (659a3f71) is red on both Nix 2.31 jobs. Every other job passed.

    Cause. Nix 2.31 percent-decodes the URI authority on parse and re-renders it decoded; 2.34+ leaves it encoded on both. Measured on 2.31:

    'file:///a%23b'  ->  authority='/a#b'   render='file:///a#b'
    

    so the escape/unescape pair the fix added is undone by Nix's own renderer, and unquote decodes a second time.

    The remaining fix, which I have not yet verified: on a decoding Nix, escape only the percent sign (% -> %25) so a literal %3B survives Nix's decode, and leave everything else raw. &, ?, # and a space still cannot round-trip there, because Nix's renderer writes them raw and its parser then reads the URI as ending at the first one -- that is Nix's limit, and the tests must skip those characters on that version rather than assert them.

    A capability probe is already in place (stores.NIX_DECODES_AUTHORITY, measured rather than keyed on a version number). What is wrong is the rule it selects, not the detection.

  3. Lillecarl commented on Aug 2, 2026

    @Lillecarl
    ContributorAuthor

    Correction: my last comment read the 2.31 difference wrongly

    That comment said the whole authority was unescapable on Nix 2.31, and
    proposed escaping only the percent sign there. Both halves of that are wrong.
    The measurement:

    An authority is a host and then a path, and Nix reads the two halves with
    different code.
    Only the path half changed between the supported versions.

    Escaping on the way out and unescaping on the way in, over the whole of ASCII:

    Nix half kept refused silently wrong
    2.34 host 96 3 0
    2.34 path 97 2 0
    2.31 host 96 3 0
    2.31 path 80 17 2

    The three columns are: comes back equal; raises, which is a usable answer; and
    returns a different value with no error, which is not.

    So the escaping this issue added is correct for the host half on both
    versions, and for the path half on 2.34. Nix 2.31 decodes the path half while
    parsing and re-renders it decoded, so the escaping is undone before anything
    reads the URI back. There, # and ? truncate the value and %26 comes back
    as &.

    No version branch in the library. nanopynix.stores keeps the one
    unconditional rule, because inventing a second one for a Nix on life support
    costs more than it buys. The 2.31 limit is recorded as a version-gated test
    that says exactly what that Nix does, and the Hypothesis path alphabet narrows
    there. Delete both with the 2.31 support.

  4. added
    source: nanopynix
    on Oct 19, 2026
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

    source: nanopynix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0