Skip to content

feat(zarr-metadata): add Hypothesis strategies for metadata fields - #414

Draft
d-v-b wants to merge 2 commits into
mainfrom
claude/zarr-metadata-property-tests-4758bf
Draft

d-v-b wants to merge 2 commits into
mainfrom
claude/zarr-metadata-property-tests-4758bf

Conversation

@d-v-b

@d-v-b d-v-b commented Oct 27, 2026

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Added zarr_metadata.testing.strategies, Hypothesis strategies that draw valid Zarr v3 metadata fields, behind a new testing extra (pip install zarr-metadata[testing]). There is one strategy for every codec, data type, chunk grid and chunk key encoding the package defines that holds no other field. fields draws every envelope spelling the spec allows, or only the canonical one with spellings="canonical". Codecs can be drawn for the Chunk they are handed, chunk grids for an array shape, and fill values for a data type. The strategies are a mapping keyed by definition, so an extension author can add strategies for their own definitions.

Tests

The agent added these tests in tests/testing/test_strategies.py:

  • Drift: every definition in scope has a strategy. The only exceptions are sharding_indexed, cast_value and struct, which hold other fields and come in a follow-up.
  • Oracle: every drawn field resolves with no problems, both as drawn and after a JSON round trip. Canonical output is a fixed point of canonicalize. Fill values fit their data type, chunk grids fit their shape, and codecs either take their chunk or are refused by their rules.
  • Reach: using find, each test checks that every optional key appears present and absent, and that every Literal value, envelope form and fill-value spelling is drawn.
  • Error cases: one test each for the LookupError, TypeError and the two ValueErrors.

To check the tests, the agent planted 12 bugs in the strategies (for example dropping uppercase hex, never writing a run as a pair, or drawing a zero chunk length). The suite catches all 12.

Where the strategies follow the spec rather than the package

  • Core data types are drawn only as bare strings, as core/index.rst requires. The package also accepts {"name": "int8"}.
  • Regular-grid chunk lengths are never 0 ("Chunk sizes must be greater than zero"). regular.py's rules accept 0.

The agent did not change either validator.

Stack

This is the first of five planned PRs:

  1. Single-field strategies, the registry, and the drift and reach tests (this PR).
  2. Composition: walking a codec pipeline via transition, and strategies for sharding_indexed, cast_value, struct and rectilinear grids.
  3. Documents: v3 arrays, v2 arrays, groups and consolidated metadata.
  4. Mutations that make a document invalid.
  5. A differential test against zarr.

🤖 Generated with Claude Code

d-v-b added 2 commits October 27, 2026 18:18
Add `zarr_metadata.testing.strategies`, behind a new `testing` extra.
It ships Hypothesis strategies that draw valid Zarr v3 metadata fields,
one for every codec, data type, chunk grid and chunk key encoding the
package defines that holds no other field.

- Each kind's strategy takes what its configurations depend on: a data
  type's fill values take its configuration, a chunk grid takes the
  array shape, and a codec takes the `Chunk` it is handed.
- `fields` draws every envelope spelling the spec allows, or only the
  canonical one.
- Strategies are a mapping keyed by definition, so an extension author
  can add strategies for their own definitions.

The tests read every draw back in `CORE_AND_EXTENSIONS` and require no
problems. They also check:
- that every definition in scope has a strategy, apart from the three
  that hold nested fields;
- reach, with targets derived from each configuration's TypedDict:
  each optional key present and absent, each `Literal` value, and a
  non-canonical spelling where one exists;
- fill-value spellings and envelope forms.

Strategies follow the spec where the package is looser. Core data types
are drawn only as bare strings, and regular-grid chunk lengths are never
zero ("Chunk sizes must be greater than zero"), although the package's
rules accept both today.

Assisted-by: ClaudeCode:claude-opus-5-5

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant