Skip to content

test: enforce stdlib-only payload with import guard - #4

Merged
neilgfoster merged 1 commit into
mainfrom
chore/stdlib-import-guard
Jun 19, 2026
Merged

test: enforce stdlib-only payload with import guard#4
neilgfoster merged 1 commit into
mainfrom
chore/stdlib-import-guard

Conversation

@neilgfoster

Copy link
Copy Markdown
Owner

What and why

Keep the stdlib-only guarantee enforced, not just asserted. The shipped payload under plugin/src/ must import only the standard library (plus its own package) at runtime — that's the portability/auditability promise. ruff/pytest are dev tooling and live outside plugin/, so they never count.

Changes

  • tests/test_stdlib_only.py — two layers:
    • test_no_forbidden_imports: a denylist grep (msal, azure, requests, urllib3, httpx, aiohttp, msgraph, pydantic, yaml, dotenv), mirrored verbatim in README so a human and CI fail on the same offenders.
    • test_every_import_is_stdlib_or_first_party: the real guarantee — AST-walks every import and asserts each top-level module is in sys.stdlib_module_names or the first-party package (example). Catches anything the denylist forgets.
  • README.md — verify section now documents the uv-based dev-tooling install (pip is unavailable in some envs) and carries the same stdlib grep one-liner.

Verification

ruff check . && ruff format --check .
python3 -m pytest -q          # 6 passed

Negative-tested: injecting import requests / import azure.identity into plugin/src/ fails both guard tests; removing them passes.

🤖 Generated with Claude Code

The shipped payload under plugin/src/ must import only the standard library (plus
its own package); ruff/pytest stay dev-only outside plugin/. Add a two-layer guard:
a denylist grep (mirrored in README's verify steps) and an AST allowlist walk that
asserts every import resolves to the stdlib or the first-party package.

Verified: guard fails on injected requests/azure imports, passes when clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@neilgfoster
neilgfoster merged commit 20932c6 into main Jun 19, 2026
1 check passed
@neilgfoster
neilgfoster deleted the chore/stdlib-import-guard branch June 19, 2026 23:28
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