Skip to content

Refactor spec loader validation into shared helper and add schema-version tests#154

Merged
aidankhogg merged 1 commit into
dev/alphafrom
codex/refactor-loader.py-to-share-validation-helper
Jun 29, 2026
Merged

Refactor spec loader validation into shared helper and add schema-version tests#154
aidankhogg merged 1 commit into
dev/alphafrom
codex/refactor-loader.py-to-share-validation-helper

Conversation

@aidankhogg

Copy link
Copy Markdown
Contributor

Motivation

  • Reduce duplication by centralizing repeated spec validation steps (YAML object checks, metadata/schema_version checks, Pydantic model creation, cross-validation, and feature-state validation) into a single private helper.
  • Ensure consistent behavior and error messages across the three public loader entry points (load_spec, load_spec_with_composition, load_spec_with_environment).

Description

  • Add _validate_spec_data(data: dict[str, Any], *, validate_feature_states: bool) -> NetEngineSpec which performs type checks on data and metadata, rejects unsupported metadata.schema_version, constructs NetEngineSpec(**data), runs _cross_validate, and optionally _validate_feature_states.
  • Update load_spec, load_spec_with_composition, and load_spec_with_environment to only load/merge YAML dictionaries and then delegate validation to _validate_spec_data.
  • Preserve existing SpecLoadError messages for schema-version rejection and other validation errors to keep test expectations stable.
  • Add focused tests in tests/test_config.py covering schema-version rejection for all three loader paths (load_spec, load_spec_with_composition, and load_spec_with_environment).

Testing

  • python -m py_compile netengine/spec/loader.py ran and succeeded to verify syntax correctness of the modified module.
  • pytest tests/test_config.py was attempted but could not run to completion due to an environment import error (ModuleNotFoundError: No module named 'logs') reported by test collection, so the new tests were added but not executed in this environment.

Codex Task

@aidankhogg aidankhogg self-assigned this Jun 29, 2026
@aidankhogg aidankhogg merged commit b171e37 into dev/alpha Jun 29, 2026
@aidankhogg aidankhogg deleted the codex/refactor-loader.py-to-share-validation-helper branch June 29, 2026 22:14
@aidankhogg aidankhogg added the bug Something isn't working label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant