Skip to content

test: add unit tests for JSONFormatter structured log output#486

Draft
madara88645 wants to merge 1 commit into
mainfrom
tests/add-json-formatter-20260629
Draft

test: add unit tests for JSONFormatter structured log output#486
madara88645 wants to merge 1 commit into
mainfrom
tests/add-json-formatter-20260629

Conversation

@madara88645

Copy link
Copy Markdown
Owner

Summary

Adds 12 unit tests for JSONFormatter.format() in app/__init__.py. This is the structured log formatter used by all VibeGraph workers in production, but it had no dedicated tests — test_app.py only covered configure_logging().

Why it matters: JSONFormatter converts LogRecord objects to JSON strings that feed into log aggregation pipelines. A regression (missing field, wrong key name, broken JSON) would silently corrupt production observability without raising a type error.

What's covered

Test Assertion
output is valid JSON json.loads() succeeds
required keys present timestamp, level, logger, message
level name matches record ERROR → "ERROR"
logger name matches record "app.routers.upload" propagated
message matches record exact string match
request_id included when attribute set key appears
request_id absent when not set key absent
exception included when exc_info set "exception" key with error text
exception absent when no exc_info key absent
timestamp is non-empty string length > 0
INFO level record "level": "INFO"
WARNING level record "level": "WARNING"

Files changed

  • tests/test_json_log_formatter.py (new — 111 lines, no source changes)

Test run

12 passed, 1 warning in 0.83s

Generated by Claude Code

Covers JSONFormatter.format() — the production log formatter used by all
VibeGraph workers. Tests verify: output is valid JSON, all required fields
are present, level/logger/message match the record, request_id is included
only when set, exception field appears only when exc_info is provided, and
timestamp is a non-empty string. 12 tests across INFO/WARNING/ERROR levels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vibegraph Ready Ready Preview, Comment Jun 29, 2026 4:15am

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