Skip to content

test: pin the JSON schema of every model in ir and the qualification modules - #2424

Merged
abrichr merged 2 commits into
mainfrom
test/schema-surface
Nov 21, 2026
Merged

abrichr merged 2 commits into
mainfrom
test/schema-surface

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

This is the schema-snapshot step of the safety net in the approved monorepo refactor plan (openadapt-internal#277, section 5, item 4). It adds tests only.

packages/flow/tests/test_schema_surface.py pins the JSON schema of every Pydantic model defined in the modules the plan moves first:

  • ir (99 models)
  • qualification (15)
  • the eleven qualification_*.py modules
  • production_qualification
  • approval_mode.model
  • records.schema
  • runtime.effects.effect

That is 178 models in 16 modules.

What it pins:

  • Both schemas. Each model gets a validation schema and a serialization schema from model_json_schema.
  • Property order. Field order is part of what a model writes, so the comparison is by serialized JSON, not just dict equality.
  • Models by name. A model is pinned by the name it is imported under from the old module. After a move, the re-export must resolve to a model with the same schemas.
  • Pydantic version. Schemas are compared only on the Pydantic version the snapshot was written with (from packages/flow/uv.lock). On another version, the test checks only that every model name still resolves.
  • One snapshot file per module, under fixtures/schema_surface/. A PR that changes models in one module touches one file.

Left out on purpose:

Collisions: I merged this branch with the heads of #2394, #2410, #2414, #2415, #2411, #2406, #2407, #2412, #2300 and #2291 (git merge-tree) and ran the test on each result. All pass. #2363 changes ir models (the second-factor wait), so it will need to regenerate openadapt_flow.ir.json after this merges:

OPENADAPT_WRITE_SCHEMA_SURFACE=1 pytest tests/test_schema_surface.py

Tested: passes locally on Python 3.12, including under env -i with a different HOME. ruff is clean.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: bc578b5

First review of this PR. Author is GitHub abrichr, not Grok. Review only; I am not merging.

The validation and serialization schemas, compared with json.dumps so property order is kept, are the right pin for what a model accepts or writes. frozen is a Python in-memory flag and does not belong in this snapshot; a format change does not depend on it. extra="forbid" already shows up in the validation schema as additionalProperties: false (58 of 99 ir models have that today; the rest omit it, which matches Pydantic's default extra="ignore"). Switching extra would already fail this test. Other model_config flags (validate_assignment, from_attributes, and so on) are not format and need not be pinned here.

The listed modules match the stated first wave (ir, qualification*, admission envelopes, approval_mode.model, records.schema, runtime.effects.effect). Receipt and Seal formats are correctly left to their vector tests, and qualify/ is documented as deferred. The most important durable-format module still missing from that list is openadapt_flow.deployment (the verify / effects config people keep in YAML, including EffectsConfig). Other on-disk shapes worth a later snapshot, not this one: runtime.effects.frame, tx.types / tx.receipt, and runtime.durable.checkpoint.

The regenerate path will drop every moved model. _defined_models only keeps a class when value.__module__ == module_name. After the split this test is written for, RunReport re-exported from openadapt_flow.ir will have __module__ like openadapt_flow.ir.report, so OPENADAPT_WRITE_SCHEMA_SURFACE=1 would rewrite the snapshot with few or no models and hide a later format change. Please regenerate from the names already pinned (plus any new models still defined in the module), resolving each name through the old module path the same way the check already does.

On a different Pydantic version the test still requires every pinned name to resolve, which is the right fallback. I am not merging.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: f701196

Delta review after my REQUEST CHANGES at bc578b574e5851cfdc7398837bd681b868f547f5 (7059127138). Author is GitHub abrichr, not Grok. Review only; I am not merging.

Regeneration now unions _defined_models with every name already pinned and resolves each through getattr on the same module, so a model that moved to a submodule and is re-exported at the old path stays pinned. The live test still fails if a pinned name no longer resolves or if its validation or serialization schema changes. openadapt_flow.deployment is in MODULES, and the new snapshot pins 19 models that match the BaseModel classes defined in deployment.py. A later change to those models (for example from #2420) will still need a deliberate regeneration.

@abrichr
abrichr merged commit 37db820 into main Nov 21, 2026
51 of 52 checks passed
@abrichr
abrichr deleted the test/schema-surface branch November 21, 2026 12:18
abrichr added a commit that referenced this pull request Nov 22, 2026
…d budgets

Review blocker (fail-open class: unbounded-read-as-evidence): a file source
that is a FIFO, a device or a link to one could block the open or never
reach EOF and hang the run. A file source is now read only when it is a
regular file: it is checked before the open, opened with O_NONBLOCK, and
fstat-checked after. Anything else is unreadable, as is a file over 256 MiB
(also while it grows during the read). Tests cover a FIFO, a link to it,
/dev/null and the size cap.

CI: deployment imported up into runtime.effects.local_state, and the eager
runtime.effects export loaded one more module for ir and receipt than
their budgets allow. The typed source models move to
openadapt_flow/local_state_sources.py (policy layer, and added to the
protected-path manifest beside runtime/effects/**). The verifier is a lazy
export of openadapt_flow.runtime, like Replayer. local_state reads
sys.platform without binding the sys namespace, so the lazy export is no new
import-layer debt site. No budget or debt row changed.

The deployment schema snapshot is regenerated on Pydantic 2.13.4 for the new
effects.local_state field (#2424).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant