Skip to content

Add extension governance validation tooling - #122

Merged
suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/5-extension-governance-security
Jun 3, 2026
Merged

suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/5-extension-governance-security

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Define extension governance validation for catalog metadata and author-side contract checks. Adds catalog CI tooling, compatibility/trust policy exports, documentation, and regression tests for metadata, dependency, entry-point, import, version, and private/internal cases.

Closes #117

@claude

claude Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 3m 54s —— View job


Code review

  • Overall assessment: Safe to merge. Clean, well-structured, and well-tested.
  • Highest-risk area: Version-specifier handling in catalog validation (extension_catalog._validate_version_policy + reused extensions._version_satisfies).
  • Merge recommendation: Safe to merge.

I reviewed extension_catalog.py, extension_testing.py, the extensions.py additions, the __init__.py/pyproject.toml/export changes, and both new test files. Correctness, EEGLAB-parity (the (EEG, com) history contract), data-structure handling, and AGENTS.md compliance all check out. I verified the static-validity test holds against the real __version__ = "0.2.23" (>=0.2 satisfies). I could not run the suite here (sandbox denied uv run pytest), so the notes below are from static analysis.

Blocking

None.

Important

None.

Nits

  • extension_catalog._validate_version_policy — double-reports a malformed eegprep_requires. When eegprep_requires fails _VERSION_SPEC_RE, the code emits "Must be a simple version specifier" and then still builds an ExtensionSpec and runs check_extension_compatibility, which parses the garbage specifier as == and adds a second, confusing "requires EEGPrep <garbage>" error (extension_catalog.py:360-381). The parallel python_requires branch already guards with if python_requires and _VERSION_SPEC_RE.match(...). Consider gating the compatibility call the same way so one bad field yields one error. Fix this →
  • _is_https_url accepts http too (extension_catalog.py:643-645). The name reads as https-only; the message and behavior allow both. Minor — rename to e.g. _is_web_url for clarity, or keep as-is since the message is accurate.
  • tools/validate_extension_catalog.py duplicates the installed eegprep-validate-extension-catalog console script. Both just call extension_catalog.main. Reasonable if the intent is a checkout-runnable wrapper that doesn't require an install — just confirming it's intentional rather than leftover.
  • Two new _LAZY_EXPORTS keys are slightly out of alphabetical order (extension_version_satisfies before epoch, load_catalog_entries after loadset). The dict is otherwise alpha-sorted; no test enforces ordering, so this is cosmetic.

Test gaps

  • No happy-path check_import test where the imported spec matches the catalog. test_imported_spec_mismatch_is_reported exercises the import path but only the mismatch branch of _validate_imported_spec_matches_catalog; the all-fields-match (report.ok) branch is never asserted. Worth one positive case so a future regression that wrongly flags a matching spec is caught.
  • No coverage for the CLI main() / --json output or directory loading (_catalog_files catalog.json special-casing vs. rglob). These are newly added surfaces; a small test invoking main(["<file>", "--json"]) and one loading a directory would lock in behavior. Low priority.

EEGLAB parity notes

  • The (EEG, com) history-tuple contract enforced by ExtensionTestHarness._assert_history_result and assert_*_history_result correctly mirrors EEGLAB's pop_* return_com convention — good parity with the console/history integration described in AGENTS.md.
  • extension_catalog reuses the hand-rolled extensions._version_satisfies (pre-existing) for python_requires/dependency specifiers. It ignores epochs/pre-releases and parses via re.findall(r"\d+", ...). This is fine for the simple specifiers the catalog allows and keeps parity with the registry, but if catalog version policy ever needs to be airtight, packaging.specifiers.SpecifierSet would be more robust. Out of scope for this PR (the helper isn't introduced here).

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Specification for #122

Problem
Issue #117 requires governance/security infrastructure around the Phase 1 extension SDK. The current tree had registry validation in src/eegprep/extensions.py, but no catalog metadata validator for a future eegprep-extension-index repo, no reusable author test harness, no public trust/compatibility policy exports, and no curation/naming policy docs. Phase 3 owns manager UX, so this PR avoids UI work.

Approach
src/eegprep/extension_catalog.py adds schema-versioned JSON catalog loading and validation. Static validation checks required metadata, curation status, trust-sensitive fields, version requirements, dependency metadata, private/internal submissions, naming warnings, and catalog conflicts without requiring installed extension code. Optional installed/import checks verify package version metadata, eegprep.extensions entry points, import failures, imported ExtensionSpec mismatches, unsupported EEGPrep versions, and dependency mismatches. src/eegprep/extension_testing.py adds ExtensionTestHarness so authors can assert spec validity, menu references, help resources, lazy action/pop loading, and EEGLAB-style (EEG, com) history results. docs/source/user_guide/extension_curation.rst defines curation policy, trust messaging, catalog format, CI usage, compatibility/deprecation policy, and naming guidance.

Key code

def validate_catalog_entries(
    entries: Iterable[Mapping[str, Any]],
    *,
    options: CatalogValidationOptions | None = None,
) -> CatalogValidationReport:
    opts = options or CatalogValidationOptions()
    errors: list[CatalogValidationIssue] = []
    warnings: list[CatalogValidationIssue] = []
    normalized_entries: list[dict[str, Any]] = []
    for index, entry in enumerate(entries):
        if not isinstance(entry, Mapping):
            errors.append(CatalogValidationIssue("Catalog entries must be mapping objects", f"entry[{index}]"))
            continue
        normalized_entries.append(dict(entry))

    _validate_static_entries(normalized_entries, opts, errors, warnings)
    _validate_catalog_conflicts(normalized_entries, errors)
    if opts.check_installed or opts.check_import:
        _validate_installed_entries(normalized_entries, opts, errors)

    return CatalogValidationReport(errors=tuple(errors), warnings=tuple(warnings))

Tests
tests/test_extension_catalog.py covers valid static metadata, schema loading, malicious-looking invalid metadata, missing license/maintainer/docs, catalog conflicts, dependency mismatches, missing packages, package without entry point, import failure, imported spec mismatch, package version mismatch, unsupported EEGPrep requirements, private/internal extension behavior, and non-load-bearing naming warnings. tests/test_extension_testing.py covers the author harness static contract checks, menu resolution failure, history result failure, entry-point loading, and failed import reporting. Focused extension/export tests pass, Ruff lint/format pass, and scoped ty passes for touched source files. Full ty currently fails on pre-existing unresolved optional imports for PySide6, pyqtgraph, and torch outside this PR.

@suraj-ranganath
suraj-ranganath merged commit 494e4a6 into feature/eegprep-extension-completion Jun 3, 2026
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