# Version data, schemas and feature definitions

Python 3.12+ and standard-library SQLite. No installation, downloads, model
requests, training or cloud services. This lab continues the synthetic user-return
feature example; it does not build a model registry or deployment pipeline.

## Run the complete experiment

Unpack the lesson ZIP, enter `mlops-feature-versions/`, then:

```sh
python3.12 -m venv .venv
source .venv/bin/activate
python inspect_versions.py
python inspect_versions.py --check
python -m unittest -v test_versions.py
```

The experiment uses temporary directories/in-memory databases. It preserves the
bundled data and records. To save a separate result:

```sh
python inspect_versions.py --save my-result.json
```

## Lock and use a snapshot yourself

Create a new manifest and preserve the identity printed at creation time:

```sh
SNAPSHOT_ID=$(python versions.py lock --out my-lock.json)
python versions.py run --manifest my-lock.json --expected-id "$SNAPSHOT_ID" --registry my-identities.sqlite
```

Run these in the same shell. `lock` refuses to overwrite an existing manifest.
`run` defaults to cutoff 2026-01-08T12:00:00Z and publication 12:30. Override them
with `--cutoff` and `--published-at` ISO UTC timestamps. Use `--inputs DIRECTORY`
for another directory containing dataset.json, schema.json and feature.json.
The implementation files are always bound from this lab's own code directory;
it does not import executable code from an input-data directory.

An input edit makes the old command fail. Do not replace SNAPSHOT_ID by rereading
an edited manifest: the expected identity is a separate reference. Creating a new
manifest is an explicit selection of a new snapshot. Its component identities
must also agree with the persistent local registry. Reusing a bound dataset or
feature version for different content fails. A genuinely new data or feature
version uses a new positive integer. A schema version increase is refused until
its schema/validator contract is implemented; it is not automatic migration.

## Files and ownership

- `dataset.json`: eight original synthetic events plus dataset name/version.
- `schema.json`: supported fields, UTC/minute semantics and schema version.
- `feature.json`: user_event_count version 1, one-day count, as-known arrival rule.
- `versions.py`: parse/validate, hash inputs and fixed code inventory, compare an
  expected manifest identity, bind immutable component identities, call the existing
  feature store. It uses the parsed bytes that were hashed.
- `inspect_versions.py`: actually runs the baseline, three refused edits, a version
  conflict and the explicit two-day feature version 2.
- `feature_history/`: unchanged copies of the preceding lesson's history.py,
  join.sql and vendor computation/validation. Only the wrapper is new. Source
  provenance is recorded in run-metadata.json.
- `test_versions.py`: 17 offline tests, including a real edited-code subprocess,
  persistent registry, transaction rollback, strict JSON and the CLI.
- `result.json` / `run-output.txt`: actual local results. No scores are invented.

## Identity and scope

Dataset identity binds original file bytes; JSON whitespace changes that identity.
Schema identity binds its descriptor and validator. Feature identity binds its
complete definition and the fixed computation/wrapper source inventory. This
conservative exercise requires a new feature version after a bound source change,
even when a developer believes the change preserves behavior. Tests, README and
result files do not form the feature implementation inventory.

A manifest ID hashes the serialized manifest body. It changes when any bound input
or implementation changes. SHA-256 is a change-detection tool, not a signature,
quality score or permission check. The registry is a local single-writer teaching
implementation; it is not an authenticated multi-user catalog. Inputs and source
files live in a trusted workspace that stays unchanged while the process runs.
Python/package environment, distributed locking, source-control provenance,
retention, schema migrations, training lineage and production rollout are outside
this exercise. Bindings can succeed even if a later computation fails; a registered
identity is not a successful-run record.
