Skip to content

ci: add public API snapshot check#667

Merged
marandaneto merged 3 commits into
mainfrom
ci/add-public-api-snapshot-check
Jun 15, 2026
Merged

ci: add public API snapshot check#667
marandaneto merged 3 commits into
mainfrom
ci/add-public-api-snapshot-check

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 15, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Add a generated public API snapshot check so CI can catch accidental changes to the SDK's exported public surface. The snapshot can be regenerated intentionally with make public_api_snapshot.

💚 How did you test it?

  • uv run --extra dev python .github/scripts/check_public_api.py
  • uv run --extra dev ruff check .github/scripts/check_public_api.py
  • uv run --extra dev ruff format --check .github/scripts/check_public_api.py

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-06-15 15:57:21 UTC
Duration: 175636ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 517ms
Format Validation.Event Has Uuid 1508ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1508ms
Format Validation.Token Is Present 1507ms
Format Validation.Custom Properties Preserved 1507ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9516ms
Retry Behavior.Does Not Retry On 400 3510ms
Retry Behavior.Does Not Retry On 401 3509ms
Retry Behavior.Respects Retry After Header 9515ms
Retry Behavior.Implements Backoff 23523ms
Retry Behavior.Retries On 500 7513ms
Retry Behavior.Retries On 502 7513ms
Retry Behavior.Retries On 504 7510ms
Retry Behavior.Max Retries Respected 23518ms
Deduplication.Generates Unique Uuids 1011ms
Deduplication.Preserves Uuid On Retry 7514ms
Deduplication.Preserves Uuid And Timestamp On Retry 14515ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7517ms
Deduplication.No Duplicate Events In Batch 1504ms
Deduplication.Different Events Have Different Uuids 1508ms
Compression.Sends Gzip When Enabled 1507ms
Batch Format.Uses Proper Batch Structure 1508ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1505ms
Error Handling.Does Not Retry On 403 3510ms
Error Handling.Does Not Retry On 413 3508ms
Error Handling.Retries On 408 7515ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 1003ms
Request Payload.Flags Request Uses V2 Query Param 1007ms
Request Payload.Flags Request Hits Flags Path Not Decide 1007ms
Request Payload.Flags Request Omits Authorization Header 1007ms
Request Payload.Token In Flags Body Matches Init 1007ms
Request Payload.Groups Round Trip 1007ms
Request Payload.Groups Default To Empty Object 1007ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 1007ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 1007ms
Request Payload.Disable Geoip Omitted Defaults To False 1007ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 1007ms
Request Lifecycle.No Flags Request On Init Alone 503ms
Request Lifecycle.No Flags Request On Normal Capture 1508ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1011ms
Request Lifecycle.Mock Response Value Is Returned To Caller 1003ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1509ms

@marandaneto marandaneto marked this pull request as ready for review June 15, 2026 15:43
@marandaneto marandaneto requested a review from a team as a code owner June 15, 2026 15:43
@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
.github/scripts/check_public_api.py:253-263
The `--check` flag is defined and documented, but `args.check` is never read in the body of `main()`. The snapshot check always runs when `--write` is absent, making the flag purely cosmetic. Per the simplicity rules, superfluous parts should be removed — callers (including the Makefile) can invoke the script without `--check` and get the same behaviour.

```suggestion
    parser.add_argument(
        "--write",
        action="store_true",
        help="write the generated public API snapshot (default: check)",
    )
    args = parser.parse_args()
```

### Issue 2 of 2
.github/scripts/check_public_api.py:150
Every branch of `_record` returns a non-`None` string; the `| None` in the return type is unreachable. This misleads type checkers and readers into thinking `None` is a meaningful output, and the downstream walrus-operator filter `if (record := _record(obj))` reads as though it guards against `None` when it only ever filters empty strings (which also never occur in practice).

```suggestion
def _record(obj: object) -> str:
```

Reviews (1): Last reviewed commit: "ci: restore release checkout depth" | Re-trigger Greptile

Comment thread .github/scripts/check_public_api.py
@marandaneto

Copy link
Copy Markdown
Member Author

Addressed Greptile's feedback in 03bab2e: removed the unused --check CLI flag, updated the Makefile to use the implicit check mode, and simplified _record to return str with a direct sorted generator.

@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "ci: simplify public API snapshot check C..." | Re-trigger Greptile

@marandaneto marandaneto merged commit f926d61 into main Jun 15, 2026
32 checks passed
@marandaneto marandaneto deleted the ci/add-public-api-snapshot-check branch June 15, 2026 18:17
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.

2 participants