Skip to content

feat(schemas): bundle adcp-agents.json as adcp.schemas package, eliminate inlined test copy#442

Draft
bokelley wants to merge 3 commits intomainfrom
claude/issue-420-bundle-adcp-agents-schema
Draft

feat(schemas): bundle adcp-agents.json as adcp.schemas package, eliminate inlined test copy#442
bokelley wants to merge 3 commits intomainfrom
claude/issue-420-bundle-adcp-agents-schema

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

@bokelley bokelley commented May 3, 2026

Closes #420

Summary

  • Adds adcp.schemas — a Python subpackage that ships JSON schemas as committed data files, loaded via importlib.resources in both editable installs and installed wheels
  • Moves adcp-agents.json (topology-manifest schema) from a 76-line inline dict in tests/test_discovery_endpoint.py into src/adcp/schemas/adcp-agents.json; future schema drift is caught by updating the single file rather than hunting test copies
  • Schema is stored in src/adcp/schemas/ (not schemas/cache/) so it is immune to the shutil.rmtree wipe in scripts/sync_schemas.py — no preservation logic needed
  • Adds ADCP_AGENTS = "adcp-agents.json" string constant to avoid typo-driven FileNotFoundError

What tested

  • ruff check src/ — clean
  • pytest tests/test_schemas_module.py tests/test_discovery_endpoint.py -v — 26 passed (10 new + 16 pre-existing); pre-existing 4 warnings about _DiscoveryTestHandler are unrelated
  • New tests cover: happy path, https:// pattern assertion, unknown-schema error, dynamic error message, 5 path-traversal variants (parametrized), corrupted-schema → FileNotFoundError surface

Notes on acceptance criterion 3 ("spec-resync workflow reads from the same source")

The schema lives in src/adcp/schemas/ rather than schemas/cache/. When upstream publishes adcp-agents.json in the protocol bundle, a follow-up can add a post-sync copy step to scripts/sync_schemas.py that updates src/adcp/schemas/adcp-agents.json automatically. For now the file is manually maintained; the inline-copy drift risk is eliminated.

Pre-PR review

  • code-reviewer: approved — path-traversal guard verified correct, json.JSONDecodeError catch confirmed via ValueError subclass, generator annotation fixed
  • dx-expert: approved — API shape (load_schema/ADCP_AGENTS) correct, dynamic error message listing, cross-reference to adcp.validation.schema_loader in module docstring

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num>
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P


Generated by Claude Code

claude added 3 commits May 3, 2026 02:57
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(testing): bundle adcp-spec schemas as adcp.schemas package, eliminate inlined copies

2 participants