Skip to content

feat: add upload_coverage_files helper and accept case-insensitive MCP Content-Type - #134

Open
ewwhardik wants to merge 1 commit into
prooflinedev:mainfrom
ewwhardik:feat/coverage-files-and-mcp-fixes
Open

ewwhardik wants to merge 1 commit into
prooflinedev:mainfrom
ewwhardik:feat/coverage-files-and-mcp-fixes

Conversation

@ewwhardik

Copy link
Copy Markdown

Who this helps

CI/CD engineers and Python SDK consumers uploading test coverage or connecting over MCP behind HTTP proxies benefit in two ways:

  1. Safe, verbatim disk coverage uploads (upload_coverage_files / read_coverage_files): Previously sdk-python only exposed the low-level upload_coverage_reports(body=...) wrapper while sdk-typescript already provided uploadCoverageFiles (readCoverageFiles). Worse, the README example using Path.read_text(encoding="utf-8") silently stripped \r\n into \n under Python universal newlines—corrupting CRLF coverage reports. Now ProoflineClient.upload_coverage_files, AsyncProoflineClient.upload_coverage_files, and read_coverage_files:
    • Validate 40-char lowercase tested_sha, 1..50 report bounds, and unique relative POSIX names before sending a request.
    • Normalize Windows/POSIX local paths safely, block relative/symlink escapes outside root, reject non-regular files, and fail fast with clear ValueError/FileNotFoundError errors.
    • Decode raw bytes (read_bytes().decode("utf-8")) so BOMs and \r\n/\n line endings stay verbatim, enforce the 30 MiB serialized JSON limit pre-upload, and offload disk I/O to anyio.to_thread.run_sync in AsyncProoflineClient.
  2. RFC 9110 case-insensitive MCP media-type check (proofline/_mcp.py):
    • _decode previously compared content-type media types case-sensitively (!= "application/json"), rejecting valid headers like Application/JSON; charset=utf-8 even though proofline/exports.py already handled media types case-insensitively.

What changed

  • proofline/coverage.py: Added CoverageFile, read_coverage_files, path/symlink containment checks, pre-read size budget checks, strict UTF-8 byte-preserving decode, and post-serialization 30 MiB check.
  • proofline/client.py: Added upload_coverage_files to both ProoflineClient and AsyncProoflineClient (anyio.to_thread.run_sync).
  • proofline/__init__.py: Exported CoverageFile and read_coverage_files.
  • proofline/_mcp.py: Normalized extracted Content-Type media type with .lower().
  • scripts/contracts.py: Registered upload_coverage_files in helpers and verified operation & claim-vocabulary contracts.
  • README.md: Documented upload_coverage_files / CoverageFile / read_coverage_files.
  • tests/test_coverage.py: Added sync/async upload tests, verbatim BOM+\r\n preservation, validation/symlink/size/encoding failure tests, server problem propagation, and mixed-case MCP Content-Type tests.

How I verified it

Verified in .venv (Python 3.13.2, pinned requirements-dev.txt packages):

  • ruff check . — all checks passed
  • ruff format --check proofline/coverage.py proofline/client.py proofline/_mcp.py proofline/__init__.py scripts/contracts.py tests/test_coverage.py — passed
  • python scripts/contracts.py — passed (Python operation and outcome-vocabulary contracts passed.)
  • mypy proofline scripts — Success: no issues found in 230 source files (and mypy --follow-imports=silent tests/test_coverage.py — 0 issues)
  • pytest -q tests/test_coverage.py tests/test_exports.py tests/test_generated_operation.py — 22 passed, 1 skipped (symlink test skips cleanly when unprivileged Windows disables symlink creation)
  • Non-timing pytest -q -k "not test_body_stream_deadline_does_not_turn_authority_into_timeout" — 220 passed, 1 skipped, 4 deselected
  • python -m build --no-isolation --outdir <temp> — built proofline_sdk-10.2.3-py3-none-any.whl and proofline_sdk-10.2.3.tar.gz cleanly

This branch has not been deployed

No deployments
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