feat(schemas): bundle adcp-agents.json as adcp.schemas package, eliminate inlined test copy#442
Draft
feat(schemas): bundle adcp-agents.json as adcp.schemas package, eliminate inlined test copy#442
Conversation
…nate inlined test copy Closes #420 Adds adcp.schemas — a small Python package that ships JSON schemas as committed data files so any module can import them by name rather than maintaining inline copies that drift. The topology-manifest schema (adcp-agents.json, used by /.well-known/adcp-agents.json) was inlined in test_discovery_endpoint.py after PR #406; this commit moves it into src/adcp/schemas/ where it is bundled into the wheel via the new adcp.schemas package-data entry and loaded via importlib.resources. Storing it in src/adcp/schemas/ (not schemas/cache/) makes it immune to the shutil.rmtree wipe in sync_schemas.py, so it survives make regenerate-schemas runs without any preservation logic. https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P
… completeness - Reject load_schema names containing '/', '\\', or '..' to prevent escaping the adcp.schemas package directory - Add ValueError (covers json.JSONDecodeError) to the except clause so a corrupted bundled schema surfaces as FileNotFoundError, not a raw parse error - Add ADCP_AGENTS to __all__ so it appears in wildcard imports and docs - Enumerate available schemas dynamically in the error message - Add tests: path-traversal parametrize, corrupted-schema guard https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P
…mments - Fix _bad_as_file return type to Iterator[Path] (mypy rejects -> None on a generator under @contextmanager) - Move test imports to module level per project convention - Add comment on intentional over-conservative '..' path-traversal guard - Add noqa comment on broad except in dynamic schema listing https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #420
Summary
adcp.schemas— a Python subpackage that ships JSON schemas as committed data files, loaded viaimportlib.resourcesin both editable installs and installed wheelsadcp-agents.json(topology-manifest schema) from a 76-line inline dict intests/test_discovery_endpoint.pyintosrc/adcp/schemas/adcp-agents.json; future schema drift is caught by updating the single file rather than hunting test copiessrc/adcp/schemas/(notschemas/cache/) so it is immune to theshutil.rmtreewipe inscripts/sync_schemas.py— no preservation logic neededADCP_AGENTS = "adcp-agents.json"string constant to avoid typo-drivenFileNotFoundErrorWhat tested
ruff check src/— cleanpytest tests/test_schemas_module.py tests/test_discovery_endpoint.py -v— 26 passed (10 new + 16 pre-existing); pre-existing 4 warnings about_DiscoveryTestHandlerare unrelatedhttps://pattern assertion, unknown-schema error, dynamic error message, 5 path-traversal variants (parametrized), corrupted-schema →FileNotFoundErrorsurfaceNotes on acceptance criterion 3 ("spec-resync workflow reads from the same source")
The schema lives in
src/adcp/schemas/rather thanschemas/cache/. When upstream publishesadcp-agents.jsonin the protocol bundle, a follow-up can add a post-sync copy step toscripts/sync_schemas.pythat updatessrc/adcp/schemas/adcp-agents.jsonautomatically. For now the file is manually maintained; the inline-copy drift risk is eliminated.Pre-PR review
json.JSONDecodeErrorcatch confirmed viaValueErrorsubclass, generator annotation fixedload_schema/ADCP_AGENTS) correct, dynamic error message listing, cross-reference toadcp.validation.schema_loaderin module docstringSession: https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P
Generated by Claude Code