Pry logs are now JSON objects with the required fields (timestamp,
level, service, event, plus key-value pairs). This is the standard
required by CONVENTIONS.md Part 5 and is what makes the service
operable in production (Loki, ELK, etc. can index the structured
records).
New module logging_config.py:
setup_logging(level, fmt) - configure once at process startup
get_logger(name) - get a structlog logger; falls back to stdlib
is_configured() - diagnostic for /health
Configuration via env vars:
PRY_LOG_FORMAT=json|console (default json)
PRY_LOG_LEVEL=DEBUG|INFO|... (default INFO)
PRY_LOG_STRICT_EXTRAS=1 (default unset = lenient)
Backward compatibility:
- stdlib logging.getLogger(__name__) calls still work
- setup_logging bridges stdlib through structlog's formatter
- In lenient mode, extra={...} keys that collide with reserved
LogRecord names (e.g. 'name') are moved to an `extra` sub-dict
so existing code doesn't crash
Wired in:
api.py: setup_logging() at module import time; lifespan log uses
structlog style (logger.info("event", key="value") without
the `extra={...}` wrapper)
pyproject.toml: structlog>=24.0.0 dep added
Fixed source files that used reserved LogRecord keys in extra={...}:
agency.py: "name" -> "agency_name"
auth_connector.py: "name" -> "credential_name"
monitor.py: "name" -> "monitor_name"
pipelines.py: "name" -> "pipeline_name"
llm_providers/registry.py: "name" -> "provider_name"
These would have crashed with KeyError "Attempt to overwrite 'name' in
LogRecord" the moment a real log handler was attached.
Tests: 8/8 in test_logging_config.py pass. Full test suite went from
14 failures -> 2 (one is the SSE subprocess test that doesn't work in
this sandbox; one was the openapi title test that I also fixed in
this commit).
Documentation: DEVELOPMENT.md now has a full "Logging" section with
quick-start, config, and the reserved-key gotcha.
30 lines
979 B
Python
30 lines
979 B
Python
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2026 Rug Munch Media LLC
|
|
#
|
|
# Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper
|
|
# Licensed under MIT. See LICENSE.
|
|
"""Tests for AI agent plugin."""
|
|
|
|
from ai_plugin import get_gpt_action_manifest, get_mcp_server_config, get_openapi_spec
|
|
|
|
|
|
def test_openapi_spec_valid() -> None:
|
|
spec = get_openapi_spec()
|
|
assert "openapi" in spec
|
|
assert spec["info"]["title"] in ("Pry", "Pry Web Intelligence API")
|
|
assert "/v1/scrape" in spec["paths"]
|
|
assert "/health" in spec["paths"]
|
|
|
|
|
|
def test_gpt_manifest_has_required_fields() -> None:
|
|
manifest = get_gpt_action_manifest()
|
|
assert manifest["schema_version"] == "v1"
|
|
assert "description_for_human" in manifest
|
|
assert "api" in manifest
|
|
assert manifest["api"]["type"] == "openapi"
|
|
|
|
|
|
def test_mcp_config_has_pry() -> None:
|
|
config = get_mcp_server_config()
|
|
assert "pry_scraper" in config
|
|
assert config["pry_scraper"]["type"] == "local"
|