You signed in with another tab or window. Reload to refresh y
8000
our session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tests: property-based round trips for stores.py #47
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.
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 silent %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.
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.
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.
Activity
Lillecarl commentedon Aug 2, 2026
Done. The property found a real escaping bug in the authority.
The gap the hand-written cases left
test_stores.pyhas 16 cases across the 11 models. Between them they set 29of the 171 supported
(model, field)pairs -- 83% of the fields in thislibrary were rendered by nothing. The worst were the widest:
S3BinaryCache4/29,HttpBinaryCache3/21,LocalOverlay4/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,endpointand 24 more. Two of them,path_info_cache_sizeandstore_dir, belong toStoreConfigand so exist onevery one of the eleven models.
tests/nanopynix/test_stores_properties.pybuilds the strategies frommodel_fields, so all 171 are covered and a field added tomorrow is coveredthe 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 queryparameters went through
quote. AFileBinaryCache's authority is adirectory path, and a directory may hold any of these. Each broke
differently, and three broke silently:
/var/cache/a&b&; the rest becomes a query parameter Nix warns about and drops/var/cache/a?b/var/cache/a/var/cache/a#b/var/cache/a/var/cache/a b/var/cache/a%bThe fix is
quoteon render andunquoteon parse. Both are needed, andthat is the part worth recording: Nix decodes a query parameter for you and
does not decode the authority --
parse_store_referencehands backwhatever percent-encoding the URI carried. Escaping alone would therefore have
turned a silent truncation into a silent
%26in 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:22and[::1]. Escaping them would give a URI that nanopynix reads back perfectly andNix reads as a host literally named
user%40host. That is the worse failure ofthe two, because nothing reports it.
The cost is that the authority must be authority syntax.
file://relativeandhttps://[are refused by Nix;ssh://:is accepted and normalised tonothing. 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
escape, so
["a b"]comes back["a", "b"].renders and comes back. The asymmetry is deliberate and is now asserted.
HttpBinaryCache(url_scheme="https")and leaving it unset render the sameURI, 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:
quoteraisesUnicodeEncodeErrorrather 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.pyopensLocalandDummyfor real; that remains the whole ofthe opening coverage.
Hypothesis is a new test dependency, in nanopynix's
testextra. The profilesets
database=None, because the packaged CI runnercds into a read-onlystore 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.
Lillecarl commentedon Aug 2, 2026
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:
so the escape/unescape pair the fix added is undone by Nix's own renderer, and
unquotedecodes 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%3Bsurvives 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.Lillecarl commentedon Aug 2, 2026
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:
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%26comes backas
&.No version branch in the library.
nanopynix.storeskeeps the oneunconditional 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.
fix(stores): escape the URI authority, and derive the round trip from…
test(nanopynix): what each entry point answers for input that is wrong